Merged
[fix] Skip incompatible Triton-Ascend smoke tests in pytest #1321
[fix] Skip incompatible Triton-Ascend smoke tests in pytest #1321
Merged
hanboyouAdd on 17 days ago
hanboyou
hanboyouCollaborators
17 days ago

描述

已知 Triton-Ascend 发布版使用 C++17 编译 launcher,与 Torch >= 2.14 的 C++20 要求不兼容。pytest 与 CI 共用版本限定规则,默认跳过 27 个受影响的 Triton smoke 用例。
--run-unsupported-triton 在 tests/conftest.py 注册,使 pytest tests 和直接 smoke 入口均可识别;保留 default=False 以兼容延迟加载。较旧的 Torch、未列出的 Triton 版本和本地构建照常执行。

类型

Checklist:

如何测试

  • Python 3.12.14:TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest -v --tb=short tests/unit_tests/tooling/test_triton_smoke_selection.py -x,10 passed(tooling,不计产品 UT);修复前已复现父目录参数解析与 Torch 2.14.1 的两项失败。
  • CI entrypoint 的 CPU 选择探针:默认跳过和显式覆盖均通过;Ruff、shell 语法与改动文件检查通过。CI #3029:代码检查、UT、NPU smoke 与 integration 全部通过(smoke:17 passed、29 skipped)。

精度和性能验证结果

仅修改 pytest 测试入口与选择逻辑,无生产计算路径改动;按 numerical_alignment.md 第 3 节跳过训练精度验证,性能未测量。

其他信息

.ci/smoke_test.sh 已移除硬编码 --deselect,使用共享规则并转发覆盖开关。未改变依赖 pin、模型实现或 checkpoint 格式。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for hanboyou's contribution.)
hanboyouhanboyouCollaborators
17 days ago Created pull request, commit f71c1b8a
atomgit-bot
atomgit-botCollaborators
17 days ago Comments:

变更摘要

本 PR 主要解决 Python 版本与 Triton-Ascend 发布版在 Torch 2.14 下的兼容性问题:将包允许的 Python 版本收窄到 >=3.12,<3.13,新增 triton_ascend 标记与 tests/smoke_tests/conftest.py 中统一的版本限定跳过规则(并提供 --run-unsupported-triton 覆盖开关),使直接 pytest 与 CI smoke 入口行为一致;同时隔离 CPU CANN recorder 与 NPU smoke 的执行进程,并加强 BF16 梯度与算子 schema 的诊断能力。此外附带回移上游依赖放宽的源码补丁与相应 tooling 自测。

主要改动

  • Python 版本约束收窄: pyproject.toml 中 requires-python 由 >=3.12 改为 >=3.12,<3.13,并新增 triton_ascend 测试标记,声明此类用例依赖 Triton-Ascend 的 Torch launcher。
  • 统一的 Triton 跳过逻辑: 新增 tests/smoke_tests/conftest.py,通过 _CPP17_TRITON_RELEASES 白名单与 _triton_launcher_skip_reason() 仅在 torch 2.14.0 加已核实 Triton-Ascend 发布版(非本地构建)时跳过 triton_ascend 标记用例,未识别版本保持正常执行以防掩盖回归。
  • CI 入口改用标记选择: .ci/smoke_test.sh 移除对 test_mhc_triton.py 与 test_qwen3_5_npu_runtime.py::test_merged_gdn_forward_backward 的硬编码 --deselect,改为 -rs 展示跳过原因并透传 "$@",使 --run-unsupported-triton 可用于验证编译器修复;对应测试文件补充 pytest.mark.triton_ascend 标记(test_mhc_triton.py 为文件级 pytestmark)。
  • CPU recorder 与 NPU smoke 进程隔离: tests/unit_tests/conftest.py 新增 pytest_collection_modifyitems,当同一 pytest 进程同时收集 tests/smoke_tests 且已安装进程级 CANN recorder 时抛出 pytest.UsageError,要求分别运行。
  • 测试断言与诊断增强: test_lightning_indexer_fused.py 用互不相同的非零梯度返回值与 BF16 输入做精确 assert_close 校验,区分第四个返回值 softmax_out;test_sparse_teacher.py 打印 cann_ops_transformer 路径及 lightning_indexer、sparse_lightning_indexer_kl_loss_grad 的 _schemas 以辅助诊断;另新增 test_cpu_smoke_isolation.py、test_triton_smoke_selection.py 与 triton-ascend-3.2.1-numpy-scipy.patch(仅放宽 numpy/scipy 版本固定)。
likedislike
Incorrect?
atomgit-bot
atomgit-botCollaborators
17 days ago Comments:

代码审查

审查结论

发现统计:P0 × 0,P1 × 0,P2 × 1,P3 × 2

Findings

  1. P2(confidence 0.60)tests/smoke_tests/conftest.py:53 — config.getoption("--run-unsupported-triton") 未给默认值。该选项由本目录 conftest 的 pytest_addoption 注册,pytest 只对“启动期 conftest”调用该 hook;在 pytest(仓库根)、pytest tests、pytest -m smoke 这类入口下该 conftest 延迟加载,选项未注册,收集期直接抛 ValueError: no option named '--run-unsupported-triton',27 个 Triton 用例既不会按版本跳过,也把同 PR 在 tests/unit_tests/conftest.py:183 新增的混合运行 UsageError 提示挡在其后(后者更晚注册、更早执行)。建议 getoption(..., default=False) 并把 pytest_addoption 迁到 tests/conftest.py。

  2. P3(confidence 0.50)tests/smoke_tests/conftest.py:38-43 — 跳过门限把 .ci/smoke_test.sh 注释里记录的 torch >= 2.14 不兼容区间收窄成 == (2, 14, 0);torch pin 一旦升到 2.15/2.16,同样的 C++17/C++20 编译错误会重新让这批用例在 CI 失败,而新增参数化用例只覆盖 2.13.0 与 2.14.0。属可选加固。

  3. P3(confidence 0.40)scripts/dependencies/patches/triton-ascend-3.2.1-numpy-scipy.patch:20-24 — 补丁移除 triton-ascend 的 numpy==1.26.4 元数据约束,而 requirements.txt:16 的 numpy 是裸依赖(注释第 17 行仍声称需要 1.26.4),源码构建路径后 numpy 可能解析到 2.x,触发 numpy 2.x C-ABI 不兼容。属可选加固。

逐文件审查确认

  • .ci/smoke_test.sh — 无问题(SMOKE_DESELECT 已彻底移除且无其他引用;-rs 与 "$@" 转发正确)
  • pyproject.toml — 无问题(requires-python 收窄与 .ci/common.sh 的 python3.12 一致;triton_ascend marker 已注册)
  • requirements.txt — 无问题(--only-binary=numpy,scipy 为合法文件级选项)
  • scripts/dependencies/patches/triton-ascend-3.2.1-numpy-scipy.patch — 见 Finding 3(hunk 计数 9/8 与上下文行数核对无误)
  • tests/smoke_tests/conftest.py — 见 Finding 1、2
  • tests/smoke_tests/ops/test_mhc_triton.py — 无问题
  • tests/smoke_tests/ops/test_qwen3_5_npu_runtime.py — 无问题
  • tests/smoke_tests/ops/test_sparse_teacher.py — 无问题(新增 print 为有意的 ABI 诊断输出,torch.ops 惰性命名空间不会因包缺失抛错)
  • tests/unit_tests/conftest.py — 无问题(UsageError 守卫的 _INSTALLED/路径判断正确,退出码 4 与工具化测试断言一致)
  • tests/unit_tests/override/deepseek_v4/test_lightning_indexer_fused.py — 无问题(attn_softmax_l1_norm.sum(-1).expand_as(w) 在 (TOKENS,1,TOPK) 与 (1,TOKENS,HEADS) 下广播合法,arange+0.5 在 bf16 下可精确表示,与断言自洽)
  • tests/unit_tests/tooling/test_cpu_smoke_isolation.py — 无问题
  • tests/unit_tests/tooling/test_triton_smoke_selection.py — 无问题(但所有子进程都用显式 tests/smoke_tests 路径,因此未覆盖 Finding 1 所述的根目录入口)

总体风险

改动集中在测试选择与依赖元数据,无生产计算路径变更,整体风险较低。主要风险点在于“跳过规则对所有入口统一生效”这一目标在根目录收集入口并不成立(P2),以及两处版本/依赖约束收窄后与文档化原因不完全对齐(P3,可选加固)。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
Incorrect?
CANN-robot
CANN-robotCollaborators
17 days ago Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/torchtitan-npu ✅ lrwei0709, xuyujun (2/2) ✅ lrwei0709 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

mystri, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
17 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
65 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
15 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
15 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
hanboyouhanboyouCollaborators
15 days ago Associated issue: [Bug-Report|缺陷反馈]: 直接 pytest 与 CI 的 Triton smoke 跳过行为不一致
CANN-robot
CANN-robotCollaborators
15 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
CANN-robot
CANN-robotCollaborators
15 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike