Pull Request has been successfully merged by CANN-robot.
(Thank you for hanboyou's contribution.)变更摘要
本 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版本固定)。


代码审查
审查结论
发现统计:P0 × 0,P1 × 0,P2 × 1,P3 × 2
Findings
-
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。 -
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。属可选加固。 -
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_ascendmarker 已注册)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、2tests/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 |
💬 仅评论


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
已知 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:
如何测试
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 的两项失败。精度和性能验证结果
仅修改 pytest 测试入口与选择逻辑,无生产计算路径改动;按 numerical_alignment.md 第 3 节跳过训练精度验证,性能未测量。
其他信息
.ci/smoke_test.sh已移除硬编码--deselect,使用共享规则并转发覆盖开关。未改变依赖 pin、模型实现或 checkpoint 格式。