KernelBench 是什么,fast_p 怎么算?
它有哪些缺陷,后来怎么修的?
先弄清楚:每个概念是什么
- 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:o1 | fast_1:DeepSeek-R1 |
|---|---|---|---|---|
| L1 | 100 | 单个 operator,比如 conv、matmul、layernorm | 10% | 12% |
| L2 | 100 | 简单的 fusion pattern,比如 conv + bias + ReLU | 24% | 36% |
| L3 | 50 | 完整网络,比如 MobileNet、VGG、MiniGPT | 12% | 2% |
表里是 one-shot 的 fast_1,baseline 是 PyTorch eager。论文摘要说整体不到 20%,分层看 L2 的两个数高于 20%。加上 execution 和 profiler 的反馈后,DeepSeek-R1 在 L2 从 36% 升到 72%。
fast_p 怎么算
手算一遍(示意)。10 题里 3 题不正确,另外 7 题的 speedup 是 0.6、0.9、1.0、1.2、1.5、1.8、2.5。
- fast_0 = 7 ÷ 10 = 70%
- fast_1 = 4 ÷ 10 = 40%,speedup 等于 1.0 的那题不算,条件是严格大于
- fast_2 = 1 ÷ 10 = 10%
分母一直是全部 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 没开 TF32 | speedup 虚高。论文估计开 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。
必答点
- 250 题分三层:L1 单个 operator,L2 fusion pattern,L3 完整网络
- 任务是给一个 PyTorch
Model,写出等价但更快的ModelNew - fast_p:正确且 speedup 大于 p 的题占全部题的比例,fast_0 是正确率
- one-shot 下 frontier model 整体不到 20%
- 缺陷:容差 1e-2、shape 固定、FP32 baseline 没开 TF32、有退化题
- KernelBench-Verified 修掉之后,GPT-5.5 从 1.43x 掉到 0.88x
追问
为什么不直接报平均 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 节