Iterative refinement、evolutionary search 和 RL
怎么选?

英文问法When would you use iterative refinement, evolutionary search, or RL to optimize kernels? · Why not just let the agent keep refining one kernel? · Is a more complex search always better?

考过推断,非面经。没有 Unity 的面经原题,别家面经里也没有直接问这题的 · 依据是公开文献(KernelBench、AlphaEvolve、Meta KernelEvolve、Kevin、CUDA Agent)· Unity 自己的 FlashVector 用的是最简单的单链循环 · 研究向,可以主动带出来

先弄清楚:每个概念是什么

Iterative refinement
一条链。写一版,看反馈,改一版,一直改同一个 kernel。
Beam search
每轮只留最好的 K 个候选,再从它们往下改。
Evolutionary search
养一个种群,每轮挑 parent 让 LLM 改出 child,好的放回种群。
MCTS
把候选排成一棵树,按以往的结果决定下一次展开哪个节点。KernelEvolve 的节点可以继承父节点的历史、参考兄弟节点,或清空重来。
RL
把试错的经验训练进模型的参数(算法见 PPO 和 GRPO)。

看图:三种方法的形状

Iterative refinement 一条链,改完再改 k1 k2 k3 反馈 反馈 容易困在第一个思路里 Search beam、evolution、MCTS k0 0.8x 1.3x 1.1x 1.2x 1.6x 只展开好的,差的剪掉 RL 把经验训进模型 LLM(policy) 环境 + harness 写 kernel reward 更新参数 推理便宜,训练贵且不稳
图 1:图里的倍数是 speedup,只作示意。

30 秒回答

Refinement is one chain: generate, read the feedback, fix. It's cheap and direct, but gets stuck on its first idea. Search keeps several candidates alive with beam, evolution or MCTS. It adds diversity without training, which suits a one-off hot kernel, but it burns tokens and is better at finding holes in the harness. RL bakes the skill into the model, which pays off across many ops, but training is unstable and amplifies hacks. In practice you combine them: RL for the base skill, search at inference. All three need a harness the agent can't game, and FlashVector shipped with just a single chain.

三种方法对比

方法优点和证据风险
Iterative
refinement
简单便宜,反馈直接。KernelBench 论文里 DeepSeek-R1 在 L2 的 fast_1 从 36% 升到 72%;Kevin 的论文里 serial refinement 比 parallel sampling 划算困在第一个思路里;context 越滚越长
Search多样性高,不用训练。AlphaEvolve 让 Gemini 的训练时间少 1%;KernelEvolve 让 Meta 的 Andromeda 广告模型 inference throughput 提升 60% 以上token 贵,CRFM 的一次实验约 7M,Houmao 约 1.9B(μCUTLASS 按 speed of light 少给接近上限的 kernel,省 19–43%,保住至少 95% 的 geomean);搜得越强,越容易找到 harness 的漏洞
RL能力训进模型,op 多时每次推理便宜。CUDA Agent 对 torch.compile 的 faster rate 是 96.8%,同一个 agent loop 里 Opus 4.5 是 66.4%训练不稳,CUDA Agent 最初 17 步就崩;hack 会被放大,CUDA-L1 有 32.8% 的 kernel 钻了计时漏洞

怎么选,怎么组合

  1. 先做 refinement 加 profiler feedback,最便宜
  2. 单链停滞,这个 kernel 又值得花 token,再上 search
  3. op 很多,推理成本压不下来,再训 RL
  4. 三种可以叠用,RL 训基础能力,推理时再 search 和 refinement

单链困住的例子是 Meta KernelAgent 的 matvec。torch.compile 是 2.09 ms。不给硬件反馈、顺序 prompt 8 轮只到 3.20 ms,比 baseline 还慢。用 Nsight Compute 的指标加 4 个并行 worker 跑 8 轮到 1.95 ms。原文说没有 profiling 时 LLM 一直沿着第一版 kernel 的写法改。

没有 agent 骗不了的 harness,搜索或 RL 越强,学到的作弊越多(见 reward hacking)。搜索复杂不等于进生产,四家系统的对照见设计 kernel agent。

必答点

追问

多花 token 多试,能换来多少?

METR 给每题约 20 美元的预算,8 路并行做 tree-style sampling 共 300 次尝试,平均 speedup 从 1.05x 到 1.81x(见 KernelBench)。METR 自己说提升主要来自 scaffold 和 prompt。

RL 论文的数字能直接比吗?

不能。CUDA Agent 批评 Kevin 和 CUDA-L1 在 KernelBench 上既训练又评测。它自己的评测也还是原 KernelBench 协议,FP32 baseline 没开 TF32。

来源ml-八股 08 第 23 题 · KernelBench · AlphaEvolve · Meta KernelEvolve · KernelAgent(matvec)· Kevin · CUDA Agent · CUDA-L1 · METR 2025-02-14 · μCUTLASS · token 用量:CRFM、Houmao · 对比表整理自文献笔记第 6 节