Pull Request已成功合入, 合并人@ascend-robot
(感谢 bellatan 的贡献)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 | ✅ liujunzhu, hbhu_bin (2/2) | ✅ liujunzhu (1/1) |
| torch_npu/npu | ✅ liujunzhu, hbhu_bin (2/2) | ✅ liujunzhu (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
bellatan, thanks for your pull request. All authors of the commits have signed the CLA. 👍


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


compile


Ascend docs pipeline is running...


Ascend docs pipeline is running...


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


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


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


/approve




The repo or branch is not access to PR-cooperate, please check the current repo https://gitcode.com/Ascend/pytorch.git, branch=v2.10.0


The repo or branch is not access to PR-cooperate, please check the current repo https://gitcode.com/Ascend/pytorch.git, branch=v2.10.0


【合入来源】
【修改方案】
1. device 入参类型缺少校验,导致非法 device 未按预期报错
API:
set_device_limit(device, cube_num, vector_num)、get_device_limit(device)API 原始约束:
set_device_limit和get_device_limit的device参数语义是指定 NPU 设备卡号,应传入明确的 NPU 设备 ID。当前问题: 传入
None和float等非int类型时未报错,不符合 API 参数约束。根因分析: 原实现中对入参
device使用了_get_device_index(device, optional=True)对入参device进行兼容性处理,导致约束之外的非法入参没有被及时拒绝。解决方案:
针对
set_device_limit/get_device_limit这两个 API,不再使用_get_device_index(device, optional=True)做宽松解析,而是直接按照 API 约束对原始device参数做严格校验。新加校验规则:
device必须是int;device不能是bool;if isinstance(device, bool) or not isinstance(device, int): raise TypeError( "device must be an int, but got {}{}".format( type(device).__name__, pta_error(ErrCode.TYPE) ) )涉及的修改文件:
torch_npu/npu/npu_config.py2. allow_hf32 入参类型缺少校验,导致非 bool 入参被错误接受
API:
matmul.allow_hf32、conv.allow_hf32API 原始约束:
torch_npu.npu.matmul.allow_hf32的语义是控制 MatMul 类算子是否允许使用 HF32 计算,应作为布尔型配置开关使用。torch_npu.npu.conv.allow_hf32的语义是控制 Conv 类算子是否允许使用 HF32 计算,应作为布尔型配置开关使用。当前问题:
allow_hf32缺少 bool 类型校验,传入非 bool 类型没有报错,不符合 API 参数约束。根因分析: 原实现直接
"enable" if value else "disable",根据 Python 对象的真假值进行判断,未判断value是否为bool类型,导致非法类型未被拒绝。解决方案: 新增
isinstance(value, bool)校验,非 bool 类型直接抛出TypeError,避免非法入参被隐式转换为开关配置。在_allowHF32Matmul.__setattr__和_allowHF32Conv.__setattr__的allow_hf32分支中增加 bool 类型校验。新加校验规则:
allow_hf32必须是bool;True或False;int、str、None、list、dict等非 bool 类型均抛出TypeError。if name == "allow_hf32": if not isinstance(value, bool): raise TypeError( "allow_hf32 must be a bool, but got {}{}".format( type(value).__name__, pta_error(ErrCode.TYPE) ) )涉及的修改文件:
torch_npu/npu/npu_config.py3. 用例适配
用例:test\nn\test_module_hooks.py,用例名:test_hook_inplace
问题:用例ci失败,报错正则匹配失败
根因:改用例预期报错的接口有变更,torch==2.12预期报错接口名为BackwardHookFunctionBackward,torch==2.13预期报错接口名变更为BackwardHookFunction。
解决:开放用例,用例报错提示适配,兼容两个版本的torch:
with self.assertRaisesRegex(RuntimeError, "Output 0 of BackwardHookFunctionBackward is "修改为with self.assertRaisesRegex(RuntimeError, "Output 0 of BackwardHookFunction(Backward)? is "with self.assertRaisesRegex(RuntimeError, "BackwardHookFunction(Backward)? is a view "修改为with self.assertRaisesRegex(RuntimeError, "Output 0 of BackwardHookFunction(Backward)? is "【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
已有用例本地验证pass,CI pass
新加用例:test/npu/test_torch_npu.py


已有用例:test/npu/test_torch_backends.py

已有用例:test/nn/test_module_hooks.py

【CheckList】