AI Tools Developer Tools

CUDA Agent RL: ByteDance and Tsinghua AIR Teach LLMs to Beat the Compiler

CUDA Agent RL trains an LLM to write GPU kernels that outrun torch.compile, hitting a 96.8% faster rate on KernelBench.

Abstract visualization of GPU kernel optimization representing CUDA Agent RL system

Large language models can already write CUDA code that compiles and runs correctly. The problem is speed: correct kernels are often slower than what a standard compiler produces on its own. ByteDance Seed and Tsinghua AIR describe this gap in a new paper introducing CUDA Agent RL, an agentic reinforcement learning system built specifically to close it. On KernelBench, the base model Seed1.6 passes 74.0% of tasks but only beats torch.compile on 27.2% of them, running at a 0.69x geometric-mean speedup — meaning its kernels are, on average, slower than the compiler’s own output.

CUDA Agent addresses that shortfall by placing the model inside an actual CUDA development environment rather than asking it to generate code in isolation. The system pairs the model with profiling tools, correctness checks, and a permission-locked sandbox, then trains it with PPO across 150 steps at a 131,072-token context window. On the hardest Level-3 split, ByteDance Seed and Tsinghua AIR report CUDA Agent scoring roughly 40 points ahead of Claude Opus 4.5 and Gemini 3 Pro on faster-rate versus compile.

What Is and Isn’t Released

The trained agent itself is not open for deployment. It sits on top of Seed1.6, a proprietary mixture-of-experts model with 23B active and 230B total parameters, and the paper does not ship model weights. What ByteDance Seed and Tsinghua AIR do publish is the CUDA-Agent-Ops-6K dataset, the SKILL.md specification that defines the agent’s CUDA workflow, and the reward and warm-up recipes used during training. Mid-size engineering teams without frontier-lab infrastructure can still adopt these components on top of an open base model, even without access to Seed1.6 or the full training setup.

The compute footprint behind the profiling sandbox is substantial: the researchers describe using 128 NVIDIA H20 GPUs, a scale that puts full replication within reach mainly for frontier labs, GPU cloud providers, and large infrastructure teams rather than smaller shops.

How the Training Data Was Built

The research team behind CUDA Agent crawled reference operators from the torch and transformers libraries, then used an LLM to sample up to five torch operator classes and stack them into a single fused layer. A filtering step kept only operators that execute correctly in both eager and compile modes, behave deterministically, produce non-constant outputs, and run between 1ms and 100ms in eager mode. Samples with AST similarity above 0.9 to any existing KernelBench task were discarded to avoid contamination. The resulting CUDA-Agent-Ops-6K dataset contains 6,000 samples, with 83.77% built from two-operator compositions.

Agent Loop and Reward Design

The agent’s tool loop follows a pattern similar to OpenHands, using Bash, Read/Write, Edit/MultiEdit, Glob, Grep, NotebookEdit, BashOutput, and KillBash under a ReAct-style reasoning pattern. CUDA-specific instructions are delivered through the Agent Skills format, with a SKILL.md file directing the model to profile the PyTorch model, rewrite it with custom kernels in model_new.py, compile inside a GPU sandbox, and iterate until the kernel beats torch.compile by at least 5% within numerical tolerances of atol=1e-2 and rtol=1e-2.

Reward hacking is a known risk in agentic RL for code generation, and the paper describes five countermeasures: permission-locked verification and profiling scripts, context managers that block torch.nn.functional fallbacks, correctness checks against five random inputs, profiling that includes device synchronization and warm-up runs, and no web search access for the agent. Rather than rewarding raw speedup ratios directly, the system uses a discrete reward scheme: -1 for correctness failure, 3 for clearing both eager and torch.compile by more than 5%, 2 for clearing eager mode only, and 1 otherwise.

Where the Gains Concentrate

  • Overall: 98.8% pass rate, 98.4% faster than eager, 96.8% faster than torch.compile, at 2.60x and 2.11x geomean respectively.
  • Level 2 (operator sequences): the strongest split, with 100% pass rate, 100% faster rate, and 2.80x geomean over torch.compile.
  • Level 3 (hardest tasks): 94.0% pass rate, 90.0% faster rate, and 1.52x geomean — still roughly 40 points ahead of Claude Opus 4.5 (50.0%) and Gemini 3 Pro (52.0%) on faster rate.

One detail worth flagging: the paper’s abstract and introduction cite 100% / 100% / 92% faster rates for Levels 1 through 3, while the main results table reports 97.0% / 100.0% / 90.0%. The table is presented as the authoritative source for these figures.

What the Ablations Show

The paper’s ablation studies point to the agent loop and reward design as the core drivers of performance, not just scale. Removing the agent loop drops the faster-rate versus torch.compile from 96.8% down to 14.1%. Swapping the discrete milestone reward for a raw speedup ratio yields only 60.4%. Removing reinforcement fine-tuning entirely produces 49.8% along with reward collapse, and skipping value pretraining produces 50.9% with runaway trajectories. Case studies illustrate what the trained policy actually learns to do: rewriting a diagonal matmul as row-wise scaling yielded a 73.31x speedup over torch.compile, reordering and fusing a matmul-divide-sum-scale chain produced 24.04x, and folding BatchNorm into convolution with cudnnConvolutionBiasActivationForward on a ResNet BasicBlock delivered 3.59x.

Where This Fits in Practice

ByteDance Seed and Tsinghua AIR point to AI infrastructure, inference serving, GPU cloud operations, autonomous driving, quantitative trading, medical imaging, and recommendation systems as domains where fused kernels sit on latency-critical paths. The stated use cases include fusing operator sequences that torch.compile handles poorly, cutting inference cost per token, and re-tuning kernels as teams move across GPU generations. Because the trained agent itself is not public, teams evaluating this work in the near term are limited to reproducing the training recipe on an open base model, using the released dataset and skill specification, rather than deploying the reported results directly.

Sources