Prhub

#22670 Migrate Intel CPU cases to the test/registered.

原始 PR 作者 1pikachu 合并时间 2026-05-12 13:27 文件变更 28 提交数 1 评论 26 代码增减 +4954 / -35

执行摘要

迁移 Intel CPU 测试至统一注册目录

原有的 CPU 测试分散在 test/srt/cpu/ 下,缺乏统一的注册和调度机制,导致 CI 覆盖不完整且难以扩展。该 PR 旨在将 CPU 测试迁移至 test/registered/cpu/,利用统一的测试注册框架提升 CI 覆盖的可维护性和触发的灵活性(PR body: 'improve CPU CI coverage and refine Xeon CI triggering')。

由于该 PR 已被 revert(#25044),建议在重新合并前必须修复所有已指出的问题。具体包括:修复 test_causal_conv1d 中的布尔张量生成错误;清理 test_binding 的类名;删除 test_bmm 中未使用的类;将 test_decode 的默认设备改为 "cpu";修正 test_extend 中的拼写错误;更新 test_mamba 的类型提示;移除 test_rope 的冗余断言。同时建议强化测试代码审查及自动化 lint 检查。

讨论亮点
  • mingfeima 询问 test/srt/cpu/ 下已有测试文件的处理方式,但未得到直接回应,PR 仍被合并。
  • gemini-code-assist 指出多个代码问题:test_causal_conv1d.py 中布尔张量生成错误(torch.randint 不支持 dtype=bool,且随后的 fill_(False) 使随机初始化失效);test_activation.py 中在循环内冗余调用 set_global_server_args_for_schedulertest_binding.py 中类名 TestGemm 应为 TestBinding(复制粘贴错误);test_bmm.py 中未使用的 Mod 类;test_decode.py 中默认设备参数为 "cuda" 在 cpu 目录下不合理;test_extend.py 中变量名 redudant 拼写错误;test_mamba.py 中过时类型提示 torch.FloatTensortest_rope.py 中冗余断言。
  • mingfeimatest_extend.py 中针对具体行给出了拼写修正建议。
  • 这些讨论中除 test_extend.py 的拼写得到 maintainer 的直接建议外,其余大部分自动评审发现的问题未在合并前修复。

实现拆解

  1. 创建共享测试工具模块 test/registered/cpu/utils.py,封装精度阈值、参数化装饰器、量化辅助函数等,统一断言标准并减少代码重复。
  2. 为每个 CPU 算子/内核路径创建独立的测试文件(共 22 个),置于 test/registered/cpu/ 下,涵盖 activation、bmm、causal_conv1d、decode/extend attention、flash_attn、gemm、mamba、mla、moe、norm、qkv_proj_with_rope、qwen3、rope、shared_expert、topk 等。
  3. 在 CI 注册框架中通过 register_cpu_ci(est_time=10, suite="stage-b-test-cpu") 注册每个测试类,指定预估运行时间和所属套件。
  4. 更新 CI 工作流文件(如 .github/workflows/slash-command-handler.yml),添加 /tag-run-cpu-ci-label/tag-cpu-and-rerun-ci 两条新的斜杠命令,允许按需触发 CPU 测试套件。
  5. 更新 CPU per-commit 流水线配置,将 stage-b-test-cpu 纳入 per-commit 自动运行套件。
文件 模块 状态 重要度
test/registered/cpu/utils.py 共享工具 added 8.05
test/registered/cpu/test_causal_conv1d.py 因果卷积 added 7.76
test/registered/cpu/test_qkv_proj_with_rope.py QKV 投影 added 7.76
.github/workflows/slash-command-handler.yml 部署脚本 modified 6.0

关键符号

parametrize per_token_quant_int8 native_w8a8_per_token_matmul causal_conv1d_ref causal_conv1d_update_ref fused_moe _bf16_gemm test_norm test_causal_conv1d test_chunk_gated_delta_rule test_bf16_moe test_bf16_qkv_proj_with_rope

关键源码片段

test/registered/cpu/test_causal_conv1d.py test-coverage

包含严重的布尔张量生成错误,是代码审查中重点讨论的缺陷文件,反映了整体测试质量问题。

class TestCausalConv1d(CustomTestCase):
    activation = "silu"
​
    @parametrize(
        batch=[1, 1024],
        dim=[96, 512],
        seqlen=[2, 36],
        width=[4],
        has_bias=[True, False],
        has_initial_state=[True, False],
    )
    def test_causal_conv1d(
        self,
        batch,
        dim,
        seqlen,
        width,
        has_bias,
        has_initial_state,
        dtype=torch.bfloat16,
        prepack=True,
    ):
        # ... 初始化 x, weight, bias ...
​
        # BUG: torch.randint 不支持 dtype=torch.bool,会抛出 RuntimeError;
        # 且随后的 .fill_(False) 使随机初始化失效。
        # 应改为:
        # has_initial_state_tensor = torch.randint(0, 2, (batch,)).to(torch.bool)
        has_initial_state_tensor = torch.randint(
            0, 2, (batch,), dtype=torch.bool # 此处会报错
        ).fill_(False) # 此覆盖无意义
​
        # ... 后续调用 causal_conv1d_fwd ...

评论区精华

旧测试文件处理 question

mingfeima 询问 `test/srt/cpu/` 下已有测试文件的处理方式,author 回应 'There is still test_arm64 using test/srt/cpu/test_*.py, so keep these files for now.'

结论:部分旧测试保留,未完全清理,但 PR 仍然合并。 · unresolved

布尔张量生成错误 正确性

gemini-code-assist 指出 `test_causal_conv1d` 中使用 `torch.randint(..., dtype=torch.bool)` 会导致 RuntimeError,且 `.fill_(False)` 使随机初始化失效。

结论:建议使用 `.to(torch.bool)` 并删除 `fill_`。 · unresolved

类名复制粘贴错误 正确性

gemini-code-assist 发现 `test_binding.py` 中类名 `TestGemm` 是复制粘贴错误,应改为 `TestBinding`。

结论:建议重命名。 · unresolved

默认设备参数误导 设计

gemini-code-assist 指出 `test_decode.py` 中 `_run_sdpa_forward_decode` 的 `device` 参数默认值为 `"cuda"`,在 cpu 测试目录下不合理。

结论:建议改为 `"cpu"`。 · unresolved

拼写错误 style

gemini-code-assist 和 mingfeima 指出 `test_extend.py` 中变量名 `per_req_query_redundant` 拼写错误(redundant)。

结论:mingfeima 直接给出了 `unsqueeze` 修正建议。 · unresolved

冗余断言 正确性

gemini-code-assist 指出 `test_rope.py` 中第 162 行的断言与第 161 行重复,属于冗余。

结论:建议删除冗余断言。 · unresolved

风险与影响

  • 测试代码质量缺陷:部分新增测试存在逻辑错误(如 test_causal_conv1d 中布尔张量生成异常)可能导致运行时 CI 失败或测试结果无效。
  • 类名复制粘贴错误test_binding.py 中的 TestGemm 类名与 test_gemm.py 冲突,可能影响测试发现和结果归因。
  • 配置变更风险:CI 工作流新增斜杠命令标签,可能与其他已有标签冲突或触发意外的流水线执行。
  • 维护负担:22 个测试文件大量重复样板代码(尽管由 utils.py 缓解),但若后续内核接口变更需要同步更新所有测试文件。
  • 后续 revert:这些质量问题可能是后续 revert PR #25044 的直接原因。
  • 用户影响:无,仅影响测试和 CI 流程。
  • 系统影响:增强了 CPU 后端的测试覆盖,但引入了不稳定的测试用例,可能降低 CI 可靠性。
  • 团队影响:增加了 22 个测试文件和共享工具模块,提升了测试代码复用性和可维护性;但也带来了需修复的代码债务。
  • 影响程度:中等。
测试代码质量缺陷 CI 配置变更 潜在运行时错误 已回滚风险

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论