Prhub

#44899 [ROCm][DSv4][Perf] Flash-decode split-K decode attention kernel

原始 PR 作者 Fangzhou-Ai 合并时间 2026-06-12 11:17 文件变更 2 提交数 5 评论 5 代码增减 +675 / -10

执行摘要

ROCm gfx950 上 DSv4 解码注意力通过 split-K 加速 8 倍

PR body 指出:'DSV4's 16 TP-local heads collapse to a single head-block, so the whole decode runs on just batch workgroups and leaves most of a 256-CU gfx950 device idle (latency flat at ~277us across batch 4 to 128).' 因此需要将 work 分配到多个 split 以提高 occupancy。

该 PR 值得精读,尤其是 flash-decode split-K 与 wave-aware 分片启发式的设计思路,对于理解注意力解码瓶颈和 ROCm 高性能 kernel 编写有参考价值。建议关注后续是否推广到其他架构。

讨论亮点

Review 中 reviewer tjtanaa 要求更新单元测试文件,作者随后添加了 gfx950-only 的单元测试。无其他设计争议。

实现拆解

  1. vllm/v1/attention/ops/rocm_aiter_mla_sparse.py 中新增两个 Triton kernel:_sparse_attn_decode_partial_kernel 负责每个 split 内的部分 softmax 计算(维护局部 m_i、l_i 和累加),_sparse_attn_decode_reduce_kernel 将各 split 的 partial 结果合并。
    2. 实现 split 数量启发式 _decode_num_splits,根据 query 数量、device CU 数、平均 main/extra 长度动态选择 split 数(范围 [1,16]),保证低 batch 增加并行度,高 batch 避免过度分割。
    3. 在入口函数(如 _sparse_attn_decode_ragged)中依据 _on_gfx950() 条件分支:gfx950 且 _decode_num_splits > 1 时走 split-K pipeline,否则回退原始单 kernel。
    4. 新增辅助函数 _decode_cu_count 获取 GPU CU 数量,_decode_partial_iters 计算 partial 迭代。
    5. 测试配套:在 tests/kernels/attention/test_rocm_triton_attn_dsv4.py 新增 test_decode_num_splits_heuristic(验证启发式合理性)和 test_sparse_attn_decode_split_k_kernel(参数化 num_splits/with_extra/with_sink,使用 GPU 验证正确性),并引入 _on_gfx950 检查与 requires_gfx950 skipif 装饰器确保仅在 gfx950 运行。
文件 模块 状态 重要度
vllm/v1/attention/ops/rocm_aiter_mla_sparse.py 注意力 modified 7.51
tests/kernels/attention/test_rocm_triton_attn_dsv4.py 测试 modified 6.97

关键符号

_sparse_attn_decode_partial_kernel _sparse_attn_decode_reduce_kernel _decode_num_splits _on_gfx950

分析完成后,这里会展示 LLM 生成的相对完整源码片段和详细注释。

评论区精华

单元测试覆盖 测试

reviewer tjtanaa 要求更新单元测试文件 tests/kernels/attention/test_rocm_triton_attn_dsv4.py。

结论:作者添加了 gfx950-only 的单元测试(包括 test_decode_num_splits_heuristic 和 test_sparse_attn_decode_split_k_kernel)。 · 已解决

风险与影响

  1. 仅限 gfx950 启用,其他架构无回归风险,但需验证 gfx950 上精度与原始路径一致(已通过内核单元测试和 GSM8K 任务验证,exact match 0.9568)。
    2. split-K 额外引入 partial+reduce 两个 kernel,高 batch 时可能 over-split 导致性能下降,但启发式限制 split 数上限 16 并测试覆盖各 split 数。
    3. 大段 Triton 模板代码增加维护成本。

影响范围:使用 AMD gfx950 推理 DeepSeek-V4 的用户,低 batch 场景下 TPOT 降低 20%,高 batch 也有 9% 改善;其他硬件/模型无影响。
影响程度:中等,性能提升显著但仅限于特定硬件和模型。

gfx950 专属路径 低 batch 显著收益 split-K 新增复杂度

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论