Learning When to Optimize: Verified Optimization Skills from Expert GPU-Kernel Lineages

Shuoming Zhang, Qiuchu Yu, Yangyu Zhang, Ruiyuan Xu, Xiyu Shi, Guangli Li, Xiaobing Feng, Huimin Cui, Jiacheng ZhaoarXiv 2026 · DOI

TL;DR

This paper introduces KLINEAGE, a novel framework that learns when to apply GPU kernel optimizations, not just what optimizations exist. By deoptimizing expert kernels, KLINEAGE extracts "skills" that capture the conditional knowledge of optimizations, leading to significantly better performance and efficiency compared to existing LLM-based approaches.

What Problem Does This Paper Address?

Modern LLMs are adept at generating code, including complex GPU kernels. However, they often struggle with optimization. While LLMs can suggest optimizations like tiling or vectorization, they lack the crucial understanding of when these optimizations are valid and beneficial. This leads to generated kernels that might fail to compile, produce incorrect results, or even perform worse than naive implementations. The core problem is the missing "when" knowledge – the preconditions, contexts, and risks associated with applying specific optimizations. Existing methods primarily learn by forward exploration, which is inefficient and can miss crucial optimization paths.

Methods

KLINEAGE tackles this by learning from expert-written GPU kernels. The core idea is guided deoptimization:

  1. Backward Walk: KLINEAGE starts with a highly optimized expert kernel and systematically applies simplification steps (e.g., removing tiling, devectorizing) using an LLM rewriter.
  2. Validation Gates: Each simplification step is validated through compilation, correctness checks, and profiling. If a step fails validation, it provides evidence for the risks of that optimization.
  3. Inverse Forward Transitions: The inverse of each successful simplification is stored as a validated "forward transition" – essentially, a step from a simpler state towards the expert kernel.
  4. Skill Induction: These validated transitions are then "lifted" into conditioned procedural skills. Each skill encapsulates the optimization intent, its code anchor (where it applies), a carrier (how to implement it), preconditions, expected effects, risks, and scope (platform, language, etc.).
  5. Verification and Reuse: Candidate skills are admitted only after a held-out roundtrip test confirms their utility. During reuse, KLINEAGE retrieves relevant skills based on the target kernel's context and an LLM agent materializes them, again under strict validation gates.

Datasets

The paper uses five expert workloads (GEMM, Conv2d, FMHA, GDN, Top-K) from various sources like CUTLASS and TileLang. For evaluation, they also use 22 held-out FlagGems Triton-bound operators that did not contribute to the skill induction.

Key Insights and Ideas

  • "When" is more important than "What": The paper strongly argues that the critical missing piece for LLM-based optimization is understanding the conditions under which optimizations are valid, not just knowing the optimizations themselves.
  • Deoptimization as a Learning Signal: Learning by undoing optimizations from expert code is a powerful way to discover validated, conditional optimization steps. This is a significant departure from typical forward-exploration methods.
  • Skills as Verified, Contextualized Knowledge: KLINEAGE's "skills" are not just abstract optimization names but are rich, code-anchored entities with explicit preconditions, effects, and risks, making them highly reusable and reliable.
  • Lineages as Curricula: The sequence of validated forward transitions derived from deoptimization forms an executable curriculum, guiding an LLM from a naive kernel towards an optimized one.

Key Results

  • Significant Speedups: KLINEAGE achieved a 1.12x geometric mean speedup over vendor references on 10/10 main-tier pairs, significantly outperforming baselines like AdaExplore (0.25x) and AccelOpt (0.54x).
  • Cross-Language Transfer: Skills learned from CUDA kernels successfully transferred to TileLang, achieving a 1.06x geometric mean speedup, demonstrating the transferable nature of the learned intents.
  • Conditional Knowledge Matters: Ablation studies showed that removing the conditional structure (preconditions, risks) from skills led to drastic performance degradation (5-14x slower on Conv2d, up to 105x slower on GDN).
  • Cost-Effective Optimization: KLINEAGE's skill induction cost is amortized, and its optimization process is efficient within a fixed budget, reaching optimal performance faster than baselines.

Limitations and Future Work

  • Dependence on Expert Evidence: The quality and coverage of the learned skills are directly dependent on the available expert kernels. A limited set of expert artifacts will result in a less comprehensive skill library.
  • Cross-Vendor Transfer: The current work is limited to NVIDIA architectures. Transferring skills to different hardware (e.g., NPUs) would require adapting the validation harness or focusing on more abstract, strategy-level skills.
  • LLM Rewriter Noise: While validation gates mitigate issues, the LLM rewriter used for deoptimization can still make mistakes.
  • Future Work: The authors suggest exploring how to degrade the library as the source pool shrinks and investigating cross-vendor transferability. They also highlight the potential for broader applications of this procedural-memory construction for LLM agents beyond kernel optimization.

Summary updated

BibTeX
@misc{zhang2026learning,
  author = {Shuoming Zhang and Qiuchu Yu and Yangyu Zhang and Ruiyuan Xu and Xiyu Shi and Guangli Li and Xiaobing Feng and Huimin Cui and Jiacheng Zhao},
  title = {{Learning When to Optimize: Verified Optimization Skills from Expert GPU-Kernel Lineages}},
  year = {2026},
  eprint = {2605.28213},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.28213},
}
Figure