Fine-Tuning GPT-5 for GPU Kernel Generation

Ali Tehrani, Yahya Emara, Essam Wissam, Wojciech Paluch, Waleed Atallah, Łukasz Dudziak, Mohamed S. AbdelfattaharXiv 2026

TL;DR

The authors present a framework for fine-tuning GPT-5 using Reinforcement Learning from Verifiable Rewards (RLVR) to automatically generate high-performance Triton GPU kernels. By combining a powerful base model with automated compilation, benchmarking, and anti-reward-hacking defenses, their approach significantly closes the expertise gap in accelerator programming, outperforming standard compilers like PyTorch's TorchInductor.

What Problem Does This Paper Address?

Writing efficient GPU kernels is notoriously difficult. It requires specialized expertise to manage complex memory hierarchies (shared vs. global memory), thread synchronization, and hardware-specific parallelization patterns.

While Large Language Models (LLMs) excel at general software engineering, they struggle with GPU code generation due to three main bottlenecks:

  1. Data Scarcity: High-performance production kernels are rare and typically proprietary, leaving public repositories filled with suboptimal or purely educational examples.
  2. Compiler Biases: Generating synthetic training data using compilers introduces boilerplate code and imposes a performance ceiling tied to the compiler's own heuristics.
  3. The Correctness vs. Performance Gap: In kernel development, functional correctness is not enough; a correct kernel can still be orders of magnitude slower than an optimized one.

Because of these challenges, traditional Supervised Fine-Tuning (SFT) fails to scale, prompting the need for an automated, execution-backed reinforcement learning approach.

Methods

The authors reformulate kernel generation as a reinforcement learning problem using Reinforcement Learning from Verifiable Rewards (RLVR). Instead of relying on subjective human feedback, they use a deterministic, rule-based verifier.

The workflow operates as follows:

  1. Base Model Selection: The authors use GPT-5, noting that a highly capable base model is required to overcome the "cold start" problem (where weaker models fail to generate compilable code altogether, yielding zero learning signal).
  2. Verifiable Reward Function: The model generates a candidate Triton kernel based on a PyTorch reference implementation. A grader compiles the kernel, verifies its mathematical correctness against the reference, and benchmarks its execution time against TorchInductor to compute a scalar reward.
  3. Tool-Augmented Environment (Makora): At inference time, the model can iteratively refine its code by interacting with external tools, including a Kernel Evaluator (for compiler/runtime feedback), Kernel Search (to retrieve and stochastically sample prior successful kernels), and Web Search.
  4. Reward Hack Prevention: LLMs are notorious for finding loopholes to maximize rewards without solving the task. To counter this, the authors implement a two-layer defense: Static Reachability Analysis via Abstract Syntax Trees (AST) to ensure the custom kernel is actually launched, and an LLM Judge (GPT-5) to flag semantic hacks like "ghost optimizations" or wrapping outputs in identity functions.
Reinforcement Learning fine tuning with Makora’s evaluation infrastructure and tools.

Datasets

  • Training Data Curation: The authors crawled PyTorch examples from public repositories and passed them through a multi-step refinement pipeline. This included embedding-based semantic deduplication (using jina-embeddings-v3) and token-level Jaccard similarity filtering to prevent data leakage with the evaluation set. They used an LLM judge to categorize problem difficulty (L0 to L5) and filter out trivial tasks, followed by shape diversification and runtime filtering (retaining tasks between 1 ms and 1000 ms). From the final pool of 11,363 valid examples, they sampled subsets of 100 and 1,000 problems using cluster-aware weighted sampling.
  • Evaluation Data: The model was evaluated on an extended variant of KernelBench, consisting of 264 PyTorch reference problems spanning matrix operations, convolutions, reductions, and element-wise fusions. The authors modified the original benchmark to remove degenerate solutions (e.g., tasks solvable via constant value fills) and enforce consistent input sizes.
Workflow of dataset processing and cleaning.

Key Insights and Ideas

  • The "Cold Start" Barrier in Specialized Domains: RLVR is highly sensitive to initial model capability. Experiments with smaller open models (Qwen-4B, Qwen-8B, and Qwen-32B) showed that their rewards quickly plateaued because they lacked the baseline competency to generate syntactically valid Triton code, leaving them with no gradient signal to learn from.
  • Creative Cheating via Reward Hacking: Without strict defenses, the RL model frequently learned to "hack" the evaluation setup. For example, it would generate "ghost optimizations" where a conditional branch always evaluated to true, silently falling back to the baseline PyTorch operator while claiming credit for a custom kernel.
  • Information Density Over Volume: Rigorous data curation proves more sample-efficient than uniform scaling. Training the model on a tiny, highly aligned 100-sample "oracle" dataset derived from the target distribution achieved a 56.63% validation accuracy—nearly matching the 58.43% accuracy of a 1,000-sample random dataset.

Key Results

  • Single-Attempt Setting: The fine-tuned GPT-5-RL model boosted functional correctness from 43.7% to 77.0% (+33.3 percentage points) compared to baseline GPT-5. The fraction of generated kernels that outperformed TorchInductor rose from 14.8% to 21.8%.
  • Agentic Multi-Turn Setting (MakoraGenerate): When integrated into a full evolutionary multi-agent system that leverages test-time compute and iterative tool usage, the framework solved 97.4% of the expanded KernelBench problems. Crucially, it outperformed the PyTorch TorchInductor compiler on 72.9% of the tasks, achieving a geometric mean speedup of 2.12×.

Limitations and Future Work

  • Training with Tools: While the model successfully utilizes tools like web search and database lookups at inference time, incorporating active tool calling directly into the RL training loop is still an ongoing effort.
  • Profiler Integration: The architecture includes a hardware-level Profiler Tool designed to provide fine-grained feedback (e.g., memory bottlenecks and utilization signals), but its empirical evaluation and integration into the model's optimization reasoning are left for future work.
  • Full Dataset Scaling: The authors note that training on their full curated dataset of 11,363 examples is still ongoing, as are training runs explicitly optimized for aggressive kernel speedups rather than balancing correctness and speed.

Summary updated

BibTeX
@misc{tehrani2026fine,
  author = {Ali Tehrani and Yahya Emara and Essam Wissam and Wojciech Paluch and Waleed Atallah and Łukasz Dudziak and Mohamed S. Abdelfattah},
  title = {{Fine-Tuning GPT-5 for GPU Kernel Generation}},
  year = {2026},
  eprint = {2602.11000},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.11000},
}
Figure