Prhub

#44681 [Refactor] Remove dead cutlass mxfp8 code

原始 PR 作者 yewentao256 合并时间 2026-06-18 12:18 文件变更 10 提交数 7 评论 3 代码增减 +0 / -1369

执行摘要

移除未使用的 cutlass MXFP8 代码及测试

这些 MXFP8 相关的算子和测试代码在 #34448 之后已不再被生产代码使用。移除它们可以清理仓库,减少维护成本和编译时间。

该 PR 是标准的死代码清理,变更清晰、审核充分,建议快速合入。对于其他死代码,可参考此 PR 的模式:提供关联 PR 证据 + 逐一清理所有引用(绑定/注册/实现/构建/测试)。

讨论亮点

审核者 Harry-Chen 在首次提交后指出初始 diff 未包含 CMakeLists.txttorch_bindings.cpp 的更改(评论:"the current diff does not include CMakeLists.txt and torch_bindings.cpp?")。PR 作者随后补充了这些文件的修改并回复 "Thanks! Now added",最终审核通过。

实现拆解

变更分为几个步骤:

  1. 移除 Python 绑定:在 vllm/_custom_ops.py 中删除 mxfp8_experts_quantcutlass_mxfp8_grouped_mm 两个函数定义及其对应的 register_fake 装饰器,消除 Python 层的入口。
  2. 移除 C++ OP 注册:在 csrc/libtorch_stable/torch_bindings.cpp 中删除 mxfp8_experts_quantcutlass_mxfp8_grouped_mmops.def 声明,切断 torch 绑定的注册。
  3. 删除 C++ 内核实现:移除 csrc/libtorch_stable/moe/mxfp8_moe/ 目录下的所有 .cu/.cuh 文件(约 6 个文件),包括量化、GEMM 启动器、functor、traits 等完整实现。
  4. 更新 CMake 构建:在 CMakeLists.txt 中移除与这些源文件相关的编译目标。
  5. 删除测试文件:完全删除 tests/kernels/moe/test_cutlass_mxfp8_grouped_mm.py,该文件专门测试这些内核。

所有删除均不可逆,但因为代码已不被任何生产路径引用,风险较低。

文件 模块 状态 重要度
vllm/_custom_ops.py 算子绑定 modified 7.69
tests/kernels/moe/test_cutlass_mxfp8_grouped_mm.py 内核测试 removed 7.19
csrc/libtorch_stable/torch_bindings.cpp C++ 注册 modified 4.92
csrc/libtorch_stable/moe/mxfp8_moe/mxfp8_experts_quant.cuh CUDA 内核 removed 5.19
csrc/libtorch_stable/moe/mxfp8_moe/cutlass_mxfp8_grouped_mm_launcher.cuh CUDA 内核 removed 4.89

关键符号

mxfp8_experts_quant cutlass_mxfp8_grouped_mm _mxfp8_experts_quant_fake _cutlass_mxfp8_grouped_mm_fake test_cutlass_mxfp8_grouped_mm

关键源码片段

tests/kernels/moe/test_cutlass_mxfp8_grouped_mm.py deletion

整个测试文件被删除,覆盖了 MXFP8 内核的正确性测试。

# 整个文件 tests/kernels/moe/test_cutlass_mxfp8_grouped_mm.py 已删除
# 以下是主要测试函数(已移除)
def is_sm100_supported() -> bool:
    return current_platform.is_cuda() and current_platform.is_device_capability_family(100)def compute_ref_output(input_tensor, weight_list, expert_offsets, expert_offset, num_experts):
    # 构建 top-1 路由得分,计算参考输出
    score = torch.full((expert_offset, num_experts), -1e9, device=input_tensor.device, dtype=torch.float32)
    for g in range(num_experts):
        start = expert_offsets[g]
        end = expert_offsets[g + 1] if g + 1 < num_experts else expert_offset
        score[start:end, g] = 0.0
    return torch_moe_single(input_tensor, torch.stack(weight_list, dim=0), score, topk=1)@pytest.mark.skipif(not is_sm100_supported(), reason="仅支持 SM100")
@pytest.mark.parametrize("num_experts", [8, 16, 32, 64])
@pytest.mark.parametrize("out_dtype", [torch.half, torch.bfloat16])
def test_cutlass_mxfp8_grouped_mm(num_experts, out_dtype):
    # 调用 ops.mxfp8_experts_quant 和 ops.cutlass_mxfp8_grouped_mm
    # 与参考输出对比,验证正确性
    ...
csrc/libtorch_stable/torch_bindings.cpp core-logic

删除了 MXFP8 算子的 C++ op 注册,是 C++ 绑定的关键入口。

// 以下 C++ OP 注册已在 PR #44681 中删除
// Expert-specialization mxfp8 blockscaled grouped quantization (SM100+).
ops.def(
    "mxfp8_experts_quant("
    " Tensor input, Tensor problem_sizes, Tensor expert_offsets,"
    " Tensor blockscale_offsets, Tensor! quant_output, Tensor! scale_factor)"
    " -> ()");// Expert-specialization mxfp8 blockscaled grouped GEMM (SM100+).
ops.def(
    "cutlass_mxfp8_grouped_mm("
    " Tensor a, Tensor b, Tensor sfa, Tensor sfb, Tensor! out,"
    " Tensor problem_sizes, Tensor expert_offsets, Tensor blockscale_offsets)"
    " -> ()");

评论区精华

Missing CMakeLists.txt and torch_bindings.cpp in initial diff question

Harry-Chen 评论说 'I'm not sure if it is a github issue, but the current diff does not include CMakeLists.txt and torch_bindings.cpp?'

结论:作者随后补充了这些文件的修改,Harry-Chen 批准 · 已解决

风险与影响

主要风险是删除可能影响其他未发现的使用点。但由于 PR 声称代码已通过 #34448 停产,且维护者确认,风险较低。此外,删除 fake 注册可能导致 torch dyn 编译在某个条件下报错(如果仍有人试图注册这些 op),但 fake 注册仅用于 torch.compile 的符号执行,实际 C++ op 已被移除,不存在混淆。整体回归风险低。

用户影响:无,因为被删功能未在产线使用。
系统影响:减少编译时间约 1-2%(取决于 CMake 目标),减小二进制体积。
团队影响:消除死代码维护负担,降低新成员理解代码的噪声。
影响程度:仅影响 SM100 架构的 MXFP8 量化路径,且该路径已未被调度。

低回归风险 不影响功能

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论