arXiv:2610.20980cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.20980

How to Train Your Little Dragon: Teaching a Small Language Model to Construct and Refine GPU Optimization Scripts

Annabelle Sujun Tang, Wei Tang, Songyao Jiang, Tianhui Li, Shengzhe Xu, Jiin Woo, Kaan Ozkara, Youngsuk Park, Zhen Jia, Hadi Esmaeilzadeh

ABSTRACT

Compiler transformations interact, making GPU kernel optimization a search for combinations that preserve the computation while improving performance. We investigate how to train a small language model to generate the optimization: a correct, performance-improving script that coordinates interacting transformations in one complete proposal. We introduce HOW TO TRAIN YOUR LITTLE DRAGON, a training method that teaches a small language model both to construct complete optimization scripts and to improve existing ones. Rather than learn only to rank search candidates or generate replacement kernel code, our LITTLE DRAGON learns to generate correct scripts that transform the under-optimized kernel and improve its performance. We devise a compact, lossless representation whose deterministic decoding reconstructs the exact compiler trace, preserving its transformation parameters and dependencies. We use a compiler framework TVM MetaSchedule to build training data on 54,116 distinct workloads, and construct 108,594 examples in two training sets: 60,236 teach the model to generate an optimized script from an unoptimized kernel, while 48,358 teach it to produce a better script given the kernel and a somewhat optimized script. Supervised fine-tuning teaches the model to construct and improve optimization scripts from these search-derived examples. We then add reinforcement learning with a shaped reward that combines correctness with measured performance, awarding a latency-based bonus only to numerically correct kernels. This enables the model learn not only from existing optimizations, but from the correctness and performance of its generated scripts. We apply this training method to a model with 8 billion parameters. After supervised fine-tuning and reinforcement learning, the model achieves per-attempt correctness of 91.27% for construction and 92.01% for refinement, while reinforcement learning produces faster kernels than supervised training on 88 of 102 construction tasks and 145 of 170 refinement prompts. With only 8 billion parameters, our LITTLE DRAGON achieves higher per-attempt correctness and better kernel performance than six frontier LLMs—GPT-6 Astra, Opus 5, Kimi-K3, and GLM-5.3 among them, each with hundreds of billions to trillions of parameters—for which task-specific training is unavailable or expensive. These results suggest that HOW TO TRAIN YOUR LITTLE DRAGON enables a small language model to learn from compiler search and direct correctness and performance feedback, internalizing an optimization policy that constructs and improves complete scripts in one shot.

1 INTRODUCTION

The cost of serving a model depends not only on the model itself, but on how efficiently its kernels use the GPU. Compiler optimization can reduce this cost by turning the same computation into a faster implementation, yet finding that implementation can itself require substantial compilation and measurement. The difficulty is that transformations interact: tiling, memory placement, and

∗^{*}Work done during an internship at Amazon Annapurna Labs.

thread mapping must work together to preserve correctness and improve performance. Search-based compilers discover effective combinations through trial and error, repeatedly generating and evaluating candidates (Zheng et al., 2020; Shao et al., 2022). We ask how to train a small language model to construct and improve complete optimization scripts in one shot, learning to coordinate interacting compiler transformations into correct, faster kernels.

Existing approaches use learning at different points in optimization. Learned cost models rank candidates for evolutionary search, while frozen language models guide exploration without updating their parameters (Chen et al., 2018b; Tang et al., 2025; 2026). Other approaches train models to generate scheduling decisions step by step, conditioning each choice on earlier decisions while its benefit may depend on transformations yet to be selected (Zhai et al., 2024). We set out to explore a research question: can a small language model learn an optimization policy across different tasks that enables it to construct and improve complete optimization scripts in one shot, and how can we train it to do so?

Our hypothesis is that learning to improve an optimization requires examples not only of effective solutions, but of how less effective solutions can become better. We therefore introduce HOW TO TRAIN YOUR LITTLE DRAGON, a training method built around two complementary sets of examples. In the first, we give the model an unoptimized kernel and teach it to generate an optimized script. In the second, we give it the unoptimized kernel together with a somewhat optimized script and teach it to generate a more optimized script. Both tasks produce a complete script, allowing refinement to revise earlier and later transformation choices together rather than merely extend the existing sequence. Through examples from different optimization tasks, we seek to teach the model which combinations work well together and how to improve them, internalizing an optimization policy that it can apply to other kernels.

The supervised examples teach correct, performance-improving optimizations. We then use reinforcement learning to strengthen the policy through feedback on the correctness and measured performance of its own complete proposals. A staged reward recognizes progress toward executable, correct kernels and awards latency bonuses only to numerically correct candidates, with refinement bonuses additionally requiring improvement over the supplied script.

Both stages require the model to express its complete optimization precisely enough for the compiler to apply it. A script must specify not only which transformations to use, but how they refer to the loops and memory structures created by earlier transformations. Raw compiler traces preserve this information through detailed parameters and temporary identifiers, while prose descriptions can explain an optimization without specifying everything needed to reproduce it. We therefore devise a compact, lossless representation that groups related transformations into typed edits while retaining their order, parameters, and dependencies. Deterministic decoding reconstructs the exact canonical compiler trace, and round-trip checks verify that representing a source script does not change it. The model is taught explicit compiler optimization decisions connected to their supporting program evidence. Optimization graphs link compiler-derived facts, optimization analysis, executable schedule edits, and expected effects, exposing both how an optimization is applied and why it is proposed. Search-derived traces fix the executable targets, while static checks ground the accompanying explanations in compiler artifacts. This provides a structured teaching interface for learning compiler optimization through SFT and execution feedback.

To supply examples in this representation, we use TVM MetaSchedule, a compiler framework that explores candidate optimizations through stochastic evolutionary search guided by performance cost models (Shao et al., 2022). From this search, we select the scripts that produce the best-performing validated kernels as training targets. We pair each target with the unoptimized kernel to teach construction, and additionally supply a somewhat optimized script to teach refinement. For refinement, we require the target's measured improvement to exceed timing variability, so the example reflects a genuine performance gain. Across 54,116 distinct workloads, we construct 108,594 training examples: 60,236 for construction and 48,358 for refinement. Thus, we turn the search process into a source of both correct optimization scripts and concrete examples of how to improve them.

We evaluate whether this training enables a small model to generate correct optimization scripts and improve the performance of the resulting kernels. We evaluate a model with 8 billion parameters on NVIDIA H100. After supervised fine-tuning and reinforcement learning, the model achieves per-attempt correctness (Correct@1) of 91.27% for construction and 92.01% for refinement. Comparing

Figure

Figure 1: HOW TO TRAIN YOUR LITTLE DRAGON: data generation and two-stage policy training. (A) Compiler search supplies verified schedules. Deterministic lifting preserves their executable edits in our Typed Schedule Edit Language (TSEL); Kimi-K3 writes explanations from compiler-derived facts. Static and round-trip checks admit construction and refinement labels. (B) Weighted token supervision trains Seed-Coder-8B-Instruct to produce complete optimization graphs; GAG_{A} denotes the optional prior graph for refinement. (C) Starting from SFT, GRPO updates the policy using numerical correctness and measured latency of sampled schedules.

each model’s fixed first output, reinforcement learning produces faster kernels than supervised training on 88 of 102 construction tasks and 145 of 170 refinement prompts for which both outputs are correct and timed. With only 8 billion parameters, HOW TO TRAIN YOUR LITTLE DRAGON achieves higher per-attempt correctness and better kernel performance than six frontier LLMs—GPT-6 Astra, Opus 5, Kimi-K3, and GLM-5.3 among them—for which task-specific training would be unavailable or expensive. These results provide an affirmative answer to our research question and a concrete way to achieve it: training on construction and refinement examples, followed by rewards for correctness and performance, enables a small model to internalize an optimization policy for generating complete scripts in one shot.

References (37)