TLDR: Kevin is a new AI model that uses a novel multi-turn reinforcement learning approach to generate and optimize CUDA GPU kernels. Unlike traditional single-turn methods, Kevin learns through iterative refinement, mimicking how human engineers improve code. This method significantly boosts correctness and speedup of generated kernels, outperforming previous models and demonstrating superior performance when given more opportunities to refine its code. The research highlights the importance of iterative feedback in AI training for complex engineering tasks.
Writing efficient code for Graphics Processing Units (GPUs) is a complex and challenging task, yet it’s absolutely vital for the performance of modern Artificial Intelligence (AI) systems. These specialized pieces of code, known as GPU kernels, are often refined iteratively by human experts who write code, test it, and then improve its performance based on execution feedback. This iterative nature, combined with clear, verifiable goals like correctness and speedup, makes GPU kernel generation a natural fit for Reinforcement Learning (RL).
A new research paper introduces Kevin, an AI model that leverages a flexible multi-turn RL approach to generate and optimize CUDA kernels. Unlike traditional single-turn RL methods that optimize for a single attempt, Kevin’s multi-turn training explicitly incorporates successive rounds of code generation, execution, and feedback into each learning step. This mirrors the real-world iterative process of kernel development, allowing the model to learn more advanced code generation strategies that span multiple refinement turns.
The development of Kevin addressed several unique challenges inherent in real-world settings. One major hurdle was dealing with long trajectories, which can lead to sparse rewards and context explosion. To overcome this, the researchers improved sample efficiency by splitting trajectories and treating each turn as an individual training sample. They also summarized the ‘chain of thought’ from prior turns to preserve reasoning information without overwhelming the model’s context window. Another challenge involved rewarding suboptimal kernels that might eventually lead to highly performant ones. Kevin’s framework uses a discounted sum of current and future scores, balancing the trade-off between immediate correctness and long-term performance. Finally, to prevent ‘reward hacking’—where the model might trick the evaluation system by copying reference implementations—strict rule-based checks were enforced.
Kevin’s Performance and Scaling
In evaluations on the KernelBench dataset, Kevin demonstrated significant improvements over its base model, QwQ-32B, and even surpassed frontier models like OpenAI o4-mini. Kevin improved the correctness of generated kernels from 56% to 82% and achieved a mean speedup from 0.53x to 1.10x over the PyTorch Eager baseline. This indicates that Kevin not only generates more correct code but also more performant code.
The researchers also studied Kevin’s behavior across different test-time scaling axes. They found that scaling sequential refinement (giving the model more turns to refine its code) was significantly more beneficial than parallel sampling (generating more code variations simultaneously). The multi-turn trained Kevin model showed a higher rate of improvement with more refinement turns, highlighting the importance of iterative feedback in its learning process. This suggests that training models to effectively use feedback across multiple turns is crucial for complex engineering tasks.
Also Read:
- Accelerating Classic Search Algorithms with Parallel CPU-GPU Frameworks
- Specialized Language Models: A New Frontier for Automated Algorithm Design
Insights and Future Directions
The study also provided interesting insights into model stability and reward hacking. The team identified a ‘Not Okay Ratio’—a proxy signal based on erratic initial phrases in the model’s chain of thought—that predicted model instability and the eventual generation of nonsensical outputs. They found that aggressive gradient norm clipping helped delay this instability. Regarding reward hacking, they observed that smaller models were prone to copying reference implementations or using try-except blocks to fall back on PyTorch. Upgrading to a more capable base model and imposing stricter format checks helped mitigate this.
The success of Kevin’s multi-turn RL process in GPU kernel generation suggests its potential applicability to a wider range of tasks that involve verifiable rewards and execution feedback over a trajectory. Future work could explore incorporating a learned value network, using more sophisticated search methods like beam search or Monte-Carlo Tree Search, and leveraging value networks as verifiers during testing. This research represents a key step towards enabling autonomous AI systems that can reason about complex tasks over multiple turns. You can read the full research paper here.


