K-Search: LLM Kernel Generation via Co-Evolving Intrinsic World Model

Shiyi Cao, Ziming Mao, Joseph E. Gonzalez, Ion StoicaarXiv 2026

TL;DR

K-Search introduces a novel framework that treats Large Language Models (LLMs) as co-evolving "world models" to automate high-performance GPU kernel generation. By explicitly decoupling high-level algorithmic planning from low-level code generation, K-Search navigates complex optimization spaces without getting stuck on temporary compilation errors, outperforming state-of-the-art evolutionary methods by up to 14.3× and surpassing human-expert designs.

What Problem Does This Paper Address?

Writing high-performance GPU kernels (like those powering FlashAttention or Mixture-of-Experts models) is a black art. Engineers must meticulously balance tiling sizes, memory layouts, and hardware-specific instructions. To make matters worse, rapid hardware evolution (e.g., moving from NVIDIA Hopper to Blackwell architectures) completely changes performance trade-offs, rendering previously optimized code obsolete.

While automated approaches leverage LLMs to generate kernel variants, existing methods typically treat LLMs as stochastic code generators embedded within traditional genetic algorithms. This creates a major bottleneck: high-level optimization intent is tightly coupled with low-level implementation. If an LLM proposes a brilliant structural optimization but introduces a minor syntax or compilation error, evolutionary heuristics immediately discard the entire strategy. Consequently, these systems struggle with deep, multi-step structural transformations where intermediate steps might temporarily break the code or degrade performance.

Methods

To solve this, the authors propose K-Search, a framework that models kernel generation as a tree-search planning problem guided by an LLM acting as an intrinsic, co-evolving world model.

Overview of the K-Search framework, illustrating the separation between high-level planning and low-level local refinement.

The core innovation is the explicit separation of the search into three iterative phases:

  1. Action Selection: The LLM world model maintains a search tree consisting of Closed nodes (visited programs) and Open nodes (pending optimization hypotheses, like "Unroll loop" or "Fuse heads"). It assigns a priority score $V$ to the open actions and selects the most promising one.
  2. Local Refinement (Program Instantiation): Instead of generating code in a single shot, a separate code-generation policy repeatedly samples and tests concrete implementations of the selected action. It continues until a "stagnation limit" ($K$ consecutive failures) is reached, ensuring a good high-level strategy isn't abandoned due to a transient bug.
  3. World Model Update (Co-Evolution): Once execution feedback (latency, compiler logs) is obtained, the LLM reasoner evaluates the entire trajectory. Using in-context learning, it dynamically updates the search tree via three topological edits: Insert (adding new optimization hypotheses), Update (re-calibrating priority scores based on what worked), and Prune (permanently deleting dead ends).
A trace visualization showing how K-Search dynamically inserts, updates, and prunes optimization hypotheses over multiple rounds.

Datasets

K-Search was evaluated against highly optimized, human-engineered baselines using two primary benchmarks:

  • FlashInfer-Bench: A suite of complex, production-grade kernels critical for LLM serving, including Grouped Query Attention (GQA) Decode, Multi-head Latent Attention (MLA) Paged Prefill, MLA Paged Decode, and FP8 Mixture-of-Experts (MoE) kernels.
  • GPUMode TriMul Competition: A public kernel optimization challenge centered on the Triangle Multiplicative Update module from AlphaFold3, evaluated on NVIDIA H100 GPUs.

Key Insights and Ideas

  • Decoupling Strategy from Syntax: By isolating the logical reasoning ("what to optimize") from the implementation details ("how to write the CUDA code"), the system becomes highly resilient to the noisy nature of LLM code generation.
  • Navigating Non-Monotonic Paths: Real-world optimization often requires taking a step backward to go forward (e.g., refactoring memory layouts before vectorization). K-Search can navigate these performance "valleys" because its world model plans multiple steps ahead rather than relying on immediate greedy rewards.
  • In-Context Learning as Evolution: Instead of expensive model fine-tuning, the world model "co-evolves" purely through in-context learning, continuously refining its understanding of hardware characteristics by digesting real-time profiling data.

Key Results

K-Search significantly outperformed state-of-the-art evolutionary baselines like OpenEvolve and ShinkaEvolve across all workloads:

Comprehensive evaluation results comparing K-Search against OpenEvolve and ShinkaEvolve across multiple iterations and workloads.
  • Overall Performance: K-Search achieved an average 2.10× improvement over OpenEvolve and 2.21× over ShinkaEvolve across the FlashInfer kernels.
  • The MoE Breakthrough: On the highly complex FP8 MoE kernel, K-Search achieved a massive 14.3× performance gain over OpenEvolve, which consistently failed to escape low-performance traps.
  • Beating Human Experts: On the competitive GPUMode TriMul benchmark, K-Search achieved a state-of-the-art latency of 1030 µs on an H100 GPU, outperforming the top human-designed solutions on the leaderboard.

Limitations and Future Work

Despite its success, the authors note a few limitations:

  • Small Batch Inefficiencies: On GQA decode workloads with very small batch sizes (e.g., batch_size=1), K-Search actually underperformed simpler baselines. This is because its world model favored an aggressive "split-K" parallelism strategy that excels at large batches but introduces unnecessary synchronization overhead for small ones.
  • Purely In-Context Evolution: The world model's evolution is currently bounded by the context window of the LLM. Future iterations could explore updating the model's weights directly via reinforcement learning or fine-tuning to retain long-term optimization insights.

Summary updated

BibTeX
@misc{cao2026k,
  author = {Shiyi Cao and Ziming Mao and Joseph E. Gonzalez and Ion Stoica},
  title = {{K-Search: LLM Kernel Generation via Co-Evolving Intrinsic World Model}},
  year = {2026},
  eprint = {2602.19128},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.19128},
}
Figure