CUDA Agent: Large-Scale Agentic RL for High-Performance CUDA Kernel Generation
arXiv:2602.24286v1 · This workspace stays on this version. Check arXiv for newer versions
Text from the PDF. The web (HTML) version of this paper couldn’t be retrieved, so this is the PDF’s text without its layout: formulas, tables and figures are not shown, and nothing was compared or corrected.
Source details
The text was extracted from the original PDF as is; it was not compared with another source or corrected.
- The HTML version has no readable article (an embedded PDF or an unfinished conversion); the PDF text is shown instead.
Figures and tables are only in the original PDF. Open original PDF
CUDA AgentCUDA Agent: Large-Scale Agentic RL for High-Performance CUDA Kernel Generation
Weinan Dai1,2,3∗, Hanlin Wu1,2,3∗, Qiying Yu1,2,3, Huan-ang Gao1,2,3, Jiahao Li1, Chengquan Jiang1, Weiqiang Lou1, Yufan Song1, Hongli Yu1,2,3, Jiaze Chen1,3, Wei-Ying Ma2,3, Ya-Qin Zhang2,3, Jingjing Liu2,3, Mingxuan Wang1,3, Xin Liu1, Hao Zhou2,3†
1ByteDance Seed 2Institute for AI Industry Research (AIR), Tsinghua University 3SIA-Lab of Tsinghua AIR and ByteDance Seed
∗Equal contributions, †Corresponding Authors
Abstract
GPU kernel optimization is fundamental to modern deep learning but remains a highly special- ized task requiring deep hardware expertise. Despite strong performance in general program- ming, large language models (LLMs) remain uncompetitive with compiler-based systems such as torch.compile for CUDA kernel generation. Existing CUDA code generation approaches either rely on training-free refinement or fine-tune models within fixed multi-turn execution-feedback loops, while both paradigms fail to fundamentally improve the model’s intrinsic CUDA optimization ability, resulting in limited performance gains. We present CUDA Agent, a large-scale agentic reinforcement learning system that develops CUDA kernel expertise through three components: a scalable data synthesis pipeline, a skill-augmented CUDA development environment with auto- mated verification and profiling to provide reliable reward signals, and RL algorithmic techniques enabling stable training. CUDA Agent achieves state-of-the-art results on KernelBench, delivering 100%, 100%, and 92% faster rate over torch.compile on KernelBench Level-1, Level-2, and Level-3 splits, outperforming the strongest proprietary models e.g. Claude Opus 4.5 and Gemini 3 Pro by about 40% on the hardest Level-3 setting.
Date: March 2, 2026 Correspondence: zhouhao@air.tsinghua.edu.cn Project Page: https://cuda-agent.github.io/
1 Introduction
GPU kernels are a foundational component of modern deep learning infrastructure [ 12, 17], with NVIDIA’s CUDA architecture currently dominating the AI hardware ecosystem. Despite its widespread adoption, the development and optimization of high-performance CUDA kernels remain highly challenging, which requires a deep understanding of GPU microarchitectural features [16], and sophisticated profiling toolkits [4].
Although Large Language Models (LLMs) have demonstrated human-comparable proficiency in general software development tasks [23], existing CUDA kernel generation approaches [4, 12] still remain uncompetitive even with automatic optimization tools such as torch.compile in CUDA kernel code generation [ 17], let
1
Correct Rate Faster Rate vs. Eager
Faster Rate vs. Compile
Speed-up vs. Eager (GM)
Speed-up vs. Compile (GM)
0
20
40
60
80
100
Percentage Metrics (%)
54.0
24.0
10.0
34.0
12.0 6.0
80.0 76.0
52.0
88.0 82.0
50.0
94.0 94.0 90.0
GLM 4.6 Kimi K2 Gemini 3 Pro Claude Opus 4.5 Ours
0.0
0.5
1.0
1.5
2.0
Speed-up Metrics (×)
0.83
0.62
0.40 0.29
1.58
1.17
1.52
1.10
1.80
1.52
alone human experts.
One line of prior work on CUDA code generation focuses on designing training-free workflows [ 5, 6, 8 ], which rely on hand-designed refinement heuristics guided by execution feedback. However, these methods do not remedy the fundamental lack of CUDA-coding abilities in the base models, causing performance gains to be significantly capped by the model’s intrinsic capabilities. Another line of research [1, 4, 11, 14] attempts to fine tune base models within a fixed multi-turn refinement loop driven by code execution feedback. However, such methods waste context length by including all previous solutions and constrain the agent’s autonomy to learn debugging, search, and profiling strategies.
To overcome these limitations, we introduce CUDA Agent, a large-scale CUDA agent training system that systematically enhances the base model’s CUDA kernel coding capabilities by making contributions in three complementary dimensions: data, agent environment, and reinforcement learning (RL) algorithmic techniques.
To support large-scale reinforcement learning, we design a scalable data synthesis pipeline that generates training problems spanning a wide range of difficulty levels, enabling effective curriculum-based RL training. For the agent environment, we adopt the agent skills paradigm [ 2], equipping the model with a structured specification that formalizes the standard workflow for writing, validating and optimizing CUDA kernels, together with automated test and profiling scripts for execution-based feedback. Notably, we implement rigorous correctness and performance tests, along with system-level permission isolation, to prevent reward hacking and ensure accurate reward signals. As for RL algorithmic improvement, we analyze the sources of instability in RL optimization and propose a multi-stage warm-up strategy for both the actor and critic models, enabling stable training of large language models for 150 steps.
Integrating these components, CUDA Agent successfully scales to a context length of 128k tokens and supports up to 200 interaction turns, achieving state-of-the-art performance. Specifically, CUDA Agent achieves speedups of 100%, 100%, and 92% over torch.compile on the Level-1, Level-2, and Level-3 splits of KernelBench [ 17], outperforming advanced proprietary models such as Claude Opus 4.5 and Gemini 3 Pro1 by approximately 40% in the Level-3 split.
Our contributions can be summarized as follows:
• We introduce CUDA Agent, a large-scale agentic reinforcement learning system for automatic CUDA kernel generation, which systematically improves the base model’s CUDA coding and optimization abilities through scalable data synthesis, a skill-augmented CUDA kernel development environment, and RL techniques designed for stable long-context, multi-turn agentic training.
• CUDA Agent achieves state-of-the-art performance on KernelBench, outperforming torch.compile in the majority of test cases and delivering the largest speedups across multiple difficulty levels. These results establish LLM-based kernel generation as a competitive—and often superior—alternative to traditional compiler-driven kernel optimization.
1We found that models in the ChatGPT-5 series (5, 5.1, and 5.2) were not amenable to evaluation on this task, as they consistently declined to respond to CUDA-related prompts.
2
Seed Problem Crawling
Mine operators from torch/transformers lib
Combinatorial Problem Synthesis
LLMs generate fused tasks
Rubric based Problem Filtering
matmul relu conv2d
Non-random
conv2d
relu
matmul
fused op
conv2d
relu
matmul
Executable
Reasonable Workload
Non-trivial
Figure 1 Overview of the three-stage data collection pipeline. We first crawl seed operators from PyTorch and Transformer libraries to build a repository of fundamental computational primitives. Next, an LLM performs combinatorial synthesis to generate fused, multi-operator tasks. Finally, a rubric-based filtering stage retains only executable, deterministic, non-trivial problems with reasonable workloads to ensure data quality and reliable evaluation.
2 Related Works
2.1 Training Free Systems for Kernel Generation
Several recent works explore designing with explicit search to address the irregular landscape of kernel optimization. STARK [ 5] employs a strategic team of agents with planning, coding, and debugging roles that explore a tree-structured search space on KernelBench, iteratively refining kernels using compilation, correctness checks, and timing feedback. ReGraphT [ 6] presents a training-free, retrieval-augmented framework that distills CUDA optimization trajectories from large language models into a reasoning graph, which is then searched via Monte Carlo Graph Search to guide smaller models toward competitive performance. EvoEngineer [ 8] formulates CUDA kernel optimization as a constrained code evolution problem and applies an LLM-driven evolutionary loop that iteratively edits and validates kernels to improve performance while preserving correctness. CudaForge [26] introduces a training-free two-agent system where a Judge uses Nsight Compute profiling and hardware specifications to diagnose bottlenecks and provide targeted optimization feedback to a Coder, achieving consistent speedups across GPUs.
Although these works demonstrate considerable performance gains, they heavily rely on the base model’s CUDA coding capability. Furthermore, those test-time scaling approaches are also orthogonal and could be applied to our model.
2.2 Fine-tuning LLM for Kernel Generation
In parallel, another line of research seeks to improve CUDA kernel generation by training base models via supervised fine-tuning or reinforcement learning. Kevin [ 4] introduces a multi-turn reinforcement learning framework for CUDA kernels that models the iterative developer workflow, achieving notable gains in both correctness and performance over its QwQ-32B base model on KernelBench. CUDA-L1 [14] proposes a contrastive reinforcement learning framework that evaluates multiple CUDA kernel variants using execution- based rewards. However, their training and evaluation are conducted on the same KernelBench dataset without a proper train–test split. This data leakage renders the reported results not directly comparable to ours. ConCuR [ 11 ] synthesize and curate CUDA kernels with reasoning traces, and uses the resulting dataset to fine-tune QwQ-32B into KernelCoder, achieving performance improvment among open-source models.
Overall, these approaches remain fundamentally constrained by the scarcity of high-quality training data, limited training scale, and hand-designed optimization loops, which collectively cap their performance improvements. A more detailed analysis and comparison of these related works can be found in Appendix C.
3 Method
Our large-scale agentic reinforcement learning system CUDA Agent is built upon three key components: 1) a scalable data collection pipeline; 2) a skill-integrated and non-hackable training environment with robust
3
📝SKILL.md
📁kernels/
📄model.py 📄binding.cpp
📁u3ls/
📄verify.py 📄profile.py
🛠Workdir
You are a PyTorch and CUDA expert. Accelerate the given PyTorch Model by crea=ng a…
🤖 CUDA Agent
Generated
📁 kernels/
📄 kernel.cu
📄kernel_binding.cpp
📄model_new.py
Performance
✅ Correctness
🕝 Generated Time: 1.26ms
🕝 Torch Eager Time: 2.30ms
🕝 Compile Time: 1.80ms
GPU Pool
Figure 2 Overview of the agent loop.
reward scheduling designing; and 3) proposed reinforcement learning algorithmic techniques for stable training. Each component plays a crucial role in achieving the final strong empirical results.
3.1 Scalable Training Data Synthesis Pipeline
The scarcity of high-performance CUDA kernels creates a significant bottleneck for supervised fine-tuning, as manual implementation of expert-level reference code is prohibitively expensive. To overcome this, we employ reinforcement learning (RL) for training CUDA Agent. RL necessitates a vast and diverse corpus of reference operators implemented in PyTorch to serve as training tasks. Since existing public datasets lack the requisite diversity and scale, we develop a scalable data collection pipeline that systematically expands the task space through seed problem crawling, LLM-based combinatorial synthesis, and rigorous execution-based filtering (Figure 1).
The key observation for our combination based data synthesis is composing multiple operators into fused tasks yields valuable new CUDA-agent training problem. This is because the combined problem is often not equivalent to trivially optimizing each operator in isolation and then chaining them. Fusion reshapes the optimization landscape by avoiding intermediate global-memory materialization, coupling stages through shared register/SMEM/occupancy constraints, and requiring a unified parallel mapping and data layout that may favor downstream consumption.
Seed Problem Crawling First, we mine reference operator implemented in PyTorch from the torch and transformers libraries, establishing a comprehensive seed problem set. Each operator is represented as a Python class with initialization and forward methods. These operator classes are widely used and well- maintained. We therefore exclude individually maintained repositories that lack sufficient code quality.
Combinatorial Problem Construction Next, to expand the dataset and introduce higher complexity, we utilize LLMs to synthesize aggregated operators. Specifically, the LLM is prompted to sample no more than 5 operator classes from the torch library. The sampled operator classes are composed sequentially by stacking them into a single computational layer. We do not sample operator classes from the transformers library, as these operators are typically higher-level modules that already encapsulate multiple primitive operations.
Problems Filtering Finally, we implement a rigorous data selection process to filter out problems that are either too easy or too difficult, based on execution feedback. We validate each operator against four criteria: (1) The operator must execute successfully in both Eager and Compile modes. (2) To ensure reproducibility, we exclude operators with inherent stochasticity. (3) For anti-hacking, we verify that outputs for different inputs are neither constant values nor numerically indistinguishable. (4) To filter out trivial or excessively heavy tasks, we restrict the execution time in eager mode to the range of 1 ms to 100 ms. Furthermore, we exclude operators that exhibit high similarity to KernelBench test cases; the similarity distribution is provided in section A.
In total, the filtered synthesized training dataset contains 6,000 samples, forming CUDA-Agent-Ops-6K2, a curated operator-level dataset for training CUDA-capable agents. Additional details on data format, contamination analysis, and dataset composition are provided in section A.
2https://huggingface.co/datasets/BytedTsinghua-SIA/CUDA-Agent-Ops-6K
4
3.2 Skill-Integrated Agent Loop
Agent Loop As CUDA kernel coding naturally arises as a subtask of coding agents, we design our agent loop to align with the widely adopted OpenHands framework [ 22] to ensure the generalizability. The LLM is provided with a standard suite of shell utilities—BashTool, GlobTool, MultiEditTool, and TodoWriteTool—to fully support CUDA coding development (see section B for the full list). On top of this, our agent loop (visualized in figure 2) follows the ReAct-style paradigm [24], interleaving reasoning, action execution, and observation to enable iterative coding, debugging, and performance optimization.
CUDA Coding Skill Inspired by the idea of Agent Skills [2], we deliberately put the CUDA coding specific instructions and tools (e.g. the profiling tool to compare the performance of generated kernel against torch.compile) as Agent Skills format. We also design a CUDA kernel coding specific instructions SKILL.md formulating the standard process to optimize the CUDA kernel (original text can be found in section B):
1. Analyze the performance of the native PyTorch implementation using the provided profile.py script. This step identifies performance bottlenecks and optimization opportunities, such as excessive kernel launches and suboptimal memory access patterns.
2. Implement custom CUDA operators by rewriting the model in model_new.py and developing the corresponding CUDA kernel source files and binding code, targeting the performance-critical operators identified in the analysis stage.
3. Compile and evaluate the optimized model in the provided GPU sandbox environment, and iteratively refine the CUDA kernel implementations until both numerical correctness and performance requirements are met.
4. Repeat the optimization process starting from Step 2 until the final implementation achieves at least a 5% speedup over the torch.compile baseline while passing all numerical correctness checks.
Base Model
Single-Turn Model
PPO
Actor Model
Critic Model
Sample Agent
Trajectories
RFT
Value
Pretraining
CUDA Agent
PPO
Single-Turn Warm-up Agent Warm-up Agentic RL
Figure 3 Overview of training pipeline. Following a single-turn RL warm-up stage, the sampled trajectories are used to initialize actor model and critic model before agentic RL stage. Robust Reward Scheduling Existing RL approaches for CUDA generation [ 1, 4, 14] use speedup over baselines as the reward signal. However, we observe that this approach suffers from outliers and bias toward easy kernels. This is because operators vary substantially in optimization difficulty, making raw speedup an unreliable proxy for code quality. To address this, we propose a normalized, robust reward scheme to remedy this and jointly optimize correctness and execution latency.
We assign a reward score r ∈ {−1, 1, 2, 3} based on correctness and performance:
r =
−1 if correctness check fails 3 if b(t, teager) ∧ b(t, tcompile) 2 if b(t, teager) 1 otherwise
(1)
where t is the generated kernel’s runtime, tnative and tcompile are the runtimes of PyTorch’s eager implementation and torch.compile version respectively, and b(t, t0) = I [(t0 − t)/t0 > 5%] indicates a significant speedup over baseline t0. We validate this design in section 4.3.2 that it significantly outperforms the commonly used speedup reward.
5
Efforts to Avoid Reward Hacking We note that previous work Lange et al. [12] suffer from the hacking issue [ 9]. Specifically, our system enforces the following constraints to avoid reward hacking: 1) the provided Python scripts for correctness verification and performance profiling are protected via file permission controls, preventing the agent from modifying or interfering with the evaluation logic; 2) to avoid trivial fallbacks, we enforce execution-time constraints using context managers that explicitly forbid invoking fallback imple- mentations from torch.nn.functional, ensuring that performance gains originate solely from the generated CUDA kernels; 3) for each problem, we validate kernel outputs against five randomly sampled inputs, strictly following the KernelBench evaluation protocol to ensure functional correctness; 4) the profiling pipeline is carefully engineered with proper device synchronization, warm-up iterations, and repeated measurements with averaging, substantially reducing measurement noise and metric fluctuation; and 5) the agent is not provided with any web search or external information retrieval tools, ensuring that all solutions are derived purely from local execution environment.
3.3 Algorithmic Improvements for Stable RL Training
We observe that our initial RL trial could only train stably for 17 steps before the model’s performance collapsed. We identified the root cause of this instability and propose warming up both the actor and critic models to adapt to the model’s distribution. With this modification, our RL trial can stably train for 200 steps with consistent reward growth.
The Root Cause of Training Instability stems from a severe domain distribution mismatch, where the base model’s learned prior deviates significantly from the data distribution required for CUDA kernel coding. This is because the CUDA coding data accounts for less than 0.01% of pretraining data [ 10, 13 ]. This distribution gap results in numerous sampled low-probability and CUDA kernel code tokens. Furthermore, when training and inference engines use different numerical precisions (e.g., BF16 vs FP16), those low-probability tokens result in large importance sampling ratio variance because small numerical errors in computing token probablities πθ (yt) near the precision floor (e.g., πθ (at | st) ≈ 10−9) cause the importance ratio ρt(θ) = πθ (at|st)π
θold (at|st)
to
fluctuate wildly or explode (similar to the discussion in Liu et al. [15]).
To achieve stable reinforcement learning, we propose a simple yet effective warm-up strategy: initializing both the actor and critic models using agent trajectories generated by the base model after single-turn RL, as illustrated in figure 3.
Single-Turn Warm-up We first perform single-turn RL on base model to enhance its capability in CUDA kernel generation. We use PPO for optimization, where the base model serves as the policy and value network.
Actor Initialization We then adopt a Rejection Fine-Tuning (RFT) stage on agent trajectories to initialize the actor model πθ . The resulting model from single-turn RL is used to collect CUDA agent trajectories by running the agent in the agent loop from section 3.2. Next, we apply RFT on the collected CUDA agent trajectories. Rejection sampling is performed to retain only high-quality rollouts according to the following rubrics: (1) Outcome filtering: we only keep trajectories that achieve a positive reward (R > 0). (2) Pattern filtering: we discard trajectories that exhibit inefficient or invalid behaviors, such as redundant multi-turn loops or hallucinations that violate the predefined tool-call schema.
The filtered trajectories are then used to optimize the actor via standard supervised fine-tuning with the following objective:
LRFT(θ) = −Eτ ∼D′
"
T
X
t=1
log πθ (at | st, a<t)
#
, (2)
where τ = (s0, s1, . . . , sT −1) denotes a filtered CUDA agent trajectory, πθ is the policy parameterized by θ, and D′ represents the dataset after rejection sampling.
Critic Initialization We perform Value Pretraining to initialize the critic, specifically, we utilize the sampled trajectory data comprising state sequences and their corresponding outcome rewards to pretrain the critic network. Let τ = (s0, s1, . . . , sT −1) denote a trajectory where st represents the state at token position t, and let r denote the outcome reward assigned at the final token (i.e., rt = 0 for t < T − 1 and rT −1 = r). We
6
Table 1 Main Results on KernelBench. We report Pass Rate, Faster Rate (percentage of kernels faster than baseline), and Geometric Mean Speed-up. Metrics are reported relative to both PyTorch Eager and PyTorch Compile baselines. Overall metrics are weighted by the number of problems in each level (Level 1: 100, Level 2: 100, Level 3: 50). Bold indicates the best performance.
Faster Rate (↑) Speed-up (Geomean, ×)
Subset Model Pass Rate vs. Eager vs. Compile vs. Eager vs. Compile
Overall†
Seed1.6 (base model) 74.0% 43.6% 27.2% 0.95× 0.69× GLM 4.6 75.6% 44.8% 19.2% 0.78× 0.57× Kimi K2 66.8% 40.8% 22.8% 0.93× 0.66× Gemini 3 Pro 91.2% 87.6% 69.6% 1.92× 1.42× Claude Opus 4.5 95.2% 90.4% 66.4% 1.99× 1.46× CUDA Agent (ours) 98.8% 98.4% 96.8% 2.60× 2.11×
Level 1
Seed1.6 (base model) 90.0% 63.0% 51.0% 1.65× 1.25× GLM 4.6 86.0% 57.0% 32.0% 0.99× 0.73× Kimi K2 85.0% 56.0% 39.0% 1.43× 1.00× Gemini 3 Pro 95.0% 90.0% 72.0% 1.99× 1.51× Claude Opus 4.5 96.0% 88.0% 72.0% 2.03× 1.54× CUDA Agent (ours) 100.0% 99.0% 97.0% 2.48× 1.87×
Level 2
Seed1.6 (base model) 74.0% 40.0% 16.0% 0.68× 0.50× GLM 4.6 76.0% 43.0% 11.0% 0.60× 0.42× Kimi K2 65.0% 40.0% 15.0% 0.93× 0.65× Gemini 3 Pro 93.0% 91.0% 76.0% 2.03× 1.46× Claude Opus 4.5 98.0% 97.0% 69.0% 2.24× 1.60× CUDA Agent (ours) 100.0% 100.0% 100.0% 3.27× 2.80×
Level 3
Seed1.6 (base model) 42.0% 12.0% 2.0% 0.60× 0.40× GLM 4.6 54.0% 24.0% 10.0% 0.83× 0.62× Kimi K2 34.0% 12.0% 6.0% 0.40× 0.29× Gemini 3 Pro 80.0% 76.0% 52.0% 1.58× 1.17× Claude Opus 4.5 88.0% 82.0% 50.0% 1.52× 1.10× CUDA Agent (ours) 94.0% 94.0% 90.0% 1.80× 1.52×
compute target values using Generalized Advantage Estimation [19]:
V targt = Vϕ(st) + ˆAt, where ˆAt =
T −1−tX
l=0
(γλ)lδt+l, (3)
and δt = rt + γVϕ(st+1) − Vϕ(st) is the temporal difference error with Vϕ(sT ) = 0. We set γ = 1 and λ = 0.95 in our experiments. We optimize the critic parameters ϕ by minimizing the mean squared error:
LVP(ϕ) =
1 2
Eτ ∼D
" 1 T
T −1X
t=0