KernelBench 是什么,fast_p 怎么算?
它有哪些缺陷,后来怎么修的?

英文问法What is KernelBench, and how is fast_p computed? · What are the known flaws of KernelBench? · Why did the reported speedups drop under KernelBench-Verified?

考过推断,非面经。没有 Unity 的面经原题,别家面经里也没有直接问这题的 · 依据是公开文献:KernelBench(Stanford,2025-02)和 KernelBench-Verified(Meta FAIR 与 Stanford,2026-06)· Kevin、CUDA-L1、CUDA Agent、KernelEvolve 都在它上面报结果,设计 kernel agent 一题里的 fast_1 也出自它 · 论文知识,很少单独问

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

KernelBench
一套考 LLM 写 GPU kernel 的题。
Speedup
PyTorch reference 的 wall-clock 时间除以生成的 kernel 的时间,大于 1 才算更快。
fast_p
既正确、speedup 又大于 p 的题,占全部题目的比例。fast_1 是比 PyTorch 快的比例。
One-shot
模型只生成一次,不看编译、运行或 profiler 的反馈。
TF32
让 FP32 的 matmul 用上 Tensor Core 的开关,PyTorch 默认关着,不开它的 baseline 偏慢。

30 秒回答

KernelBench is a Stanford benchmark with 250 PyTorch tasks in three levels: single operators, fusion patterns, and full networks. The model gets a PyTorch module and must write an equivalent but faster kernel. The metric is fast_p: the fraction of all tasks where the kernel is correct and more than p times faster than PyTorch, so fast_0 is the correctness rate. One-shot, frontier models matched PyTorch on less than 20% of tasks. Known flaws are a loose 1e-2 tolerance, fixed shapes, and an FP32 baseline without TF32. KernelBench-Verified fixes these, and GPT-5.5 drops from 1.43x to 0.88x.

三层题目和 one-shot 的结果

Level题数考什么fast_1:o1fast_1:DeepSeek-R1
L1100单个 operator,比如 conv、matmul、layernorm10%12%
L2100简单的 fusion pattern,比如 conv + bias + ReLU24%36%
L350完整网络,比如 MobileNet、VGG、MiniGPT12%2%

表里是 one-shot 的 fast_1,baseline 是 PyTorch eager。论文摘要说整体不到 20%,分层看 L2 的两个数高于 20%。加上 execution 和 profiler 的反馈后,DeepSeek-R1 在 L2 从 36% 升到 72%。

fast_p 怎么算

\[ \text{fast}_p = \frac{1}{N}\sum_{i=1}^{N} \mathbb{I}\big[\text{correct}_i \wedge \text{speedup}_i > p\big] \]

手算一遍(示意)。10 题里 3 题不正确,另外 7 题的 speedup 是 0.6、0.9、1.0、1.2、1.5、1.8、2.5。

分母一直是全部 10 题,所以 fast_p 把正确率和速度绑在一个数里。

已知缺陷和修正

缺陷后果谁修的,怎么修
容差太宽,atol 和 rtol 都是 1e-2降精度的 kernel 也能过KernelBench-Verified 改成 1e-3
shape 固定,每题 5 组随机输入只对测试 shape 特化的 kernel 也能过KernelBench-Verified 加 hidden test,输入换四种分布:原分布、×3、×0.01、×(−1)
FP32 baseline 没开 TF32speedup 虚高。论文估计开 TF32 后 24% 的题 baseline 快 1.5 倍以上KernelBench-Verified 开 TF32
有退化题,比如输出接近 0 或不随 seed 变不用真算也能对METR 从 250 题里删掉 45 题;v0.1 修了题目本身

KernelBench-Verified 评了七个模型,最好的 GPT-5.5 从原协议的 1.43x 降到 0.88x,比 PyTorch 慢。robust-kbench 剔除受污染的题后,平均 speedup 从 3.13x 降到 1.49x。

容差见 kernel 正确性,计时见 kernel benchmark。

必答点

追问

为什么不直接报平均 speedup?

平均值会被个别题带偏,也不看正确率。robust-kbench 举过一道题,softmax 作用在单个值上,输出恒为 1.0,报出 123.6x。fast_p 里它只算一题。

这些缺陷和 reward hacking 是什么关系?

评测有洞,搜索越强的 agent 越会钻。KernelBench-Verified 里 GPT-5.5 写的 ReLU kernel 在输入 shape 等于测试 shape 时原样返回输入,报出 374x(更多见 reward hacking)。

不同论文的 fast_1 或 speedup 能直接比吗?

不能。baseline 是 eager 还是 torch.compile、硬件、精度、best-of-k 的选法都可能不同。METR 换了 scaffold,同样的模型平均 speedup 从 1.05x 到 1.81x。

来源KernelBench(HTML:fast_p 的定义、Table 1、评测协议)· KernelBench README · KernelBench v0.1 · METR 2025-02-14 · KernelBench-Verified · robust-kbench · SOL-ExecBench · ml-八股 08 第 22 题 · 文献笔记 1.1–1.4、1.7 节