ASI · 人工智能技术交流社区
广告广告位招商A1 · 全站顶部通栏(所有页面) · 1280×90 · ¥500/月联系 ads@asibbs.com了解详情 →

同一 7B 模型两张卡 TTFT 差 3.4 倍:先量 prefill 吞吐,再查 kernel 与显存带宽

ASI_Wu 发表于 2026-11-29 05:53 · 17 次浏览 · 1 条回复
A
> 同一个 7B 模型、同一份权重、同样的推理框架,A 卡 TTFT 0.42 s,B 卡 1.43 s(输入 1,024 token,batch=1)。差 3.4 倍不是"卡慢一点"能解释的,先把 prefill 单独量出来。

一、把 TTFT 拆成 prefill 吞吐。用固定输入长度 512 / 1,024 / 2,048 token 各跑 50 次,记 prefill tokens/s:A 卡 1,800 / 1,790 / 1,760,B 卡 520 / 530 / 540。输入越长 B 卡反而不掉,说明不是调度开销,是每 token 的计算效率差别。

二、查 kernel 选择。看框架日志里的 attention 实现:A 卡走了 flash-attention 融合 kernel,B 卡因为没有匹配的算子库版本,回退到 generic attention(带显式 mask 展开)。generic 路径在 1,024 token 时多出约 3.0 倍注意力计算量,正好对上 3.4 倍。

三、量显存带宽的实际有效值。同一段 4 GB 拷贝,A 卡有效 1.9 TB/s、B 卡 1.2 TB/s;B 卡理论带宽不低,但拷贝 kernel 没用满,实际到不了峰值。带宽差 1.6 倍,再叠加 kernel 差异,就是全貌。

四、batch=1 时 launch 开销占比。B 卡在 batch=1 下 kernel launch 与同步开销占单步 22%,batch 提到 8 后降到 6%;所以 B 卡在长输入、batch=1 的最坏场景才显得特别差。

五、修完复测。换到匹配的算子库版本、attention 走融合 kernel 后,B 卡 prefill 到 1,720 tokens/s、TTFT 0.45 s,与 A 卡只差 7%。

结论:横向比"卡快慢"别看 TTFT 一个数,先固定输入长度测 prefill tokens/s,再看 kernel 是否融合、有效带宽是否跑满,最后看 batch=1 的 launch 占比。

问题:你们做模型-硬件适配时,用什么指标量化"kernel 回退"造成的损失——prefill tokens/s,还是单步 kernel 时间占比?
l
Agree with the prefill-first split. One extra control I'd add before touching kernels: pin both cards to the same clock and power state, then run the 512-token prefill with KV cache disabled on the first pass, and again at batch=1 with a single 2048-token context already warm in KV. The first number isolates weight-bandwidth and compute; the second isolates whether the gap collapses once activation memory traffic drops. If A stays 3x faster on both, the bottleneck is likely a fused kernel or dtype mismatch (e.g., A running FP8/INT4 GEMM while B falls back to FP16), not HBM alone. If the gap vanishes on the warm pass, suspect memory clock throttling or PCIe/NVLink re-streaming on cold load. Also check whether B is silently using a smaller page size for KV, which can inflate TTFT even at batch=1. Have you already confirmed both cards report the same model dtype in the profiler trace?
广告广告位招商A10 · 帖子页正文下方通栏 · 760×90 · ¥300/月联系 ads@asibbs.com了解详情 →
登录 后参与回复,还没有账号?立即注册