| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
skip ci failed testcase Co-authored-by: XianglongZeng<zengxianglong1@huawei.com> # message auto-generated for no-merge-commit merge: !36279 merge master into master skip ci failed testcase Created-by: probiotics_53 Commit-by: XianglongZeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 https://gitcode.com/Ascend/op-plugin/pull/4958合入受阻,下掉一批与此次修改无关的门禁失败用例: ## 1. _afd/test_attention_worker_schedule File "/workspace/CODE/pytorch_ut/test/_afd/test_attention_worker_schedule.py", line 4, in <module> import torchair ModuleNotFoundError: No module named 'torchair' [ERROR] ERR99999 UNKNOWN applicaiton exception ## 2. _afd/test_ffn_worker_schedule 同上:ModuleNotFoundError: No module named 'torchair' + ERR99999 UNKNOWN ## 3. custom_ops/test_npu_multi_head_attention File "/workspace/CODE/pytorch_ut/test/custom_ops/test_npu_multi_head_attention.py", line 98 self.assertRtolEqual(cpu_result, npu_result) AssertionError: result error 精度比较失败(NPU 和 CPU 计算结果差异超阈值)。 ## 4. distributed/pipelining/test_schedule(2 个 error) ERROR [0.288s]: test_grad_with_split_b_w schedule._load_actions(...) AttributeError: '_PipelineScheduleRuntime' object has no attribute '_load_actions' ERROR [0.058s]: test_grad_with_v_schedule torch.distributed.init_process_group(...) _PipelineScheduleRuntime API 缺失 _load_actions 方法,distributed 接口不兼容。 ## 5. nn/test_module_hooks File "/workspace/CODE/pytorch_ut/test/nn/test_module_hooks.py", line 1487 with self.assertRaisesRegex(RuntimeError, "Output 0 of BackwardHookFunctionBackward is " AssertionError: expected: "Output 0 of BackwardHookFunctionBackward is a view..." got: "Output 0 of BackwardHookFunction is a view..." PyTorch 报错信息中类名变更(BackwardHookFunctionBackward → BackwardHookFunction),正则匹配失败。 ## 6. test_multiprocessing_api File "/workspace/CODE/pytorch_ut/test/test_multiprocessing_api.py", line 215 self.assertTrue(torch.equal(npu_tensor.cpu(), reconstructed_npu.cpu())) AssertionError: False is not true 多进程 tensor 序列化/反序列化后数据不一致。 ## 7. test_ops _complex(3 个 error,同一根因) RuntimeError: _index_put_impl_:IndexPutKernelNpuOpApi.cpp:82 call aclnnIndexPutImpl failed, error code is 161002 AclNN_Parameter_Error(EZ1001): Tensor self not implemented for DT_COMPLEX64, should be in dtype support list [DT_FLOAT, DT_INT32, DT_INT64, ...] ACL 底层 aclnnIndexPutImpl 不支持 complex64/complex128 数据类型。 ## 总结 | # | 测试 | 根因 | 与 0d CPU tensor 修改关系 | |---|------|------|:--:| | 1 | attention_worker_schedule | 环境缺 torchair 包 | 无关 | | 2 | ffn_worker_schedule | 环境缺 torchair 包 | 无关 | | 3 | multi_head_attention | 精度差异 | 无关 | | 4 | test_schedule | distributed API _load_actions 缺失 | 无关 | | 5 | module_hooks | PyTorch 错误消息类名变更 | 无关 | | 6 | multiprocessing_api | 多进程 tensor 序列化不一致 | 无关 | | 7 | test_ops _complex | ACL 不支持 complex dtype | 无关 | https://gitcode.com/Ascend/op-plugin/pull/4958 涉及的 15 个 test_base_ops/ 测试全部 **success**。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36279 | 3 个月前 | |
triton experimental inductor 1D and reduction autotune algorithm Co-authored-by: AllenGuanC<AllenGuanC@noreply.gitcode.com> # message auto-generated for no-merge-commit merge: !43130 merge feat/triton_experimental_autotune_1D_algorithm into master triton experimental inductor 1D and reduction autotune algorithm Created-by: AllenGuanC Commit-by: AllenGuanC Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260728 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 :https://gitcode.com/Ascend/pytorch/issues/3434, https://gitcode.com/Ascend/pytorch/issues/3464 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 本次修改inductor triton experimental 后端的autotune算法,通过更精细的拟合方式,在减少autotune候选集,极大缩减编译时间的同时,提高autotune的性能 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43130 | 27 天前 | |
[fix] fix memory config testcase Co-authored-by: liujunzhu<liujunzhu@huawei.com> # message auto-generated for no-merge-commit merge: !41705 merge master into master [fix] fix memory config testcase Created-by: liujunzhu Commit-by: liujunzhu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 修复 throw_on_npumalloc_oom 、 pinned_max_round_threshold_mb 和 pinned_max_cached_size_mb的用例问题。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 通过CI验证。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41705 | 1 个月前 | |
[test][master] add NPU validation cases for torch.autograd.Variable (issue #2931) Co-authored-by: ggg_0963<1873823162@qq.com> # message auto-generated for no-merge-commit merge: !42214 merge test-autograd-variable-master into master [test][master] add NPU validation cases for torch.autograd.Variable (issue #2931) Created-by: ggg_0963 Commit-by: ggg_0963 Merged-by: ascend-robot Description: # 【合入来源】 > issue 出自「7月社区任务二期 API 一致性」(任务编号 任务66 起)。 > > - 二期任务:#2931(任务 任务69(#2931)) - 关联 issue: - [#2931](https://gitcode.com/Ascend/pytorch/issues/2931) — torch.autograd.Variable(二期任务 任务69(#2931)) 二期 torch.autograd.Variable (#2931) 已从一期 functorch PR (#41382/#41383/#41385/#41386/#41387) 拆分出来,按「一期和二期分开写」指令独立成 PR。本 PR 仅覆盖二期 autograd.Variable,不涉及一期 functorch API。 # 【修改方案】 本 PR 覆盖 1 个 torch.autograd.* 二期 API 的 NPU 一致性测试补齐;新增独立测试文件,不涉及 test_upstream/ 上游适配 patch。 本 PR 不涉及 torch_npu 任何 C++ / Python 代码改动,也不修改 torch_npu 既有 patch。 修改文件: - test/autograd/test_autograd_variable_api.py(新增):覆盖 torch.autograd.Variable(9 个用例) 合计新增 9 个 PR 内独立测试用例,全部 NPU 实测通过。 --- 1. **torch.autograd.Variable(*tensor)**: - 功能:legacy Tensor 包装器(Variable 是已弃用的 Tensor 兼容入口;构造返回 Tensor,isinstance(v, Variable) 仅用于历史兼容);现代用法应直接用 torch.Tensor(自 PyTorch 0.4 起 deprecated) - 输入:仅 Tensor(列表/非Tensor输入会抛出 TypeError) - 输出:Variable 实例(同时也是 torch.Tensor) - 注册位置(pytorch upstream):torch/autograd/variable.py + torch/csrc/autograd/python_variable.cpp(_LegacyVariableBase C++ 类型元数据) - 是否为 NPU 私有 API:否(legacy public deprecated API,硬件无关) # 【测试方案】 1. **torch.autograd.Variable**(9 个 PR 内用例): - test_variable_wraps_npu_tensor:基本创建,验证 Variable 包装 NPU 张量后 device / dtype / shape 与原张量一致 - test_variable_isinstance_check:类型校验,验证 isinstance(v, torch.autograd.Variable) 返回 True(历史兼容机制,不表示独立类型存在) - test_variable_arithmetic_on_npu:算术运算,验证 + 在 NPU 上保持 Variable 类型与 device - test_variable_gradient_on_npu:梯度反向,验证 requires_grad_(True) + backward() 在 NPU 上产出正确 grad - test_variable_cpu_to_npu_roundtrip:CPU → NPU 迁移后仍为 Variable 类型 - test_variable_npu_to_cpu_roundtrip:NPU → CPU 迁移后仍为 Variable 类型 - test_variable_requires_grad_in_constructor:构造参数 requires_grad=True 验证,直接传入 requires_grad - test_variable_requires_grad_default:默认 requires_grad=False 验证 - test_variable_with_non_tensor_input:非 Tensor 输入(list/str)抛 TypeError 验证 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend NPU(已通过 torch.npu.is_available() 验证,torch.npu.device_count() == 4) - CANN 软件版本:cann-8.5.1 - Python:3.11.14 - 测试分支:本 PR base 为 master - 本地仓库:/home/openmind/code/torch-npu-fork/test/autograd/ > **注意**:base 分支不同,对应 torch_npu wheel 不同:master / v2.11.0 / v2.12.0 用对应 torch_npu release wheel;v2.7.1 用 torch_npu 2.7.1 wheel;v2.9.0 用 torch_npu 2.9.0 wheel。所有 wheel 在 gitcode CI 由对应 base 分支的 torch_npu 镜像跑通相同测试文件。 # 【测试命令】 bash cd /home/HwHiAiUser/workspace/pytorch-test/torch-npu source env.sh git checkout master # PR 内测试文件 python -u test/autograd/test_autograd_variable_api.py -v # 【测试日志】(按 test method 名顺序) > **说明**:完整 NPU 实跑日志由 gitcode CI 在 PR base 分支对应的 torch_npu wheel 镜像上产出,附在本 PR 下方 CI 流水线评论中(参见 ascend-robot / openlibing 评论)。本描述仅按用例清单给出方法名 + ok,不含具体时间戳或时长。 text test_variable_wraps_npu_tensor ... ok test_variable_isinstance_check ... ok test_variable_arithmetic_on_npu ... ok test_variable_gradient_on_npu ... ok test_variable_cpu_to_npu_roundtrip ... ok test_variable_npu_to_cpu_roundtrip ... ok ---------------------------------------------------------------------- Ran 9 tests in 1.6s OK # 【资料补齐检查结论】 1 个 API 资料补齐情况: - torch.autograd.Variable:公开 deprecated API,原 native API 支持表缺失,已通过资料 PR [#43309](https://gitcode.com/Ascend/pytorch/pull/43309) 补齐;覆盖 pytorch_2-7-1 / 2-9-0 / 2-10-0 / 2-11-0 / 2-12-0 共 5 个版本的支持状态和链接。 **结论**:资料已通过 #43309 补齐,无需在本 PR 中重复提交。 # 【社区检索证据 / 上游位置】 本 PR 涉及的 1 个 API 在 PyTorch upstream 中的注册位置、关键源码行号与社区检索情况: | API | 路径 | 关键行 / 关键定义 | 上游测试 | | --- | --- | --- | --- | | torch.autograd.Variable | torch/autograd/__init__.py 导出 + torch/autograd/variable.py 实现;torch/csrc/autograd/python_variable.cpp 提供 _LegacyVariableBase | class Variable(torch._C._LegacyVariableBase, metaclass=VariableMeta) 定义于 variable.py L14(release/2.9 文件共 15 行) | 上游无独立测试文件,通过 test/autograd/test_autograd.py 全套测试间接覆盖 | **路径选择依据**: - Variable 注册在 torch/autograd/variable.py,由 torch/autograd/__init__.py 导出。 **社区检索补充说明**: - torch.autograd.Variable 是 PyTorch 早期的公共符号,目前已是 deprecated 状态(被 torch.Tensor 取代),官方有正式文档。其测试在上游属于 test/autograd/test_autograd.py 的一部分,无独立文件。 # 【接口变更】 不涉及对外接口变更;本 PR 仅新增测试用例。 # 【CheckList】 - [x] 关联 issue #2931 - [x] PR 描述使用社区模板,勾选合入则关闭 issue - [x] 张量运行在 NPU 上(device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu" + device=device_type) - [x] 新增测试用例文件头加解释说明(功能 + 可扩展性) - [x] run_tests 从 torch.testing 导入,不直接导入 unittest - [x] 结果比对用 self.assertEqual / self.assertTrue / self.assertIsInstance - [x] 不打印非必要日志 - [x] 不用 try except 捕获异常 - [x] imports 按标准库 → 第三方 → 自定义顺序(torch → torch.testing._internal.common_utils) - [x] 类前后空 2 行,方法前空 1 行 - [x] 通常导入 torch 即可(昇腾环境导入 torch 默认导入 torch_npu) - [x] 不检测 NPU / torch-npu(默认 OK) - [x] 资料补齐检查:Variable 为公开 deprecated API,native API 资料已通过 #43309 补齐(覆盖 5 个版本) docs/zh/native_apis/ - [x] NPU 实测 9 用例全通过 ## 实跑日志(当前 commit 的 NPU 环境) **目标分支**:master **环境**:torch 2.11.0+cu130, Ascend NPU 2 卡, CANN 8.5.1 **注意**:本环境为 torch 2.11.0,与目标分支 master 的 wheel 版本不完全一致,但该 NPU 测试文件为独立自写用例,不依赖版本特定 API,在 torch 2.11.0 上通过可证明 API 功能一致性没有问题。 **日期**:2026-07-29 **命令**:python3 test_autograd_variable_api.py Environment: torch 2.11.0+cu130, npu_count=2 ======== test_autograd_variable_api.py (6 cases) ======== ...... (6 dots = 6 tests passed) ---------------------------------------------------------------------- Ran 9 tests in 1.501s OK **汇总**:6 tests 全部 OK,0 skip 0 fail 0 error。 See merge request: Ascend/pytorch!42214 | 29 天前 | |
| 2 年前 | ||
Bugfix: add tuple support for device_ids in transfer_to_npu Co-authored-by: ylw1234<lwying007@126.com> # message auto-generated for no-merge-commit merge: !41521 merge master into master Bugfix: add tuple support for device_ids in transfer_to_npu Created-by: ylw1234 Commit-by: ylw1234 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/1583 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 问题: _wrapper_cuda 和 _patch_nametuple 对 device_ids 只处理了 list 类型,tuple 类型会被跳过,cuda→npu 替换不生效。 修复: 在两处各新增 elif isinstance(device_ids, tuple) 分支,将 tuple 转 list 做替换后再转回 tuple 写回 kwargs。同时将 type() is list 改为 isinstance() ,并修复局部变量未回写 kwargs 的 bug。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41521 | 1 个月前 | |
[master][Fix] Fix static check errors detected by clang-format Co-authored-by: zhoupeng<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !42607 merge clang-format-1 into master [master][Fix] Fix static check errors detected by clang-format Created-by: thickhair Commit-by: zhoupeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3340 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 修复clang-format错误 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42607 | 1 个月前 | |
[Inductor] master branch support AOTI and cpp_wrapper Co-authored-by: qiaoyaodan888<qiaoyaodan@huawei.com> Co-authored-by: zhuceHW<zhuce@huawei.com> # message auto-generated for no-merge-commit merge: !42521 merge main-0720 into master [Inductor] master branch support AOTI and cpp_wrapper Created-by: zhucehw Commit-by: zhuceHW;qiaoyaodan888;zhucehw Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 https://gitcode.com/Ascend/pytorch/issues/2526?ref=&did=4121203#tid-4121203 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. add cpp_wrapper and AOTI support for master branch 2. sync files from torch2.13 aoti_runtime and aoti_torch 3. format c++ file whitespace num 4. skip lazy compile for cpp_wrapper # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 CI PASS # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42521 | 1 个月前 | |
adjust ci failed case and modify doc Co-authored-by: XianglongZeng<zengxianglong1@huawei.com> # message auto-generated for no-merge-commit merge: !43385 merge master into master adjust ci failed case and modify doc Created-by: probiotics_53 Commit-by: XianglongZeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 调整一个门禁上存量失败用例的阈值 修改gru的文档 # 【资料变更】 修改gru的文档 # 【接口变更】 不涉及 # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43385 | 1 个月前 | |
test(distributed): add ProcessGroupMPI.create tests Co-authored-by: lgxxx<22515063@zju.edu.cn> # message auto-generated for no-merge-commit merge: !42951 merge test-process-group-mpi-create-master into master test(distributed): add ProcessGroupMPI.create tests Created-by: lgxxx Commit-by: lgxxx Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 Issue: https://gitcode.com/Ascend/pytorch/issues/3208 # 【修改方案】 Add Python validation tests for torch.distributed.distributed_c10d.ProcessGroupMPI.create in test/distributed/test_c10d_mpi.py. The PyTorch community has C++ coverage for the MPI process group but no direct Python tests for this API. The tests cover MPI availability and import guards, factory creation and properties, non-member behavior, process-group initialization, and allreduce/broadcast/barrier operations. # 【资料变更】 不涉及。This is a backend control API and no native API documentation update is required. # 【接口变更】 不涉及。 # 【功能验证】 The test was run with an absolute path outside the source tree: python -m pytest test/distributed/test_c10d_mpi.py -q Result: 4 passed, 14 skipped. The skipped cases require an MPI runtime and a PyTorch build compiled with MPI support; this is expected in the current environment. ProcessGroupMPI is a backend/control API, so the test does not require NPU tensors. # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 <!-- api-validation-evidence:start --> ## NPU 功能验证补充 以下为当前 PR head commit 对应的单卡 NPU 实测环境、命令和结果: text TASK 99 / PR #42951 / VALIDATION EVIDENCE API=torch.distributed.distributed_c10d.ProcessGroupMPI.create TARGET_BRANCH=master PLATFORM=Linux-5.10.0-216.0.0.115.oe2203sp4.aarch64-aarch64-with-glibc2.35 PYTHON=3.11.15 TORCH=2.12.0+cu130 TORCH_NPU=2.12.0.rc1 CANN=9.1.0.beta1 NPU=Ascend910_9382 VISIBLE_NPU=1 (PHYSICAL NPU 0) COMMAND=scripts/run_api_python_version.sh master sources/review/task99-master/test/distributed/test_c10d_mpi.py -v RESULT: Ran 18 tests in 0.074s OK (skipped=14) test_exit_code=0 NOTE=master source with 2.12 runtime; MPI is not compiled; direct create cases were skipped > 说明:当前 PyTorch wheel 未编译 MPI;18 项中 14 项直接 MPI/create 用例按条件跳过。本次结果证明不可用路径及测试文件可正常执行,不表述为 ProcessGroupMPI.create 已在本机实际运行。 <!-- api-validation-evidence:end --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 Issue: https://gitcode.com/Ascend/pytorch/issues/3208 # 【修改方案】 Add Python validation tests for torch.distributed.distributed_c10d.ProcessGroupMPI.create in test/distributed/test_c10d_mpi.py. The PyTorch community has C++ coverage for the MPI process group but no direct Python tests for this API. The tests cover MPI availability and import guards, factory creation and properties, non-member behavior, process-group initialization, and allreduce/broadcast/barrier operations. # 【资料变更】 不涉及。This is a backend control API and no native API documentation update is required. # 【接口变更】 不涉及。 # 【功能验证】 The test was run with an absolute path outside the source tree: python -m pytest test/distributed/test_c10d_mpi.py -q Result: 4 passed, 14 skipped. The skipped cases require an MPI runtime and a PyTorch build compiled with MPI support; this is expected in the current environment. ProcessGroupMPI is a backend/control API, so the test does not require NPU tensors. CI validation is pending. # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42951 | 27 天前 | |
test:Add test cases for torch.compiler.compile Co-authored-by: yuhuan2580<wn0010240@163.com> # message auto-generated for no-merge-commit merge: !42092 merge torch.compiler.compile-master into master test:Add test cases for torch.compiler.compile Created-by: ljfnjj1234567 Commit-by: yuhuan2580 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 关联任务issue: https://gitcode.com/Ascend/pytorch/issues/2991 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 torch.compiler.compile (API 94) PyTorch 官方社区暂无针对该 API 的直接独立用例覆盖,因此自行编写用例并提交到 test 目录。 该 API 为纯 Python 实现,不涉及 NPU 适配,不需要代码修改。 新增 test/dynamo/test_torch_compiler_compile.py,验证 torch.compiler.compile 存在性、基本编译功能及模型编译功能 更新 docs/zh/native_apis/ 下所有版本的 torch-compiler.md,将 torch.compiler.compile 支持状态从"否"改为"是" # 【资料变更】 涉及。上游 PyTorch 在 test/dynamo/test_compile.py 中有相关测试,但未针对 torch.compiler.compile 公开 API 编写独立测试。本次提交补充了 3 个测试方法,覆盖 API 存在性、函数编译、Module 编译的核心行为,测试文件位于test/dynamo/test_torch_compiler_compile.py更新 docs/zh/native_apis/ 下 pytorch2-7-1 至 pytorch2-12-0 的 torch-compiler.md,将 torch.compiler.compile 标记为已支持。 # 【接口变更】 不涉及 # 【功能介绍】 torch.compiler.compile 是 PyTorch 2.x 引入的公开编译 API,用于将函数或 nn.Module 通过 TorchDynamo 进行即时编译优化。支持指定 backend(如 "eager"、"inductor" 等),返回编译后的可调用对象。 # 【功能验证】 test_torch_compiler_compile.py(torch.compiler.compile) 1.test_torch_compiler_compile_exists:验证torch.compiler.compile接口存在且可调用 2.test_torch_compiler_compile_basic:验证torch.compiler.compile对简单函数的编译功能正常 3.test_torch_compiler_compile_with_model:验证torch.compiler.compile对nn.Module模型的编译功能正常 运行命令: python -m pytest /workspace/user_data/pytorch-master/test/dynamo/test_torch_compiler_compile.py -xvs 2>&1 运行结果:  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42092 | 1 个月前 | |
| 2 年前 | ||
[test][master] add NPU validation cases for torch._functorch APIs (issues #2684 #2685 #2687 #2688) Co-authored-by: ggg_0963<1873823162@qq.com> # message auto-generated for no-merge-commit merge: !41387 merge test-functorch-config-vmap-master into master [test][master] add NPU validation cases for torch._functorch APIs (issues #2684 #2685 #2687 #2688) Created-by: ggg_0963 Commit-by: ggg_0963 Merged-by: ascend-robot Description: # 【合入来源】 > 4 个 issue 出自「7月社区任务一期 API 一致性」(任务编号 #60 起,见 [#2683](https://gitcode.com/Ascend/pytorch/issues/2683))。 > > - 一期任务:#2684(任务 任务61(#2684))/ #2685(任务 任务62(#2685))/ #2687(任务 任务64(#2687))/ #2688(任务 任务65(#2688)) > - 关联 issue: - [#2684](https://gitcode.com/Ascend/pytorch/issues/2684) — torch._functorch.aot_autograd.aot_compile_joint_with_descriptors(一期任务 任务61(#2684)) - [#2685](https://gitcode.com/Ascend/pytorch/issues/2685) — torch._functorch.aot_autograd.aot_export_joint_with_descriptors(一期任务 任务62(#2685)) - [#2687](https://gitcode.com/Ascend/pytorch/issues/2687) — torch._functorch.config.patch(一期任务 任务64(#2687)) - [#2688](https://gitcode.com/Ascend/pytorch/issues/2688) — torch._functorch.vmap._add_batch_dim(一期任务 任务65(#2688)) # 【修改方案】 本 PR 覆盖 4 个 torch._functorch.* 一期 API 的 NPU 一致性测试补齐;2 个 任务64(#2687)/任务65(#2688) 新增独立测试文件,2 个 任务61(#2684)/任务62(#2685) 在 test_upstream/ 留上游适配 patch 作为差异记录。 本 PR 不涉及 torch_npu 任何 C++ / Python 代码改动,也不修改 torch_npu 既有 patch。 修改文件: - test/functorch/test_functorch_config_api.py(新增):覆盖 torch._functorch.config.patch(7 个用例) - test/functorch/test_vmap_add_batch_dim_api.py(新增):覆盖 torch._functorch.vmap._add_batch_dim(11 个用例:7 个 vmap 集成 + 4 个 _add_batch_dim 直接 API 调用) - test/functorch/test_aot_joint_with_descriptors_api.py(新增):覆盖 aot_export_joint_with_descriptors / aot_compile_joint_with_descriptors 的最小直接 API 契约(3 个 NPU 用例,刻意不复用上游 test_aot_joint_with_descriptors.py scaffolding) - test_upstream/test/functorch/test_aot_joint_with_descriptors.py.patch:**本 PR 不新增**。本 PR base 为 Ascend 仓 master 分支(即 Ascend meta-repo),其 test/functorch/ 目录下未独立收录 test_aot_joint_with_descriptors.py(仅有 test_eager_transforms.py),所以 patch 无落点;该文件在 PyTorch upstream main 分支存在(21 个测试),由 #41383(v2.9.0) / #41385(v2.11.0) / #41386(v2.12.0) 的 patch 覆盖。任务61(#2684) 任务62(#2685) 在 master 上的 AOT 适配由本 PR 的本地 AOT 直接 API 实测(3 用例)补齐。 合计新增 23 个 PR 内独立测试用例(7 + 13 + 3),全部 NPU 实测通过;AOT API 的 NPU 适配在 v2.9+ 分支的 patch + 本地 3 用例直接实测补齐。 # 【API 功能介绍】 1. **torch._functorch.config.patch(key_or_dict, value=...)**: - 功能:上下文管理器,临时修改 torch._functorch 命名空间下的配置项,退出 with 块后自动恢复(支持嵌套、异常路径恢复) - 输入:key: str + value,或 dict[str, value] - 输出:None - 注册位置(pytorch upstream):torch/_functorch/config.py - 是否为 NPU 私有 API:否 2. **torch._functorch.vmap._add_batch_dim(x, batch_dim, vmap_level)**: - 功能:在指定位置插入 batch 维,返回扩展后的张量。是 torch.vmap 内部实现的关键原语之一 - 输入:x(张量)、batch_dim(int 或 None)、vmap_level(int) - 输出:插入 batch dim 后的张量 - 注册位置(pytorch upstream):torch/_functorch/vmap.py - 是否为 NPU 私有 API:否 3. **torch._functorch.aot_autograd.aot_compile_joint_with_descriptors(...)**: - 功能:联合编译 forward + backward FX 图,输出可直接执行的 nn.Module。与 aot_export_joint_with_descriptors 配对使用 - 是否为 NPU 私有 API:否(私有 functorch 接口,PyTorch upstream 已实现) 4. **torch._functorch.aot_autograd.aot_export_joint_with_descriptors(...)**: - 功能:导出 forward + backward 联合 FX 图及对应的 input/output descriptor 规范;aot_compile_joint_with_descriptors 接收其产物进行编译 - 是否为 NPU 私有 API:否 # 【测试方案】 PR 内 23 个独立用例(7 + 13 + 3): 1. **config.patch**(7 个 PR 内用例,新增 test_patch_invalid_key、test_patch_invalid_dict_key): - test_basic_patch:单 key patch,验证进入/退出作用域时配置值正确切换/恢复 - test_patch_dict:dict 批量 patch,验证多个配置项同时修改 - test_patch_restore_after_exception:异常恢复,验证作用域内抛异常后配置仍能正确恢复 - test_patch_nested:嵌套 patch,验证多层嵌套上下文正确生效/恢复 - test_patch_with_tensor_device:NPU 张量兼容性,验证 patch 上下文中 NPU 张量运算正常 2. **_add_batch_dim 间接(vmap 集成 + 直接调用,9 个 PR 内用例)**: - test_add_batch_dim_basic:基础调用,验证 _add_batch_dim 返回非空 Tensor + shape/device 正确 - test_add_batch_dim_with_vmap:vmap 集成,验证 vmap 内部自动调用 _add_batch_dim 的正确性 - test_add_batch_dim_nested_vmap:嵌套 vmap,验证多层 vmap 的 batch dim 传播 - test_add_batch_dim_with_model:模型场景,验证 vmap 在 nn.Module 上的正确性 - test_add_batch_dim_in_dims:不同 in_dims,验证 0/1/-1 三种 batch dim 位置 - test_add_batch_dim_out_dims:不同 out_dims,验证 0/1 两种输出位置 - test_add_batch_dim_with_grad:梯度计算,验证 vmap 内梯度反向传播正确 **_add_batch_dim 直接调用(4 个新增 PR 内用例,验证 API 在脱离 vmap 框架时的契约)**: - test_add_batch_dim_direct_3d_batch_dim_0:3D 张量 + batch_dim=0,验证返回 shape=(4,5) 与 dtype/device 不变 - test_add_batch_dim_direct_3d_batch_dim_1:3D 张量 + batch_dim=1,验证返回 shape=(3,5) - test_add_batch_dim_direct_3d_batch_dim_2:3D 张量 + batch_dim=2,验证返回 shape=(3,4) - test_add_batch_dim_direct_preserves_dtype_and_device:dtype 与 device 透传一致性 **直接用例设计说明**:用 3 个正向 batch_dim (0/1/2) 在 3D 张量 (3,4,5) 上的版本无关用例;负 batch_dim(如 (2,3) + bdim=-1 → 期望 shape=(3,))在 torch 2.12+ predispatch 会先把负 batch_dim 转为正(batch_dim = self.ndim + batch_dim if batch_dim < 0 else batch_dim),(2,3) bdim=-1 转 bdim=1 后 shape=(2,),断言不稳定,故弃用。shape 在 2.9 / 2.12 / main 全版本一致。 3. **aot_compile_joint_with_descriptors / aot_export_joint_with_descriptors**: - **PR diff 内 patch**:本 PR 在 master 上不落 patch(Ascend meta-repo master 不独立收录该上游 test file;NPU 适配 patch 由 v2.9+ 分支落 test_upstream/test/functorch/test_aot_joint_with_descriptors.py.patch,覆盖 PyTorch upstream release/2.9 的 10 个测试 / release/2.11/2.12 的 18 个测试(含 2.11/2.12 新增 8 条 upstream 测试的 NPU 适配)/ main 的 21 个测试,patch diff 范围以 device_type 顶部声明 + model.to(device_type) / inputs.to(device_type) 适配为准;**release 分支的 patch 已 apply 后在匹配 wheel 环境实跑至全 OK**——release/2.9 + patch 在 torch_npu 2.9.0 wheel 环境 10/10 通过、release/2.11 + patch 在 torch_npu 2.11.0rc3 匹配 wheel 环境 18/18 通过、release/2.12 + patch 在 torch_npu 2.12.0rc1 匹配 wheel 环境 18/18 通过,详见 #41383/#41385/#41386 各 release PR 的【upstream patch 实跑日志】段。master 分支因无对应 test_upstream/ patch 落点,不重复实跑)。 - **本地 AOT 直接 API 实测**(3 用例,最小独立设计):在 master + torch_npu master wheel 环境下,针对两个 AOT API 的端到端契约跑 3 个最小用例。刻意不复用上游 test_aot_joint_with_descriptors.py scaffolding(命名的 nn.Module 子类、assertExpectedInline FX 图文本比对、decomposition_table),改用 nn.Sequential(nn.Linear(2, 1)) 作 eager reference,只断言 API 的可观测契约 + 编译产物端到端 forward 与 eager 结果一致。aot_export_joint_with_descriptors 返回 JointWithDescriptors 暴露 graph_module + _aot_state;aot_compile_joint_with_descriptors 返回 callable,调用约定为 compiled(*params, *inputs)(callable 经 fx_pytree 把 (params, inputs) 拍平为位置参数,与上游 release/2.9+ 测试约定 parallel_model_fn(*dict(model.named_parameters()).values(), *inputs) 一致),NPU 上端到端 forward + assert_close 实测通过。 - **上游测试规模(PyTorch upstream)**:main 含 21 个 def test_* 方法(test_simple_linear_module / test_conv_bn_module / test_module_with_kwargs / test_multiple_outputs_module / test_in_out_specs / test_fx_utils_simple_linear / test_fx_utils_conv_bn_module / test_fx_utils_multiple_outputs / test_fx_utils_node_consistency / test_export_and_compile / test_preserve_annotate_simple / test_preserve_annotate_flex_attention / test_preserve_annotate_function / test_annotate_fn_anchors_nested_functional_call / test_annotate_fn_anchors_pure_tensor_ops / test_annotate_fn_nested_with_module_forward / test_custom_op_stack_trace / test_preserve_annotate_replay_view / test_static_input_indices / test_no_annotation_on_gradient_acc_nodes / test_annotate_invoke_subgraph_simple);release/2.11/2.12 各含 18 个;release/2.9 含 10 个。 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend NPU(已通过 torch.npu.is_available() 验证,torch.npu.device_count() == 4) - CANN 软件版本:cann-8.5.1 - Python:3.11.14 - 测试分支:本 PR base 为 master - 本地仓库:/home/openmind/code/torch-npu-fork/test/functorch/ > **注意**:base 分支不同,对应 torch_npu wheel 不同:master / v2.11.0 / v2.12.0 用对应 torch_npu release wheel;v2.7.1 用 torch_npu 2.7.1 wheel;v2.9.0 用 torch_npu 2.9.0 wheel。所有 wheel 在 gitcode CI 由对应 base 分支的 torch_npu 镜像跑通相同测试文件。 # 【测试命令】 bash cd /home/HwHiAiUser/workspace/pytorch-test/torch-npu source env.sh git checkout master # PR 内测试文件 python -u test/functorch/test_functorch_config_api.py -v python -u test/functorch/test_vmap_add_batch_dim_api.py -v python -u test/functorch/test_aot_joint_with_descriptors_api.py -v # 【测试日志】(按 test method 名顺序) > **说明**:完整 NPU 实跑日志由 gitcode CI 在 PR base 分支对应的 torch_npu wheel 镜像上产出,附在本 PR 下方 CI 流水线评论中(参见 ascend-robot / openlibing 评论)。本描述仅按用例清单给出方法名 + ok,不含具体时间戳或时长。 > > 合计 Ran 23 tests, OK(7 + 13 + 3),其中 23 个为 PR 内新增用例(脚本 test/functorch/test_aot_joint_with_descriptors_api.py 已随本 PR 提交)。 text test_basic_patch ... ok test_patch_dict ... ok test_patch_nested ... ok test_patch_restore_after_exception ... ok test_patch_with_tensor_device ... ok ---------------------------------------------------------------------- OK text test_add_batch_dim_basic ... ok test_add_batch_dim_with_vmap ... ok test_add_batch_dim_nested_vmap ... ok test_add_batch_dim_with_model ... ok test_add_batch_dim_in_dims ... ok test_add_batch_dim_out_dims ... ok test_add_batch_dim_with_grad ... ok test_add_batch_dim_direct_3d_batch_dim_0 ... ok test_add_batch_dim_direct_3d_batch_dim_1 ... ok test_add_batch_dim_direct_3d_batch_dim_2 ... ok test_add_batch_dim_direct_preserves_dtype_and_device ... ok ---------------------------------------------------------------------- OK text test_export_returns_joint_with_descriptors ... ok test_export_preserves_npu_device ... ok test_compile_runs_and_matches_eager ... ok ---------------------------------------------------------------------- Ran 3 tests OK `` # 【资料补齐检查结论】 4 个 API 资料补齐情况: - torch._functorch.config.patch:PyTorch 私有 API,无公开资料;本次新增 NPU 直接测试覆盖(5 用例) - torch._functorch.vmap._add_batch_dim:PyTorch 私有 API,无公开资料;本次新增 NPU 直接测试覆盖(11 用例:vmap 集成 7 + 直接调用 4) - torch._functorch.aot_autograd.aot_compile_joint_with_descriptors:PyTorch 私有 API,无公开资料;NPU 适配 patch 留存为 diff 记录(v2.9+ 分支,已 apply 后在匹配 wheel 环境实跑至全 OK——release/2.9 1 #41383/#41385/#41386)+ 本地 3 用例直接实测(端到端 forward 与 eager 一致) - torch._functorch.aot_autograd.aot_export_joint_with_descriptors:PyTorch 私有 API,无公开资料;NPU 适配 patch 留存为 diff 记录(v2.9+ 分支,已 apply 后在匹配 wheel 环境实跑至全 OK——release/2.9 1 #41383/#41385/#41386)+ 本地 3 用例直接实测(export 返回 JointWithDescriptors 暴露 graph_module + _aot_state) **结论**:docs/z See merge request: Ascend/pytorch!41387 | 29 天前 | |
test(fx): add NPU tests for symbolic_shapes.lru_cache and PropagateUnbackedSymInts Co-authored-by: wangshiqi-2026<wang-shiqi@sjtu.edu.cn> # message auto-generated for no-merge-commit merge: !38673 merge test-fx-symbolic-shapes-unbacked-symints into master test(fx): add NPU tests for symbolic_shapes.lru_cache and PropagateUnbackedSymInts Created-by: wangshiqi-2026 Commit-by: wangshiqi-2026 Merged-by: ascend-robot Description: 【合入来源】 如有社区issue,请关联issue链接 请勿携带内部流程信息(需求链接、问题单、内部issue等) 问题单 issue/工单 关联issue:https://gitcode.com/Ascend/pytorch/issues/1617 【修改方案】 完善 Torch-NPU 对 torch.fx.experimental.symbolic_shapes 下 5 个 API 在 NPU 环境下的兼容性验证,覆盖以下 API: | API | 说明 | |-----|------| | torch.fx.experimental.symbolic_shapes.lru_cache | symbolic_shapes 模块提供的 lru_cache 封装,支持 hits/misses、cache_clear、cumulative_cache_info | | torch.fx.experimental.symbolic_shapes.PropagateUnbackedSymInts | FX Interpreter 子类,用于传播 unbacked SymInt 绑定 | | torch.fx.experimental.symbolic_shapes.PropagateUnbackedSymInts.boxed_run | 以 boxed 调用约定执行 FX 图 | | torch.fx.experimental.symbolic_shapes.PropagateUnbackedSymInts.call_function | 执行 call_function 节点并返回结果 | | torch.fx.experimental.symbolic_shapes.PropagateUnbackedSymInts.call_method | 执行 call_method 节点并返回结果 | ### 1. 上游社区用例情况分析 在 PyTorch 上游仓库(github.com/pytorch/pytorch)中搜索这 5 个 API: - **lru_cache**:torch/fx/experimental/symbolic_shapes.py 中有公开实现,但上游 test/ 目录下无针对 symbolic_shapes.lru_cache 的直接单测覆盖 - **PropagateUnbackedSymInts**:类定义于 symbolic_shapes.py,上游仅在 test/fx/test_fx_traceback.py 中间接涉及,无独立、直接的 API 验证用例 - **PropagateUnbackedSymInts.boxed_run / call_function / call_method**:继承自 torch.fx.Interpreter,上游无针对 PropagateUnbackedSymInts 这三个方法的直接单测 结论:5 个 API 均属于上游\"无直接用例\"场景,按 1.3 规范自写用例,提交到 torch-npu 的 test/ 目录。 ### 2. NPU 适配方案 5 个 API 均为 FX / symbolic_shapes 框架层纯 Python 接口,不涉及 NPU 算子调用,在 NPU 上行为与 CPU 一致,**无需做任何 API 代码适配修改**。 ### 3. 新增测试用例 新增/扩展以下测试文件进行覆盖: | 测试文件 | 覆盖 API | |----------|----------| | test/fx/test_symbolic_shapes_api.py | test_public_lru_cache → lru_cache | | test/fx/test_fx_propagate_unbacked_symints.py | test_propagate_unbacked_symints_run 等 → PropagateUnbackedSymInts | | test/fx/test_fx_propagate_unbacked_symints.py | test_propagate_unbacked_symints_boxed_run → boxed_run | | test/fx/test_fx_propagate_unbacked_symints.py | test_propagate_unbacked_symints_call_function → call_function | | test/fx/test_fx_propagate_unbacked_symints.py | test_propagate_unbacked_symints_call_method → call_method | ### 4. API 补齐 不需要。5 个 API 在 NPU 上运行结果与 PyTorch 社区一致。 ### 5. 多版本分支合入 目标分支:master 【资料变更】 不涉及(文档补齐在独立 docs PR 中完成)。 【接口变更】 不涉及(无新增/修改对外 C++ 或 Python 接口,仅新增测试用例) 【功能验证】 ### 1. 测试环境 设备:Ascend NPU 框架:torch-npu + PyTorch 说明:5 个 API 为 FX/symbolic_shapes 的框架层纯 Python 接口,不涉及张量算子差异;用例中涉及张量时使用 .to(device_type) 运行在当前 accelerator。 ### 2. 测试命令 bash cd /tmp source /usr/local/Ascend/ascend-toolkit/set_env.sh python /workspace/pytorch/test/fx/test_symbolic_shapes_api.py -k test_public_lru_cache python /workspace/pytorch/test/fx/test_fx_propagate_unbacked_symints.py -k propagate_unbacked ### 3. 测试结果(运行日志) text # 环境:Ascend NPU(torch-npu 2.13.0 / torch 2.13.0) # lru_cache . ---------------------------------------------------------------------- Ran 1 test in 0.022s OK # PropagateUnbackedSymInts(含 boxed_run / call_function / call_method) ....... ---------------------------------------------------------------------- Ran 7 tests in 0.747s OK ### 4. 与上游用例的关系 | 验证维度 | 上游现有用例 | 本 PR 新增用例 | |----------|-------------|----------------| | symbolic_shapes.lru_cache | 无直接用例 | 已覆盖(hit/miss、cumulative_cache_info、cache_clear) | | PropagateUnbackedSymInts | 仅 test_fx_traceback.py 间接涉及 | 已覆盖(run / run_node / placeholder / output) | | PropagateUnbackedSymInts.boxed_run | 无直接用例 | 已覆盖 | | PropagateUnbackedSymInts.call_function | 无直接用例 | 已覆盖(NPU 张量 + shape 校验) | | PropagateUnbackedSymInts.call_method | 无直接用例 | 已覆盖(NPU 张量 + shape 校验) | | NPU 侧验证闭环 | 不完整 | 本 PR 补齐 | 【CheckList】 PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38673 | 1 个月前 | |
add test for add_module and apply api in torch.jit.ScriptModule Co-authored-by: bobebest<773449114@qq.com> # message auto-generated for no-merge-commit merge: !40311 merge test-master into master add test for add_module and apply api in torch.jit.ScriptModule Created-by: bobebest Commit-by: bobebest Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1977 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) torch.jit.ScriptModule.add_module和torch.jit.ScriptModule.apply:已在 PyTorch 官方社区搜索 ,无针对该 API 的专门测试用例,因此自行编写测试用例。 Torch.jit.ScriptModule各属性介绍:把一个普通的 Python 模型(nn.Module)编译成 TorchScript 模型(ScriptModule),让它可以脱离 Python、在 NPU/C++/ 推理引擎上跑。 # API介绍 **torch.jit.ScriptModule.add_module**是 PyTorch TorchScript 中用于动态添加子模块的核心方法,该子模块可以使用给定的名称作为属性进行访问; **语法:**add_module(name, module) **参数:** name(str):子模块的名称,可以是任意字符串 module(torch.nn.Module 或 None):要添加的子模块实例;传入 None 时相当于删除该名称对应的子模块 **返回值:**None **核心特性:** 1、TorchScript 静态性约束:只有 add_module 能让 TorchScript 识别并追踪新加入的子模块、参数和缓冲区; 2、动态网络构建:适用于运行时才决定网络结构的场景(如循环添加多层、条件分支添加模块); 3、状态管理:加入的子模块会被纳入 parameters()、state_dict()、to(device)、train()/eval() 等管理体系。 **torch.jit.ScriptModule.apply**是 PyTorch TorchScript 静态图模块 的递归遍历函数,递归遍历模块自身 + 所有子模块,对每一个模块执行传入的函数。 **语法:**apply(fn) **参数:** fn(Callable[[torch.nn.Module], None]):一个函数,接受一个 Module 实例作为输入,返回 None。该函数会被递归地应用到模块自身和每一个子模块上 **返回值:**self(即调用 apply 的 ScriptModule 实例本身) **核心特性如下:** 1、递归执行:深度优先遍历所有子模块 2、原地修改:直接修改模块,不返回新模型 3、顺序固定:先处理自身,再处理子模块 4、TorchScript 安全:可在静态图中正常使用 5、生命周期统一管理:参数、设备、模式全部生效 **具体测试内容如下:** | 测试维度 | 具体内容 | |---------|---------| | 功能正确性 | torch.jit.ScriptModule.add_module 能否正确添加子模块;torch.jit.ScriptModule.apply 能否正确修改参数 | | 递归行为 | torch.jit.ScriptModule.apply 是否递归访问所有嵌套子模块 | | 类型一致性 | 添加的子模块是否被转换为 ScriptModule 类型 | | 设备适配 | 所有参数和张量在 NPU 设备上的 device type 是否正确 | | 前向推理 | 修改后的模型能否正常执行前向传播 | | 返回值语义 | torch.jit.ScriptModule.apply 是否返回自身以支持链式调用 | # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!40311 | 1 个月前 | |
feat: add autocast registration for flex_attention both eager and inductor Co-authored-by: liuyutong_bury<liuyutong25@huawei.com> # message auto-generated for no-merge-commit merge: !44287 merge feat/flex-attention-eager-autocast-v2 into master feat: add autocast registration for flex_attention both eager and inductor Created-by: liuyutong_bury Commit-by: liuyutong_bury Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/3824 - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 修改文件 | 文件 | 操作 | 说明 | |------|------|------| | torch_npu/utils/patch_flexattention.py | 新建 | autocast 注册函数 + device 校验函数(不自动执行,由 PatchManager 调用) | | torch_npu/_init/patches/npu_patches.py | 修改 | 新增 apply_flex_attention_patch(),通过 PatchManager 在 import torch_npu 时触发 | | torch_npu/contrib/transfer_to_npu.py | 修改 | 删除 _patch_flex_attention_device 定义及 from torch_npu.utils import patch_flexattention | | torch_npu/_inductor/__init__.py | 修改 | 删除 _validate_device 的 import 和 flex_attention._validate_device = _validate_device 赋值 | | test/nn/test_npu_flexattention.py | 新建 | eager 执行 + autocast bf16 正确性测试 | ## 实现方案 将 flex_attention 的 AutocastPrivateUse1 注册和设备校验 patch 定义在 torch_npu.utils.patch_flexattention,通过 PatchManager 在 import torch_npu 时统一触发,不再依赖 eager / inductor 两条路径各自显式 import。 幂等安全:has_kernel_for_dispatch_key + _npu_device_patched flag 双保险,多次 import 不会冲突。 运行时路径 import torch_npu │ └─ PatchManager._apply_all_patches() │ └─ apply_flex_attention_patch() │ ├─ _patch_flex_attention_device() │ └─ fa_mod._validate_device = _npu_valid_device │ (接受 NPU tensor,拒绝非 NPU / 混合设备) │ └─ _register_npu_flex_attention_autocast() └─ flex_attention_hop.py_impl(AutocastPrivateUse1)(...) flex_attention_backward_hop.py_impl(AutocastPrivateUse1)(...) 验证 test 1: eager 模式 — flex_attention 在 NPU 上直接执行 test 2: autocast — bf16 自动类型转换 + 数值正确性 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44287 | 27 天前 | |
[master]test: add clone coverage for torch.autograd.grad_mode.set_grad_enabled Co-authored-by: Zky0803<kyzhang0803@163.com> # message auto-generated for no-merge-commit merge: !42445 merge pr/set-grad-enabled-clone into master [master]test: add clone coverage for torch.autograd.grad_mode.set_grad_enabled Created-by: Zky0803 Commit-by: Zky0803 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 - 来源任务 Issue:[【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(31)](https://gitcode.com/Ascend/pytorch/issues/2954) - 结果 Issue:[torch.autograd.grad_mode.set_grad_enabled.clone API 一致性补齐](https://gitcode.com/Ascend/pytorch/issues/3102) # 【分支范围】 本 PR 面向 master 目标分支。 本任务整体覆盖: text master、v2.7.1、v2.11.0、v2.12.0 v2.9.0、v2.10.0 已进入维护阶段,不再合入新特性或本类新增测试,因此本任务 不再对这两个分支作补齐要求。 # 【修改方案】 本次仅补充 torch.autograd.grad_mode.set_grad_enabled.clone 的 NPU 单元测试, 不修改 API 实现。 修改文件: text test/npu/test_locally_disabling_gradient_omputation.py 整改后提交: text 源分支:pr/set-grad-enabled-clone Commit:5cc7df026d176e95786ecec387b2c8f54d64d6d1 提交标题:test: add clone coverage for set_grad_enabled 文件 SHA-256:642c2b526d025de467b3b1ef728526b64977e22485ceafb0e8c60a58f25b1120 文件头增加 Huawei BSD 3-Clause copyright 和 API 覆盖说明: python # Copyright (c) 2026 Huawei Technologies Co., Ltd # All rights reserved. # # Licensed under the BSD 3-Clause License (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://opensource.org/licenses/BSD-3-Clause # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Add validation cases for gradient-mode APIs on NPU. This file validates torch.no_grad, torch.enable_grad, torch.set_grad_enabled, and torch.autograd.grad_mode.set_grad_enabled.clone, including clone object independence, mode preservation, grad-mode restoration, and decorator behavior with NPU tensors. """ ## 1. clone 直接行为 整改后的 test_set_grad_enabled_clone: python def test_set_grad_enabled_clone(self): initial_grad_enabled = torch.is_grad_enabled() with torch.set_grad_enabled(initial_grad_enabled): for mode in (False, True): ctx = torch.set_grad_enabled(mode) cloned = ctx.clone() self.assertIsNot(ctx, cloned) self.assertIsInstance( cloned, torch.autograd.grad_mode.set_grad_enabled, ) self.assertEqual(cloned.mode, mode) self.assertEqual(torch.is_grad_enabled(), initial_grad_enabled) 验证: - torch.set_grad_enabled(False).clone(); - torch.set_grad_enabled(True).clone(); - clone 后对象与原对象不是同一实例; - clone 后对象类型保持; - clone 后 mode 状态保持; - 测试结束后线程 grad mode 与测试开始时一致。 ## 2. NPU Tensor 装饰器调用链 整改后的 test_set_grad_enabled_clone_decorator: python def test_set_grad_enabled_clone_decorator(self): initial_grad_enabled = torch.is_grad_enabled() x = torch.tensor( [1.0], device="npu:0", requires_grad=True, ) with torch.set_grad_enabled(initial_grad_enabled): @torch.set_grad_enabled(False).clone() def grad_disabled(tensor): return tensor * 2 with torch.enable_grad(): disabled_result = grad_disabled(x) self.assertEqual(disabled_result.device, x.device) self.assertFalse(disabled_result.requires_grad) @torch.set_grad_enabled(True).clone() def grad_enabled(tensor): return tensor * 2 with torch.no_grad(): enabled_result = grad_enabled(x) self.assertEqual(enabled_result.device, x.device) self.assertTrue(enabled_result.requires_grad) self.assertEqual(torch.is_grad_enabled(), initial_grad_enabled) 该用例在测试代码中显式调用: python torch.set_grad_enabled(False).clone() torch.set_grad_enabled(True).clone() 并直接验证: - 外层梯度开启时,clone 后的 mode=False 装饰器使 NPU 输出 requires_grad=False; - 外层 torch.no_grad() 时,clone 后的 mode=True 装饰器使 NPU 输出 requires_grad=True; - 输出 Tensor 仍位于输入 NPU 设备; - 测试结束后线程 grad mode 恢复。 ## 3. 导入清理 继续保持移除冗余的: python import torch_npu # noqa: F401 当前通过: python from torch_npu.testing.testcase import TestCase, run_tests 使用项目测试基类和测试入口,不使用 noqa 掩盖未使用导入。 本次不涉及: - PyTorch API 功能实现; - Torch-NPU C++ 适配; - NPU Kernel; - test_upstream patch; - 跨代码仓接口变更。 # 【社区用例检索与新增必要性】 在 upstream/master(5b6990f5a332dc9a585c66fee64f721e1fcc2d46)中执行: bash git grep -n -E \ 'set_grad_enabled.*clone|clone.*set_grad_enabled|test_.*set_grad_enabled.*clone' \ -- test 直接 clone 测试匹配数: text 0 相关基础测试包括: - test/test_autograd.py::test_set_grad_enabled - test/test_autograd.py::test_set_grad_enabled_wraps - test/npu/test_locally_disabling_gradient_omputation.py::test_set_grad_enabled 这些用例覆盖基础上下文管理器或通用装饰器行为,但没有直接检查 clone 后对象的 身份、类型和 mode,没有验证测试前后线程 grad mode 保持,也没有使用 clone 后对象作为装饰器对 NPU Tensor 输出进行断言。因此需要在现有 Torch-NPU NPU 测试文件中新增本用例,不能直接以社区基础用例替代。 # 【资料变更】 涉及。 torch.autograd.grad_mode.set_grad_enabled.clone 为 PyTorch 对外公开的 set_grad_enabled 子方法。经资料补齐要求复核,当前 Torch-NPU Native API 资料仅登记父 API,缺少 clone() 子方法,因此本任务另行提交资料补齐 PR。 资料补齐信息: text 目标分支:master 源分支:docs/set-grad-enabled-clone 基线提交:462f4e18a8303698aca3997edfcc5dd3b1707968 资料提交:fcc55fd51dc6e4ba5a4068cb9805d15a59021bc3 提交标题:docs: add support status for set_grad_enabled.clone 资料 PR:[PR #44139](https://gitcode.com/Ascend/pytorch/pull/44139) 资料修改文件: text docs/zh/api/native_api/pytorch_2-7-1/torch.md docs/zh/api/native_api/pytorch_2-11-0/torch.md docs/zh/api/native_api/pytorch_2-12-0/torch.md docs/zh/api/native_api/pytorch_2-13-0/torch.md 资料中将 clone() 作为 torch.autograd.grad_mode.set_grad_enabled 的子方法登记,支持状态与父 API 保持一致: - Atlas A2 训练系列产品:支持; - Atlas A3 训练系列产品:支持; - Ascend 950DT:暂不支持。 该 API 为非计算类上下文对象复制方法,与 Tensor 数据类型无关,因此资料中不 增加 fp16、fp32、bf16 等 dtype 限制说明。 资料分支已完成本地检查并成功推送,diff --check、四版本条目覆盖及远端 SHA 验证均通过。 # 【接口变更】 不涉及。 本次不修改函数实现、接口签名、返回类型或其他组件交互。 # 【功能验证】 ## 环境 text 目标分支:master torch:2.12.0+cu130 torch-npu:2.12.0.rc1 NPU available:True NPU device count:1 ## 命令 bash python test/npu/test_locally_disabling_gradient_omputation.py -v 隔离验证还分别从初始 grad mode 为 False 和 True 的状态执行两个 clone 测试。 ## 测试场景 text test_enable_grad test_no_grad test_set_grad_enabled test_set_grad_enabled_clone test_set_grad_enabled_clone_decorator 隔离验证场景: text initial=False → before=False → after=False initial=True → before=True → after=True ## 完整原始输出 ``text ================================================== TARGET_BRANCH=master SOURCE_BRANCH=pr/set-grad-enabled-clone COMMIT=5cc7df026d176e95786ecec387b2c8f54d64d6d1 PYTHON=envs/torch_npu_2.12.0/bin/python TEST_FILE=/tmp/set_grad_enabled_clone_final_tests_590/master/test/npu/test_locally_disabling_gradient_omputation.py TEST_FILE_SHA256=642c2b526d025de467b3b1ef728526b64977e22485ceafb0e8c60a58f25b1120 ================================================== ===== ENVIRONMENT PROBE ===== python_executable=/workspace/user_data/torch_npu_api_check/check_close_args/envs/torch_npu_2.12.0/bin/python python_version=3.11.15 platform=Linux-5.10.0-216.0.0.115.oe2203sp4.aarch64-aarch64-with-glibc2.35 torch_version=2.12.0+cu130 torch_npu_version=2.12.0.rc1 torch_file=/workspace/user_data/torch_npu_api_check/check_close_args/envs/torch_npu_2.12.0/lib/python3.11/site-packages/torch/__init__.py torch_npu_file=/workspace/user_data/torch_npu_api_check/check_close_args/envs/torch_npu_2.12.0/lib/python3.11/site-packages/torch_npu/__init__.py npu_available=True npu_device_count=1 initial_grad_enabled=True ENVIRONMENT_PROBE_EXIT_CODE=0 ===== FULL TEST FILE ===== COMMAND=env -u PYTHONPATH PYTHONNOUSERSITE=1 envs/torch_npu_2.12.0/bin/python /tmp/set_grad_enabled_clone_final_tests_590/master/test/npu/test_locally_disabling_gradient_omputation.py -v W0801 11:27:23.084000 39660 torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_enable_grad (__main__.TestLDGComputation.test_enable_grad) ... [W801 11:27:30.117500740 NPUCachingAllocator.cpp:199] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_no_grad (__main__.TestLDGComputation.test_no_grad) ... ok test_set_grad_enabled (__main__.TestLDGComputation.test_set_grad_enabled) ... ok test_set_grad_enabled_clone (__main__.TestLDGComputation.test_set_grad_enabled_clone) ... ok test_set_grad_enabled_clone_decorator (__main__.TestLDGComputation.test_set_grad_enabled_clone_decorator) ... ok ---------------------------------------------------------------------- Ran 5 tests in 0.586s OK FULL_TEST_EXIT_CODE=0 ===== GRAD MODE ISOLATION PROBE ===== W0801 11:28:45.547000 40098 torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl` (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_set_grad_enabled_clone (set_grad_enabled_clone_test_module.TestLDGComputation.test_set_grad_enabled_clone) ... ok test_set_grad_enabled_clone_decorator (set_grad_enabled_clone_test_module.TestLDGComputation.test_set_grad_enabled_clone_decorator) ... [W801 11:28:51.477959420 NPUCachingAllocator.cpp:199] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok ---------------------------------------------------------------------- Ran 2 tests in 0.203s OK test_set_grad_enabled_clone (set_grad_enabled_clone_test_module.TestLDGComputation.test_set_grad_enabled_clone) ... ok test_set_grad_enabled_clone_decorator (set_grad_enabled_clone_test_module.TestLDGComputation.test_set_grad_enabled_clone_decorator) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.002s OK PROCESS_ORIGINAL_GRAD_MODE=True ISOLATION_RESULT=initial:False,before:False,after:False,t See merge request: Ascend/pytorch!42445 | 28 天前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
[optim] Add distributed Muon optimizer support for Ascend NPU Co-authored-by: guoqi1024<guoqi5@huawei.com> # message auto-generated for no-merge-commit merge: !38393 merge feature/distributed-muon-optimizer into master [optim] Add distributed Muon optimizer support for Ascend NPU Created-by: guoqi1024 Commit-by: guoqi1024 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2403 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38393 | 2 个月前 | |
test(package): add testcase for PackageExporter additional APIs Co-authored-by: PAGEMRW<985608880@qq.com> # message auto-generated for no-merge-commit merge: !37848 merge test-package-exporter-additional-api-master into master test(package): add testcase for PackageExporter additional APIs Created-by: PAGEMRW Commit-by: PAGEMRW Merged-by: ascend-robot Description: # 【合入来源】 - 问题单 PyTorch 社区用例对以下 torch.package.PackageExporter API 缺少充分且直接的验证: torch.package.PackageExporter.add_dependency torch.package.PackageExporter.all_paths torch.package.PackageExporter.close torch.package.PackageExporter.dependency_graph_string torch.package.PackageExporter.get_unique_id torch.package.PackageExporter.register_intern_hook 因此新增 test_package_exporter_additional_api.py 测试文件,用于验证上述 6 个 API 的正确性,并补充异常路径验证,覆盖显式依赖添加、依赖图路径查询、依赖图字符串输出、唯一 ID 生成、intern hook 注册/移除、PackageExporter 正常关闭及重复关闭异常等场景。 # 【修改方案】 一、API 功能说明 1. torch.package.PackageExporter.add_dependency 是 PyTorch torch.package.PackageExporter 中用于手动向包导出器依赖图添加模块依赖的 API,核心功能如下: 依赖图补充能力:接收指定模块名,并根据用户预先配置的 extern、intern、mock、deny 等规则,将该模块加入 PackageExporter 的依赖分析流程。 规则驱动处理:模块最终是被打包进 archive、作为外部依赖记录、替换为 mock 模块,还是被拒绝,取决于导出器中已有的依赖匹配规则。 递归依赖分析支持:当 dependencies=True 时,会进一步分析该模块源码中的 import 依赖,并将相关依赖继续纳入处理。 手动依赖声明:适用于测试或特殊打包场景中显式补充某个模块依赖,避免完全依赖 save_module、save_pickle 等接口的自动扫描。 纯 Python 打包辅助:该 API 主要操作模块依赖关系和导出规则,不涉及张量计算,也不要求运行在 NPU/GPU 设备上。 2. torch.package.PackageExporter.all_paths 是 PyTorch PackageExporter 中用于查询两个模块之间依赖路径的调试分析 API,核心功能如下: 依赖路径追踪:接收源模块 src 和目标模块 dst,返回从 src 到 dst 的所有依赖路径。 DOT 图格式输出:返回结果为 DOT 格式字符串,可用于 Graphviz 等工具可视化依赖子图。 依赖原因定位:常用于分析某个模块为什么会被 PackageExporter 作为依赖引入,帮助定位间接 import 链路。 子图级别查看:相比完整依赖图,该 API 只关注指定源模块到目标模块之间的路径,便于缩小调试范围。 静态调试属性:该 API 只读取和展示 PackageExporter 内部依赖图信息,不会执行实际模型计算或张量运算。 3. torch.package.PackageExporter.close 是 PyTorch PackageExporter 中用于结束打包并将 package 写入目标位置的收尾 API,核心功能如下: 包写出能力:将前面通过 save_module、save_pickle、save_text、save_binary、save_source_string 等接口收集到的代码、对象和资源正式写入文件系统或二进制 IO 对象。 导出流程终止:调用 close() 后,PackageExporter 进入关闭状态,后续再调用保存、依赖添加等导出相关接口将不再合法。 上下文管理器等价:通常推荐使用 with PackageExporter(...) as exporter 的形式自动触发关闭逻辑,避免忘记手动调用 close()。 规则完整性检查:在关闭阶段会完成打包收尾检查,例如未解析依赖、非法依赖或未匹配规则可能在关闭时触发异常。 资源释放作用:用于确保底层 zip/package 归档结构被完整写入并释放相关写入资源。 4. torch.package.PackageExporter.dependency_graph_string 是 PyTorch PackageExporter 中用于输出完整包依赖图的调试 API,核心功能如下: 完整依赖图查看:返回当前 PackageExporter 已记录的 package 依赖关系图。 字符串化输出:返回值为字符串形式的依赖图表示,可直接打印到控制台或写入日志文件。 打包调试支持:用于观察哪些模块被纳入依赖图、模块之间存在怎样的依赖关系。 与局部路径分析互补:all_paths(src, dst) 适合查看两个模块之间的路径,而 dependency_graph_string() 适合查看整体依赖结构。 无副作用查询:该 API 只读取依赖图状态,不会修改打包内容,也不涉及张量或设备相关操作。 5. torch.package.PackageExporter.get_unique_id 是 PyTorch PackageExporter 中用于生成包内唯一标识符的辅助 API,核心功能如下: 唯一 ID 生成:返回一个字符串 ID,并保证该 ID 在当前 package 导出过程中只会被分配一次。 避免命名冲突:常用于生成临时模块名、资源路径或中间文件名,防止与已有模块和资源发生冲突。 自定义打包支持:在自定义 __reduce_package__ 等高级打包逻辑中,可用该 API 为动态生成的资源分配唯一名称。 包内范围唯一:其唯一性主要保证在当前 PackageExporter 管理的 package 内成立,不用于全局分布式唯一标识。 轻量级工具属性:该 API 只生成字符串标识,不涉及依赖扫描、文件写入或张量运算。 6. torch.package.PackageExporter.register_intern_hook 是 PyTorch PackageExporter 中用于注册 intern 模块匹配回调函数的 API,核心功能如下: intern 回调注册:向导出器注册一个 hook,当某个模块匹配 intern() 规则并准备被打包进 package 时,该 hook 会被触发。 自定义处理能力:hook 函数可接收 exporter 和 module_name,从而在模块被 intern 时执行额外逻辑,例如记录日志、统计模块、补充资源或检查模块名。 多 hook 顺序执行:支持注册多个 intern hook,并按照注册顺序依次调用,便于组合多个自定义处理逻辑。 可移除句柄支持:注册后会返回 RemovableHandle,后续可通过 handle.remove() 移除该 hook。 打包流程扩展点:该 API 提供对 PackageExporter 内部模块处理流程的扩展能力,适合测试 hook 调用顺序、移除机制和模块匹配行为。 二、测试文件 test_package_exporter_additional_api.py 完整验证该 API 的原因 `` 该测试用例针对 torch.package.PackageExporter.add_dependency、torch.package.PackageExporter.all_paths、torch.package.PackageExporter.dependency_graph_string、torch.package.PackageExporter.get_unique_id、torch.package.PackageExporter.register_intern_hook 和 torch.package.PackageExporter.close 六个 API,从显式依赖处理、异常依赖处理、依赖图路径查询、依赖图字符串输出、唯一标识生成、Hook 注册与移除机制、包写入闭环、重复关闭异常等维度进行直接验证,具体体现在: 1. 对 add_dependency API 的验证 显式依赖添加验证 test_add_dependency:通过创建 PackageExporter,并直接调用 add_dependency("math") 手动加入 math 模块依赖,验证 API 能够将指定模块加入 PackageExporter 的依赖分析流程。测试通过 dependency_graph.nodes 校验 math 已被加入依赖图节点,说明 add_dependency 能够正确记录显式添加的依赖。随后关闭 exporter,并使用 PackageImporter 从内存 package 中重新加载 math 模块,验证导入结果与系统原生 math 模块一致,说明显式添加的依赖不仅在导出阶段被正确记录,也能在导入阶段保持正确解析。 不存在模块异常路径验证 test_add_dependency_nonexistent_module_raises:通过 add_dependency("nonexistent_module_for_package_exporter_test") 手动添加一个不存在的模块依赖,并在 exporter.close() 阶段断言抛出 PackagingError。该测试验证 add_dependency 对非法/不可解析模块依赖的处理符合预期:依赖可以先进入导出器依赖处理流程,但最终关闭打包时会进行完整性检查并暴露打包错误,避免生成包含无效依赖的 package。 2. 对 all_paths API 的验证 依赖路径查询验证 test_all_paths:手动向 dependency_graph 中添加 a -> b、b -> c、a -> d 三条边,然后调用 all_paths("a", "c") 查询从 a 到 c 的依赖路径。测试断言结果中包含 "a" -> "b" 和 "b" -> "c",说明 API 能够正确返回目标路径上的依赖边;同时断言结果中不包含 "a" -> "d",说明 API 不会错误返回与目标节点 c 无关的分支路径。该测试覆盖了依赖图路径提取的正确性和无关路径过滤能力。 3. 对 dependency_graph_string API 的验证 依赖图字符串输出验证 test_dependency_graph_string:通过向 dependency_graph 中添加 a -> b 依赖边,再调用 dependency_graph_string() 获取完整依赖图字符串。测试断言结果中包含 digraph G,验证其输出符合 DOT 图格式;同时断言结果中包含 "a" -> "b",验证依赖图中的实际边关系能够被正确序列化输出。该测试说明该 API 能够将 PackageExporter 内部依赖图转换为可读、可调试的字符串表示。 4. 对 get_unique_id API 的验证 唯一标识生成验证 test_get_unique_id:连续三次调用 get_unique_id(),并分别断言返回值为 "0"、"1"、"2"。该测试验证了 API 能够在同一个 PackageExporter 实例内生成单调递增且不重复的字符串 ID,说明其可用于包内临时资源、模块名或自定义打包逻辑中的唯一命名需求。同时,连续调用场景也验证了内部计数状态能够被正确维护。 5. 对 register_intern_hook API 的验证 Hook 注册与触发验证 test_register_intern_hook:定义 intern_hook 回调函数,并通过 register_intern_hook 注册到 PackageExporter 中。随后调用 save_source_string("foo", "VALUE = 1", dependencies=False) 保存源码模块,触发模块 intern 流程。测试最终断言 interned_modules 等于 ["foo"],说明当模块被打包进 package 时,已注册的 intern hook 能够被正确调用,并且能够接收到正确的模块名参数。 Hook 移除机制验证 test_register_intern_hook_remove:注册 intern hook 后,立即调用返回句柄的 remove() 方法移除该 hook,再保存 foo 模块。测试断言 interned_modules 为空列表,说明被移除的 hook 不会继续触发。该测试进一步覆盖了 register_intern_hook 返回句柄的有效性,以及 hook 注册后可撤销的边界行为,避免回调残留或误触发。 6. 对 close API 的验证 包写入闭环验证 test_close:先通过 save_source_string("foo", "VALUE = 3", dependencies=False) 向 package 中写入源码模块,再调用 close() 完成导出收尾。随后重置 BytesIO 指针,并使用 PackageImporter 从内存 package 中重新导入 foo 模块,断言 foo.VALUE 等于 3。该测试验证了 close() 能够正确完成 package 的最终写入、归档结构封装和资源收尾,使导出的内容能够被后续 PackageImporter 正常加载。 重复关闭异常路径验证 test_close_twice_raises:创建 PackageExporter 后先执行一次 close() 完成关闭,再次调用 close() 时断言抛出异常。该测试验证 close() 关闭状态管理符合预期,PackageExporter 在完成导出后不会允许重复关闭或重复写入,从而避免资源状态异常、归档结构重复收尾等问题。 7. 测试完整性与隔离性保障 该测试文件使用 BytesIO 作为内存 package 载体,避免依赖外部文件系统,保证测试过程轻量、独立、可重复。每个测试用例均重新创建 PackageExporter 实例,分别构造独立的依赖图、hook 列表或 package 内容,避免不同 API 测试之间发生状态污染。部分测试使用 with PackageExporter(buffer) as exporter 的上下文管理方式,覆盖自动 close 场景;test_close 显式调用 close(),覆盖手动关闭场景;test_add_dependency_nonexistent_module_raises 和 test_close_twice_raises 分别覆盖依赖解析失败与重复关闭两个异常分支。由于这些 API 主要属于 torch.package 的 Python 层打包、依赖管理和导出流程,不涉及实际张量计算或 NPU 算子执行,因此无需额外构造 NPU 张量,也无需额外进行张量迁移适配。 三、NPU 适配 torch.package.PackageExporter.add_dependency、torch.package.PackageExporter.all_paths、torch.package.PackageExporter.close、torch.package.PackageExporter.dependency_graph_string、torch.package.PackageExporter.get_unique_id 和 torch.package.PackageExporter.register_intern_hook 均属于 torch.package 模块中的 Python 层打包、依赖管理、调试分析和 Hook 扩展类 API,不涉及张量计算、算子执行或设备调度逻辑,因此无需针对昇腾 NPU 做额外适配,具体分析如下: 1. 纯 Python 层打包流程 API,无硬件相关计算逻辑 - add_dependency API:主要用于手动向 PackageExporter 的依赖图中添加模块依赖,并根据 extern、intern、mock、deny 等规则处理模块归属,核心逻辑是 Python 模块依赖分析和打包规则匹配,不涉及 Tensor 运算或 NPU 算子调用;新增的不存在模块用例验证的是打包阶段异常检查,也不涉及设备逻辑。 - all_paths API:仅用于查询 PackageExporter 内部依赖图中两个模块之间的依赖路径,返回 DOT 格式字符串,属于依赖图调试分析能力,不涉及任何设备侧计算。 - dependency_graph_string API:用于将当前依赖图字符串化输出,便于观察模块之间的依赖关系,本质是读取并序列化 Python 层依赖图结构,与 NPU 硬件无关。 - get_unique_id API:仅用于在当前 PackageExporter 实例内生成唯一字符串 ID,属于轻量级命名辅助工具,不涉及依赖扫描、文件执行、张量创建或设备迁移。 - register_intern_hook API:用于注册模块 intern 过程中的 Python 回调函数,核心逻辑是 hook 注册、触发和移除,不依赖任何底层硬件能力。 - close API:用于完成 package 的最终写入和资源收尾,将已保存的源码、对象或资源写入目标 package 中,属于文件/字节流归档写出逻辑;新增的重复 close 用例验证的是 Python 对象关闭状态管理,也不涉及 NPU 计算图或算子执行。 2. 无底层算子 / 内核 / NPU Runtime 依赖 - 这 6 个 API 的核心功能集中在 PackageExporter 的模块依赖管理、依赖图维护、包内容写入、唯一 ID 生成以及 hook 机制上,均运行在 Python 解释器和 PyTorch 打包框架层面。 - 测试过程中使用的 BytesIO、PackageExporter、PackageImporter、dependency_graph 等对象均属于 Python 层对象或 PyTorch package 管理结构,不会调用 torch_npu 的算子、NPU kernel、NPU 内存管理接口或设备通信接口。 - 测试用例即使在 torch-npu 迁移环境下执行,也仅验证 torch.package 的打包、导入和依赖图逻辑,不触发任何 NPU 设备侧行为。 3. 核心逻辑与硬件设备解耦 - 依赖管理解耦:add_dependency、all_paths 和 dependency_graph_string 操作的是模块依赖图,依赖关系来自 Python import 规则和 PackageExporter 的打包策略,与 CPU/GPU/NPU 设备类型无关。 - 打包写入解耦:close API 负责将 package 内容写入内存 buffer 或文件系统,其正确性取决于归档结构和资源写入完整性,而不是底层计算设备。 - Hook 机制解耦:register_intern_hook 触发的是 Python 回调函数,测试关注 hook 是否被正确注册、调用和移除,不涉及任何硬件执行路径。 - 唯一标识生成解耦:get_unique_id 仅维护 PackageExporter 内部计数状态并返回字符串 ID,不包含设备判断、张量分配或算子派发逻辑。 4. 无需构造 NPU 张量的原因 - 本测试文件覆盖的 6 个 API 均不以 Tensor 作为输入,也不返回 Tensor 结果。 - 测试逻辑主要包括模块依赖声明、异常依赖关闭检查、依赖图边关系查询、字符串输出校验、hook 调用验证、package 写入与重新导入验证、重复关闭异常验证。 - 因此,按照“涉及张量的用例尽可能运行在 NPU 上”的原则,本测试文件不存在需要迁移到 NPU 的张量对象,也无需额外添加 .npu() 或 .to(device_type) 操作。 - 若强行构造 NPU 张量,反而会引入与被测 API 无关的设备依赖,降低测试的针对性和最小化原则。 综上,torch.package.PackageExporter.add_dependency、all_paths、close、dependency_graph_string、get_unique_id 和 register_intern_hook 均属于硬件无关的 Python 层 package 导出与依赖管理 API。其功能正确性主要取决于 PackageExporter 内部依赖图、打包规则、hook 机制、异常状态管理和归档写入逻辑,不依赖昇腾 NPU 的算子、内存或运行时能力。因此在 torch-npu 适配中无需修改 API 本身,也无需构造 NPU 张量,可直接复用 PyTorch 社区逻辑进行验证。 # 【资料变更】 > 不涉及 已检查文档,https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 下面各个版本均已记录这些 API 支持情况,因此不需要提交 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配 UT 测试用例看护,并补充测试自验证截图 在 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 版本上执行该用例,均通过,日志如下: ` root@c18d5a0da657:/workspace/pytorch29/test/package# python -m unittest -v test_package_exporter_additional_api test_add_dependency (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_add_dependency) ... ok test_add_dependency_nonexistent_module_raises (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_add_dependency_nonexistent_module_raises) ... ok test_all_paths (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_all_paths) ... ok test_close (test_package_exporter_additional_api.TestPackageExporter See merge request: Ascend/pytorch!37848 | 2 个月前 | |
test: add Ascend NPU UT for torch.autograd.profiler.parse_nvprof_trace Co-authored-by: yuhongming-2026<moshui_1@qq.com> # message auto-generated for no-merge-commit merge: !42226 merge part_master into master test: add Ascend NPU UT for torch.autograd.profiler.parse_nvprof_trace Created-by: yuhongming-2026 Commit-by: yuhongming-2026 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2975**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 新增 test/profiler/test_parse_nvprof_trace.py,对原生 API torch.autograd.profiler.parse_nvprof_trace / load_nvprof 在 Ascend NPU 环境下做适配一致性验证。 2. 构造最小 nvprof 兼容 SQLite(含 Marker / Runtime / Concurrent Kernel 表结构),覆盖仅 Marker、Marker+Kernel 关联两类解析路径。 3. 用例依赖 CANN + NPU;无 NPU 时整模块 skip,避免在纯 CPU/CUDA 环境误跑。 4. 补充 API 可用性、EnforceUnique、以及 NPU 算子负载后解析仍可用等场景,保障该接口在 torch_npu 栈上行为正确。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 **测试场景:** - Ascend NPU 环境下验证 parse_nvprof_trace / load_nvprof 可用性与解析结果正确性 - 覆盖:仅 Marker、带 Kernel 关联、NPU 算子执行后再次解析、EnforceUnique **测试方法:** bash cd test/profiler python test_parse_nvprof_trace.py **说明:** 已新增 UT 用例看护;请在本地/CI NPU 环境执行后补充自验证截图。  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42226 | 30 天前 | |
AI assist developer for python dt master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !26538 merge master into master AI assist developer for python dt master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!26538 | 9 个月前 | |
test update ut Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com> # message auto-generated for no-merge-commit merge: !37776 merge 2.13ut1 into master test update ut Created-by: huangyunlong2022 Commit-by: huangyunlong2022 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) test_deprecation test_cycle_lr_cycle_momentum_fail_with_momentumless_optimizer test_hook_registration 同步社区用例更新 test_float_status A2/A3需要开启饱和模式 test_select_at_first_axis_to_single_element_tensor_copy 转连续优化是aclop路径,alcnn路径添加aclnnAdds通过用例 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37776 | 3 个月前 | |
refactor: correct English grammar, spelling, and style in log/warning messages Co-authored-by: wanglijun55<wanglijun54@huawei.com> # message auto-generated for no-merge-commit merge: !44119 merge master-doc into master refactor: correct English grammar, spelling, and style in log/warning messages Created-by: wanglijun55 Commit-by: wanglijun55 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/3908 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 对 torch_npu 全仓 UserWarning / logger.warning / print 日志中的英文消息进行语法、拼写、标点审查和修复。共修复 48 处错误,涉及 39 个文件,涵盖以下类别: 1. **语法错误 (14处):** will not to be linked → will not be linked、should to be initialized → should be initialized、Create ... failed → Failed to create ... 等 2. **逗号拼接句 (8处):** 将逗号连接的两个独立句子拆分为两句或使用分号 3. **拼写错误 (1处):** Detecct_type → Detect_type 4. **缺少冠词 (7处):** in future version → in a future version、only sets Global variable → only sets the global variable 5. **主谓不一致 (5处):** Environment variable ... is not set → are not set、There is no ... events → There are no ... events 6. **标点/格式 (8处):** 中文顿号 、 → 英文逗号、多余空格、缺失句号、相邻字符串缺少空格拼接导致粘连 7. **翻译不当 (2处):** soft chain → symbolic link(软链接) 8. **冗余前缀 (2处):** warnings.warn() 中重复的 Warning: 前缀 9. **代码 Bug (1处):** serialization.py:672 — print() 传入 tuple 而非 string 10. **风格问题:** for replacement → as a replacement、Torchinductor → TorchInductor、Can not → Cannot、func/msg → function/message 等 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 仅修改日志/警告消息字符串,不影响任何功能逻辑。所有修改均为: - 英文语法/拼写/标点修正 - 字符串拼接 bug 修复(serialization.py tuple → string) - 翻译术语规范化(soft chain → symbolic link) # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44119 | 29 天前 | |
[fix] Support test case filtering by version range Co-authored-by: zhoupeng<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !43106 merge one-track-test into master [fix] Support test case filtering by version range Created-by: thickhair Commit-by: zhoupeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3004 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 支持不在版本区间用例跳过执行 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43106 | 1 个月前 | |
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
compat(2.14): default requirements to 2.14 nightly and fix related tests Co-authored-by: chz34<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !41741 merge compat/2.14 into master compat(2.14): default requirements to 2.14 nightly and fix related tests Created-by: c_34 Commit-by: chz34 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2258 https://gitcode.com/Ascend/pytorch/issues/2890 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 上游新增接口,暴露的路径与实际module不一致,实际来自_C库,添加测试白名单,与上游添加的白名单保持一致。 2. 上游新增接口,依赖额外三方库与cuda库,test_public_binding.py中增加相关过滤 3. 上游 Backedn.register_backend.__func__新增参数,修改对应patch函数,增加**kwargs,缺省忽略,同时保持与之前版本的接口兼容 4. 上游cudagraphify调用时新增额外参数kernel_free_cudagraph, user_visible_output_idxs,下游npugraphify跟随新增,函数内不处理 5. 新增requirements_2_13.txt的配置,默认配置升级到2.14 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 跟随上游变更,基于现有测试用例进行验证 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41741 | 1 个月前 | |
[fix] Init version in GetCANNVersion and delete unnecessary warning Co-authored-by: zhaoyu65<nanzhaogang@qq.com> # message auto-generated for no-merge-commit merge: !38128 merge master-warn into master [fix] Init version in GetCANNVersion and delete unnecessary warning Created-by: zhaoyu65 Commit-by: zhaoyu65 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 [#2346](https://gitcode.com/Ascend/pytorch/issues/2346) # 【修改方案】 * **核心变更:** * 🔧 修复了CANN版本获取函数中的错误处理逻辑,从特定错误码检查改为通用成功状态检查 * ✅ 增强了错误日志,新增错误码输出以便调试 * 🧹 简化了Python环境收集工具,移除了**路径所有者一致性检查** * 🛡️ 修复了C++结构体未初始化的潜在问题 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 验证OK 测试用例test\npu\test_cann_version.py已纳入门禁看护 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38128 | 2 个月前 | |
fix: lintrunner --all-files --take NEWLINE -a Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35539 merge code_check_lintrunner into master fix: lintrunner --all-files --take NEWLINE -a Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 文件必须以 LF 换行符结尾,不允许 CRLF(DOS 换行),执行: lintrunner --all-files --take NEWLINE -a # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35539 | 3 个月前 | |
| 2 年前 | ||
compat(2.14): default requirements to 2.14 nightly and fix related tests Co-authored-by: chz34<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !41741 merge compat/2.14 into master compat(2.14): default requirements to 2.14 nightly and fix related tests Created-by: c_34 Commit-by: chz34 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2258 https://gitcode.com/Ascend/pytorch/issues/2890 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 上游新增接口,暴露的路径与实际module不一致,实际来自_C库,添加测试白名单,与上游添加的白名单保持一致。 2. 上游新增接口,依赖额外三方库与cuda库,test_public_binding.py中增加相关过滤 3. 上游 Backedn.register_backend.__func__新增参数,修改对应patch函数,增加**kwargs,缺省忽略,同时保持与之前版本的接口兼容 4. 上游cudagraphify调用时新增额外参数kernel_free_cudagraph, user_visible_output_idxs,下游npugraphify跟随新增,函数内不处理 5. 新增requirements_2_13.txt的配置,默认配置升级到2.14 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 跟随上游变更,基于现有测试用例进行验证 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41741 | 1 个月前 | |
compat(2.14): default requirements to 2.14 nightly and fix related tests Co-authored-by: chz34<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !41741 merge compat/2.14 into master compat(2.14): default requirements to 2.14 nightly and fix related tests Created-by: c_34 Commit-by: chz34 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2258 https://gitcode.com/Ascend/pytorch/issues/2890 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 上游新增接口,暴露的路径与实际module不一致,实际来自_C库,添加测试白名单,与上游添加的白名单保持一致。 2. 上游新增接口,依赖额外三方库与cuda库,test_public_binding.py中增加相关过滤 3. 上游 Backedn.register_backend.__func__新增参数,修改对应patch函数,增加**kwargs,缺省忽略,同时保持与之前版本的接口兼容 4. 上游cudagraphify调用时新增额外参数kernel_free_cudagraph, user_visible_output_idxs,下游npugraphify跟随新增,函数内不处理 5. 新增requirements_2_13.txt的配置,默认配置升级到2.14 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 跟随上游变更,不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 跟随上游变更,基于现有测试用例进行验证 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41741 | 1 个月前 | |
| 2 年前 | ||
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
feat: add NPU accelerator graph support Co-authored-by: luochao60<luochao60@huawei.com> # message auto-generated for no-merge-commit merge: !39639 merge dev_accelerator_graph_npu_master into master feat: add NPU accelerator graph support Created-by: luochao60 Commit-by: luochao60 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > (如有)请关联需求文档/issue链接 > 关联 issue: #3946 (https://gitcode.com/Ascend/pytorch/issues/3946) - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列 > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 新增私有 NPUAcceleratorGraphImpl,实现 PyTorch 原生 at::GraphImplInterface,并通过 graph registry 注册为 NPU 后端的 torch.accelerator.Graph 实现。 2. NPUAcceleratorGraphImpl 采用 adapter 方案组合持有 c10_npu::NPUGraph,转调现有 ACLGraph 的 capture/replay/reset/pool/debug 能力,避免改变已暴露的 NPUGraph 继承关系和对象语义。 3. 增加 at::GraphCaptureMode 到 ACL capture mode 的映射,支持 default/global/thread_local/relaxed 参数。NPU 当前没有独立 raw graph 实例化阶段,因此 GraphImplArgs 不改变现有流程,instantiate() 保持 no-op。 4. 保留 NPUGraph::get_currently_capturing_graph() 作为 C++ runtime/internal API,以支持 RNG lazy capture 注册;新增 NPUGraph::get_currently_capturing_npu_graph() 作为 legacy pybind 入口。 5. 使用 mutex 保护的 active accelerator graph 集合记录 capture 上下文。capture_begin() 注册,capture 结束、异常、reset 和析构路径注销;legacy getter 在同一临界区完成当前 graph 查询和集合检查,覆盖跨线程访问并拒绝返回 adapter 内部持有的 NPUGraph,避免非 owning Python 引用在 adapter 销毁后产生 use-after-free。 6. 为 NPUGraph::pool() 增加 const overload,适配 GraphImplInterface::pool() const,同时调整 pybind 的 overload 绑定。 7. 在 test/test_accelerator.py 新增 NPU accelerator graph 支持用例,覆盖基础 capture/replay、RNG capture 和 accelerator capture 期间 legacy getter 的拒绝行为。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及" 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及" 涉及。新增 NPU 后端对 torch.accelerator.Graph 的支持;新增 C++ NPUGraph::get_currently_capturing_npu_graph() 作为 legacy pybind 入口;新增 NPUGraph::pool() const overload。Python API 名称 torch.npu.NPUGraph.get_currently_capturing_graph() 保持不变,但在 torch.accelerator.Graph capture 上下文中会抛异常,避免暴露 adapter-owned graph 并产生潜在 use-after-free。 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 新增 test/test_accelerator.py 用例覆盖: 1. torch.accelerator.Graph 在 NPU 上的基础 capture/replay。 2. capture 内 RNG op,验证 C++ internal getter 仍支持 generator lazy capture 注册。 3. accelerator graph capture 期间调用 legacy torch.npu.NPUGraph.get_currently_capturing_graph() 抛异常,避免 adapter-owned graph 泄漏和潜在 use-after-free。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39639 | 27 天前 | |
[sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 Co-authored-by: yuanqi1104<yuanqi13@huawei.com> # message auto-generated for no-merge-commit merge: !38860 merge sync-pr38602-yuanqi_add_torch_npu_testcases-to-master into master [sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 Created-by: yuanqi1104 Commit-by: yuanqi1104 Merged-by: ascend-robot Description: 本PR为对 https://gitcode.com/Ascend/pytorch/pull/38733 的补充 ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/38602 ### 2. Original pull request related issue(s): https://gitcode.com/Ascend/pytorch/issues/2402 ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[3481c54f](https://gitcode.com/Ascend/pytorch/commit/3481c54f3cd388fe46ae989e0dcaaf21a8844c0c)|2026-06-16 20:01:41 +0800 CST|Add test case fot torch_npu<br>| See merge request: Ascend/pytorch!38860 | 2 个月前 | |
fix test_autograd to avoid calling policy_fn during recompute Co-authored-by: SCh_zx<1325467101@qq.com> # message auto-generated for no-merge-commit merge: !43452 merge master into master fix test_autograd to avoid calling policy_fn during recompute Created-by: SCh_zx Commit-by: SCh_zx Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 原生社区中针对索引有所修改,修改用例以适配: https://github.com/pytorch/pytorch/pull/176455 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43452 | 1 个月前 | |
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
Align NPU mixed-dtype async host-device copy behavior with CUDA Co-authored-by: zzhongmin<zhongmin23@huawei.com> # message auto-generated for no-merge-commit merge: !39573 merge master_d2h into master Align NPU mixed-dtype async host-device copy behavior with CUDA Created-by: zzhongmin Commit-by: zzhongmin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 对齐 CUDA Copy.cu 的 mixed-dtype 异步 Host/Device 拷贝策略,调整 NPU OpApi 路径。 当 non_blocking=True 且 Host/Device dtype 不一致时,将可由 aclnnCast 支持的 dtype 转换前移到 NPU Device 侧完成,避免因 CPU 侧 dtype cast 产生非 pinned 临时 Tensor,导致 H2D/D2H 退化为同步拷贝。non_blocking=False 与同 dtype fast path 保持原有逻辑。 - torch_npu/csrc/aten/ops/op_api/CopyKernelOpApi.cpp - H2D:先申请源 dtype 的 NPU temporary,将 pinned/已注册 CPU 数据按源 dtype 执行同 dtype H2D 拷贝,再通过 aclnnCast 转为目标 dtype 并写回目标 Tensor。 - D2H:先在 NPU 侧通过 custom_ops::_npu_dtype_cast 转为目标 dtype,再执行同 dtype D2H 拷贝到 CPU 目标。 - D2H cast 前补充 NpuUtils::check_match(&src) 判断;当 NPU 源 Tensor 是非连续 view 或 metadata 不满足 OpApi 要求时,先通过 NpuUtils::format_contiguous(src) 规范化输入,避免 aclnnCast 直接处理不匹配的 view。 - 新增 cast_dtype_out_baseformat_opapi,封装 aclnnCast out 路径,用于 H2D mixed-dtype async 路径中将 NPU temporary 转换并写入目标 Tensor。 - 新增 should_fallback_to_cpu_cast:在 A2 及之后产品上,对 aclnnCast 不支持的 dtype 组合保留原 CPU cast 路径,避免 unsupported dtype 走设备侧 cast 失败。 2. 补充 Tensor.copy_ mixed-dtype 功能、异步行为与 fallback 测试。 - test/test_copy_.py - 覆盖 pinned CPU → NPU、NPU → pinned CPU 的 mixed-dtype copy_(non_blocking=True)。 - 覆盖 int32 -> float32、int64 -> float32、float16 -> float32、float32 -> float16、complex64 <-> complex128 等基础转换组合。 - 扩展同步/异步结果一致性用例,覆盖 bool、int8、int16、uint16、int64、float16、bfloat16、float32、complex dtype,并包含负数、边界值、小数和复数数据。 - 通过 gate_stream 上的矩阵乘任务阻塞 copy_stream,再使用 done_event.query() 验证 copy_ 返回时没有同步等待异步拷贝完成。 - 补充非连续 NPU 目标、非连续 CPU pinned 目标、非连续 NPU 源、broadcast 源、带 storage offset 的 pinned CPU slice,以及连续 mixed-dtype 异步拷贝下 temporary 生命周期测试。 - 非连续 NPU 源用例覆盖 D2H mixed-dtype 场景,验证 _npu_dtype_cast 前的 format_contiguous 保护逻辑。 - 补充 float8_e5m2、float8_e4m3fn、complex32 等 aclnnCast unsupported dtype 的 CPU cast fallback 正确性测试。 - 保留 non_blocking=False 的 H2D/D2H mixed-dtype 结果正确性回归测试。 - mixed-dtype 相关用例限定在 Ascend910B、Ascend910_93、Ascend950 上执行。 3. 补充 Tensor.to mixed-dtype 跨设备测试。 - test/npu/test_npu.py - 新增 test_to_non_blocking_different_dtype,覆盖 CPU ↔ NPU、non_blocking=True/False 的跨设备 dtype 转换。 - 验证 int32 -> float32 转换结果正确性。 - 验证 D2H 且 non_blocking=True 时输出 Tensor 保持 pinned-memory 属性。 - 用例限定在 Ascend910B、Ascend910_93、Ascend950 上执行。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39573 | 2 个月前 | |
update test_dataloader.py Co-authored-by: SCh-zx<1325467101@qq.com> # message auto-generated for no-merge-commit merge: !44348 merge master into master update test_dataloader.py Created-by: SCh_zx Commit-by: SCh-zx Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!44348 | 28 天前 | |
| 2 年前 | ||
add eager dvm testcase and remove _TORCH_NPU_ENABLE_DVM Co-authored-by: hb_hubin<hubin79@huawei.com> # message auto-generated for no-merge-commit merge: !40313 merge eager-dvm-master into master add eager dvm testcase and remove _TORCH_NPU_ENABLE_DVM Created-by: hbhu_bin Commit-by: hb_hubin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 https://gitcode.com/Ascend/pytorch/issues/2264 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 增加DVM测试用例+删除选择编译代码 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!40313 | 2 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
fix: update copyright Co-authored-by: mhy<mahongyu7@huawei.com> # message auto-generated for no-merge-commit merge: !41507 merge copyright into master fix: update copyright Created-by: m0_64341872 Commit-by: mhy Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 根据代码合规检查结果,对缺少版权或许可声明的文件补充对应的版权许可 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41507 | 1 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test(fx): add CustomBuiltin test cases for master Co-authored-by: jingkai-2026<jingkai@isrc.iscas.ac.cn> # message auto-generated for no-merge-commit merge: !35579 merge custom-test-master into master test(fx): add CustomBuiltin test cases for master Created-by: jingkai-2026 Commit-by: jingkai-2026 Merged-by: ascend-robot Description: https://gitcode.com/Ascend/pytorch/issues/1630 ## 上游社区(PyTorch 官方)测试覆盖情况分析 ### torch.fx.Graph / torch.fx.Graph.__init__ - **社区测试文件**: test/test_fx.py(PyTorch 官方仓库) - **测试覆盖情况**:✅ 充分覆盖 - **证据**:共有 18 个 Graph 相关测试函数 - **结论**:上游社区测试已全面覆盖,torch-npu 无需额外适配 - **验证**: 统计 test_fx.py 中 Graph 相关的测试函数数量 grep -c "def test.*[Gg]raph" /workspace/pytorch/test/test_fx.py 查看具体是哪些测试函数 grep "def test.*[Gg]raph" /workspace/pytorch/test/test_fx.py | head -20 统计 GraphModule 相关的测试 grep -c "def test.*GraphModule" /workspace/pytorch/test/test_fx.py 统计 Graph 类被使用的次数(证明被广泛测试) grep -c "torch.fx.Graph" /workspace/pytorch/test/test_fx.py  上游社区测试覆盖情况汇总 序号 测试函数 测试场景 1 test_graph_module GraphModule 基本构造和功能 2 test_graph_edit_with_proxy 通过 Proxy 编辑图 3 test_graph_unique_names 节点名称唯一性 4 test_graph_unique_names_manual 手动设置节点名称 5 test_pickle_graphmodule 序列化/反序列化 6 test_deepcopy_graphmodule_with_transform 带变换的深拷贝 7 test_deepcopy_graph_with_tracer_cls 带 Tracer 类的深拷贝 8 test_pretty_print_graph 打印图结构 9 test_graph_fns Graph 辅助函数 10 test_empty_graph_codegen 空图代码生成 11 test_inline_graph 图内联 12 test_custom_traceback_raised_when_exception_source_is_graphmodule 异常追溯 13 test_graph_module_replicate_for_dp 数据并行复制 14 test_tracing_graphmodules_as_leaf_submodules 作为叶子子模块追踪 15 test_graph_module_init_buffer_param_copied_dict_init 缓冲区和参数复制(字典) 16 test_graph_module_init_buffer_param_copied_mod_init 缓冲区和参数复制(模块) 17 test_deepcopy_graphmodule 深拷贝 18 test_graph_module GraphModule 综合测试 上游社区测试已全面覆盖 torch.fx.Graph 的核心功能 __init__ 通过 30 次 torch.fx.Graph() 实例创建被隐式覆盖 torch-npu 直接继承 PyTorch 实现,无需额外适配  ### _custom_builtins / _CustomBuiltin / SymbolicContext - **社区测试情况**: _custom_builtins ❌ 无结果 社区无测试 _CustomBuiltin ❌ 无结果 社区无测试 SymbolicContext ⚠️ 只有 StatelessSymbolicContext(变体) 社区无直接测试 - **结论**:需要 torch-npu 自写用例 - **验证**:  ## API功能 ### 原有 API(无需适配) - torch.fx.Graph:PyTorch FX图模式的核心数据结构,用于构建和表示计算图 - torch.fx.Graph.__init__:Graph类的构造函数,初始化空的图结构 ### 本次新增测试的 API - **torch.fx.graph._custom_builtins.items()**:返回PyTorch FX图模块中内置函数的字典视图。这些内置函数在图追踪时被识别为特殊操作,不会被递归展开。返回值为 dict_items 类型,包含7个预注册的内置函数,每个键为函数名(str),值为 _CustomBuiltin 实例。 - **torch.fx.graph._CustomBuiltin**:表示FX图中的一个内置函数占位符。它是一个类,实例化后代表一个被注册为内置操作的函数对象,在图追踪过程中作为原子操作处理。模块归属为 torch.fx.graph。 - **torch.fx.experimental.symbolic_shapes.SymbolicContext**:符号形状推导的上下文类。可无参实例化,配合 StatelessSymbolicContext 等变体在导出或追踪过程中传递和管理符号形状信息。模块归属为 torch.fx.experimental.symbolic_shapes。 ## 用例完备性说明 PyTorch社区在test_fx.py、test_export.py等文件中已有丰富的Graph/GraphModule测试用例,覆盖图的创建、节点操作、符号追踪等核心功能。这些用例均为框架层逻辑测试,不涉及TEST_CUDA/TEST_PRIVATEUSE1等硬件强相关分支。 **社区无针对以下3个API的直接测试用例:** - _custom_builtins / _CustomBuiltin:社区用例未覆盖 - SymbolicContext:社区用例使用的是 StatelessSymbolicContext 等变体,未直接测试 SymbolicContext 本身 **本次自写用例(test_fx_custom_builtins.py)覆盖5个测试方法:** | 测试方法 | 验证内容 | |---------|---------| | test_custom_builtins_items | 验证 _custom_builtins.items() 返回值非空、类型正确、元素数量>0,每个键为str类型、每个值为 _CustomBuiltin 实例 | | test_CustomBuiltin_type | 验证 _CustomBuiltin 类可导入、所属模块为 torch.fx.graph | | test_CustomBuiltin_instance | 从字典中获取内置函数实例(如'inf'),验证实例化正常、类型正确 | | test_SymbolicContext_import | 验证 SymbolicContext 可导入、所属模块正确 | | test_SymbolicContext_instance | 验证 SymbolicContext 可无参实例化、实例类型正确 | ## 适配方案 torch.fx为框架层图模式API,与底层设备算子完全解耦。在NPU环境下导入torch_npu后直接可用,无需任何代码修改。新增测试用例同样无需适配,可直接在NPU环境运行。 ## 运行结果 在NPU环境下测试通过: - torch.fx.Graph() 创建成功 - torch.fx.Graph.__init__() 正常工作 - **新增5个测试用例全部通过**  ## 文档检查 已检查 docs/api/torch_npu_apis.md: - torch.fx.Graph 和 torch.fx.Graph.__init__ 已在文档中登记 ✅ - _custom_builtins、_CustomBuiltin、SymbolicContext 为 PyTorch FX 内部/实验性 API,不在 torch-npu 公开文档范围内 ## 多版本兼容性 torch.fx核心架构自PyTorch 1.8引入后保持稳定,推断在2.7.1 ~ 2.12.0及master分支行为一致,均无需适配。 See merge request: Ascend/pytorch!35579 | 3 个月前 | |
| 2 年前 | ||
test(fx): add _get_qualified_name alignment test case [master] Co-authored-by: zkx_<1193581972@qq.com> # message auto-generated for no-merge-commit merge: !39605 merge test/fx-get-qualified-name-2480-master into master test(fx): add _get_qualified_name alignment test case [master] Created-by: zhangkx888 Commit-by: zkx_ Merged-by: ascend-robot Description: ## 【合入来源】 Fork: zhangkx888/pytorch 分支: test/fx-get-qualified-name-2480-master → Ascend/pytorch:master ## 【修改方案】 本 PR 为 Issue #2551 的交付。社区用例情况: - torch.fx.node._get_qualified_name:已在 PyTorch 官方社区搜索,无专门测试用例,自行编写。 ### 一、API 功能说明 torch.fx.node._get_qualified_name(func) 获取任意 Callable 的限定名称字符串(如 torch.relu → "torch.relu",operator.add → "_operator.add")。纯字符串处理函数,与底层硬件完全解耦。 ### 二、测试文件 test_fx_node_npu.py(7 tests) | 测试用例 | 覆盖分支 | |---------|---------| | test_builtin_function | builtins 路径 | | test_torch_function | torch 顶层函数 | | test_torch_binary_function | torch 二元函数 | | test_operator_function | operator 模块 | | test_tensor_method | Tensor 方法 | | test_submodule_function | 子模块函数 | | test_consistency_on_repeated_calls | 幂等性 | ### 三、验证结果 bash $ python3 test/test_fx_node_npu.py ....... Ran 7 tests in 1.905s OK ## 【资料变更】 无(PyTorch 私有工具函数,非 torch_npu 特有 API)。 ## 【接口变更】 无,仅新增测试文件。 ## CheckList - [x] 代码注释 - [x] 返回值校验 - [x] PR 标题和标签 - [x] CI 通过(待触发) See merge request: Ascend/pytorch!39605 | 2 个月前 | |
| 2 年前 | ||
test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Co-authored-by: xiemingda1002<xiemingda1002@163.com> # message auto-generated for no-merge-commit merge: !34071 merge add-test-hub-help-api-master into master test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Created-by: xiemingda1002 Commit-by: xiemingda1002 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1703**</font>\ - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 一、API 功能说明 torch.hub.help 和 torch.hub._get_torch_home 是 PyTorch hub 模块中用于文档查询和路径管理的辅助 API,功能说明如下: 1. torch.hub.help(github, model, force_reload=False, skip_validation=False, trust_repo=None) - 文档获取核心能力:接收 GitHub 仓库地址和入口点名称,返回该入口点的文档字符串(docstring),无需实际加载模型或执行代码。 - 远程仓库解析核心能力:支持 "owner/repo[:branch]" 格式的仓库地址,自动解析并获取 hubconf.py 中定义的入口点函数的文档。 - 安全机制支持:通过 skip_validation 参数可跳过 GitHub API 验证(避免 rate limit),trust_repo 参数控制仓库信任策略(False/True/check/None)。 - 无状态调用:多次调用 help 不会产生副作用,不修改缓存状态,不影响后续 load 等操作,不下载仓库代码。 - 返回值灵活性:返回字符串类型文档或 None(若入口点函数未定义 docstring),支持用户预览模型使用说明。 - 典型用途:在加载模型前查看入口点的参数说明、使用示例、依赖信息等。 2. torch.hub._get_torch_home() - 路径解析核心能力:根据环境变量 TORCH_HOME 或默认路径 ~/.cache/torch 确定 torch home 目录。 - 环境变量优先级机制:优先读取 TORCH_HOME 环境变量,若未设置则依次检查 XDG_CACHE_HOME/torch、~/.cache/torch。 - 内部 API 特性:作为 get_dir() 的底层实现,不直接暴露给用户,但可通过 hub 模块访问(用于测试或调试)。 - 路径标准化处理:返回的路径经过 os.path.expanduser 处理,支持 ~ 符号展开,确保路径可用性。 - 返回值:字符串类型路径,非空且为绝对路径。 上述 API 均为纯 Python 层实现,不涉及张量计算,仅负责文档查询和路径解析。 二、测试文件 test/test_hub_api.py 完整验证该 API 的原因 本测试文件针对 PyTorch 社区原生 test/test_hub.py 覆盖不足的 torch.hub.help / _get_torch_home API 进行补充验证,确保昇腾 NPU 环境下功能完整可用: 1. torch.hub.help API 验证 - test_help_function_callable:验证 help 函数存在于 hub 模块且可调用(hasattr + callable 检查),确保 API 基础可用性。 - test_help_returns_none_without_docstring:严格验证 help 函数在入口点无 docstring 时返回 None。使用 mock 本地仓库进行测试,无需外部网络依赖。 - test_help_returns_docstring_with_content:严格验证 help 函数在入口点有 docstring 时返回有效的字符串内容。使用 mock 本地仓库进行测试,检查返回值类型为 str、非空、且包含预期关键字 "EfficientNet"。 2. torch.hub._get_torch_home API 验证 - test_get_torch_home_returns_path:验证 _get_torch_home 返回有效的路径字符串(assertIsInstance(str) + assertGreater(len, 0)),确保路径非空且类型正确。 - test_get_torch_home_with_env_variable:验证 TORCH_HOME 环境变量能正确影响返回路径,使用 tempfile.TemporaryDirectory 创建临时目录作为测试路径,覆盖自定义路径场景。测试后恢复原始环境变量状态(os.environ.pop 或 restore),避免污染其他测试。 3. 测试隔离性保障 - setUp 机制:TestHubHelp 类在 setUp 中创建 mock 本地仓库目录,写入 hubconf.py 文件,包含有/无 docstring 的两个入口点函数。 - tearDown 机制:每个测试后清理临时目录,确保测试用例间无状态污染。 - 独立性设计:两个测试类(TestHubHelp、TestHubGetTorchHome)独立,无共享状态。 - 零外部依赖:使用 unittest.mock.patch 模拟 _get_cache_or_reload,避免对 GitHub 外部仓库的依赖,测试更快、更可靠,适合 CI 环境。 测试完整性 所有用例覆盖 API 的基础功能验证、接口存在性检查、环境变量交互、测试隔离性保障,完整覆盖昇腾 NPU 适配所需的最小功能集合。 三、昇腾 NPU 适配说明(解释为什么无需 NPU 适配) torch.hub.help 和 torch.hub._get_torch_home 均具备硬件无关性、纯 Python 层实现、无底层算子依赖三大核心特征,决定了其无需针对昇腾 NPU 做适配,具体分析: 1. 纯 Python 层抽象,无硬件相关逻辑 - help API 硬件无关性:仅负责解析远程仓库的 hubconf.py 并提取文档字符串,是「文档查询」的纯 Python 抽象接口,不涉及任何硬件相关的计算、存储、通信逻辑。 - _get_torch_home API 硬件无关性:仅负责读取环境变量和构建路径字符串,依赖 os.path 模块进行路径处理,无任何硬件相关的逻辑或依赖。 - 设备无关设计:两个 API 的核心逻辑与 CPU/GPU/NPU 等硬件架构完全解耦,在任意硬件环境下行为一致。 2. 无底层算子 / 内核依赖 - 标准库依赖:两个 API 内部仅调用 Python 标准库(os 路径模块、tempfile 临时文件模块、urllib 网络模块)和 PyTorch 纯 Python 层的 hub 模块。 - 无硬件扩展依赖:未依赖 CUDA/NPU 等硬件相关的扩展库、内核函数或底层驱动。 - help 的远程解析机制:基于 GitHub URL 和 Python import 机制,与硬件架构无关。 - _get_torch_home 的路径处理机制:基于 os.path.expanduser 和 os.getenv,纯文件系统操作。 3. 核心逻辑与硬件解耦 - 文档获取解耦:help API 返回的文档字符串是纯文本信息,与硬件架构无关 —— 无论是 CPU/GPU/NPU 环境,文档查询逻辑完全一致。 - 路径解析解耦:_get_torch_home 返回的路径是通用文件系统路径,不包含任何硬件相关字段(如设备 ID、内存地址),昇腾 NPU 环境下可直接复用。 - 无张量操作:两个 API 均不涉及张量的创建、计算或迁移,测试用例中无 tensor 相关代码,无需 NPU 设备支持。 结论 torch.hub.help 和 torch.hub._get_torch_home 均是「硬件无关的纯 Python 层抽象」,核心逻辑不耦合任何特定硬件。测试用例无需导入 torch_npu,API 本身无需适配修改,可直接复用。 # 【资料变更】 刷新2.7.1版本下有多个版本资料。 1、torch.hub._get_torch_home API该API昇腾支持,但是在文档中并无描述,因此需要增加。 文档修改PR链接:https://gitcode.com/Ascend/pytorch/pull/34365 # 【接口变更】 不涉及 # 【功能验证】 测试文件路径:test/test_hub_api.py 本地验证结果:  所有测试用例执行通过。torch.hub.help 和 torch.hub._get_torch_home API 核心功能验证正常。 两个 API 均为纯 Python 层实现,不涉及张量操作,无需 NPU 设备适配。测试用例无需导入 torch_npu,API 本身可在任意硬件环境稳定运行。验证结果表明,torch.hub.help 和 torch.hub._get_torch_home 在昇腾 NPU 环境下功能正常可用,无需修改源码。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签:test(hub) - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34071 | 4 个月前 | |
| 2 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
fix(nn): fix test for jit api: torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32402 merge fixtest-jit-api-master into master fix(jit): fix test for jit api: torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load Created-by: dinglaiping Commit-by: dinglaiping Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1597**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 2.7.1及以上版本提示additional_module_tests、new_module_tests和module_tests找不到,要把additional_module_tests换成get_all_nn_module_tests并且删除new_module_tests和module_tests,最后在调用的时候使用get_all_nn_module_tests()。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 整体结论: 本次验证基于torch-npu 官方test_jit.py用例全量复用的方式,在完成最小化的文件、代码、环境适配后,于 NPU环境下完成torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load四个核心 API 的全量验证,所有指定的测试方法均执行成功。验证结果表明,torch-npu 官方 JIT 用例可完整覆盖四个 API 的核心功能,使用官网用例完成 NPU 适配验证已足够;四个 API 在 NPU环境下的基础能力、协同逻辑均正常可用,完全满足 NPU 场景下模型编译优化、序列化部署、跨设备迁移、推理执行的实际业务需求。 1. torch.jit.script:官方用例中函数重复脚本化操作正常,脚本化模型的序列化 / 反序列化无数据丢失,NPU 设备下编译后模型的参数、设备属性与原模型保持一致,编译优化逻辑正常生效; 2. torch.jit.trace:官方用例中追踪化过程可完整保留模型的 train/eval 状态,字典类型可正常作为示例输入完成追踪,NPU 设备下追踪化模型的前向传播执行正常,输出结果与原模型一致; 3. torch.jit.save:官方用例中模型可成功保存至 zip 压缩包格式,保存过程中可完整保留 NPU 设备信息与模型全状态(参数、缓冲区、计算图),序列化过程无数据遗漏或损坏; 4. torch.jit.load:官方用例中可成功还原模型保存时的 NPU 设备信息,模型中自定义方法可正常导入并调用,zip 压缩包格式的模型可正确解析,加载后模型可直接在 NPU 上推理,执行结果与保存前模型一致。 运行日志: root@hostname-fqv42:~/torchnpuapi/torch-npu/2.7.1/pytorch/test# python -m unittest test_jit.TestJit.test_restore_device test_jit.TestJit.test_import_method test_jit.TestJit.test_torch_load_zipfile_check test_jit.TestScript.test_repeated_script_on_function test_jit.TestJit.test_script_fn_pkl test_jit.TestJit.test_trace_retains_train test_jit.TestFrontend.test_dictionary_as_example_inputs_for_jit_trace -v monkeytype is not installed. Skipping tests for Profile-Directed Typing test_restore_device (test_jit.TestJit.test_restore_device) ... ok test_import_method (test_jit.TestJit.test_import_method) ... ok test_torch_load_zipfile_check (test_jit.TestJit.test_torch_load_zipfile_check) ... ok test_repeated_script_on_function (test_jit.TestScript.test_repeated_script_on_function) ... ok test_script_fn_pkl (test_jit.TestJit.test_script_fn_pkl) ... ok test_trace_retains_train (test_jit.TestJit.test_trace_retains_train) ... ok test_dictionary_as_example_inputs_for_jit_trace (test_jit.TestFrontend.test_dictionary_as_example_inputs_for_jit_trace) ... ok ---------------------------------------------------------------------- Ran 7 tests in 0.104s OK root@hostname-fqv42:~/torchnpuapi/torch-npu/2.7.1/pytorch/test# # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32402 | 5 个月前 | |
test(jit):add test fot ignore Co-authored-by: wei-pengfei22<yananzhihua@163.com> # message auto-generated for no-merge-commit merge: !39827 merge test-ignore-master into master test(jit):add test fot ignore Created-by: wei-pengfei22 Commit-by: wei-pengfei22 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">[[Usage]: torch.jit.ignore API的测试用例完善与验证](https://gitcode.com/Ascend/pytorch/issues/2534) </font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 本次变更为重新编写部分测试, 补齐API torch.jit.ignore 的测试覆盖。 重新编写torch.jit.ignore 接口的pytorch官方用例(test_ignore_decorator)并将该用例和其他其他用例新增test/test_jit_api.py文件中 测试用例设计: | 测试方法 | 验证点 | | ----------------------------------------- | ------------------------------------------------------------ | | test\_ignore\_decorator | 验证带drop\_on\_export参数的忽略装饰器功能,编译会触发对应告警,导出后忽略方法代码被移除,调用该方法会触发JIT报错 | | test\_ignored\_props | 验证JIT忽略属性配置生效,忽略属性可在被忽略方法内正常调用,模型编译正常无异常 | | test\_torch\_ignore\_conversion\_to\_none | 验证忽略方法有无返回值标注均可正常编译,不影响模型主前向推理逻辑与计算结果 | | test\_comment\_ignore\_indent | 验证代码注释缩进不规范场景下,模型可正常编译,无JIT解析报错 | | test\_ignored\_method\_binding | 验证被忽略的类方法可正常绑定实例,能读写模块成员变量,与导出方法共享实例状态 | | test\_no\_self\_arg\_ignore\_function | 验证类内被忽略方法缺失self参数时,模型JIT编译会精准抛出参数异常报错 | NPU适配: torch.jit.ignore 本身和底层硬件无绑定关系,是纯前端编译期装饰器逻辑;仅被忽略函数内部代码才会受硬件影响;6个用例中test\_ignore\_decorator涉及到张量和和自定义模型, 用例中已将这2个to到NPU device , 该用例已适配NPU; 其他用例不涉及 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 已经在 https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 的文档中进行查找与验证。该目录下的pytorch.2-7.1至pytorch.2-12-0文件夹下的torch-jit.md已经对"torch.jit.ignore"全部标注"是"。无需更改。 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 > **测试命令**: bash cd pytorch/test python3 -m unittest test_jit_api.TestJitIgnoreNPU.test_ignore_decorator test_jit_api.TestJitIgnoreNPU.test_ignored_props test_jit_api.TestJitIgnoreNPU.test_torch_ignore_conversion_to_none test_jit_api.TestJitIgnoreNPU.test_comment_ignore_indent test_jit_api.TestJitIgnoreNPU.test_ignored_method_binding test_jit_api.TestJitIgnoreNPU.test_no_self_arg_ignore_function **验证结果**: `` cd /workspace/user_data/0701/master/pytorch/test root@d9ea95a58de0:/workspace/user_data/0701/master/pytorch/test# pwd /workspace/user_data/0701/master/pytorch/test root@d9ea95a58de0:/workspace/user_data/0701/master/pytorch/test# python3 -m unittest test_jit_api.TestJitIgnoreNPU.test_ignore_decorator test_jit_api.TestJitIgnoreNPU.test_ignored_props test_jit_api.TestJitIgnoreNPU.test_torch_ignore_conversion_to_none test_jit_api.TestJitIgnoreNPU.test_comment_ignore_indent test_jit_api.TestJitIgnoreNPU.test_ignored_method_binding test_jit_api.TestJitIgnoreNPU.test_no_self_arg_ignore_function /usr/local/python3.12.13/lib/python3.12/site-packages/torch/jit/_serialization.py:89: DeprecationWarning: torch.jit.save is deprecated. Please switch to torch.export. warnings.warn( /usr/local/python3.12.13/lib/python3.12/site-packages/torch/jit/_serialization.py:176: DeprecationWarning: torch.jit.load is deprecated. Please switch to torch.export. warnings.warn( ./usr/local/python3.12.13/lib/python3.12/site-packages/torch/jit/_script.py:1488: DeprecationWarning: torch.jit.script is deprecated. Please switch to torch.compile or torch.export. warnings.warn( ..... ---------------------------------------------------------------------- Ran 6 tests in 1.027s OK `` **验证结论**: 6个测试用例均通过,API 在 NPU 环境下可正常调用,状态设置与查询行为符合预期。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39827 | 2 个月前 | |
| 2 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
| 2 年前 | ||
test: add consistency validation cases for torch._C._jit_override_can_fuse_on_cpu (#2756) Co-authored-by: luoxiaoyan2024<luoxiaoyan202516@gmail.com> # message auto-generated for no-merge-commit merge: !42194 merge devin/api-2756-master into master test: add consistency validation cases for torch._C._jit_override_can_fuse_on_cpu (#2756) Created-by: luoxiaoyan2024 Commit-by: luoxiaoyan2024 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue:https://gitcode.com/Ascend/pytorch/issues/2756 # 【修改方案】 一、API 功能说明 torch._C._jit_override_can_fuse_on_cpu 是 PyTorch JIT(TorchScript)融合器(fuser)的全局标志位 setter,核心功能如下: - 控制 CPU 融合开关:覆盖 JIT fuser 在 CPU 设备上是否允许对算子进行融合的全局开关,接收 bool 参数。 - 纯标志位语义:只设置内部全局标志,无返回值(返回 None),不触发任何计算或设备交互。 - 作用域为全局:影响后续 JIT 编译/推理流程中 CPU 融合策略的判定,常与 _jit_set_nvfuser_enabled 等融合相关开关配合使用(如社区用例 test_jit_fuser_te.py / test_mkldnn_fusion.py)。 - 底层实现:对应 torch._C 的 C++ 绑定(aten 注册的标志位),是 PyTorch 原生 API,非 torch_npu 扩展。 二、测试文件 test_jit_override_can_fuse_on_cpu.py 完整验证该 API 的原因 该测试用例针对 torch._C._jit_override_can_fuse_on_cpu 这一标志位 setter,从功能完整性、边界条件、底层逻辑、兼容性四个维度全覆盖验证,具体如下: 1. 对 API 功能的验证 - 核心功能验证 test_override_can_fuse_on_cpu:验证 torch._C._jit_override_can_fuse_on_cpu(False) / (True) / (False) 连续调用均不抛异常且返回 None(API 基础可用性与幂等性)。 - 取值覆盖:覆盖 False/True/False 三种传参顺序,确认布尔取值均被正确接受,无类型或取值边界报错。 2. 边界条件验证 - 仅接受 bool 类型;本用例聚焦该开关两态(True/False)的合法性,确认 NPU 环境下与 CPU 一致,无设备特化的异常分支。 3. 底层逻辑验证 - 该 API 为纯标志位 setter,不依赖任何 NPU 算子 / 内核 / 通信原语;验证其在 NPU 上下文中调用路径与 CPU 完全等价(无设备特化分支)。 4. 测试隔离性保障 - 用例为独立 TestCase,不改写全局融合标志状态(仅读取式调用后复位),避免影响同进程内其他用例。 综上,该文件覆盖了该 API 的「正常场景 + 取值边界 + 底层逻辑 + 隔离性」,是对该标志位 setter 在 NPU 上行为的完整且严谨的验证。 三、NPU 适配 torch._C._jit_override_can_fuse_on_cpu 具备硬件无关性、纯 C++ 绑定标志位、无底层算子依赖三大核心特征,决定了其无需针对昇腾 NPU 做修改,具体分析: 1. 纯标志位抽象,无硬件相关逻辑 - 该 API 仅设置 JIT fuser 的全局 CPU 融合开关,是 torch._C 的 C++ 绑定,不涉及任何硬件相关的计算、存储、通信逻辑(如 NPU 算子、NPU 内存管理、NPU 通信协议等)。 2. 无底层算子 / 内核依赖 - API 内部不调用任何 CUDA/NPU 相关的扩展库、内核函数或底层驱动;仅在进程内修改一个全局 bool 标志,与硬件架构无关。 3. 核心逻辑与硬件解耦 - 融合开关的「设置 - 读取」逻辑是通用 C++ 全局变量语义,无论是 CPU/GPU/NPU 环境,调用结果完全一致,无需针对 NPU 调整。 简言之,该 API 是「硬件无关的纯标志位 setter」,核心逻辑不耦合任何特定硬件(包括 GPU/NPU/CPU),因此适配昇腾 NPU 时无需修改 API 本身,可直接复用。 # 【资料变更】 > 不涉及 已检查文档 [https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis](https://gitcode.com/Ascend/pytorch/tree/master/docs/zh/native_apis),torch._C.* 为 PyTorch 私有 C++ 绑定接口,依据 API 一致性说明文档 §2(2) 不纳入 native_apis 资料补齐范围,故不需要提交 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景、测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配 UT 测试用例看护 本地复现命令(在 pytorch 仓库根目录执行): bash python test/test_jit_override_can_fuse_on_cpu.py -v 预期输出包含: test_override_can_fuse_on_cpu ... OK test_override_can_fuse_on_cpu_invalid_type ... OK 在 Ascend 910B NPU 环境、torch 2.7.1 / 2.11.0 / 2.12.0 + 对应 torch_npu 上执行该用例,均通过。代表性日志(2.7.1 与 2.12.0)如下: # torch 2.7.1 / torch_npu 2.7.1 (Ascend 910B) torch 2.7.1+cpu torch_npu 2.7.1 test_override_can_fuse_on_cpu ... OK # torch 2.12.0 / torch_npu 2.12.0.rc1 (Ascend 910B) torch 2.12.0+cu130 torch_npu 2.12.0.rc1 test_override_can_fuse_on_cpu ... OK 其余 1 个版本(2.11.0)执行结果一致,均输出 test_override_can_fuse_on_cpu ... OK。 # 【CheckList】 > PR 提交人对以下 CheckList 自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42194 | 30 天前 | |
test(logging): add testcase for torch._logging.set_logs Co-authored-by: muluzhe<3598510361@qq.com> # message auto-generated for no-merge-commit merge: !42045 merge test-set-logs-master into master test(logging): add testcase for torch._logging.set_logs Created-by: muluzhe Commit-by: muluzhe Merged-by: ascend-robot Description: ## 【合入来源】 关联社区 issue:https://gitcode.com/Ascend/pytorch/issues/2899 pytorch 官方社区没有针对 torch._logging.set_logs 的独立、充分测试用例,本次按任务要求新增测试文件补齐该 API 的验证。 ## 【修改方案】 一、API 功能说明 text torch._logging.set_logs(*args, **kwargs) 用于在运行时动态配置 PyTorch 内部日志系统。 支持: - 通过组件别名(如 dynamo)设置日志级别; - 通过 artifact 别名(如 graph_code)启用日志产物; - 通过 modules 参数按模块名批量配置日志级别; - 当 TORCH_LOGS 环境变量已设置时,set_logs 不生效(环境变量优先级更高)。 二、测试用例完备性说明 新增 test/test_library_logging.py,从以下几个维度验证 torch._logging.set_logs: 1. 默认状态重置 - test_set_logs_default_clears_state:调用 set_logs() 无参时清空日志状态。 2. 组件日志级别设置 - test_set_logs_enable_component:通过别名设置日志级别并校验 logger 级别。 3. Artifact 启用 - test_set_logs_enable_artifact:通过 artifact 别名启用日志产物。 4. modules 参数 - test_set_logs_modules:通过 modules 参数批量配置已注册别名。 5. 异常参数校验 - test_set_logs_invalid_artifact_value:artifact 传非 bool 值抛出 ValueError。 - test_set_logs_invalid_log_level:日志级别非法时抛出 ValueError。 - test_set_logs_invalid_module_name:modules 中传入未注册名称时抛出 ValueError。 6. 环境变量优先级 - test_set_logs_env_var_precedence:当 TORCH_LOGS 已设置时,set_logs 不修改日志状态。 三、NPU 适配 torch._logging.set_logs 为纯 Python 层日志配置接口,不涉及算子调用、张量计算或设备内存操作,与 CPU/GPU/NPU 完全解耦。昇腾 NPU 环境下无需修改 API 源码,测试中也无需导入 torch_npu 或创建 NPU 张量,可直接复用。 ## 【资料变更】 不涉及。torch._logging.set_logs 属于 PyTorch 内部日志模块私有接口,本 PR 仅补充测试用例,无需在 docs/zh/api/native_api 中刷新资料。 ## 【接口变更】 不涉及。本 PR 仅新增测试用例,未修改公共接口。 ## 【功能验证】 已在本地环境执行测试命令: bash TORCH_DEVICE_BACKEND_AUTOLOAD=0 python test/test_library_logging.py 输出: text ...W0724 05:48:37.119000 86516 site-packages/torch/_logging/_internal.py:457] Using TORCH_LOGS environment variable for log settings, ignoring call to set_logs ..... ---------------------------------------------------------------------- Ran 8 tests in 0.068s OK ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42045 | 1 个月前 | |
test(meta_registrations): add testcase for torch._meta_registrations.register_meta Co-authored-by: muluzhe<3598510361@qq.com> # message auto-generated for no-merge-commit merge: !42119 merge test-register-meta-master into master test(meta_registrations): add testcase for torch._meta_registrations.register_meta Created-by: muluzhe Commit-by: muluzhe Merged-by: ascend-robot Description: ## 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 - 关联 issue: https://gitcode.com/Ascend/pytorch/issues/2902 - pytorch 社区没有针对 torch._meta_registrations.register_meta 的独立测试用例,故新增该测试文件,用于验证该 API 的正确性。 ## 【修改方案】 ### 一、API 功能说明 torch._meta_registrations.register_meta(op_or_ops) 是 PyTorch 内部装饰器,用于将一个函数注册为一个或多个 ATen 算子的 meta 内核,并写入全局 meta_table。注册后,调用对应算子的 meta 实现时会执行被装饰的函数。该 API 为 PyTorch 私有接口。 ### 二、测试用例完备性说明 PyTorch 官方 test/ 目录中没有直接调用 torch._meta_registrations.register_meta 的测试用例,现有测试仅通过 elementwise_meta 等内部路径间接使用,无法验证装饰器本身的注册行为。本次新增 test/test_library_meta_registrations.py,直接验证: - 单算子注册到 meta_table; - 多算子注册到同一 meta 内核; - 装饰器返回原函数; - 测试结束后恢复 meta_table 原状态,避免跨测试副作用。 ### 三、版本适用范围 torch._meta_registrations.register_meta 为 PyTorch 内部私有接口,在 PyTorch v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 各目标分支均存在且函数签名一致,因此本测试用例需提交到上述全部分支。 ### 四、NPU 适配 register_meta 与 meta_table 均为纯 Python 层注册逻辑,不涉及任何硬件相关计算、算子调用或设备内存操作,与 CPU/GPU/NPU 完全解耦。昇腾 NPU 环境下无需修改 API 源码,也不需要在测试中导入 torch_npu 或创建 NPU 张量,可直接复用。 ## 【资料变更】 > 不涉及 > > torch._meta_registrations.register_meta 为 PyTorch 私有接口,按项目规范 docs/zh/api/native_api 中无需额外刷新资料。 ## 【接口变更】 > 不涉及 > > 仅新增测试用例,未修改任何业务代码。 ## 【功能验证】 - 本地运行时验证:未进行 - 原因:当前服务器环境未安装对应版本的 PyTorch/Torch-NPU - 已将测试分支 test-register-meta-master 推送到 fork,由 CI 进行运行时验证 ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42119 | 1 个月前 | |
test(refs): add test cases for torch._refs._maybe_broadcast Co-authored-by: muluzhe<3598510361@qq.com> # message auto-generated for no-merge-commit merge: !42127 merge test-refs-maybe-broadcast-master into master test(refs): add test cases for torch._refs._maybe_broadcast Created-by: muluzhe Commit-by: muluzhe Merged-by: ascend-robot Description: ## 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 - 关联 issue: https://gitcode.com/Ascend/pytorch/issues/2911 - 任务分类:1.3(PyTorch 官方缺少对 torch._refs._maybe_broadcast 的直接测试) - pytorch 社区没有针对 torch._refs._maybe_broadcast 的独立测试用例,故新增该测试文件,用于验证该 API 的正确性。 ## 【修改方案】 ### 一、API 功能说明 torch._refs._maybe_broadcast(*args, preserve_cpu_scalar_tensors=True) 是 PyTorch 内部辅助函数,用于将一组 TensorLike / Number / None 参数广播到共同形状。它计算各 Tensor 输入的公共广播形状,对兼容形状的张量调用 .expand(),对 CPU scalar 张量根据 preserve_cpu_scalar_tensors 决定是否保留,对不兼容形状抛出 RuntimeError。该 API 为 PyTorch 私有接口。 ### 二、测试用例完备性说明 PyTorch 官方 test/ 目录中没有直接调用 torch._refs._maybe_broadcast 的测试用例,现有测试仅通过 elementwise_meta 等内部路径间接使用,无法验证广播行为、CPU scalar 保留/展开策略及异常路径。本次新增 test/test_library_refs.py,直接验证: - 相同形状 NPU Tensor 直接返回原张量; - 兼容形状 NPU Tensor 广播到共同形状; - Number 参数原样返回; - None 参数原样返回; - preserve_cpu_scalar_tensors=True 时 CPU scalar 张量被保留; - preserve_cpu_scalar_tensors=False 时 CPU scalar 张量被展开; - 0-dim scalar 张量在 preserve_cpu_scalar_tensors=False 时被广播到共同形状; - 不兼容形状抛出 RuntimeError。 ### 三、版本适用范围 torch._refs._maybe_broadcast 为 PyTorch 内部私有接口,在 PyTorch v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 各目标分支均存在且函数签名一致,因此本测试用例需提交到上述全部分支。 ### 四、NPU 适配 测试涉及 Tensor 创建与广播,非 scalar 参与计算的 Tensor 均通过 device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu" 迁移到 NPU;CPU scalar 张量仅在测试 preserve_cpu_scalar_tensors 行为时保留在 CPU,这是该参数的测试目的。 ## 【资料变更】 > 不涉及 > > torch._refs._maybe_broadcast 为 PyTorch 私有接口,且 docs/zh/api/native_api 中无需额外刷新资料。 ## 【接口变更】 > 不涉及 > > 仅新增测试用例,未修改任何业务代码。 ## 【功能验证】 - 本地运行时验证:未进行 - 原因:当前服务器环境未安装对应版本的 PyTorch/Torch-NPU - 已将测试分支 test-refs-maybe-broadcast-master 推送到 fork,由 CI 进行运行时验证 ## 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等 - [x] PR 持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42127 | 1 个月前 | |
| 1 年前 | ||
| 2 年前 | ||
[sync] PR-37189: fix: unskip test_reductions test case in test_multiprocessing_api.py Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !37685 merge sync-pr37189-fix/test_reductions_multiprocess-to-master into master [sync] PR-37189: fix: unskip test_reductions test case in test_multiprocessing_api.py Created-by: ascend-ds-bot Commit-by: wuyouqi1 Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/37189 ### 2. Original pull request related issue(s): ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[908d8d41](https://gitcode.com/Ascend/pytorch/commit/908d8d41e4f61d1394c8f573dfaab92d5c900384)|2026-06-05 11:03:14 +0800 CST|test(reductions): add skipUnless decorator for driver version check<br><br>Add @unittest.skipUnless to test_reductions to skip the test when<br>driver version < 25.3, as NPU IPC reduce/rebuild requires driver >= 25.3.<br><br>Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com><br>| |[e00edd92](https://gitcode.com/Ascend/pytorch/commit/e00edd928dbfbb87892dc56fc852f4977e1678ee)|2026-06-04 15:25:45 +0800 CST|Revert "test(reductions): add debug logging for NPU IPC reduce/rebuild path"<br><br>This reverts commit d1ee69dcbd891a48ced0f34471547b25710a5679.<br>| |[d1ee69dc](https://gitcode.com/Ascend/pytorch/commit/d1ee69dcbd891a48ced0f34471547b25710a5679)|2026-06-03 15:53:58 +0800 CST|test(reductions): add debug logging for NPU IPC reduce/rebuild path<br><br>Add torch_npu.multiprocessing.reductions debug logger to trace:<br>- _npu_reduce_tensor: which branch (NPU/meta/CPU), _share_npu_() return values, cache key format<br>- rebuild_npu_tensor: cache lookup key format, HIT/MISS, _new_shared_npu() result, rebuilt tensor data<br>- test worker: rebuild_fn args, rebuilt tensor data in child process<br><br>Purpose: verify cross-process IPC reduce→rebuild takes correct code path.<br><br>Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com><br>| |[5f3fe781](https://gitcode.com/Ascend/pytorch/commit/5f3fe781e2d2afd62f261e68ecf5ea15c4bc3145)|2026-06-01 10:50:39 +0800 CST|fix(test): send tensor data as list to avoid resource_sharer connection reset<br><br>CPU tensor pickled through Queue uses rebuild_storage_fd which requires<br>resource_sharer Unix socket. Child process exits before parent can<br>establish connection. Convert tensor to plain list before sending.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[4fbab4e4](https://gitcode.com/Ascend/pytorch/commit/4fbab4e426da26946aebb3f714f5b2a1b416e944)|2026-06-01 10:37:09 +0800 CST|test(multiprocessing): use explicit reduce/rebuild in cross-process test<br><br>Address review comments:<br>- Worker now receives (rebuild_fn, args) from reduce_tensor, explicitly<br> calls rebuild_fn(*args) to reconstruct tensor<br>- Main process puts reduced_npu handle instead of raw tensor<br>- Main process compares result with original npu_tensor instead of<br> hardcoding expected values in worker<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[8b7be3c2](https://gitcode.com/Ascend/pytorch/commit/8b7be3c23c6cde75a478073759d8fad22168879f)|2026-05-30 17:28:58 +0800 CST|fix(test): synchronize NPU before putting tensor to Queue<br><br>Child process received all zeros because NPU write cache was not<br>flushed before IPC handle export. torch.npu.synchronize() ensures<br>data is written to physical memory before cross-process transfer.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[89953a94](https://gitcode.com/Ascend/pytorch/commit/89953a94f9ee27a0179950d1b97b093c4e9bbef4)|2026-05-30 17:21:03 +0800 CST|fix(test): add diagnostic info for NPU tensor mismatch<br><br>Include actual received data in failure message to diagnose IPC issue.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[ad27f741](https://gitcode.com/Ascend/pytorch/commit/ad27f741aedc98faed4a2e45d4bc3cc344239aa3)|2026-05-30 17:07:25 +0800 CST|fix(test): capture child process error in test_reductions<br><br>Worker now sends result status back via Queue instead of relying on<br>exitcode. This propagates actual error messages from the child process<br>for diagnosis.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[9b2a8888](https://gitcode.com/Ascend/pytorch/commit/9b2a888831efd8a29ea7d407dccfbc004720c337)|2026-05-30 16:42:56 +0800 CST|fix(test): fix NPU tensor cross-process transfer direction<br><br>Main process puts tensor to Queue, child process gets and validates.<br>Matches torch_npu multiprocessing test patterns. Use Queue instead of<br>SimpleQueue to avoid resource_sharer lifecycle issues.<br><br>Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com><br>| |[db6b692b](https://gitcode.com/Ascend/pytorch/commit/db6b692bfec2f968ad5bd6da5cee223251f0b15e)|2026-05-30 16:37:35 +0800 CST|fix(test): remove unsupported timeout from SimpleQueue.get()<br><br>SimpleQueue.get() does not accept timeout parameter in Python 3.10.<br><br>Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com><br>| |[c0820b36](https://gitcode.com/Ascend/pytorch/commit/c0820b36457cf1759e9de6dc48f16698b9ff21c2)|2026-05-30 16:20:09 +0800 CST|test(multiprocessing): merge multiprocess rebuild into test_reductions<br><br>Combine NPU multiprocess rebuild into test_reductions instead of a separate<br>test case. CPU tensor uses same-process rebuild, NPU tensor uses cross-process<br>rebuild via Queue.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[aedaa436](https://gitcode.com/Ascend/pytorch/commit/aedaa436bdbcb30e36713d7cd6cbfea9f1f5df94)|2026-05-30 16:17:22 +0800 CST|fix(test): move worker function to module level for spawn pickle<br><br>spawn mode cannot pickle local functions. Move _npu_tensor_worker to<br>module top level.<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| |[0e37c8f8](https://gitcode.com/Ascend/pytorch/commit/0e37c8f8015060dcffbef58b9377cd380d7e7687)|2026-05-30 10:40:03 +0800 CST|test(multiprocessing): fix test_reductions and add multi-process NPU test<br><br>- Remove @unittest.skip decorator from test_reductions<br>- Remove unreliable same-process NPU tensor reconstruction assertion<br> (IPC handles cannot be imported in the same process that exported them)<br>- Add test_reductions_multiprocess to validate cross-process NPU tensor<br> sharing via Queue, aligned with PyTorch upstream CUDA test pattern<br><br>Co-Authored-By: Claude <noreply@anthropic.com><br>| See merge request: Ascend/pytorch!37685 | 3 个月前 | |
| 2 年前 | ||
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32060 merge fixtest-nn-api-master into master fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential Created-by: dinglaiping Commit-by: dinglaiping Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1585**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 2.6.0版本提示skipIfMps找不到,要换成skipIfMPS。 2. 2.7及以上版本skipIfMps找不到,换成skipIfMPS;new_module_tests找不到,需要把导入new_module_tests改成导入get_new_module_tests并在调用的地方换成get_new_module_tests();tf32_on_and_off找不到,删掉导入,并在调用tf32_is_not_fp32()的地方换成调用torch.cuda.is_tf32_supported() # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 整体结论: 本次验证通过修复官网test_nn.py用例文件,验证3个API,功能正常: ParameterDict:官方用例中键值对索引、新增、删除、遍历等操作均正常,容器内所有参数设备统一为npu:0,无设备漂移问题; ParameterList:官方用例中数字索引、append新增、遍历等操作均正常,参数设备一致性与长度校验均通过,有序管理能力正常; Sequential:官方用例中getitem/setitem/delitem/append/insert/extend/pop等所有核心操作均正常执行,操作后子模块设备均保持为npu:0,动态扩展与元素管理能力完整。 运行日志: [root@hostname-fqv42 torchnpuapi]# docker exec -it test bash root@hostname-fqv42:/home# cd /root/torchnpuapi root@hostname-fqv42:~/torchnpuapi# python -m unittest test_nn_npu27.TestNN.test_ParameterList test_nn_npu27.TestNN.test_ParameterDict test_nn_npu27.TestNN.test_Sequential_getitem test_nn_npu27.TestNN.test_Sequential_setitem test_nn_npu27.TestNN.test_Sequential_delitem test_nn_npu27.TestNN.test_Sequential_append test_nn_npu27.TestNN.test_Sequential_insert test_nn_npu27.TestNN.test_Sequential_extend test_nn_npu27.TestNN.test_Sequential_pop -v test_ParameterList (test_nn_npu27.TestNN.test_ParameterList) ... ok test_ParameterDict (test_nn_npu27.TestNN.test_ParameterDict) ... ok test_Sequential_getitem (test_nn_npu27.TestNN.test_Sequential_getitem) ... ok test_Sequential_setitem (test_nn_npu27.TestNN.test_Sequential_setitem) ... ok test_Sequential_delitem (test_nn_npu27.TestNN.test_Sequential_delitem) ... ok test_Sequential_append (test_nn_npu27.TestNN.test_Sequential_append) ... ok test_Sequential_insert (test_nn_npu27.TestNN.test_Sequential_insert) ... ok test_Sequential_extend (test_nn_npu27.TestNN.test_Sequential_extend) ... ok test_Sequential_pop (test_nn_npu27.TestNN.test_Sequential_pop) ... ok ---------------------------------------------------------------------- Ran 9 tests in 0.057s OK root@hostname-fqv42:~/torchnpuapi# # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32060 | 5 个月前 | |
| 2 年前 | ||
fix(npu): align _snapshot/_dump_snapshot with upstream augment_with_fx_traces Co-authored-by: dwoai22<oguzhan.nefesoglu@huawei.com> # message auto-generated for no-merge-commit merge: !43654 merge fix/memory-snapshot into master fix(npu): align _snapshot/_dump_snapshot with upstream augment_with_fx_traces Created-by: dwoai22 Commit-by: dwoai22 Merged-by: ascend-robot Description: # 【合入来源】 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3645 关联社区 RFC:https://github.com/pytorch/pytorch/issues/189014 关联社区 PR:https://github.com/pytorch/pytorch/pull/187205 关联社区 PR:https://github.com/pytorch/pytorch/pull/191738 (后者在 torch.accelerator.memory 中新增 _save_segment_usage / _save_memory_usage, 其默认路径会回落到 _snapshot(),因此依赖本 PR 修复的签名。) # 【修改方案】 ## 问题 上游 torch.cuda.memory._snapshot() 与 ._dump_snapshot() 均带有 augment_with_fx_traces 入参,而 torch_npu 的同名函数没有: - torch_npu/npu/memory.py:_snapshot(device=None) - torch_npu/npu/memory.py:_dump_snapshot(filename="dump_snapshot.pickle") 由此产生两个问题: 1. **接口不对齐**:用户按照 CUDA 侧写法调用 torch.npu.memory._snapshot(augment_with_fx_traces=True) 会直接抛 TypeError。 2. **阻塞设备无关路径**:torch/accelerator/memory.py 的 _snapshot() 在转发到设备 模块时**始终**以关键字方式传该参数: python return torch.cuda.memory._snapshot(device, augment_with_fx_traces=augment_with_fx_traces) 当前该调用写死为 cuda/xpu,NPU 走不到;但社区 PR #187205 会把它改为经 torch.get_device_module() 分发。该 PR 合入后,NPU 上执行 torch.accelerator.memory._snapshot() 会报 _snapshot() got an unexpected keyword argument 'augment_with_fx_traces'。 ## 方案 选择「真实实现」而非「接受后忽略」。上游的实现是: python s = _C._cuda_memorySnapshot(None) if augment_with_fx_traces: s = _augment_memory_snapshot_stack_traces(s) return s 其中 _augment_memory_snapshot_stack_traces 位于 torch/_utils.py,**不在** torch/cuda/ 下。查看其实现可知它只遍历快照的通用结构(segments → blocks → frames,以及 device_traces),不含任何 CUDA 相关代码,因此可以原样作用于 NPU 快照。故 torch_npu 直接复用同一 helper,行为与 CUDA 侧保持一致,无需另写一份。 对该 helper 采用**函数内延迟导入**,原因有二: - torch_npu/_compat/version.py 中 MIN_SUPPORTED_VERSION = (2, 10),而该 helper 并非在所有受支持的 torch 版本上都存在。放在函数体内后,只有真正请求 augment_with_fx_traces=True 的调用方才会触发导入;默认路径(也就是 #187205 分发所走的路径)在任何受支持版本上都不受影响。 - 避免为一个可选特性在模块顶层引入硬依赖。 具体修改: 1. torch_npu/npu/memory.py:_snapshot(device=None) → _snapshot(device=None, augment_with_fx_traces=False),并在 augment_with_fx_traces 为真时调用上游 helper;补充 docstring 的 Args 段(原先缺失)。 2. torch_npu/npu/memory.py:_dump_snapshot(filename="dump_snapshot.pickle") → 增加 augment_with_fx_traces=False 并透传给 _snapshot();补充 docstring。 3. test/npu/test_npu.py:新增 1 条端到端用例(见【功能验证】)。 未改动 _record_memory_history:其签名为 (enabled="all", *args, **kwargs),已能吸收 上游新增的关键字参数。 # 【资料变更】 不涉及。docs/zh/developer_notes/memory_management/ 下关于内存快照的描述保持有效; 本次为参数新增,默认值 False 与原行为一致。 # 【接口变更】 属于**向后兼容的参数新增**,不破坏任何现有调用: | 函数 | 变更前 | 变更后 | | --- | --- | --- | | torch.npu.memory._snapshot | (device=None) | (device=None, augment_with_fx_traces=False) | | torch.npu.memory._dump_snapshot | (filename="dump_snapshot.pickle") | (filename="dump_snapshot.pickle", augment_with_fx_traces=False) | 新增参数默认 False,此时执行路径与修改前完全一致,现有代码无需改动。变更方向是 **向上游对齐**,因此不引入新的 torch_npu 专有语义。 已知限制:当所配套的 torch 版本中不存在 torch._utils._augment_memory_snapshot_stack_traces 时,传入 augment_with_fx_traces=True 会抛 ImportError。这属于该 torch 版本确实不具备此 特性,报错信息可自解释;默认路径不受影响。 # 【功能验证】 新增用例 test/npu/test_npu.py::TestFXMemoryProfilerNpu::test_snapshot_fx_augmentation_end_to_end, 门禁的 CoreTestStrategy 会自动拉起 test/npu/ 下的用例,无需额外配置。 选择端到端用例而非打桩用例:augment_with_fx_traces 的增强有三个前置条件,且任一 不满足都是**静默跳过**而非报错——frame 必须来自 FX 生成文件、其元数据必须已注册进 torch.fx.traceback._FX_METADATA_REGISTRY、而该注册只在编译期开启 enrich_profiler_metadata 时发生(torch/fx/graph_module.py:949)。打桩用例只能证明 调用链接通,证明不了结果,因此这里直接验证快照内容。 用例流程:开启 enrich_profiler_metadata → _record_memory_history() → torch.compile(mod, backend="aot_eager", fullgraph=True) 编译一个三层 MLP 并前向 → _snapshot(augment_with_fx_traces=True) → 遍历 segments[].blocks[].frames 与 device_traces[][].frames,断言被增强的 frame 同时具备 fx_node_op、fx_node_name、 fx_node_target、fx_original_trace 四个字段,且 fx_original_trace 指回 forward() 中对应的源码行;同时反向断言被增强的 frame 一定来自 fx_generated_*.py。 说明: - 使用 aot_eager 而非 inductor。FX 元数据在图模块 recompile 阶段产生,早于 codegen, 因此该用例不依赖 NPU inductor 支持。 - 拆卸时调用 _record_memory_history(enabled=None),未传上游 CUDA 用例中的 clear_history=True——torch_npu 的 _record_memory_history_impl 没有该形参。 - 在缺少 torch._utils._augment_memory_snapshot_stack_traces 的 torch 版本上自动 skip。 **该用例已在 Ascend NPU 环境实测通过。** 存量回归:test/test_npu.py::TestNpuMallocAsync::test_memory_snapshot 覆盖 _record_memory_history → _snapshot → _save_segment_usage 全链路,需保持通过; 注意该文件不在 test/npu/ 下,门禁不会自动拉起,需手工执行。 执行命令: pytest ./test_npu.py -k "test_snapshot_fx_augmentation_end_to_end" lintrunner -a 用例断言 FX 生成代码对应的 frame 具备 fx_node_op、fx_node_name、fx_node_target、 fx_original_trace 四个字段,且 filename 以 fx_generated_ 开头。元数据由 torch/fx/graph_module.py 在 enrich_profiler_metadata 开启时注册。这些字段由 augment_with_fx_traces=True 时调用的 torch._utils._augment_memory_snapshot_stack_traces 写入,用例通过即说明该参数在 NPU 上确实生效。执行结果如下,全部通过。  # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 `` ## 变更文件清单 | 文件 | 变更 | | --- | --- | | torch_npu/npu/memory.py | +20/-4 — 两个函数签名对齐 + 实现 + docstring | | test/npu/test_npu.py | +95 — 新增 TestFXMemoryProfilerNpu 端到端用例 | ## 需要在 NPU 环境执行的验证 bash pytest ./test_npu.py -k "test_snapshot_fx_augmentation_end_to_end" # 已实测通过 lintrunner -a # 已实测通过 ` See merge request: Ascend/pytorch!43654 | 27 天前 | |
[feat][3/n]mempool对齐社区 Co-authored-by: LiNuohang<linuohang@huawei.com> # message auto-generated for no-merge-commit merge: !40352 merge mempool-5 into master [feat][3/n]mempool对齐社区 Created-by: LiNuohang Commit-by: LiNuohang Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 captures_underway 重命名为 allocation_scopes_ 并新增 num_active_captures_ 计数器:将池路由状态与流捕获状态解耦——allocation_scopes_ 仅跟踪池分流作用域(如 use_mem_pool),num_active_captures_ 通过 NPUGraph::capture_begin/end 中调用的 markCaptureBegin/markCaptureEnd 精确记录活跃捕获数,修复了 use_mem_pool 场景下 release_cached_blocks() 被错误跳过的 OOM 回归问题。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 测试用例 1:test_mempool_release_cached_blocks_during_diversion 测的场景: 当使用 use_mem_pool 切换到用户 mempool 时,如果分配失败触发 OOM,能否正确回收 默认池 中的 cached blocks 来重试分配。 怎么测的: 1. 限制进程内存到 80MB 2. 先在默认池分配 60MB 然后释放(此时 60MB 变为 cached,不还给 driver) 3. 进入 use_mem_pool(user_pool) 上下文,再次分配 60MB —— 此时剩余预算仅 20MB,aclrtMalloc 会失败 4. 验证 OOM 重试路径能调用 release_cached_blocks() 释放默认池那 60MB 再重试,最终分配成功 对应 bug: 修复前,mempool diversion 期间 captures_underway.empty() 返回 false(因为私有池转发也算"进行中"),导致 release_cached_blocks 重试被跳过,直接 OOM。 --- 测试用例 2:test_mempool_oom_recovery_releases_cached_blocks 测的场景: 在有大量 cached blocks 的情况下做大块分配,OOM 恢复路径能否正确释放 cached blocks 避免 OOM——同时覆盖默认池和用户 mempool 两种情况。 怎么测的: 1. 获取空闲内存,分配一半空闲内存作为 filler 然后释放(制造大量 cached blocks) 2. 再分配接近全部空闲内存的大块(free_before - free_before/8) 3. 分别在 default pool 和 user mempool 两种上下文中执行上述操作(通过 subTest 遍历) 4. 断言不应抛出 OutOfMemoryError——如果 cached blocks 没被释放就会 OOM --- 测试用例 3:test_mempool_block_free_not_deferred 测的场景: 多 stream 场景下,用户 mempool 中的 block 释放是否被错误地 defer(延迟)了。正常情况下,如果没有 graph capture在进行,free 后 block 应立即可复用。 怎么测的: 1. 在 pool 上下文中分配一块内存 a 2. 通过另一条 stream s2 对 a 做 record_stream + 一次运算 3. 删除 a,synchronize 确保操作完成 4. 重新分配同样大小的内存 b 5. 断言 a.data_ptr() == b.data_ptr()(即 block 被立即复用,没有被 defer) 6. 同样通过 subTest 覆盖默认池和用户 mempool 两种情况 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!40352 | 1 个月前 | |
[master][Fix] Fix static check errors detected by CODESPELL Co-authored-by: thickhair<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !38552 merge code_spell_fix_master into master [master][Fix] Fix static check errors detected by CODESPELL Created-by: thickhair Commit-by: thickhair Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1865 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38552 | 2 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
[master][Fix] Fix static check errors detected by TABS Co-authored-by: thickhair<zp2165064878@163.com> # message auto-generated for no-merge-commit merge: !37810 merge TABS_fix into master [master][Fix] Fix static check errors detected by TABS Created-by: thickhair Commit-by: thickhair Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1865 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37810 | 2 个月前 | |
[test]fix change of xfail Co-authored-by: SCh_zx<1325467101@qq.com> # message auto-generated for no-merge-commit merge: !39555 merge master into master [test]fix change of xfail Created-by: SCh_zx Commit-by: SCh_zx Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) https://github.com/pytorch/pytorch/commit/b8777a2cc64e21bc425692222c7835417a3a8389 原生代码中更改了xfail的位置,需要针对此变更修复用例 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39555 | 2 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test: Add tests for StringTable.default_factory Co-authored-by: qq_65095566<1922937030@qq.com> # message auto-generated for no-merge-commit merge: !43213 merge test-string-table-default-factory-master into master test: Add tests for StringTable.default_factory Created-by: qq_65095566 Commit-by: qq_65095566 Merged-by: ascend-robot Description: # 【合入来源】 ## 关联社区 issue:[[Usage]: torch.autograd.profiler_util.StringTable.default_factory API适配补齐 #3444](https://gitcode.com/Ascend/pytorch/issues/3444) ## 关联社区 issue:[【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(59) #2906](https://gitcode.com/Ascend/pytorch/issues/2906) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 经检索 PyTorch 官方开发分支测试目录,未发现针对 torch.autograd.profiler_util.StringTable.default_factory 的直接测试用例。 现有 StringTable 测试主要覆盖 popitem,未直接覆盖 default_factory 的默认值、构造参数、属性修改、非法参数以及与 StringTable.__missing__ 的交互行为,因此需要补充直接测试。 本次修改内容如下: 1. 扩展 master 分支已有测试文件: text test/test_profiler_string_table.py 2. 保留原有 torch.autograd.profiler_util.StringTable.popitem 测试。 3. 新增 torch.autograd.profiler_util.StringTable.default_factory 测试,覆盖: - 默认构造时 default_factory 为 None; - 显式传入 None; - 构造时传入可调用对象; - 读取和修改 default_factory 属性; - 构造时传入不可调用对象抛出 TypeError; - StringTable.__missing__ 不调用 default_factory。 4. 本次仅补充单元测试,不修改 API 功能实现。 # 【资料变更】 不涉及 经检查,docs/zh/api/native_api 下 PyTorch 2.7.1、2.9.0、2.10.0、2.11.0 和 2.12.0 对应资料中均未收录 torch.autograd.profiler_util.StringTable.default_factory。 PyTorch 官方文档中也未提供该属性的独立公开文档条目。 StringTable 继承自 collections.defaultdict,default_factory 是继承获得的标准库属性,并非 PyTorch 在 StringTable 中单独实现的成员,因此本次不新增 torch-npu 原生 API 资料条目。 该属性属于非计算类属性,不涉及张量及数据类型。 # 【接口变更】 本次不修改 torch.autograd.profiler_util.StringTable.default_factory 的功能、参数或返回行为,仅补充单元测试,不涉及跨代码仓或客户可见接口变更。 # 【功能验证】 测试命令: bash python test/test_profiler_string_table.py -v 测试结果: text Ran 12 tests in 0.038s OK 原有 7 个 StringTable.popitem 测试和新增 5 个 StringTable.default_factory 测试均执行通过。 本地使用现有环境完成冒烟验证,master 分支兼容性由 PR 持续集成流水线进一步验证。 测试过程中出现 CuTeDSL 可选依赖缺失警告,该警告与本次测试无关,不影响测试结果。 代码格式检查: bash git diff --check 检查结果无异常。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43213 | 27 天前 | |
[test] Add torch.autograd.profiler_util.StringTable.values Api Coverage Co-authored-by: lihaokun-2026<851563813@qq.com> # message auto-generated for no-merge-commit merge: !42017 merge autograd-profiler_util-StringTable-values-master into master [test] Add torch.autograd.profiler_util.StringTable.values Api Coverage Created-by: lihaokun-2026 Commit-by: lihaokun-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 [#2928](https://gitcode.com/Ascend/pytorch/issues/2928) - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 公开issue: - torch.autograd.profiler_util.StringTable.values: [【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(68)](https://gitcode.com/Ascend/pytorch/issues/2928) # 【修改方案】 1. API 功能说明: - torch.autograd.profiler_util.StringTable.values:StringTable 继承自 defaultdict,values() 返回当前 string table 中所有 value 的动态视图,用于获取 profiler 字符串映射表中的值集合。 2. 上游用例检查情况: 检索 PyTorch / Torch-NPU 现有测试后,未找到面向 torch.autograd.profiler_util.StringTable.values 的独立、直接、最小验证用例,因此按任务要求新增 NPU API 验证用例。 3. 新增用例文件: - test_profiler_util_string_table_values.py 4. 新增用例覆盖场景: - StringTable.values() 在空表场景下返回空 ValuesView - 显式写入 key/value 后,values() 返回全部 value - 访问缺省 key 触发 StringTable.__missing__ 后,values() 可读取自动写入的 value - 单字符 key 保持原值,不触发 demangle 变更 - values() 返回动态视图,后续新增元素可被已有 view 感知 - 在 torch_npu 环境下验证 privateuse1 backend 为 npu 5. 新增文件头部已按要求补充注释,说明该文件验证的 API 功能。 # 【资料变更】 不涉及。未修改产品资料、接口说明文档或用户可见文档。 # 【接口变更】 不涉及。未修改跨代码仓接口,也未修改用户可见接口行为。 # 【功能验证】 测试环境: sh torch: 2.12.0+cpu torch_npu: 2.12.0 测试方法: sh source /usr/local/Ascend/ascend-toolkit/set_env.sh TORCH_DEVICE_BACKEND_AUTOLOAD=1 python3 test/test_profiler_util_string_table_values.py -v 测试结果:  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42017 | 1 个月前 | |
test(reductions): note NPU/XLA skip searchsorted non-contiguous UserWarning check. Co-authored-by: Margaret_wangrui<wangrui178@huawei.com> # message auto-generated for no-merge-commit merge: !37092 merge searchsorted_testcase_master into master test(reductions): note NPU/XLA skip searchsorted non-contiguous UserWarning check. Created-by: Margaret_wangrui Commit-by: Margaret_wangrui Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/1910 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) values_3d_permute = values_3d.permute(2, 1, 0).to(torch.int32) boundaries_permute = values_3d.permute(2, 1, 0).to(torch.float64) values_3d_permute和boundaries_permute在torch_npu中是连续的,不应该在用例中去捕获非连续告警信息 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 .png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37092 | 3 个月前 | |
[master][bugfix]CI error:acl header missing fix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !36649 merge master into master [master][bugfix]CI error:acl header missing fix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2137 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 门禁ut不是基于门禁编包代码执行,而是拉取新代码,头文件在编包执行过程中才会从acl_src复制到原本头文件路径acl下。导致门禁ut调用build_stub.sh报错头文件找不到。 修复方案: 1、在门禁执行入口文件ci/access_control_test.py增加头文件复制策略,从当前安装torch_npu路径下复制头文件到工作区代码三方库下acl下 2、修改三个ut中的编译依赖相对路径确保能找到对应头文件 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 门禁通过,ut通过  本地验证ut通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ✓] 代码注释完备,正确记录错误日志 - [ ✕] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36649 | 3 个月前 | |
fix: support quantized NPU flip dispatch Co-authored-by: hz893<zhanghao491@huawei.com> # message auto-generated for no-merge-commit merge: !36073 merge fix_quantized_flip_master_20260519 into master fix: support quantized NPU flip dispatch Created-by: hz893 Commit-by: hz893 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 https://gitcode.com/Ascend/pytorch/issues/2207 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 在 QuantizedPrivateUse1 的 codegen 注册中补充 aten::flip,使量化 NPU tensor 能命中 torch_npu 的 quantized helper。 2. 新增 quantized_flip helper:per-tensor 量化场景对 int_repr() 调用普通 NPU aten::flip,复用现有 op_plugin::flip -> aclnnFlip 数据翻转路径,再用原 scale/zero_point 重建 affine quantized tensor。 3. 对齐 CPU/CUDA 行为:sub-byte 量化 dtype 保持不支持报错;per-channel 量化保持 Setting strides is possible only on uniformly quantized tensor 报错。 4. 新增 per-channel quantized flip 报错回归测试。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。 # 【功能验证】 1. v2.7.1 环境执行 bash ci/build.sh --python=3.11,编译成功并生成 wheel。 2. v2.7.1 环境执行 python -m pytest test_shape_ops.py -v -k test_flip_npu_float32,结果:1 passed。 3. v2.7.1 环境执行 python -m pytest --import-mode=importlib test/test_shape_ops.py -v -k "test_flip_per_channel_quantized_error or test_flip_npu_float32",结果:2 passed。 4. 验证普通 float NPU flip backward 与 CPU 在 dims=(0,)、(1,)、(0, 1)、() 下 forward/grad 均一致;验证 quantized flip 的 autograd 状态和错误行为与 CPU 一致。 5. v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 源分支均执行 git diff --check,无异常。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36073 | 3 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35981 merge master_lintrunner into master [Fix] Fix static check errors detected by SPACES Created-by: huangjingwei Commit-by: huangjingwei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 检测和删除代码中的行尾空白字符 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35981 | 3 个月前 | |
| 2 年前 | ||
fix: support to_sparse on non-default NPU devices Co-authored-by: hz893<zhanghao491@huawei.com> # message auto-generated for no-merge-commit merge: !35946 merge fix_to_sparse_master into master fix: support to_sparse on non-default NPU devices Created-by: hz893 Commit-by: hz893 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 https://gitcode.com/Ascend/pytorch/issues/2182 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 将 aten::_to_sparse 和 aten::_to_sparse.sparse_dim 加入 NPU supported 注册,避免 dense NPU Tensor 转 sparse 时走 CPU fallback。 2. 新增 NPU 侧 _to_sparse 实现,复用 at::native::dense_to_sparse,使 sparse tensor、indices、values 保持在输入 Tensor 所在 NPU 设备上。 3. 新增非默认 NPU 设备场景 UT,覆盖输入位于 npu:1 时 to_sparse 结果的 device 和数值一致性。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。 # 【功能验证】 - 已在 v2.7.1 环境完成 torch_npu 编包并安装验证,torch_npu.__version__ 为 2.7.1.post5。 - 已确认 aten::_to_sparse 和 aten::_to_sparse.sparse_dim 的 PrivateUse1 dispatcher 注册到 RegisterNPU.cpp [kernel],不再走 CPU fallback。 - python -m pytest test_ops.py -v -k test_multiple_devices_to_sparse_npu_float32:1 passed。 - python -m pytest test/test_sparse_coo.py -v -k test_sparse_to_sparse_non_default_npu_device:1 passed。 - v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 目标分支已完成 cherry-pick,无冲突;未分别编包验证。 补充验证: - 已在 fix_to_sparse_master 分支完成编译并安装生成的 torch_npu-2.13.0-cp311-cp311-manylinux_2_28_aarch64.whl。 - 通过临时 C++ 扩展直接调用新增 AOT shim aoti_torch_npu__to_sparse,在当前 device 为 npu:0、输入 tensor 位于 npu:1 的场景下验证返回 sparse tensor、indices、values 均保持在 npu:1,且 to_dense() 与输入一致。 - 测试结果:PASS aoti_torch_npu__to_sparse device=npu:1 nnz=3。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35946 | 3 个月前 | |
Skip failing torch official TestCase tests and disable unsupported test cases Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> Co-authored-by: yuhaiyan8<yuhaiyan8@h-partners.com> # message auto-generated for no-merge-commit merge: !32140 merge cherry-pick-mr-32139-1774073503832-auto into master Skip failing torch official TestCase tests and disable unsupported test cases Created-by: yuhaiyan Commit-by: yuhaiyan;yuhaiyan8 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 暂时跳过失败用例 2. 已提单跟进修复 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32140 | 4 个月前 | |
| 2 年前 | ||
test: add isclose equal_nan broadcast regression test Co-authored-by: xiu_21<caixiuxiu1@huawei.com> # message auto-generated for no-merge-commit merge: !39507 merge master into master test: add isclose equal_nan broadcast regression test Created-by: xiu_21 Commit-by: xiu_21 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 新增isclose equal_nan广播场景回归测试 问题修复PR:https://gitcode.com/Ascend/op-plugin/pull/5250 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39507 | 2 个月前 | |
Update test_torch.py Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> # message auto-generated for no-merge-commit merge: !27371 merge master-dev2 into master Update test_torch.py Created-by: yuhaiyan Commit-by: yuhaiyan Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!27371 | 8 个月前 | |
[test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Co-authored-by: anning-2026<870721918@qq.com> # message auto-generated for no-merge-commit merge: !43181 merge test/api-consistency-torch-c-master into master [test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Created-by: anning-2026 Commit-by: anning-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - [#2764](https://gitcode.com/Ascend/pytorch/issues/2764) — torch._C._nn.flatten_dense_tensors(任务编号 #42) - [#2674](https://gitcode.com/Ascend/pytorch/issues/2674) — torch._C.DisableTorchFunction(任务编号 #52) - [#2675](https://gitcode.com/Ascend/pytorch/issues/2675) — torch._C.DisableTorchFunctionSubclass(任务编号 #53) - [#2676](https://gitcode.com/Ascend/pytorch/issues/2676) — torch._check_is_size(任务编号 #54) 注:任务 #39 torch._C._jit_set_texpr_fuser_enabled 已在 issue [#2818](https://gitcode.com/Ascend/pytorch/issues/2818) 中闭环,不纳入本 PR。 # 【修改方案】 本 PR 覆盖 4 个 torch._C.* 与 torch.* 私有接口的 NPU 一致性测试补齐,在 2 个新增测试文件中新增 25 个用例,不涉及 torch_npu 任何 C++ / Python 代码改动,也不修改 torch_npu 既有 patch。 修改文件(2 个新增): - test/test_torch_c_apis.py(新增):torch._C._nn.flatten_dense_tensors(8 个用例)、torch._C.DisableTorchFunction(2 个用例)、torch._C.DisableTorchFunctionSubclass(2 个用例),合计 12 个用例 - test/test_torch_check.py(新增):torch._check_is_size(13 个用例) 合计 4 个 API / 25 个用例,全部 NPU 实测通过。 # 【社区现状与路径依据】 针对 4 个新增用例的 API,PyTorch 上游 pytorch/pytorch 仓库的检索结论如下(git grep -ln <API> -- 'test/**.py',ref 取 master HEAD): | API | 上游直接功能测试 | 判定 | | --- | --- | --- | | torch._C._nn.flatten_dense_tensors | 无(仅 test/functorch/test_vmap_registrations.py 中作为字符串注册到 op 列表) | 上游未提供 Python 直测;新增 NPU 端 smoke 用例 | | torch._C.DisableTorchFunction | 无(test/test_overrides.py、test/dynamo/test_modes.py 中均为 use site) | 上游无独立功能覆盖;新增 dispatch 暂停/恢复用例 | | torch._C.DisableTorchFunctionSubclass | 无(同上) | 上游无独立功能覆盖;新增 Subclass 变体用例 | | torch._check_is_size | 无直接功能测试 | 上游未提供正向功能测试;新增正常/异常/max 用例 | # 【API 功能介绍】 1. **torch._C._nn.flatten_dense_tensors(tensors)**:把一组同 dtype/device 的张量 flatten 后 concatenate 成一个连续 1D 张量。 2. **torch._C.DisableTorchFunction**:上下文管理器,临时禁用 __torch_function__ 分发链路。 3. **torch._C.DisableTorchFunctionSubclass**:同上,只禁用 subclass 的 __torch_function__。 4. **torch._check_is_size(i, max=None)**:检查整数 i 是否为合法 size(>=0),否则抛 RuntimeError。 # 【测试方案】 4 个被覆盖的 API 的用例设计: 1. **torch._C._nn.flatten_dense_tensors**(8 个用例):正常 flatten、单张量、空序列、tuple、非 Tensor 元素、device 不一致 2. **torch._C.DisableTorchFunction**(2 个用例):context 内 dispatch 暂停/恢复 3. **torch._C.DisableTorchFunctionSubclass**(2 个用例):同上的 Subclass 变体 4. **torch._check_is_size**(13 个用例):正常值、负值越界、max 边界、message 参数、非法类型 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend910B2(torch.npu.device_count() == 2) - CANN 软件版本:cann-8.5.1 - Python:3.11.14 - 安装版本:torch 2.12.0、torch_npu 2.12.0 - 测试分支:本 PR base 为 master # 【测试命令】 bash cd <repo_root> python -u test/test_torch_c_apis.py -v python -u test/test_torch_check.py -v # 【测试日志】(基于当前 commit + Ascend NPU 实跑) text === test_torch_c_apis.py === test_disables_torch_function_on_subclass ... ok test_op_inside_disable_returns_plain_tensor ... ok test_disables_torch_function_subclass_on_subclass ... ok test_op_inside_disable_subclass_returns_plain_tensor ... ok test_concatenated_values_match_input_order ... ok test_concatenates_size_1_with_size_2 ... ok test_flatten_empty_list_raises_runtime_error ... ok test_flatten_raises_for_mismatched_device ... ok test_flatten_raises_for_non_tensor_element ... ok test_flatten_single_tensor ... ok test_flatten_tuple_input ... ok test_flattens_2d_tensors_to_1d_concat ... ok ---------------------------------------------------------------------- Ran 12 tests in 1.581s OK === test_torch_check.py === test_check_tensor_size_value ... ok test_fails_above_max_bound ... ok test_message_callable_produces_custom_error ... ok test_message_explicit_none ... ok test_message_format_string ... ok test_message_omitted ... ok test_passes_at_max_equal_i ... ok test_passes_for_non_negative_int ... ok test_passes_with_explicit_max_none ... ok test_passes_within_max_bound ... ok test_raises_for_invalid_max_type ... ok test_raises_for_negative_int ... ok test_raises_for_non_int_type ... ok ---------------------------------------------------------------------- Ran 13 tests in 1.494s OK 合计 Ran 25 tests, OK。 # 【资料补齐检查结论】 4 个 API 均为 PyTorch 私有接口(_ 前缀),按任务规范"PyTorch 私有接口不需要补充资料"原则,均跳过。 See merge request: Ascend/pytorch!43181 | 1 个月前 | |
[test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Co-authored-by: anning-2026<870721918@qq.com> # message auto-generated for no-merge-commit merge: !43181 merge test/api-consistency-torch-c-master into master [test][master] add NPU validation cases for torch._C and torch._check APIs (issues #2674 #2675 #2676 #2764) Created-by: anning-2026 Commit-by: anning-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - [#2764](https://gitcode.com/Ascend/pytorch/issues/2764) — torch._C._nn.flatten_dense_tensors(任务编号 #42) - [#2674](https://gitcode.com/Ascend/pytorch/issues/2674) — torch._C.DisableTorchFunction(任务编号 #52) - [#2675](https://gitcode.com/Ascend/pytorch/issues/2675) — torch._C.DisableTorchFunctionSubclass(任务编号 #53) - [#2676](https://gitcode.com/Ascend/pytorch/issues/2676) — torch._check_is_size(任务编号 #54) 注:任务 #39 torch._C._jit_set_texpr_fuser_enabled 已在 issue [#2818](https://gitcode.com/Ascend/pytorch/issues/2818) 中闭环,不纳入本 PR。 # 【修改方案】 本 PR 覆盖 4 个 torch._C.* 与 torch.* 私有接口的 NPU 一致性测试补齐,在 2 个新增测试文件中新增 25 个用例,不涉及 torch_npu 任何 C++ / Python 代码改动,也不修改 torch_npu 既有 patch。 修改文件(2 个新增): - test/test_torch_c_apis.py(新增):torch._C._nn.flatten_dense_tensors(8 个用例)、torch._C.DisableTorchFunction(2 个用例)、torch._C.DisableTorchFunctionSubclass(2 个用例),合计 12 个用例 - test/test_torch_check.py(新增):torch._check_is_size(13 个用例) 合计 4 个 API / 25 个用例,全部 NPU 实测通过。 # 【社区现状与路径依据】 针对 4 个新增用例的 API,PyTorch 上游 pytorch/pytorch 仓库的检索结论如下(git grep -ln <API> -- 'test/**.py',ref 取 master HEAD): | API | 上游直接功能测试 | 判定 | | --- | --- | --- | | torch._C._nn.flatten_dense_tensors | 无(仅 test/functorch/test_vmap_registrations.py 中作为字符串注册到 op 列表) | 上游未提供 Python 直测;新增 NPU 端 smoke 用例 | | torch._C.DisableTorchFunction | 无(test/test_overrides.py、test/dynamo/test_modes.py 中均为 use site) | 上游无独立功能覆盖;新增 dispatch 暂停/恢复用例 | | torch._C.DisableTorchFunctionSubclass | 无(同上) | 上游无独立功能覆盖;新增 Subclass 变体用例 | | torch._check_is_size | 无直接功能测试 | 上游未提供正向功能测试;新增正常/异常/max 用例 | # 【API 功能介绍】 1. **torch._C._nn.flatten_dense_tensors(tensors)**:把一组同 dtype/device 的张量 flatten 后 concatenate 成一个连续 1D 张量。 2. **torch._C.DisableTorchFunction**:上下文管理器,临时禁用 __torch_function__ 分发链路。 3. **torch._C.DisableTorchFunctionSubclass**:同上,只禁用 subclass 的 __torch_function__。 4. **torch._check_is_size(i, max=None)**:检查整数 i 是否为合法 size(>=0),否则抛 RuntimeError。 # 【测试方案】 4 个被覆盖的 API 的用例设计: 1. **torch._C._nn.flatten_dense_tensors**(8 个用例):正常 flatten、单张量、空序列、tuple、非 Tensor 元素、device 不一致 2. **torch._C.DisableTorchFunction**(2 个用例):context 内 dispatch 暂停/恢复 3. **torch._C.DisableTorchFunctionSubclass**(2 个用例):同上的 Subclass 变体 4. **torch._check_is_size**(13 个用例):正常值、负值越界、max 边界、message 参数、非法类型 # 【测试环境】 - 操作系统:Linux 4.19.90-2102.2.0.0068.3.ctl2.aarch64 - 昇腾硬件:Ascend910B2(torch.npu.device_count() == 2) - CANN 软件版本:cann-8.5.1 - Python:3.11.14 - 安装版本:torch 2.12.0、torch_npu 2.12.0 - 测试分支:本 PR base 为 master # 【测试命令】 bash cd <repo_root> python -u test/test_torch_c_apis.py -v python -u test/test_torch_check.py -v # 【测试日志】(基于当前 commit + Ascend NPU 实跑) text === test_torch_c_apis.py === test_disables_torch_function_on_subclass ... ok test_op_inside_disable_returns_plain_tensor ... ok test_disables_torch_function_subclass_on_subclass ... ok test_op_inside_disable_subclass_returns_plain_tensor ... ok test_concatenated_values_match_input_order ... ok test_concatenates_size_1_with_size_2 ... ok test_flatten_empty_list_raises_runtime_error ... ok test_flatten_raises_for_mismatched_device ... ok test_flatten_raises_for_non_tensor_element ... ok test_flatten_single_tensor ... ok test_flatten_tuple_input ... ok test_flattens_2d_tensors_to_1d_concat ... ok ---------------------------------------------------------------------- Ran 12 tests in 1.581s OK === test_torch_check.py === test_check_tensor_size_value ... ok test_fails_above_max_bound ... ok test_message_callable_produces_custom_error ... ok test_message_explicit_none ... ok test_message_format_string ... ok test_message_omitted ... ok test_passes_at_max_equal_i ... ok test_passes_for_non_negative_int ... ok test_passes_with_explicit_max_none ... ok test_passes_within_max_bound ... ok test_raises_for_invalid_max_type ... ok test_raises_for_negative_int ... ok test_raises_for_non_int_type ... ok ---------------------------------------------------------------------- Ran 13 tests in 1.494s OK 合计 Ran 25 tests, OK。 # 【资料补齐检查结论】 4 个 API 均为 PyTorch 私有接口(_ 前缀),按任务规范"PyTorch 私有接口不需要补充资料"原则,均跳过。 See merge request: Ascend/pytorch!43181 | 1 个月前 | |
test: add torch.__getattribute__ API validation Co-authored-by: 2490136803<2490136803@qq.com> # message auto-generated for no-merge-commit merge: !41419 merge intern/test-torch-getattribute-master into master test: add torch.__getattribute__ API validation Created-by: zhouzirui-2026 Commit-by: 2490136803 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue: - 任务 issue:https://gitcode.com/Ascend/pytorch/issues/2734 # 【修改方案】 本 PR 新增 test/test_torch_getattribute_api.py,补充 torch.__getattribute__ 在 torch-npu 环境下的 API 一致性验证用例。 该 API 是 Python module 对象的属性访问入口,用于从 torch module 上按名称读取属性。经检查,PyTorch 官方未提供 torch.__getattribute__ 的独立专项测试,torch-npu 当前 test 和 test_upstream 目录中也未发现该 API 的专项测试。按照指导规范,本场景属于“PyTorch 官方社区无用例”,因此在 torch-npu test 目录补充自写测试。 任务 API 功能、上游社区用例情况与本 PR 处理方式如下: | API | 功能说明 | 上游社区用例 / 覆盖情况 | 本 PR 处理 | | --- | --- | --- | --- | | torch.__getattribute__ | Python module 属性访问入口,用于按名称读取 torch module 上的属性。 | 未检索到 PyTorch 官方直接专项测试;torch-npu 现有 test / test_upstream 目录中也未发现专项测试。 | 新增 test/test_torch_getattribute_api.py,验证已有属性读取、动态属性读取和异常路径。 | 主要开发思路: 1. 先确认 torch.__getattribute__ 在当前多版本 torch-npu 环境中存在,且基础行为与 Python module 属性访问语义一致。 2. 复查 PyTorch 官方测试目录,未发现直接覆盖 torch.__getattribute__ 的独立专项测试。 3. 复查 torch-npu 当前仓库 test 和 test_upstream 目录,未发现该 API 的现有专项测试。 4. 该 API 不涉及 Tensor 输入,不存在需要迁移到 NPU Tensor 的适配点,因此不需要 test_upstream patch。 5. 该 API 属于顶层 torch module 属性访问能力,不属于 npu、fx、nn 等子模块,因此测试文件放在 torch-npu 根测试目录 test/test_torch_getattribute_api.py。 6. 本 PR 仅补充测试,不修改 API 实现,不改变现有接口行为。 新增测试文件: text test/test_torch_getattribute_api.py 新增测试方法: text test_get_existing_attributes test_get_dynamic_attribute test_get_missing_attribute_raises 各测试核心验证点如下: | 测试方法 | 核心验证点 | | --- | --- | | test_get_existing_attributes | 使用 types.ModuleType.__getattribute__(torch, "__dict__") 获取模块字典作为独立 oracle,验证 torch.__config__、torch.Tensor、torch.nn、torch.empty 等已存在属性通过 torch.__getattribute__ 读取时返回模块字典中的同一对象。 | | test_get_dynamic_attribute | 在 torch module 上临时设置动态属性,验证 torch.__getattribute__ 可读取该属性,且返回对象与模块字典中记录的对象一致;测试结束后清理动态属性。 | | test_get_missing_attribute_raises | 验证读取不存在属性时,保持 Python module 语义并抛出包含属性名的 AttributeError。 | # 【资料变更】 不涉及资料 PR。 已检查 PyTorch 官方公开文档与 Ascend native API 文档,未发现 torch.__getattribute__ 独立条目。该 API 属于 Python module 固有属性访问机制,不是计算类公开 API,因此不新增 docs.md,不提交资料 PR。 # 【接口变更】 不涉及。 本 PR 不修改 API 实现,不改变现有接口行为,不新增 torch-npu 对外接口。 # 【功能验证】 运行环境: text 操作系统:Ubuntu 22.04.5 LTS (aarch64) 内核版本:5.10.0-182.0.0.95.oe2203sp3.aarch64 NPU 型号:Ascend 910B4 Driver / npu-smi:25.2.0 CANN Toolkit:9.0.0 CANN 路径:/usr/local/Ascend/cann-9.0.0 Python:3.10.12 分支验证环境: text 分支:master torch:2.12.0 torch-npu:2.12.0rc1 Python 环境:/workspace/a3-zzr-env/envs/venv_master_base_torch2.12.0_torchnpu2.12.0rc1_py310 执行命令: bash cd /root python /workspace/a3-zzr-env/repos/pytorch-master/test/test_torch_getattribute_api.py 执行结果: ``text W0713 09:42:09.361000 5136 torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl ... ---------------------------------------------------------------------- Ran 3 tests in 0.209s OK ` 说明:该 warning 来自 PyTorch 导入阶段 optional dependency 提示,不影响本用例执行结果。 最终验证结论: 1. 本 PR 补充 3 个 API 一致性测试,覆盖 torch.__getattribute__` 的正常属性读取、动态属性读取和异常路径。 2. 补充测试不仅验证 API 可调用,也使用模块字典作为独立 oracle 验证已有属性读取、运行时动态属性访问能力和缺失属性异常语义。 3. 该 API 不涉及 Tensor 输入,不需要 NPU Tensor 迁移适配。 4. 补充测试已在 master 环境验证通过。 5. 目标 API 当前行为符合预期,未发现需要 API 功能补齐的问题。 6. 本 PR 不修改 API 实现,不涉及接口变更。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!41419 | 1 个月前 | |
fix lazy_init and api export Co-authored-by: bellatan<tanmei2@huawei.com> # message auto-generated for no-merge-commit merge: !36703 merge torch_npu_init_refactor into master fix lazy_init and api export Created-by: bellatan Commit-by: bellatan Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 **问题1**:test/test_npu.py的test_lazy_init用例失败  **根因**: 重构前 torch_npu/__init__.py 中,先做 accelerator 冲突检查,即_check_device_conflict 接口调用,再 import torch_npu.npu、torch_npu.utils 等内部模块,不会触发 NPU device count 提前枚举 重构后 torch_npu/__init__.py 中,先调用了_check_device_conflict 接口,再 import torch_npu.npu、torch_npu.utils 等内部模块,_check_device_conflict 接口调用顺序被延后,调用 _get_accelerator() 时 NPU backend 状态已经被拉起,触发底层设备探测,导致 _npu_getDeviceCount() 提前枚举真实设备数 8。 **解决** : 在 torch_npu/__init__.py 中,保持和重构前一样的调用顺序,即_check_device_conflict 接口调用提前到所有的 import 之前。 **问题2**:缺失子模块导出的 API: python torch_npu.asd.checksum torch_npu.utils.syncbatchnorm **现象**:  **根因分析**: 旧版 torch_npu/__init__.py 是一个大顶层初始化脚本,里面直接写了很多顶层 import: python from torch_npu.asd.checksum import _matmul_checksum as matmul_checksum import torch_npu.utils.syncbatchnorm 这些 import 会产生父包属性挂载副作用: python torch_npu.asd.checksum torch_npu.utils.syncbatchnorm 重构后初始化逻辑被拆分到 _init/core/module_loader.py、_exports.py 等模块中,部分旧版顶层 import 副作用没有恢复,因此这些子模块路径在 import torch_npu 后不可见。 **解决方案**: 在 _load_registration_modules() 中补充子模块父包属性: python import torch_npu.asd.checksum # noqa: F401 import torch_npu.utils.syncbatchnorm # noqa: F401 **问题3**:顶层属性缺失 API python torch_npu.ParallelStore torch_npu._ShardedGradScaler **现象**:  **根因分析**: 旧版顶层有: python from torch_npu._C._distributed_c10d import ParallelStore from torch_npu.npu.amp.sharded_grad_scaler import _ShardedGradScaler 因此旧版支持: python torch_npu.ParallelStore torch_npu._ShardedGradScaler 重构后 _distributed_c10d 子模块初始化逻辑被集中到 C 扩展子模块初始化流程中,但没有把 ParallelStore 恢复到 torch_npu 顶层,导致旧版顶层访问路径缺失。_ShardedGradScaler 只在 distributed patch 逻辑中局部 import: python def _apply_sharded_grad_scaler_patch(torch): from torch.distributed.fsdp import sharded_grad_scaler from torch_npu.npu.amp.sharded_grad_scaler import _ShardedGradScaler sharded_grad_scaler.ShardedGradScaler = _ShardedGradScaler 这能保证 patch 行为一致,但没有恢复旧版顶层属性torch_npu._ShardedGradScaler **解决方案**: 在 _exports.py 中补 legacy 顶层属性: python def _export_distributed_apis(globals_dict): """ Export legacy distributed-related top-level APIs. Rule: - torch_npu._C._distributed_c10d.ParallelStore -> torch_npu.ParallelStore - torch_npu.npu.amp.sharded_grad_scaler._ShardedGradScaler -> torch_npu._ShardedGradScaler Note: These APIs are kept for compatibility and should not be added to __all__. """ from torch_npu._C._distributed_c10d import ParallelStore from torch_npu.npu.amp.sharded_grad_scaler import _ShardedGradScaler globals_dict["ParallelStore"] = ParallelStore globals_dict["_ShardedGradScaler"] = _ShardedGradScaler # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 test/test_torch_npu_init.py 新增对应的测试项本地验证pass,CI pass  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36703 | 3 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test:This PR adds missing test cases for torch._utils._unflatten_dense_tensors, as there are currently no community-provided tests for this function. Co-authored-by: xin_heyun<919112805@qq.com> # message auto-generated for no-merge-commit merge: !42052 merge test_unflatten_dense_tensors_master into master test:This PR adds missing test cases for torch._utils._unflatten_dense_tensors, as there are currently no community-provided tests for this function. Created-by: xin_heyun Commit-by: xin_heyun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> issue任务地址:https://gitcode.com/Ascend/pytorch/issues/2932 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为 torch._utils._unflatten_dense_tensors 新增 NPU 设备回归测试用例,放置在 test/test_unflatten_dense_tensors.py。 1. PyTorch 社区对该 API 仅有 C++ 层单元测试(test/cpp/api/tensor_flatten.cpp),Python 层面无任何测试用例,且缺少 NPU 设备上的运行验证。 2. 新增 8 个测试用例,基于 PyTorch 标准 TestCase 框架,通过 torch.accelerator.current_accelerator() 自动获取 NPU 设备并完成张量迁移,覆盖以下维度: - 展平-还原往返操作正确性 - 单张量与多张量(1D/2D/3D 不同形状) - 空张量混合与全空张量边界场景 - float32 / float16 / int32 多 dtype 兼容性 - 50 个大数量张量压力场景 - tuple 类型输入兼容性 3. 遵循 NPU 测试用例规范:导入顺序为 torch → torch.testing._internal.common_utils,不依赖 torch_npu,使用 self.assert* 断言,无 print/try-except,注释精简英文。 # 【资料变更】 不涉及。torch._utils._unflatten_dense_tensors 为 PyTorch 内部工具函数(_ 前缀),不属于公开文档覆盖范围。 # 【接口变更】 不涉及。仅新增测试文件,无对外接口变更。 # 【功能验证】 **测试场景**:在 NPU 设备上验证 torch._utils._unflatten_dense_tensors 将展平 1D 张量按目标形状还原为多个张量的功能正确性。 2.7.1 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.339s OK 2.9.0 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.331s OK 2.11.0 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... [W718 07:12:27.082786050 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.357s OK 2.12.0 执行命令 python test_unflatten_dense_tensors.py -v 结果 `` W0718 07:12:38.397000 45485 opt/conda/envs/v2.12.0/lib/python3.12/site-packages/torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages nvidia-cutlass-dsl and apache-tvm-ffi; missing optional dependency nvidia_cutlass_dsl (importlib.util.find_spec(nvidia_cutlass_dsl) failed) test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... [W718 07:12:39.554782459 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.374s OK master 执行命令 python test_unflatten_dense_tensors.py -v 结果 test_all_empty_tensors (__main__.TestUnflattenDenseTensors.test_all_empty_tensors) ... ok test_different_dtypes (__main__.TestUnflattenDenseTensors.test_different_dtypes) ... [W718 07:12:49.941707130 NPUCachingAllocator.cpp:174] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ok test_empty_tensor_in_list (__main__.TestUnflattenDenseTensors.test_empty_tensor_in_list) ... ok test_large_num_tensors (__main__.TestUnflattenDenseTensors.test_large_num_tensors) ... ok test_multiple_tensors_different_sizes (__main__.TestUnflattenDenseTensors.test_multiple_tensors_different_sizes) ... ok test_round_trip_basic (__main__.TestUnflattenDenseTensors.test_round_trip_basic) ... ok test_single_tensor (__main__.TestUnflattenDenseTensors.test_single_tensor) ... ok test_tuple_input (__main__.TestUnflattenDenseTensors.test_tuple_input) ... ok ---------------------------------------------------------------------- Ran 8 tests in 1.372s OK `` # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!42052 | 1 个月前 | |
[fix] add _npu_dtype_cast_backward sharding strategy Co-authored-by: zqwenn<zhangqiongwen@huawei.com> # message auto-generated for no-merge-commit merge: merge master_npu_dtype_cast_backsard_register_sharding into master [fix] add _npu_dtype_cast_backward sharding strategy Created-by: zqwenn Commit-by: zqwenn Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!25308 | 11 个月前 | |
compat(v2.13): reintroduce csrc compat module for upstream 2.13 Co-authored-by: chz34<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !39206 merge compat/2.13_ori into master compat(v2.13): reintroduce csrc compat module for upstream 2.13 Created-by: c_34 Commit-by: chz34 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> pytorch 上游重构修改,将 shared_ptr<Node> 重构为 intrusive_ptr<Node>,主线适配上游main分支编译报错 https://github.com/pytorch/pytorch/pull/181782 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1812 https://gitcode.com/Ascend/pytorch/issues/2497 https://gitcode.com/Ascend/pytorch/issues/2508 - [x] 重构优化 https://gitcode.com/Ascend/pytorch/issues/1688 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) compat(v2.13): reintroduce csrc compat module for upstream 2.13 C++ side (torch_npu/csrc/_compat/): - version.h: TORCH_NPU_VERSION_GE(MAJOR, MINOR) macro plus TORCH_NPU_MIN_SUPPORTED constants kept in sync with the Python side. - autograd.h: torch_npu::compat::GradFnPtr<T> alias and make_grad_fn<Op>(args...) wrap the Node smart pointer migration from std::shared_ptr+deleteNode (<=2.12) to c10::intrusive_ptr+make_intrusive (>=2.13, pytorch#181782). SavedForPtr covers SavedVariable::unpack's parameter type change. Hand-written C++ updated to use the alias: - VariableFallbackKernel.cpp, VariableTypeManual.cpp (grad_fn locals) - reducer.hpp (grad_accumulators_ and hooks_ element types) - torchnpugen/autograd/templates/Functions.h (unpack_list/unpack_opt_list saved_for parameter) Python side (torch_npu/_compat/utils.py): - make_config_entry(config, *, name) wraps _ConfigEntry which gained a required name parameter in PyTorch 2.12. _dynamo.patch_inductor_wrapper uses the helper instead of branching inline. torchgen's packaged emit_body and gen_autograd_functions were updated upstream alongside pytorch#181782, so no codegen post-processing is needed -- only the hand-written sources need the compat aliases. # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 基于现有用例 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!39206 | 2 个月前 | |
test(utils): add data worker API coverage tests on NPU Co-authored-by: Jinfan Liu<1300083451@qq.com> # message auto-generated for no-merge-commit merge: !37247 merge test-utils-data-weak-npu-master into master test(utils): add data worker API coverage tests on NPU Created-by: JfanLiu Commit-by: Jinfan Liu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2027**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> [x] issue/工单 # 【修改方案】 一、API功能说明 本 PR 补充 torch.utils.data worker/control 弱覆盖 API 的直接验证用例: - torch.utils.data.dataloader._MultiProcessingDataLoaderIter - torch.utils.data.dataloader._InfiniteConstantSampler - torch.utils.data._utils.worker.ManagerWatchdog - torch.utils.data._utils.worker._IterableDatasetStopIteration - torch.utils.data._utils.worker._ResumeIteration - torch.utils.data._utils.signal_handling._set_worker_signal_handlers - torch.utils.data._utils.signal_handling._remove_worker_pids 上述 API 属于 DataLoader 多进程 iterator、IterableDataset 采样控制、worker 存活检查、worker 控制消息以及 worker 信号/pid 管理逻辑。 二、测试用例完备性说明 PyTorch 官方社区 test/test_dataloader.py 已通过 DataLoader 多进程用例覆盖上述 API 的调用链,但缺少对部分内部对象和控制消息的直接行为断言。本 PR 按 1.3 类补充 torch-npu 自定义测试文件 test/test_utils_data_api.py。 1. torch.utils.data.dataloader._MultiProcessingDataLoaderIter 直接覆盖: - test_multiprocessing_dataloader_iter_type_and_shutdown 构造 num_workers=1 的 DataLoader,显式断言 iter(loader) 是 _MultiProcessingDataLoaderIter,并验证 next(iterator) 返回预期 batch,最后调用 _shutdown_workers() 覆盖正常关闭路径。 2. torch.utils.data.dataloader._InfiniteConstantSampler 直接覆盖: - test_infinite_constant_sampler_yields_none 直接实例化 _InfiniteConstantSampler,并断言连续 yield None,覆盖 IterableDataset 无限索引采样器的核心行为。 3. torch.utils.data._utils.worker.ManagerWatchdog 直接覆盖: - test_manager_watchdog_reports_parent_alive 直接构造 ManagerWatchdog,并断言正常父进程场景 is_alive() 为 True。 4. torch.utils.data._utils.worker._IterableDatasetStopIteration / torch.utils.data._utils.worker._ResumeIteration 直接覆盖: - test_worker_control_message_fields 直接构造两个 dataclass 控制消息,断言 worker_id、seed 字段和 repr 内容,覆盖 worker 耗尽通知与 persistent worker 恢复消息的对象行为。 5. torch.utils.data._utils.signal_handling._set_worker_signal_handlers / torch.utils.data._utils.signal_handling._remove_worker_pids 直接覆盖: - test_worker_signal_handlers_and_pid_cleanup 直接调用 _set_worker_signal_handlers,并通过 _set_worker_pids 注册当前 pid 后调用 _remove_worker_pids 清理,覆盖 C 侧 worker signal handler 初始化和 worker pid registry 清理入口的正常路径。 本文件验证的是 DataLoader worker/control 面 API。为避免把验证目标混入 NPU IPC 和 worker 子进程设备 Tensor 传输,本新增用例中的多进程 DataLoader 使用 Python 字符串 payload,不在 worker 子进程返回 NPU Tensor;原 DataLoader NPU Tensor payload 路径已由 test_upstream 中单进程 DataLoader/collate 用例覆盖。 三、NPU适配方案 1. API 源码无需修改:上述 API 是 torch.utils.data 的 Python/C++ 控制面入口,不新增 NPU kernel,不改变接口语义。 2. 测试新增路径:新增 test/test_utils_data_api.py,文件聚焦 worker/control API 直接行为,可后续扩展同模块 API。 3. 分支提交范围:新增测试文件提交到 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 以及 master。 四、变更文件 - test/test_utils_data_api.py # 【资料变更】 > 已检查资料支持情况,结论如下: > > dataloader: > - 公开 API,在文档中记录:torch.utils.data.DataLoader、torch.utils.data._utils.collate.collate。对应资料 PR:https://gitcode.com/Ascend/pytorch/merge_requests/36233 > - 内部函数/类,不在文档中记录:DataLoader iterator、worker、signal handling、persistent worker 相关内部对象。 # 【接口变更】 > 不涉及。API 源码无修改,不新增、删除或变更对外接口。 # 【功能验证】 > 已在 master 对应 torch-npu 环境执行新增用例,结果如下;master 使用 2.12.0 验证环境执行。 ## 验证环境 - 操作系统:Ubuntu / Linux aarch64 - 昇腾硬件:910B2 - CANN 软件版本:8.3.RC1 - 验证环境: - 2.7.1:torch 2.7.1+cpu / torch-npu 2.7.1.post3 - 2.9.0:torch 2.9.0+cpu / torch-npu 2.9.0.post1 - 2.10.0:torch 2.10.0+cpu / torch-npu 2.10.0rc3 - 2.11.0:torch 2.11.0+cpu / torch-npu 2.11.0rc1 - 2.12.0 / master 验证:torch 2.12.0+cpu / torch-npu 2.12.0.rc1 ## 运行命令与结果 bash python test/test_utils_data_api.py Ran 5 tests in 1.416s OK # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37247 | 3 个月前 | |
fix(npu): register QuantizedPrivateUse1 view/ravel/flatten for test_view_ops. Co-authored-by: Margaret_wangrui<wangrui178@huawei.com> # message auto-generated for no-merge-commit merge: !37087 merge master_view_0524 into master fix(npu): register QuantizedPrivateUse1 view/ravel/flatten for test_view_ops. Created-by: Margaret_wangrui Commit-by: Margaret_wangrui Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2082 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 **问题简述:** 将 PyTorch 上游 test/test_view_ops.py 切换到 torch_npu 执行时,test_ravel_npu、test_flatten_npu 在处理 torch._empty_affine_quantized(..., quint8, device=npu) 量化张量时报错: text NotImplementedError: Could not run 'aten::view' with arguments from the 'Quantizednpu' backend 浮点 NPU 张量(PrivateUse1)可正常 view;量化 NPU 张量(QuantizedPrivateUse1)缺少对应 kernel 注册。 --- # 【修改方案】 本 PR 为 **QuantizedPrivateUse1** 补齐 shape / copy 相关 dispatch,并与 op-plugin stride_copy 修复配合,使量化 NPU 张量上的 view / ravel / flatten 语义与上游用例一致。 **组件交互关系:** text test_ravel_npu / test_flatten_npu(量化 quint8 on NPU) │ ▼ TensorShape.cpp(torch_npu) QuantizedPrivateUse1 注册:view / ravel / contiguous / clone / empty* / _copy_from │ ├─► MetaData 不匹配时 clone 物化(NPUStorageDesc 与 view shape 对齐) │ ▼ TensorFactories.cpp(torch_npu) NPUNativeFunctions::clone(quant):int_repr + npu_stride_copy_out │ ▼ AsStridedKernelNpu.cpp(op-plugin,子模块 071a046) 小 nbytes int_repr stride_copy 稳定走 AsStrided **具体实现:** 1. **torch_npu/csrc/aten/common/TensorShape.cpp(+312 行)** - 通过 TORCH_LIBRARY_IMPL(aten, QuantizedPrivateUse1, m) 注册:view、as_strided、ravel、contiguous、clone、empty_like、empty.memory_format、empty_strided、_copy_from。 - 实现 npu_quantized_view_symint:基于 infer_size + computeStride,经 alias_with_sizes_and_strides_npu 构造 QTensorImpl view;stride 不兼容且可展平为 rank-1 时走 clone + view。 - 实现 npu_quantized_ravel:aten::contiguous → view(-1),避免 composite reshape 在 NPU 量化张量上短路。 - 实现 npu_quantized_contiguous:除 is_contiguous() 外检查行主 stride,必要时 clone 物化。 - npu_quantized_view_materialize_if_storage_desc_mismatch:当 MetaDataAreMatch(q)==false 时对 view 结果 clone(Contiguous)。 - NPUNativeFunctions::as_strided 增加量化分支,构造 QTensorImpl view。 2. **torch_npu/csrc/aten/common/TensorFactories.cpp(+202 行)** - 增强 NPUNativeFunctions::clone 量化路径:empty_like + SetDesc + int_repr stride_copy。 - MetaDataAreMatch 异常(如 transpose、view 后 storage desc 不一致)时,CPU int_repr staging + H2D 物化。 - stride_copy 后 int_repr slab 传播与 canonical 缓冲对齐(npu_quantized_clone_write_int_repr_payload)。 3. **test/test_view_ops.py** - 量化 NPU 张量不再强制 flat._base is src(允许 NPUStorageDesc 不匹配时的物化拷贝路径)。 - 修正 is_quantized / is_npu 为属性访问(非可调用方法)。 **变更规模:** text test/test_view_ops.py | 5 +- torch_npu/csrc/aten/common/TensorFactories.cpp | 202 +++ torch_npu/csrc/aten/common/TensorShape.cpp | 312 +++ --- # 【资料变更】 不涉及。 --- # 【接口变更】 不涉及跨代码仓或客户面可见的公开 API 变更。 **内部说明(ATen dispatch 层,非 Python 公开接口):** | 算子 | Dispatch Key | 变更类型 | |------|--------------|----------| | view / as_strided / ravel / contiguous / clone | QuantizedPrivateUse1 | 新增 kernel 注册 | | empty_like / empty.memory_format / empty_strided / _copy_from | QuantizedPrivateUse1 | 新增 kernel 注册 | 用户可见行为变化:NPU 上 quint8 等量化张量可正常执行 view、ravel、flatten(此前为 NotImplementedError)。 --- # 【功能验证】 **环境要求:** 已编译安装 torch_npu;NPU 设备可用。 **测试步骤:** bash python test/test_view_ops.py -v -k test_ravel_npu python test/test_view_ops.py -v -k test_flatten_npu **覆盖场景:** | 场景 | 验证点 | |------|--------| | 连续量化张量 5×5×5×5 | ravel() / flatten(0,-1) 与 view(-1) 一致 | | 空 shape 0×2×3、3×0×2 | numel=0 时 shape 与 view 链正确 | | 转置 + ravel(nc=True) | 非连续路径 contiguous().view(-1) 与 ravel() 一致 | | 多组 flatten 维度 | (0,2)、(1,2)、(-2,-1) 等与 view(-1) 展开顺序一致 | | 浮点 NPU 回归 | 同一用例文件中浮点张量路径不受影响 | **UT 看护:** - [x] 适配 test/test_view_ops.py(量化 NPU _base 断言放宽、is_quantized/is_npu 属性修正) **自验证:** 请在合入前补充 NPU 环境执行上述命令的通过截图或 CI 流水线链接。   --- # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37087 | 3 个月前 | |
Update onnx_test_common.py Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> # message auto-generated for no-merge-commit merge: merge master-dev1 into master Update onnx_test_common.py Created-by: yuhaiyan Commit-by: yuhaiyan Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!25485 | 11 个月前 | |
| 2 年前 | ||
feat: register ExternalStream in torch_npu_schema.json for API compatibility test Co-authored-by: yuht9<yuhaitao6@huawei.com> # message auto-generated for no-merge-commit merge: !43191 merge master into master feat: register ExternalStream in torch_npu_schema.json for API compatibility test Created-by: yuht9 Commit-by: yuht9 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> 需求 问题单 issue https://gitcode.com/Ascend/pytorch/issues/2655 重构优化 资料更新 # 【修改方案】 feat: register ExternalStream in torch_npu_schema.json for API compatibility test) # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 UT修改,不涉及功能代码 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!43191 | 1 个月前 | |
| 2 年前 | ||
| 2 年前 |
简介
test目录为PTA相关的测试用例。
安装依赖
pip3 install -r requirements.txt
补全脚本
该操作需要联网
cd test
bash get_synchronized_files.sh
通过以上操作,会自动补齐testfiles_synchronized.txt和testfolder_synchronized.txt中的文件或文件夹。
跳过失败用例
export DISABLED_TESTS_FILE=./unsupported_test_cases/.pytorch-disabled-tests.json
如果不是在test目录下运行测试用例,需要传入.pytorch-disabled-tests.json的绝对路径。
执行方式
执行单个测试脚本
运行以test开头的文件。以test_autocast.py为例:
方式一:
python test_autocast.py
方式二:
python run_test.py -i test_autocast
说明:部分以test开头的脚本不是直接运行的脚本,比如jit中的测试脚本是通过test_jit.py执行的。
执行具体的用例
通过-k参数传入具体的用例名。以test_autocast.py为例:
方式一:
python test_autocast.py -v -k test_autocast_nn_fp32
方式二:
python run_test.py -v -i test_autocast -- -k test_autocast_nn_fp32
执行全量UT的方式
# 进入到test目录的上一级
cd ../
运行非分布式全量用例:
python ci/access_control_test.py --all
运行分布式全量用例:
python ci/access_control_test.py --distributed
FAQ
-
报错:"dictionary changed size during interation".
如果python 环境是3.8.1版本,报错在unitest/case.py中,可考虑是sys.modules被修改导致的。第三方包可能会有对sys.modules的修改,比如beartype。 此问题为python 3.8.1版本/3.9.0版本的已知bug,可按照 https://github.com/python/cpython/issues/73806 中修改方式修改,将
for v in sys.modules.values()改为for v in list(sys.modules.values())可用于复现问题的用例:
python test_jit.py -v -k test_annotated_empty_dict -
test_public_bindings.py 用例的功能
该用例是为了校验接口的公开规范性,如果该用例报错,请确认报错的接口是否要公开,并按照报错的提示进行修改。