Prhub

#47164 fix: skip cooperative top-K on SM120

原始 PR 作者 lucifer1004 合并时间 2026-07-01 12:32 文件变更 1 提交数 2 评论 0 代码增减 +1 / -0

执行摘要

跳过 SM120 上的 cooperative top-K

SM120 GPU 上 clustered kernel 启动会失败,返回 cudaErrorInvalidValue,导致合作 top-K 无法正常工作。需要跳过 cooperative top-K 以避免错误,并利用现有的 persistent top-K 实现作为 fallback。

可以安全合并。变更简单、目标明确,已由作者手工验证。建议在 SM120 上增加自动化测试覆盖,但非阻塞。

讨论亮点

仅有自动化审查评论(由 claude[bot] 提及来自 fork 的 PR 自动审查被禁用)和 zyongye 的批准,没有实质性讨论。

实现拆解

vllm/model_executor/layers/sparse_attn_indexer.py 文件中,修改 use_cooperative_topk 的判断条件:

  1. 在原有条件(平台为 CUDA、topk_tokens 为 512/1024/2048、num_rows <= 32、stride 对齐 4、计算能力 >= 90)的基础上,增加 not current_platform.is_device_capability_family(120)
  2. 当 SM120 时,use_cooperative_topk 为 False,代码会判断 use_persistent_topk(仅依赖 CUDA 平台和 topk_tokens 值)为 True,从而执行 torch.ops._C.persistent_topk 作为 fallback。
    整修变更仅一行新增代码,不涉及测试或其他文件修改。
文件 模块 状态 重要度
vllm/model_executor/layers/sparse_attn_indexer.py 核函数 modified 4.65

关键符号

sparse_attn_indexer

关键源码片段

vllm/model_executor/layers/sparse_attn_indexer.py data-contract

修改了 cooperative top-K 的判断条件,增加了 SM120 排除逻辑。

# file: vllm/model_executor/layers/sparse_attn_indexer.py
# 决定是否使用 cooperative top-K 的条件判断
# 新增一行排除 SM120,因为该架构上 clustered kernel 会失败
use_cooperative_topk = (
    current_platform.is_cuda()
    and topk_tokens in (512, 1024, 2048)
    and num_rows <= 32
    and logits.stride(0) % 4 == 0 # TMA 16-byte alignment
    and current_platform.has_device_capability(90)
    and not current_platform.is_device_capability_family(120) # 新增:跳过 SM120
)

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

风险极低:变更仅增加一个对 SM120 的排除检查,不影响其他 GPU 的行为。SM120 上原本 cooperative top-K 会失败,现在使用 persistent top-K 正常 fallback,不会引入新的回归。但若 future SM 系列也遇到类似问题,可能需要更通用的架构范围判断而非硬编码。

仅影响 SM120 计算能力的 NVIDIA GPU。在这些 GPU 上,合作 top-K 被禁用,但 persistent top-K 作为 fallback 继续工作。对其他所有 GPU 无影响。

缺少测试覆盖

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论