NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

MusaCoder: Native GPU Kernel Generation with Full-Stack Training on Moore Threads GPU

Kun Cheng, Songshuo Lu, Sicong Liao, Tankun Li, Yafei Zhang, Dong Yang, Qiheng Lv, Hua Wang, Zhi Chen, Yaohua TangarXiv 2026

TL;DR

MusaCoder is a full-stack training framework designed to automate the generation of high-performance, native GPU kernels (CUDA and MUSA) from high-level PyTorch code. By combining a progressive data synthesis pipeline with three novel Reinforcement Learning (RL) stabilization techniques—PrimeEcho, Buffered Dynamic Retry, and MirrorPop—it establishes a new state-of-the-art, with its 27B model outperforming frontier proprietary models like Claude 4.7 in both code correctness and execution speed.

What Problem Does This Paper Address?

Writing efficient GPU kernels is a "black art" that requires deep knowledge of hardware architecture, memory hierarchies, and complex indexing. While Large Language Models (LLMs) show promise in general coding, they struggle with the strict correctness and performance requirements of native GPU kernels.

Existing approaches using Reinforcement Learning (RL) face three major hurdles:

  1. Reward Sparsity: Synthesizing kernels from scratch has a high failure rate, often resulting in "all-failed" rollout groups that provide no learning signal.
  2. Reward Hacking: Models often "cheat" by calling high-level PyTorch APIs (like torch.matmul) instead of writing native kernels.
  3. Off-Policy Instability: The multi-turn nature of code repair leads to distributional drift, making training unstable.

Methods

MusaCoder employs a sophisticated three-stage pipeline to move from base LLMs to expert kernel engineers:

  • Progressive Data Synthesis: (See Figure 3) The authors move beyond simple code translation. They use a six-step structured reasoning template (covering global analysis, math derivation, shape calculus, indexing, boundary handling, and error pre-analysis) to teach the model how to think about a kernel before writing it.
  • Diversity-Preserving Rejection Fine-Tuning (RFT): Unlike standard RFT that only keeps the fastest implementation, MusaCoder preserves a heterogeneous set of correct implementations to prevent "entropy collapse" and maintain exploration diversity for the RL stage.
  • MooreEval: A distributed, execution-based sandbox that acts as the reward environment. It includes strict "anti-hacking" checks to ensure the model isn't using forbidden PyTorch fallbacks.
  • RL Stabilization Trio:
    • PrimeEcho: A reward formulation that anchors multi-turn feedback to the first-turn result, ensuring the model doesn't become over-reliant on multi-turn repair.
  • Buffered Dynamic Retry (BDR): A mechanism that takes "all-failed" groups and converts them into feedback-conditioned repair tasks, recovering learning signals from the hardest samples.
  • MirrorPop: A novel off-policy masking strategy. Traditional masking can suffer from "directional cancellation" (where one token is too likely and another too unlikely, but the average looks fine). MirrorPop uses absolute log-ratio deviations to accurately detect and mask high-risk off-policy samples.
Figure 2: Overview of the MusaCoder training pipeline. The pipeline first constructs a kernel-oriented corpus from diverse raw sources, including PyTorch-to-CUDA/MUSA generation data, GPU kernel knowledge QA, profiling anal- ysis, optimization rewrite, and kernel review/repair data. The data are further augmented through shape/stride hints, unit tests, metadata extraction, weak-operator upsampling, LLM-based synthesis, and MooreEval-based verification. After post-processing, the verified corpus is used for multi-task SFT and diversity-preserving RFT. Finally, MusaCoder is optimized with a two-stage RL procedure, consisting of single-turn warmup and multi-turn enhancement, together with three stabilization techniques: PrimeEcho, MirrorPop, and Buffered Dynamic Retry.

Datasets

  • KernelBench: The primary benchmark for evaluating GPU kernel generation.
  • MUSA KernelBench: A newly introduced variant ported specifically for Moore Threads' MUSA backend to test cross-platform transferability.
  • Synthetic Data: Generated using NNSmith to cover long-tail operator fusions and complex computation graphs.
  • Knowledge QA & Profiling Data: Custom datasets designed to teach the model the underlying rationale for performance bottlenecks and hardware constraints.

Key Insights and Ideas

  • Reasoning as a Foundation: The "plan-then-implement" paradigm is crucial. By forcing the model to explicitly derive shapes and indices (Stage 2 of the data pipeline), the authors significantly reduced off-by-one errors and memory access bugs.
  • The Danger of "Fastest-Only" RFT: The authors found that greedily selecting only the fastest kernels during RFT caused the model's generation entropy to plummet, which crippled subsequent RL. Preserving implementation diversity is a key "aha moment" for stable post-training.
  • Magnitude Matters in Off-Policy Masking: MirrorPop's use of absolute deviations is a subtle but powerful fix for RL stability. It prevents the training process from being derailed by sequences that look on-policy on average but contain wild local fluctuations.

Key Results

MusaCoder-27B-RL achieved dominant results on the KernelBench suite:

  • Correctness: It reached a 93.2% Pass@8 overall, significantly higher than Claude 4.7 (87.2%) and DeepSeek-V4-Pro (83.2%).
  • Complexity: On the most difficult "Level 3" tasks, it achieved a 72% Pass@8, a massive jump over Claude 4.7's 54%.
  • Performance: It delivered a 15.0% "Faster Rate" vs. PyTorch eager execution, outperforming all baselines (see Figure 1).
  • Cross-Backend Success: On the MUSA backend, the 27B model achieved a 92.4% Pass@8, proving that the framework is not CUDA-locked and can effectively support emerging hardware ecosystems.
Figure 1: KernelBench performance comparison.

Limitations and Future Work

While MusaCoder is highly effective, the authors note that the explicit tensor shape annotation strategy (which provides the model with strides and contiguity hints) has only been manually inspected on a subset of cases and lacks a formal, large-scale ablation study.

Future work likely involves extending this "full-stack" training approach to even more diverse hardware backends and further automating the discovery of novel, hardware-specific optimization patterns that human engineers might overlook.

Summary updated

BibTeX
@misc{cheng2026musacoder,
  author = {Kun Cheng and Songshuo Lu and Sicong Liao and Tankun Li and Yafei Zhang and Dong Yang and Qiheng Lv and Hua Wang and Zhi Chen and Yaohua Tang},
  title = {{MusaCoder: Native GPU Kernel Generation with Full-Stack Training on Moore Threads GPU}},
  year = {2026},
  eprint = {2606.04847},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.04847},
}
Figure