AutoTriton: Automatic Triton Programming with Reinforcement Learning in LLMs

Shangzhan Li, Zefan Wang, Ye He, Yuxuan Li, Qi Shi, Jianling Li, Yonggang Hu, Wanxiang Che, Xu Han, Zhiyuan Liu, Maosong Sun · OpenReview

Abstract

Kernel development in deep learning requires optimizing computational units across hardware while balancing memory management, parallelism, and hardware-specific optimizations through extensive empirical tuning. Although domain-specific languages like Triton simplify GPU programming by abstracting low-level details, developers must still manually tune critical parameters such as tile sizes and memory access patterns through iterative experimentation, creating substantial barriers to optimal performance and wider adoption. In this work, we introduce AutoTriton, the first model dedicated to Triton programming powered by reinforcement learning (RL). AutoTriton performs supervised fine-tuning (SFT) to be equipped with essential Triton programming expertise using a high-quality data gathering pipeline, and conducts RL with Group Relative Policy Optimization (GRPO) algorithm, combining a rule-based reward and an execution-based reward to further improve Triton programming ability, sequentially. Experiments across five evaluation channels of TritonBench and KernelBench illustrate that our 8B model AutoTriton achieves performance comparable to mainstream large models, including Claude-4-Sonnet and DeepSeek-R1-0528. Further experimental analysis demonstrates the crucial role of each module within AutoTriton, including the SFT stage, the RL stage, and the reward design strategy. These findings underscore the promise of RL for automatically generating high-performance kernels, and since high-performance kernels are core components of AI systems, this breakthrough establishes an important foundation for building more efficient AI systems.

Introduction

Efficient deep learning execution relies heavily on high-performance kernels—low-level code that manages data movement and mathematical operations on GPUs. Historically, this required writing CUDA, a process known for its steep learning curve and error-prone nature. OpenAI’s Triton language emerged as a Python-like abstraction to simplify GPU programming. However, Triton does not eliminate the need for manual optimization; developers must still tune tiling sizes and memory access patterns to achieve peak performance.

While Large Language Models (LLMs) have shown proficiency in general coding, they often struggle with Triton due to its status as a niche Domain-Specific Language (DSL) with sparse training data. Furthermore, standard Supervised Fine-Tuning (SFT) often fails to capture the complex hardware-level reasoning necessary for true kernel optimization.

Methodology

AutoTriton utilizes a two-stage training process built upon the Seed-Coder-8B backbone.

Data Gathering and SFT

The first stage involves constructing a high-quality dataset of 14,102 <instruction, CoT, Triton code> triplets. This is achieved through a specialized pipeline that collects PyTorch kernels from sources like GitHub and HuggingFace, then converts them into Triton via two methods:

  1. Distillation: Leveraging powerful models like DeepSeek-R1 to generate Triton code alongside step-by-step Chain-of-Thought (CoT) explanations.
  2. Compilation-Refinement: Using torch.compile to generate raw Triton code, which is subsequently "cleaned" by an LLM to improve readability and educational value.

Reinforcement Learning with GRPO

The core of AutoTriton is the application of Reinforcement Learning (RL) using the Group Relative Policy Optimization (GRPO) algorithm. This allows the model to explore various kernel implementations beyond simple imitation.

The AutoTriton framework overview, illustrating the data gathering, supervised fine-tuning, and reinforcement learning stages.

To ensure the validity of generated code, a dual-reward system is employed:

  • Rule-based Reward: Validates the presence of the @triton.jit decorator and adherence to Triton syntax, preventing "reward hacking" where the model might use standard PyTorch.
  • Execution-based Reward: Checks if the code compiles and produces numerically identical results to the PyTorch reference.

Experimental Results

AutoTriton was evaluated on TRITONBENCH (real-world and PyTorch-aligned kernels) and KERNELBENCH (ranging from single kernels to full architectures like MobileNet).

Performance comparison on TRITONBENCH-G and TRITONBENCH-T benchmarks.

As shown in the results, AutoTriton-8B significantly outperforms much larger frontier models. On TRITONBENCH-T, it achieved an execution accuracy of 39.16%, compared to 30.12% for DeepSeek-R1-0528 and 15.06% for GPT-4o. In KERNELBENCH Level 2 tasks, it reached a compilation accuracy of 97.0%, the highest among all tested models.

Conclusion and Future Work

AutoTriton demonstrates that RL is a powerful tool for mastering domain-specific hardware programming, allowing a specialized 8B model to rival massive general-purpose models. While the current framework ensures correctness, future iterations will incorporate Performance-Guided Training, rewarding the model for generating kernels that are not only correct but also optimized for execution speed.

Summary updated

BibTeX
@misc{li2025autotriton,
  author = {Shangzhan Li and Zefan Wang and Ye He and Yuxuan Li and Qi Shi and Jianling Li and Yonggang Hu and Wanxiang Che and Xu Han and Zhiyuan Liu and Maosong Sun},
  title = {{AutoTriton: Automatic Triton Programming with Reinforcement Learning in LLMs}},
  year = {2025},
  eprint = {2507.05687},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.05687},
}
Figure