TL;DR
MKEvolve is a new framework that generates high-performance GPU kernels by breaking complex machine learning modules into smaller, manageable sub-problems. By iteratively refining both the modular structure and the individual subkernels, it achieves higher correctness and faster execution speeds than monolithic generation methods while using up to 35% fewer LLM tokens.
What Problem Does This Paper Address?
Writing "kernels"—the low-level code that tells a GPU exactly how to move data and perform math—is a notorious bottleneck in machine learning. While high-level frameworks like PyTorch make it easy to design models, getting them to run at peak efficiency on hardware often requires custom kernels written in languages like Triton or CUDA.
Currently, using Large Language Models (LLMs) to generate this code faces two major hurdles:
- The Monolith Problem: Most tools try to generate one giant, "monolithic" kernel for a complex operation (like an entire Transformer block). These are incredibly difficult for LLMs to write correctly and even harder to debug.
- Optimization Inefficiency: If you want to optimize a small part of a large kernel, you often have to re-generate and re-test the entire thing, which is slow and wastes expensive LLM tokens.
Methods
The authors introduce MKEvolve (Modular Kernel Evolve), which shifts the strategy from "write one big thing" to "compose many small things." The framework operates through an iterative loop:
- Modular Decomposition: An
LLMDecomposeagent breaks a complex PyTorch module into smaller submodules. - Independent Evolution: Each submodule gets its own dedicated optimization loop. MKEvolve uses beam search to explore different versions of a subkernel, keeping the ones that are both correct and fast.
- Topology Evolution: The framework doesn't just stick with the first split. It can iteratively split subkernels that are too complex or fuse successful ones together to reduce memory overhead.
- Programmatic Verification: Unlike other methods that rely on LLMs to write their own tests (which can be unreliable), MKEvolve uses a strict programmatic pipeline. It checks for functional correctness, ensures input shapes match, and uses a "cheating detector" to make sure the LLM isn't just calling existing libraries instead of writing real kernel code.
- Subkernel Swapping: If the LLM fails to produce a kernel faster than the standard
torch.compilebaseline, MKEvolve can programmatically swap that specific part back to a standard implementation, ensuring the final product is never a regression.
Datasets
The researchers evaluated MKEvolve using KernelBench, a benchmark designed to test LLM-driven kernel generation:
- Level 2 (L2): 100 problems consisting of sequences of primitive operators (e.g., a Convolution followed by a ReLU and a Bias addition).
- Level 3 (L3): 50 problems involving full model architectures, such as AlexNet, MiniGPT, and Vision Transformers.
Key Insights and Ideas
- Modularity as a Search Strategy: By breaking the problem down, MKEvolve makes the "search space" more tractable. It is much easier for an LLM to find a clever optimization for a single activation function than for a 500-line monolithic block.
- Traceability is Debugging: In a monolithic kernel, a numerical error is just a "fail." In MKEvolve, you can pinpoint exactly which subkernel (e.g., the "Self-Attention" block) introduced the error.
- Zero-Shot Transferability: Because the kernels are modular, they are highly adaptable. The authors demonstrated that an optimized kernel for MobileNetV1 could be adapted to variants (like MaxPool or LPPool versions) with just a few additional LLM calls to replace the specific pooling subkernel.
- Local vs. Global Error: The paper provides a mathematical intuition that local subkernel verification is a more robust way to ensure global correctness, especially when dealing with lower-precision formats like BF16 where errors can "hide" or accumulate.
Key Results
MKEvolve was tested using both frontier models (Claude 4.5 Opus) and open-source models (GPT-OSS 120B).
- Better Performance: On the complex L3 tasks, MKEvolve (with the "Swap" feature) achieved a 94% correctness rate, significantly higher than the 76% achieved by the previous state-of-the-art, KernelFalcon.
- Significant Speedups: It consistently produced kernels that were faster than
torch.compile, often reaching speedups of 1.5x to 2x on specific sub-problems. - Token Efficiency: MKEvolve reduced LLM token usage by 15% to 35% compared to end-to-end beam search baselines. By focusing the "improvement effort" only on the subkernels that needed it, the system avoided redundant work.
Limitations and Future Work
- Threshold Sensitivity: The system currently uses fixed thresholds for correctness. The authors suggest that adaptive threshold selection—adjusting how much error is "acceptable" based on the specific math operation—could improve results further.
- Advanced Search: While beam search worked well, the authors see potential in using more sophisticated algorithms like Monte Carlo Tree Search (MCTS) to explore the space of modular decompositions.
- Framework Expansion: The current work focuses on Triton. Extending this modular approach to other frameworks like CUDA or ROCm is a logical next step.
Summary updated