Pull Request已成功合入, 合并人@ascend-robot
(感谢 mihudan 的贡献)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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| test | ✅ medivh-x, luochao60 (2/2) | ✅ medivh-x (1/1) |
| torch_npu/npu | ✅ medivh-x, luochao60 (2/2) | ✅ medivh-x (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
mihudan, thanks for your pull request. All authors of the commits have signed the CLA. 👍


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.12.0 | ||
| v2.11.0 | ||
| v2.7.1-26.1.0 | ||
| v2.9.0 | ||
| v2.9.0-26.1.0 | ||
| v2.10.0 | ||
| v2.12.0-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| v2.10.0-26.1.0 | ||
| ci-test | ||
| sync-pr28113--to-v2.9.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


Ascend docs pipeline is running...


Ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


✅ 跳过 docs ci 检查,没有需要检查的文档文件


审查结果
文件 1: torch_npu/npu/npugraph_ex/scope/__init__.py
变更内容:为 limit_core_num 函数增加了 stream=None 可选参数,并透传给底层 scope.limit_core_num。
审查结论:无问题。参数使用 None 作为默认值(不可变对象),向后兼容旧调用方式,透传逻辑正确。
文件 2: test/dynamo/test_npugraph_ex.py
变更内容:新增测试方法 test_limit_core_num_with_stream,验证 limit_core_num 配合 stream 参数的使用场景。
审查结论:无问题。测试模式与已有的 test_limit_core_num 一致,通过 torch.compile 编译后执行模型来验证功能正确性;torch.npu.Stream() 创建和 torch.npu.stream() 上下文管理器的使用均符合 NPU API 惯例。
文件 3: test/torch_npu_schema.json
变更内容:更新 torch_npu.npu.npugraph_ex.scope.limit_core_num 的签名,从 (op_aicore_num: int, op_vectorcore_num: int) 改为 (op_aicore_num: int, op_vectorcore_num: int, stream=None)。
审查结论:无问题。JSON schema 签名与新接口定义一致,stream=None 正确反映了可选参数的语义。


代码审查
Now I have all the context I need. Let me compile my findings.
审查总结
本次变更包含 3 个文件,逐文件审查结果如下:
| 文件 | 结论 |
|---|---|
torch_npu/npu/npugraph_ex/scope/__init__.py |
发现问题 2 项(P2 ×1,P3 ×1) |
test/dynamo/test_npugraph_ex.py |
无新增问题(测试为已有模式的合理扩展) |
test/torch_npu_schema.json |
无问题(签名文档正确更新) |
发现统计:
- P2:1 项 — wrapper 无条件传递
stream=stream关键字参数,对未同步升级的底层 torchair 实现构成兼容性风险 - P3:1 项 —
stream参数缺失类型注解,与同签名的其他参数不一致
整体风险评估:中等。核心功能变更(添加 stream 可选参数)本身设计合理,向后兼容(stream=None 默认值)。主要风险在于 wrapper 层始终以关键字形式传递 stream 给底层实现,在跨仓协同升级出现版本偏差时会导致所有调用(包括不传 stream 的旧用法)直接 runtime 崩溃。建议对 stream 为 None 时使用原有位置参数调用路径,以消除此兼容性风险。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 3 |
💬 仅评论


🔵 Low Priority
第2310行:签名字符串正确反映了新增的 stream=None 参数,JSON key "torch_npu.npu.npugraph_ex.scope.limit_core_num" 与实际模块路径一致,未发现拼写错误或格式问题。
该文件是本次变更的配套文档更新,与 Python 代码变更保持一致。
建议:无需修改,签名正确。


🔵 Low Priority
第4行:op_aicore_num 和 op_vectorcore_num 均有 : int 类型注解,但新增的 stream 参数无任何类型提示,与同一函数签名的风格不一致。
虽然这不是功能缺陷,但缺失类型注解会降低代码可读性,且 IDE/类型检查器无法对 stream 提供类型推导与校验。合理的注解应为 stream: Optional[torch.npu.Stream] = None(需从 typing 导入 Optional)。
建议:为 stream 参数添加类型注解,例如 stream: Optional[torch.npu.Stream] = None,与其他参数保持风格一致。


🟡 Medium Priority
变更后的 wrapper limit_core_num 始终将 stream 以关键字参数形式传递给底层 scope.limit_core_num(第6行:stream=stream),即使 stream 取默认值 None 时也是如此。
受影响的合约/行为:旧版 scope.limit_core_num(来自 torch_npu.dynamo.npugraph_ex,实际由 torchair 提供)的签名为 (op_aicore_num, op_vectorcore_num),不接受 stream 关键字参数。
失效模式:若 torchair 包未同步升级,所有 对 limit_core_num 的调用(包括不传 stream 的现有用法,如已有测试 test_limit_core_num 第175行)都会抛出 TypeError: limit_core_num() got an unexpected keyword argument 'stream'。
触发条件:torchair 版本未包含对应的 stream 参数支持(PR #3181),而本变更已合入。虽然此次发布是协同进行的,但在部分环境升级或版本回退场景下会直接 runtime 崩溃。
建议:在 wrapper 中判断 stream 是否为 None,仅在非 None 时才以关键字参数传递,保持对旧版 torchair 的向后兼容。
|
6 | + def limit_core_num(op_aicore_num: int, op_vectorcore_num: int, stream=None): |
|
7 | + from torch_npu.dynamo.npugraph_ex import scope |
|
8 | + if stream is not None: |
| 6
| - return scope.limit_core_num(op_aicore_num, op_vectorcore_num, stream=stream) |
|
9 | + return scope.limit_core_num(op_aicore_num, op_vectorcore_num, stream=stream) |
|
10 | + return scope.limit_core_num(op_aicore_num, op_vectorcore_num) |


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


/approve


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




【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】