文件最后提交记录最后更新时间
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 报错信息中类名变更(BackwardHookFunctionBackwardBackwardHookFunction),正则匹配失败。 ## 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!3627912 天前
fix: fix log message bug Co-authored-by: luochao60<luochao60@huawei.com> # message auto-generated for no-merge-commit merge: !37363 merge Pynative_fix_log_bug_20260601_master into master fix: fix log message bug Created-by: luochao60 Commit-by: luochao60 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > (如有)请关联需求文档/issue链接 > 关联 issue: #2212https://gitcode.com/Ascend/pytorch/issues/2212) - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列 > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 修改 test/_inductor/test_inductor_graph_partition.pyTestGraphPartitionNPU.test_graph_partition_log_message 的日志校验文本。 2. 将 NPU graph tree record 日志匹配从旧格式 [NPUGRAPH-TREE][Node][Record] function=0, graph=0 更新为当前实际输出 NPUGRAPH-TREE Node Record function=0, graph=0。 3. 该改动只调整测试期望文本,保持图分区和 NPU graph 录制逻辑不变。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及" 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及" 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 修改现有 UT test/_inductor/test_inductor_graph_partition.py::TestGraphPartitionNPU::test_graph_partition_log_message 的日志匹配文本,用于适配当前 NPU graph tree record 日志格式。待 CI 在 v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 分支完成验证。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!373637 小时前
[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通过 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/97941307-5dcc-4588-9bc3-dd968506ae68/image.png 'image.png') 本地验证ut通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ✓] 代码注释完备,正确记录错误日志 - [ ✕] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!366495 天前
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!3553915 天前
!9500 The test cases support NPU. Merge pull request !9500 from yuhaiyan/master-dev4 2 年前
将test_mish、test_silu等skip掉的用例重新补回来 Co-authored-by: xiaoqi-zhou<zhouxiaoqi9@h-partners.com> # message auto-generated for no-merge-commit merge: !33564 merge transfer_master into master 将test_mish、test_silu等skip掉的用例重新补回来 Created-by: xiaoqi-zhou Commit-by: xiaoqi-zhou Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 之前test_mish、test_silu、test_EnsembleDropout、test_npu_roi_align_1等因为门禁机器问题以及用例构造有问题导致阻塞其他PR合入,需要下掉用例。 PR合入后,将这些用例补充回来。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 UT全部通过,门禁已过。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!335647 天前
[Feature]rename head file and add cmake for libtorch_npu 2 年前
支持c++外部流接口getStreamFromExternal Co-authored-by: panweicheng<panweicheng@huawei.com> Co-authored-by: pwc10490<pwc10490@gitcode.com> # message auto-generated for no-merge-commit merge: !36666 merge master into master 支持c++外部流接口getStreamFromExternal Created-by: pwc10490 Commit-by: panweicheng;pwc10490 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/2163 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 test/cpp_extensions/test/test_external_stream.py ![image.png](https://raw.gitcode.com/user-images/assets/7404318/682ab412-f5ab-4776-8115-9cce9487be0f/image.png 'image.png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!366661 天前
[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!3598112 天前
Unblock Pipeline UT Cases on CI Co-authored-by: limuan<liyijie16@huawei.com> # message auto-generated for no-merge-commit merge: !37206 merge ut_fix/master into master Unblock Pipeline UT Cases on CI Created-by: limuan Commit-by: limuan Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 将之前屏蔽的用例从屏蔽名单中释放出来,master/2.12.0分支,用例需要调用torch.random.fork_rng,其初始化cuda导致报错. 使用torch.random.fork_rng = lambda *args, **kwargs: contextlib.nullcontext() 进行代替 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/4b212cee-0248-4243-8482-beb132b1dfbe/image.png 'image.png') # 【CheckList】 - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!3720621 小时前
Skip old torch(<=2.2) test case in test/dynamo/test_activate_checkpoint.py Co-authored-by: zhangafei<zhangafei@huawei.com> # message auto-generated for no-merge-commit merge: !37357 merge master into master Skip old torch(<=2.2) test case in test/dynamo/test_activate_checkpoint.py Created-by: HandsoemLemon Commit-by: zhangafei Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ [Bug]: 26.1.0版本图模式Bug修复:https://gitcode.com/Ascend/pytorch/issues/1962 > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 当前测试用例为对2024年1月pytorch 2.2版本测试用例,其中存在大量与现版本API不一致问题,修改用例,检测当时torch若大于2.2,则跳过部分用例。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!373571 小时前
!8437 Add official source code for test_autograd.py Merge pull request !8437 from yuhaiyan/master-dev1 2 年前
!16093 Update test_common_rules.py/test_eager_transformers.py Merge pull request !16093 from yuhaiyan/master-dev2 1 年前
[test] ShapeEnv APIs NPU兼容性验证与资料更新 Co-authored-by: hongwei-2026<feizi_050920@qq.com> # message auto-generated for no-merge-commit merge: !36138 merge add_pr5_renwu21_master into master [test] ShapeEnv APIs NPU兼容性验证与资料更新 Created-by: hongwei-2026 Commit-by: hongwei-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> <!-- MR: https://gitcode.com/Ascend/pytorch/pull/36138 | 分支: add_pr5_renwu21_master → master --> # 【合入来源】 > **https://gitcode.com/Ascend/pytorch/issues/1627** > **请勿携带内部流程信息(需求链接、问题单、内部issue等)** - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 本 PR 在仓库已有 **test/fx/test_symbolic_shapes.py**(torch.fx.experimental.symbolic_shapes 模块测试)中增补 **TestShapeEnvNPU**,对 issue #1627 要求的 **ShapeEnv 守卫与符号表 API** 在 **Ascend NPU(master 日构建)** 上做单元验证,写法与文件内现有 TestSymbolicShapes 一致(**TestCase + run_tests()**)。 **合入目标分支:master(MR 36138)** ## 1. 上游社区与仓库现有测试情况 | 测试位置 | 覆盖侧重点 | 与本次 API 的关系 | |---------|-----------|------------------| | test/fx/test_symbolic_shapes.py | is_accessor_nodeis_concrete_*is_symbolic;已使用 ShapeEnv | **本 PR 在此文件扩展** ShapeEnv 守卫类 API 用例 | | test/fx/test_symbolic_shapes_api.py | definitely_trueDimConstraints 等其它 symbolic_shapes API | 不同 API 类别,不混放 | | test/dynamo/test_export.pytest/dynamo/test_misc.py | 导出等集成路径中间接使用 ShapeEnv | 缺少下列公开方法的独立、可回归 NPU 用例 | | test/fx/test_fx_passes.py 等 | FX Pass / Graph 变换 | 不涉及 ShapeEnv 守卫字符串与 sympy 简化 | 结论:需在 **test_symbolic_shapes.py** 中补齐 ShapeEnv 守卫类 API 在 NPU 上的直接单测;**不新增 test_cases.py**(评审已明确要求合并至本文件)。实现方式与 [MR 36139](https://gitcode.com/Ascend/pytorch/pull/36139)~[MR 36204](https://gitcode.com/Ascend/pytorch/pull/36204) 保持一致。 ## 2. 目标 API 功能说明(全称,master 测试范围) | API 全称 | 功能简述 | 本 PR 是否编写用例 | |---------|---------|------------------| | torch.fx.experimental.symbolic_shapes.ShapeEnv.produce_guards_expression | 根据占位 FakeTensor 等输入,生成守卫**表达式字符串** | 是 | | torch.fx.experimental.symbolic_shapes.ShapeEnv.produce_guards_verbose | 结合 Source 生成更详细的守卫信息 | 是(_produce_guards_verbose_works() 探测,不可用时 skip) | | torch.fx.experimental.symbolic_shapes.ShapeEnv.replace | 在 ShapeEnv 符号表上下文中替换 sympy 表达式 | 是 | | torch.fx.experimental.symbolic_shapes.ShapeEnv.add_backed_var_to_val | 为 **backed** 符号绑定具体整型值(**2.11.0+**) | 是(_shape_env_has() 检测) | | torch.fx.experimental.symbolic_shapes.ShapeEnv.set_unbacked_var_to_val | 为 **unbacked** 符号绑定具体值 | 是(_shape_env_set_unbacked_var_to_val_works() 探测,不可用时 skip) | | torch.fx.experimental.symbolic_shapes.ShapeEnv.simplify | 在 ShapeEnv 环境下对 sympy 表达式做化简 | 是 | > **关于 add_backed_var_to_val(回应评审疑问)** > 该 API 来自 issue #1627,由上游在 **PyTorch 2.11.0+** 引入。v2.7.1~v2.10.0 MR(36139/36201/36202)**故意不包含**;master 与 [MR 36203](https://gitcode.com/Ascend/pytorch/pull/36203)、[MR 36204](https://gitcode.com/Ascend/pytorch/pull/36204) 同属 2.11.0+ 策略(wheel 未导出则 skip)。 ## 3. 用例设计与开发思路 ### 3.1 总体原则 1. **模块归属**:在同一文件新增 **TestShapeEnvNPU**,与 TestSymbolicShapes 并列,**不用** test_cases.py。 2. **一 API 一用例**:方法名 test_torch_fx_experimental_symbolic_shapes_ShapeEnv_<api>,便于 CI 报告与 issue 追溯。 3. **设备约束**:@unittest.skipUnless(torch.npu.is_available(), "requires npu")。 4. **断言驱动**:「构造 → 调用 → 断言」;能力不满足时由 **@skipUnless + 探测函数** 决定 SKIP。 ### 3.2 公共辅助逻辑 | 辅助项 | 作用 | |--------|------| | _shape_env_with_fake_placeholders(shape=(3, 4)) | NPU FakeTensor + FakeTensorMode(shape_env=env) 占位场景 | | _shape_env_has(name) | 判断 API 是否存在(用于 add_backed_var_to_val) | | _produce_guards_verbose_works() | 端到端探测 produce_guards_verbose;bare Source() 失败则 SKIP | | _shape_env_set_unbacked_var_to_val_works() | 端到端探测 set_unbacked_var_to_valnon-nested SymInt 则 SKIP | > master 上部分 API「存在但不可用」,仅用 hasattr 会 CI ERROR;端到端探测保证 **PASS / SKIP** 语义正确。 ### 3.3 分 API 用例设计 #### (1)produce_guards_expression - **目的**:NPU FakeTensor 占位场景下生成守卫表达式字符串。 - **步骤**:_shape_env_with_fake_placeholders()produce_guards_expressionassertIsInstance(guards, str)。 - **说明**:不校验 guards 具体内容,只验证接口可达性。 #### (2)produce_guards_verbose - **目的**:提供 Source 列表时生成详细守卫信息。 - **步骤**:构造 placeholders → [Source()] * len(placeholders)produce_guards_verboseassertIsNotNone。 - **SKIP**:_produce_guards_verbose_works() 为 False(bare Source() 无完整 name,不代表 NPU 缺陷)。 #### (3)replace - **目的**:sympy 表达式替换路径行为正确。 - **步骤**:ShapeEnv() + a,b = symbolsassertEqual(env.replace(a+b), a+b)。 #### (4)add_backed_var_to_val(2.11.0+) - **目的**:backed 符号绑定 API 在 NPU 环境可调用。 - **步骤**:add_backed_var_to_val(sympy.Symbol("test_backed_1"), 10),无异常即通过。 - **SKIP**:_shape_env_has("add_backed_var_to_val") 为 False。低版本 MR 不含此用例。 #### (5)set_unbacked_var_to_val - **目的**:unbacked 符号绑定路径可触发。 - **步骤**:create_unbacked_symint()set_unbacked_var_to_val(sym, 4)。 - **SKIP**:_shape_env_set_unbacked_var_to_val_works() 为 False(non-nested SymInt 上游限制)。 #### (6)simplify - **目的**:sympy 化简 (a+b)-b → a。 - **步骤**:assertEqual(env.simplify((a+b)-b), a)。 ### 3.4 版本分支覆盖 | API | v2.7.1~v2.10.0 MR | master 本 MR | |-----|-------------------|--------------| | produce_guards_expression / replace / simplify | 测 | 测 | | produce_guards_verbose / set_unbacked_var_to_val | 测(多 SKIP) | 测(多 SKIP) | | add_backed_var_to_val | **不测** | **测** | ### 3.5 与现有 TestSymbolicShapes 的关系 - **TestSymbolicShapes**:谓词/图节点(is_accessor_nodeis_concrete_* 等)。 - **TestShapeEnvNPU**:ShapeEnv 实例方法(守卫生成、符号绑定、sympy 改写)。 - 同文件、同 run_tests(),可单独跑 TestShapeEnvNPU。 ### 3.6 运行与 CI 对接 ```bash cd test python fx/test_symbolic_shapes.py -v TestShapeEnvNPU ``` ## 4. 变更范围 - **仅修改** test/fx/test_symbolic_shapes.py(+95 行),无业务代码变更。 - **评审修订**:不新增 test_cases.py,并入 TestShapeEnvNPU。 - 低版本见 36139/36201/36202;2.11.0+ 见 36203/36204;资料见 [MR 36144](https://gitcode.com/Ascend/pytorch/pull/36144)。 # 【资料变更】 不涉及。资料由 docs MR 单独提交。 # 【接口变更】 不涉及。 # 【功能验证】 ## 测试环境 - 硬件:Ascend 910B(CI ascend-pytorch-*) - 软件:**PyTorch master 日构建** + torch_npu + CANN ## 测试命令 ```bash cd test python fx/test_symbolic_shapes.py -v TestShapeEnvNPU ``` ## 预期结果(master) | API 全称 | 预期 | |---------|------| | ShapeEnv.produce_guards_expression | PASS | | ShapeEnv.produce_guards_verbose | SKIP(bare Source() 无法满足 name) | | ShapeEnv.replace | PASS | | ShapeEnv.add_backed_var_to_val | PASS 或 SKIP(视 wheel 是否导出) | | ShapeEnv.set_unbacked_var_to_val | SKIP(non-nested SymInt) | | ShapeEnv.simplify | PASS | **合计 6 用例;典型 3~4 PASS + 2~3 SKIP** ## 自验证 - 本地/CI 可见各 test_torch_fx_experimental_symbolic_shapes_ShapeEnv_* 的 PASS/SKIP 状态。 - ![image.png](https://raw.gitcode.com/user-images/assets/7404318/2d945950-2939-4597-8fb8-28b1d62bf3c8/image.png) # 【CheckList】 - [x] 测试并入 test/fx/test_symbolic_shapes.py,未使用 test_cases.py - [x] add_backed_var_to_val 纳入 master(2.11.0+),与 issue #1627 一致 - [x] 代码注释完备,错误由断言与 unittest 机制暴露 - [x] TestCase + run_tests() 规范写法 - [x] PR 标题使用类型标签(如 test:) - [ ] CI 执行通过 See merge request: Ascend/pytorch!361381 天前
Adapt test_jit_is_trancing in trace for NPU Co-authored-by: qq_42437014<yandj5@163.com> # message auto-generated for no-merge-commit merge: !37098 merge test-jit-is_tracing-in-trace-master into master Adapt test_jit_is_trancing in trace for NPU Created-by: qq_42437014 Commit-by: qq_42437014 Merged-by: ascend-robot Description: # 【合入来源】 [[Usage]: torch.jit.is_tracing () ----此API,在trace模式下,测试样例缺失](https://gitcode.com/Ascend/pytorch/issues/1706) > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) ## API 功能 torch.jit.istracing 是 TorchScript 核心执行模式判断 API,用于在静态图编译与执行阶段检测当前代码是否处于 tracing 编译上下文,支持在 tracing / scripting 混合编码场景下实现条件分支、执行路径切换、图编译行为适配,保障不同执行模式下代码逻辑的正确性,是 TorchScript 动态适配、图优化、模式感知的基础能力。 ## 测试用例说明 1. scrpit模式下,API torch.jit.is_tracing () PyTorch 官方 test_jit.py(官方路径:pytorch/test/test_jit.py;行号位置:两个测试用例的位置大概在9783-9798行)包含test_script_is_tracing、test_script_get_tracing_state 两个测试用例。 **测试用例详解** • test_script_get_tracing_state:调用底层私有接口判定追踪状态,依托NPU张量运算分支结果,校验底层接口识别追踪模式的有效性。 • test_script_is_tracing:使用官方标准接口判断追踪状态,结合NPU张量执行脚本编译校验,验证公开接口在图追踪场景下判定逻辑正常。 2. trace模式下,API torch.jit.is_tracing () 添加新测试用例test/test_jit_is_tracing_in_trace.py • 基础环境适配:引入torch_npu库启用NPU设备能力,构造NPU张量作为测试输入数据 • 核心功能验证:校验进入JIT轨迹录制流程时,接口可正确返回真值 **测试用例详解** • test_is_tracing_returns_true_in_trace_mode:基于接口返回结果编写分支判断逻辑,使用NPU张量执行轨迹录制。通过最终运算输出结果,确认程序成功走入轨迹模式分支,验证接口状态判定逻辑有效。 **测试用例构造说明** 由于 PyTorch 的 torch.jit.trace 机制限制,在被追踪函数内部执行时,底层的 Python 级追踪标志位(tracing flag)依然保持为 False,因此无法直接在函数内部进行断言验证。本测试转而采用严格的“行为验证”方案:利用 Tracer “仅记录单条执行路径”的特性,通过校验最终的输出结果,反向证明 is_tracing() 成功触发了目标分支,且该计算路径已被正确固化到 TorchScript 图中。 ## NPU 适配说明 1. scrpit模式下,API torch.jit.is_tracing ()适配说明 torch.jit.istracing 为 TorchScript 前端执行模式检测 API,无硬件相关底层算子依赖,NPU 完全兼容 PyTorch 原生实现,功能行为、状态语义、编译逻辑与 CPU 保持一致。此测试样例无需修改,可直接测试验证。 • 基础环境适配:将仓库test_upstream/test/test_jit.py.patch,进行apply之后,已有import torch_npu基础环境的适配; • 张量设备调整:将仓库test_upstream/test/test_jit.py.patch,进行apply之后,代码已将cpu的张量修改为npu上运行。确保异步计算的结果载体(张量)运行在 NPU 上,贴合 NPU 场景使用需求。 2. trace模式下,API torch.jit.is_tracing ()适配说明 新增测试用例:test/test_jit_is_tracing_in_trace.py,补齐NPU设备场景下接口相关测试覆盖。 • 基础环境适配:引入torch_npu库启用NPU设备能力,构造NPU张量作为测试输入数据。 # 【资料变更】 **需要添加2.9.0~2.12.0的API说明** 在 https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 的文档中进行查找与验证。该目录下的pytorch_2-7-1文件夹下的torch-jit.md有API的说明,"torch.jit.is_tracing"全部标注"是 支持fp32"。 pytorch_2-9-0~pytorch_2-12-0没有对此API的说明,故对pytorch_2-9-0、pytorch_2-10-0、pytorch_2-11-0、pytorch_2-12-0文件夹下的torch-jit.md添加了API的说明,"torch.jit.is_tracing"全部标注"是 支持fp32"。 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 **测试命令:** ``` #script模式下,测试命令 cd pytorch/test python -m unittest test_jit.TestScript.test_script_is_tracing test_jit.TestScript.test_script_get_tracing_state -v #trace模式下,测试命令 cd pytorch/test python test_jit_is_tracing_in_trace.py -v ``` **测试结果:** 1. script模式下,测试结果 ``` root@5534245c24de:/workspace/user_data/527/pytorch/test_upstream#python -m unittest test_jit.TestScript.test_script_is_tracing test_jit.TestScript.test_script_get_tracing_state -v /usr/local/python3.11.14/lib/python3.11/site-packages/torch_npu/contrib/transfer_to_npu.py:362: ImportWarning: ************************************************************************************************************* The torch.Tensor.cuda and torch.nn.Module.cuda are replaced with torch.Tensor.npu and torch.nn.Module.npu now.. The torch.cuda.DoubleTensor is replaced with torch.npu.FloatTensor cause the double type is not supported now.. The backend in torch.distributed.init_process_group set to hccl now.. The torch.cuda.* and torch.cuda.amp.* are replaced with torch.npu.* and torch.npu.amp.* now.. The device parameters have been replaced with npu in the function below: torch.logspace, torch.randint, torch.hann_window, torch.rand, torch.full_like, torch.ones_like, torch.rand_like, torch.randperm, torch.arange, torch.frombuffer, torch.normal, torch._empty_per_channel_affine_quantized, torch.empty_strided, torch.empty_like, torch.scalar_tensor, torch.tril_indices, torch.bartlett_window, torch.ones, torch.sparse_coo_tensor, torch.randn, torch.kaiser_window, torch.tensor, torch.triu_indices, torch.as_tensor, torch.zeros, torch.randint_like, torch.full, torch.eye, torch._sparse_csr_tensor_unsafe, torch.empty, torch._sparse_coo_tensor_unsafe, torch.blackman_window, torch.zeros_like, torch.range, torch.sparse_csr_tensor, torch.randn_like, torch.from_file, torch._cudnn_init_dropout_state, torch._empty_affine_quantized, torch.linspace, torch.hamming_window, torch.empty_quantized, torch._pin_memory, torch.load, torch.set_default_device, torch.get_device_module, torch.sparse_compressed_tensor, torch.Tensor.new_empty, torch.Tensor.new_empty_strided, torch.Tensor.new_full, torch.Tensor.new_ones, torch.Tensor.new_tensor, torch.Tensor.new_zeros, torch.Tensor.to, torch.Tensor.pin_memory, torch.nn.Module.to, torch.nn.Module.to_empty ************************************************************************************************************* warnings.warn(msg, ImportWarning) /usr/local/python3.11.14/lib/python3.11/site-packages/torch_npu/contrib/transfer_to_npu.py:291: RuntimeWarning: torch.jit.script and torch.jit.script_method will be disabled by transfer_to_npu, which currently does not support them, if you need to enable them, please do not use transfer_to_npu. warnings.warn(msg, RuntimeWarning) /usr/local/python3.11.14/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: torch.jit.script_method is deprecated. Please switch to torch.compile or torch.export. warnings.warn( monkeytype is not installed. Skipping tests for Profile-Directed Typing test_script_is_tracing (test_jit.TestScript.test_script_is_tracing) ... /usr/local/python3.11.14/lib/python3.11/site-packages/torch/jit/_script.py:1480: DeprecationWarning: torch.jit.script is deprecated. Please switch to torch.compile or torch.export. warnings.warn( /usr/local/python3.11.14/lib/python3.11/site-packages/torch/jit/_serialization.py:89: DeprecationWarning: torch.jit.save is deprecated. Please switch to torch.export. warnings.warn( /usr/local/python3.11.14/lib/python3.11/site-packages/torch/jit/_serialization.py:176: DeprecationWarning: torch.jit.load is deprecated. Please switch to torch.export. warnings.warn( ok test_script_get_tracing_state (test_jit.TestScript.test_script_get_tracing_state) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.160s ``` 2. trace模式下,测试结果 ``` root@5534245c24de:/workspace/user_data/527/pytorch/test/jit# python test_jit_is_tracing_in_trace.py -v test_is_tracing_returns_true_in_trace_mode (__main__.TestJitIsTracing.test_is_tracing_returns_true_in_trace_mode) Validates that torch.jit.is_tracing() returns True during trace recording. ... /usr/local/python3.11.14/lib/python3.11/site-packages/torch/jit/_trace.py:1000: DeprecationWarning: torch.jit.trace is deprecated. Please switch to torch.compile or torch.export. warnings.warn( ok ---------------------------------------------------------------------- Ran 1 test in 1.373s OK ``` **验证结论:** NPU 环境运行script/trace模式下的测试用例,三个用例执行成功,无功能失败项。torch.jit.is_tracing 模式检测、状态返回、控制流分支适配等能力均符合 PyTorch 标准语义,适配完成且验证通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!370983 天前
test(nn): add PackedSequence API tests on NPU Co-authored-by: Jinfan Liu<1300083451@qq.com> # message auto-generated for no-merge-commit merge: !37118 merge test-packed-sequence-api-clean-npu-master into master test(nn): add PackedSequence API 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/2003**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> [x] 问题单 # 【修改方案】 一、API功能说明 ``` API范围: - torch.nn.utils.rnn.PackedSequence - torch.nn.utils.rnn.PackedSequence.count - torch.nn.utils.rnn.PackedSequence.index - torch.nn.utils.rnn.PackedSequence.is_pinned - torch.nn.utils.rnn.PackedSequence.to 1. torch.nn.utils.rnn.PackedSequence 是 PyTorch RNN 工具模块中表示变长序列压缩结果的数据结构,主要由 torch.nn.utils.rnn.pack_padded_sequence、torch.nn.utils.rnn.pack_sequence 等接口构造,也可以直接由 data、batch_sizes、sorted_indices、unsorted_indices 四元组构造。 核心能力:保存压缩后的 data Tensor、每个 time step 的 batch_sizes,以及可选的 sorted_indices / unsorted_indices,用于在压缩序列和 padded 序列之间恢复顺序关系。 设备约束:data 可以位于 NPU;sorted_indices / unsorted_indices 跟随 data 的设备;batch_sizes 是序列结构元数据,按 PyTorch 接口约束保持 CPU int64 Tensor。 2. torch.nn.utils.rnn.PackedSequence.to 是 PackedSequence 的设备和 dtype 迁移接口,语义对齐 torch.Tensor.to。 核心能力:对 data 执行目标 device / dtype 转换,并同步迁移 sorted_indices / unsorted_indices;当 data 已满足目标配置时返回 self,避免不必要拷贝。 边界约束:to 不迁移 batch_sizes,保持 PackedSequence 对 batch_sizes 的 CPU 元数据约束。 3. torch.nn.utils.rnn.PackedSequence.count / torch.nn.utils.rnn.PackedSequence.index 是 PackedSequence 继承自 NamedTuple 的实例方法。 核心能力:count 返回指定成员值在 PackedSequence 四元组中的出现次数;index 返回指定成员值首次出现的位置。 验证重点:PackedSequence 有自定义构造逻辑,需要在真实 PackedSequence 实例上确认 NamedTuple 的 tuple-like 行为没有被破坏。 4. torch.nn.utils.rnn.PackedSequence.is_pinned 是 PackedSequence 的 pinned memory 状态查询接口。 核心能力:返回 self.data.is_pinned() 的结果,用于判断 PackedSequence 的实际 data Tensor 是否处于 pinned memory 状态。 设备边界:NPU Tensor 不走 CPU pinned memory 语义,验证重点是接口可调用、返回值稳定,并且不会破坏 PackedSequence 的 NPU data Tensor 路径。 ``` 二、测试用例完备性说明 ``` PyTorch 社区 test/nn/test_packed_sequence.py 已覆盖 torch.nn.utils.rnn.PackedSequence.to 及 pack/pad/unpack 集成路径,但缺少 torch.nn.utils.rnn.PackedSequence.count、torch.nn.utils.rnn.PackedSequence.index、torch.nn.utils.rnn.PackedSequence.is_pinned 的直接用例。 master 分支不提交 test_upstream patch。本 PR 在 torch-npu test 目录新增 test/nn/test_packed_sequence_api.py,包含 3 个直接用例: 1. test_packed_sequence_constructor_and_to_on_npu:构造 NPU data + CPU batch_sizes + NPU sorted/unsorted indices 的 PackedSequence,验证构造、设备约束、is_pinned,以及 to("cpu") / to("npu") 迁移。 2. test_packed_sequence_namedtuple_methods_on_optional_indices:验证 count(None)、index(None)、count("non_existent") 和 index 不存在成员抛 ValueError,覆盖 NamedTuple 方法。 3. test_packed_sequence_rejects_accelerator_batch_sizes:验证 NPU batch_sizes 按 PyTorch 约束抛出 ValueError。 ``` 三、NPU适配方案 ``` 1. API 源码无需修改:上述 API 位于 PyTorch 框架层,核心逻辑为 PackedSequence 结构管理、Tensor.to 调用转发和 NamedTuple 行为。 2. 新增 torch-npu 原生测试:补齐 PyTorch 社区缺少的 count/index/is_pinned 直接验证,并补充 PackedSequence.to 与 batch_sizes CPU 元数据约束验证。 ``` # 【资料变更】 > 已检查 v2.7.1 docs/zh/native_apis 中各版本 torch-nn.md,以及 v2.12.0 docs/api/torch_npu_apis.md。torch.nn.utils.rnn.PackedSequence、torch.nn.utils.rnn.PackedSequence.count、torch.nn.utils.rnn.PackedSequence.index、torch.nn.utils.rnn.PackedSequence.is_pinned、torch.nn.utils.rnn.PackedSequence.to 均已列入 API 支持列表。本次只补充/适配测试用例,不涉及资料补充。 # 【接口变更】 > 不涉及。API 源码无修改,不新增、删除或变更对外接口。 # 【功能验证】 > 新增用例与 2.12.0 分支同源,已在 2.12.0 torch-npu 环境执行通过: ```bash python test/nn/test_packed_sequence_api.py Ran 3 tests in 1.446s OK ``` See merge request: Ascend/pytorch!371181 天前
[feat] 950 not support ACL_OP_INIT_MODE=0 Co-authored-by: LiNuohang<linuohang@huawei.com> # message auto-generated for no-merge-commit merge: !36109 merge aclop-m into master [feat] 950 not support ACL_OP_INIT_MODE=0 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/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 950不支持acl_op_init_mode==0,如果是950设备,acl_op_init_mode被设置成0的时候,自动转成1,并报warning # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增UT,测试不同设备不同设置 本地测试:pass (lnh_310_m) [linuohang@ascend127 ~]$ python /home/linuohang/test/test_temp.py [W528 15:38:42.620871180 OptionsManager.cpp:541] Warning: ========lnh mode = 1======== (function operator()) (lnh_310_m) [linuohang@ascend127 ~]$ python /home/linuohang/test/test_temp.py [W528 15:39:31.866144040 OptionsManager.cpp:541] Warning: ========lnh mode = 0======== (function operator()) (lnh_310_m) [linuohang@ascend127 ~]$ python /home/linuohang/test/test_temp.py [W528 15:39:51.578598300 OptionsManager.cpp:541] Warning: ========lnh mode = 2======== (function operator()) (lnh_310_m) [linuohang@ascend127 ~]$ python /home/linuohang/test/test_temp.py [W528 15:40:23.776321440 OptionsManager.cpp:531] Warning: Get env ACL_OP_INIT_MODE not in [0, 1, 2], so reset it to the default value 1. (function operator()) [W528 15:40:23.776356620 OptionsManager.cpp:541] Warning: ========lnh mode = 1======== (function operator()) (lnh_310_m) [linuohang@ascend127 ~]$ # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!361094 天前
[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!3598112 天前
[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!3598112 天前
[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!3598112 天前
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!265386 个月前
[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!3598112 天前
Unblock Pipeline UT Cases on CI Co-authored-by: limuan<liyijie16@huawei.com> # message auto-generated for no-merge-commit merge: !37206 merge ut_fix/master into master Unblock Pipeline UT Cases on CI Created-by: limuan Commit-by: limuan Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 将之前屏蔽的用例从屏蔽名单中释放出来,master/2.12.0分支,用例需要调用torch.random.fork_rng,其初始化cuda导致报错. 使用torch.random.fork_rng = lambda *args, **kwargs: contextlib.nullcontext() 进行代替 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/4b212cee-0248-4243-8482-beb132b1dfbe/image.png 'image.png') # 【CheckList】 - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!3720621 小时前
[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!3598112 天前
!21966 Document description optimization Merge pull request !21966 from shaoyf/master_readme 11 个月前
!20432 Fixed the failed testcases Merge pull request !20432 from yuhaiyan/master-dev1 1 年前
!20432 Fixed the failed testcases Merge pull request !20432 from yuhaiyan/master-dev1 1 年前
TORCH MAIN SYNC: switch to release candidate of torch 2.12 update Co-authored-by: chansinging<chenxingying2@huawei.com> Co-authored-by: Chansinging<1183520536@qq.com> # message auto-generated for no-merge-commit merge: !35103 merge main_sync_0509 into master TORCH MAIN SYNC: switch to release candidate of torch 2.12 update Created-by: chansinging Commit-by: Chansinging;chansinging Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 同步社区演进,例行更新 lintrunner规避,见[issue](https://gitcode.com/Ascend/pytorch/issues/1865) # 【修改方案】 出包参考社区改动,https://github.com/pytorch/pytorch/pull/177570/ # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 本地A3服务器和ci流水线已跑通测试 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/a7797f8a-f0ad-4dc4-860a-3c1ff2d11f53/image.png 'image.png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!3510323 天前
!19783 Remove expose for deprecated apis. Merge pull request !19783 from 刘嘉巍/master 1 年前
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!3553915 天前
!11238 To get synchronized files. Merge pull request !11238 from yuhaiyan/master-dev1 2 年前
Update to v2.13.0 Co-authored-by: Chansinging<1183520536@qq.com> # message auto-generated for no-merge-commit merge: !35159 merge main_sync_20260510 into master Update to v2.13.0 Created-by: chansinging Commit-by: Chansinging Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 [版本升级](https://gitcode.com/Ascend/pytorch/issues/1923) - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 社区演进和版本升级 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/86a4d28a-f4aa-4d05-9403-5904dc8a7ca0/image.png 'image.png') # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!3515919 天前
!6717 [Codecheck] test codecheck. Merge pull request !6717 from will-devil/myccheck 2 年前
!12854 [RFC][Feature] Add support for device extension autoloading Merge pull request !12854 from Yuanhao Ji/feat/autoload 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!3598112 天前
add test case for event elapsed_time Co-authored-by: chenkun<chenkun82@huawei.com> # message auto-generated for no-merge-commit merge: !26731 merge master_event_ut into master add test case for event elapsed_time Created-by: kuhn7 Commit-by: chenkun 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!267316 个月前
[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!3598112 天前
!15327 Delete some skipped test cases for test_convolution.py / test_autograd.py / test_optim.py. Merge pull request !15327 from yuhaiyan/master-dev5 1 年前
!12854 [RFC][Feature] Add support for device extension autoloading Merge pull request !12854 from Yuanhao Ji/feat/autoload 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!3598112 天前
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!337141 个月前
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!337141 个月前
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!337141 个月前
feat: detect Ascend950 SoC for TORCH_NPU_USE_COMPATIBLE_IMPL default Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !36752 merge sync-pr36613-master into master feat: detect Ascend950 SoC for TORCH_NPU_USE_COMPATIBLE_IMPL default Created-by: wuyouqi1 Commit-by: wuyouqi1 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/2091 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 TORCH_NPU_USE_COMPATIBLE_IMPL 环境变量默认值根据 SoC 型号自动检测: 1. 新增 _is_ascend950() 函数,通过 Python ctypes 直接调用 CANN 库 libascendcl.soaclrtGetSocName() 接口获取 SoC 名称,判断是否以 "Ascend950" 开头 2. 仅在环境变量 TORCH_NPU_USE_COMPATIBLE_IMPL **未设置**时触发检测: - Ascend950:默认值 "1"(启用 ACL API 路径,与 GPU 行为对齐) - 其他型号:默认值 "0"(保持缓存路径,原有行为不变) 3. 用户显式设置环境变量时,保持用户值不变,不做检测覆盖 修改文件: - torch_npu/__init__.py — SoC 检测 + 环境变量默认值 - test/test_compatible_impl_soc_detect.py(新增)— 4 个测试用例 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。TORCH_NPU_USE_COMPATIBLE_IMPL 环境变量接口不变,仅调整未设置时的默认值逻辑。无新增/变更客户面 API。 # 【功能验证】 测试场景: 1. **Ascend950 机器,环境变量未设置**:CheckCompatibleImpl() 返回 true 2. **非 Ascend950 机器(如 Ascend910B),环境变量未设置**:CheckCompatibleImpl() 返回 false 3. **任意机器,用户显式设置 TORCH_NPU_USE_COMPATIBLE_IMPL=1**:用户值优先 4. **无 CANN 环境**:ctypes 加载失败,_is_ascend950() 返回 False,默认 "0",不抛异常 自动化测试:python3 test/test_compatible_impl_soc_detect.py - A2场景: ``` (wyq) [root@localhost HPC]# python test_compatible_impl_soc_detect.py -v test_compatible_impl_default_matches_soc (__main__.TestCompatibleImplSocDetect) ... skipped 'TORCH_NPU_USE_COMPATIBLE_IMPL was pre-set in environment' test_compatible_impl_respects_user_value (__main__.TestCompatibleImplSocDetect) ... ok test_is_ascend950_matches_cpp_soc_version (__main__.TestCompatibleImplSocDetect) ... ok test_is_ascend950_returns_bool (__main__.TestCompatibleImplSocDetect) ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.001s OK (skipped=1) ``` - A5场景: ``` (/root/my_envs/tmp_ffmh) [root@A5-PoD-A04-CPU3 0128]# python test_compatible_impl_soc_detect.py -v test_compatible_impl_default_matches_soc (__main__.TestCompatibleImplSocDetect) ... skipped 'TORCH_NPU_USE_COMPATIBLE_IMPL was pre-set in environment' test_compatible_impl_respects_user_value (__main__.TestCompatibleImplSocDetect) ... ok test_is_ascend950_matches_cpp_soc_version (__main__.TestCompatibleImplSocDetect) ... ok test_is_ascend950_returns_bool (__main__.TestCompatibleImplSocDetect) ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.001s OK (skipped=1) ``` # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!367526 天前
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!337141 个月前
!8912 Synchronize the different test cases for v2.2.0. Merge pull request !8912 from yuhaiyan/master-dev1 2 年前
!9500 The test cases support NPU. Merge pull request !9500 from yuhaiyan/master-dev4 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!3598112 天前
!10958 Add test files: test_flop_counter/test_jit_autocast/test_jit_fuser/... Merge pull request !10958 from yuhaiyan/master-dev3 2 年前
!8912 Synchronize the different test cases for v2.2.0. Merge pull request !8912 from yuhaiyan/master-dev1 2 年前
!9365 The test files support NPU. Merge pull request !9365 from 王夏夏/master 2 年前
!9365 The test files support NPU. Merge pull request !9365 from 王夏夏/master 2 年前
!10598 Delete the URL in code. Merge pull request !10598 from yuhaiyan/master-dev7 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 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/4f48a660-c3d7-41b2-a8ee-bca1d17a1733/image.png 'image.png') 上游社区测试覆盖情况汇总 序号 测试函数 测试场景 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 实现,无需额外适配 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/5921d449-7154-4cfb-9f74-ba71c6caf0f8/image.png 'image.png') ### _custom_builtins / _CustomBuiltin / SymbolicContext - **社区测试情况**: _custom_builtins ❌ 无结果 社区无测试 _CustomBuiltin ❌ 无结果 社区无测试 SymbolicContext ⚠️ 只有 StatelessSymbolicContext(变体) 社区无直接测试 - **结论**:需要 torch-npu 自写用例 - **验证**: ![image.png](https://raw.gitcode.com/user-images/assets/7404318/e9e18c87-692e-40dd-9cea-a362588b584f/image.png 'image.png') ## 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个测试用例全部通过** ![屏幕截图 2026-05-13 213606.png](https://raw.gitcode.com/user-images/assets/7404318/c8ea9188-bcf9-4220-81f0-387f133a043f/屏幕截图_2026-05-13_213606.png '屏幕截图 2026-05-13 213606.png') ## 文档检查 已检查 docs/api/torch_npu_apis.md: - torch.fx.Graphtorch.fx.Graph.__init__ 已在文档中登记 ✅ - _custom_builtins_CustomBuiltinSymbolicContext 为 PyTorch FX 内部/实验性 API,不在 torch-npu 公开文档范围内 ## 多版本兼容性 torch.fx核心架构自PyTorch 1.8引入后保持稳定,推断在2.7.1 ~ 2.12.0及master分支行为一致,均无需适配。 See merge request: Ascend/pytorch!355794 天前
!9365 The test files support NPU. Merge pull request !9365 from 王夏夏/master 2 年前
!9365 The test files support NPU. Merge pull request !9365 from 王夏夏/master 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 本地验证结果: ![image.png](https://raw.gitcode.com/user-images/assets/7404318/78941546-13bc-4c7e-9cc7-c6544df41397/image.png 'image.png') 所有测试用例执行通过。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!340711 个月前
!7605 Add UT files Merge pull request !7605 from yuhaiyan/master-dev1 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!3598112 天前
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!324022 个月前
[feat] Add test cases for verifying torch.jit.ScriptModule hook API on NPU Co-authored-by: hxm_<ha_m@foxmail.com> # message auto-generated for no-merge-commit merge: !35821 merge master into master [feat] Add test cases for verifying torch.jit.ScriptModule hook API on NPU Created-by: hxm_ Commit-by: hxm_ Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 issue连接:https://gitcode.com/Ascend/pytorch/issues/1723 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 一、背景说明 1. 通过torch.jit.script()创建的模型是RecursiveScriptModule实例,与测试目的不符,所以本次测试模型均通过继承torch.jit.ScriptModule创建。 2. torch.jit.ScriptModule 继承自 torch.nn.Module,在 __init__ 执行完毕后通过 torch.jit.ScriptModule .init_then_script() 将模块编译为 TorchScript,内部持有 torch.jit.ScriptModule ._actual_script_moduleRecursiveScriptModule 实例)作为 C++ 侧代理。编译过程只迁移参数/子模块/缓冲区的存储,不替换类上的方法,也不影响 hook 相关属性(torch.jit.ScriptModule ._backward_hookstorch.jit.ScriptModule ._backward_pre_hooks 等),因此大部分 hook API 在 ScriptModule 子类上行为与普通 Module 一致。 3. torch.jit.ScriptModule .register_full_backward_hook 例外的原因:该方法内部会设置 self._is_full_backward_hook = True,该属性赋值被 ScriptModule.__setattr__ 代理到 C++ 侧后,因类型不匹配(C++ 侧期望 NoneType)导致 RuntimeError。这是pytorch自身的bug。 ## 二、API 功能说明 ### 1. torch.jit.ScriptModule.register_full_backward_hook(hook, prepend=False) -> RemovableHandle 在模块上注册反向传播后置 hook。hook 签名为 hook(module, grad_input, grad_output) -> tuple[Tensor] or None,在模块梯度计算完成时被调用,可返回新的 grad_input 替代原有值。prepend=True 时 hook 在已有 hook 之前执行。返回 RemovableHandle 用于移除 hook。 ### 2. torch.jit.ScriptModule.register_full_backward_pre_hook(hook, prepend=False) -> RemovableHandle 在模块上注册反向传播前置 hook。hook 签名为 hook(module, grad_output) -> tuple[Tensor] or None,在模块梯度计算之前被调用,可返回新的 grad_output 影响后续梯度计算。prepend=True 时 hook 在已有 hook 之前执行。返回 RemovableHandle 用于移除 hook。 ### 3. torch.jit.ScriptModule.register_load_state_dict_pre_hook(hook) -> RemovableHandle 在 load_state_dict 调用前触发 hook。hook 签名为 hook(module, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) -> None,可用于在加载前对 state_dict 进行预处理。返回 RemovableHandle 用于移除 hook。 ### 4. torch.jit.ScriptModule.register_load_state_dict_post_hook(hook) -> RemovableHandle 在 load_state_dict 调用后触发 hook。hook 签名为 hook(module, incompatible_keys) -> None,incompatible_keys 包含 missing_keys 和 unexpected_keys,可原地修改。返回 RemovableHandle 用于移除 hook。 ### 5. torch.jit.ScriptModule.register_state_dict_pre_hook(hook) -> RemovableHandle 在 state_dict 调用前触发 hook。hook 签名为 hook(module, prefix, keep_vars) -> None,可用于在序列化前执行预处理。返回 RemovableHandle 用于移除 hook。 ### 6. torch.jit.ScriptModule.register_state_dict_post_hook(hook) -> RemovableHandle 在 state_dict 调用后触发 hook。hook 签名为 hook(module, state_dict, prefix, local_metadata) -> None,可原地修改 state_dict。返回 RemovableHandle 用于移除 hook。 ## 三、测试用例说明 ### 1. torch.jit.ScriptModule.register_full_backward_hook | 用例 | 说明 | |------|------| | test_register_full_backward_hook_raises | 验证调用 register_full_backward_hook 时抛出 RuntimeError | ### 2. torch.jit.ScriptModule.register_full_backward_pre_hook | 用例 | 说明 | |------|------| | test_register_full_backward_pre_hook_called | 验证 hook 在反向传播时被调用 | | test_register_full_backward_pre_hook_modify_grad | 验证 hook 返回修改后的 grad_output 可影响梯度计算(返回全零梯度,输入梯度为零) | | test_register_full_backward_pre_hook_prepend | 验证 prepend=True 时 hook 在已有 hook 之前执行 | | test_register_full_backward_pre_hook_remove | 验证 handle.remove() 后 hook 不再触发 | ### 3. torch.jit.ScriptModule.register_load_state_dict_pre_hook & torch.jit.ScriptModule.register_load_state_dict_post_hook | 用例 | 说明 | |------|------| | test_load_state_dict_pre_hook_fires_before_module_and_post_hook | 验证完整时序 pre_hook -> module(load_state_dict) -> post_hook,post_hook 先注册证明调用顺序与注册顺序无关;pre_hook 修改 state_dict 为全零,post_hook 检查权重已加载为零,证明 module 在 pre 和 post 之间执行 | | test_register_load_state_dict_pre_hook_called | 验证 pre_hook 在 load_state_dict 时被调用,接收到正确的 prefix 参数 | | test_register_load_state_dict_pre_hook_with_module | 验证 pre_hook 接收到的 module 参数就是当前模型实例 | | test_register_load_state_dict_pre_hook_remove | 验证 handle.remove() 后 pre_hook 不再触发 | | test_register_load_state_dict_post_hook_called | 验证 post_hook 在 load_state_dict 后被调用 | | test_register_load_state_dict_post_hook_with_module | 验证 post_hook 接收到的 module 参数就是当前模型实例 | | test_register_load_state_dict_post_hook_remove | 验证 handle.remove() 后 post_hook 不再触发 | ### 4. torch.jit.ScriptModule.register_state_dict_pre_hook & torch.jit.ScriptModule.register_state_dict_post_hook | 用例 | 说明 | |------|------| | test_state_dict_pre_hook_fires_before_module_and_post_hook | 验证完整时序 pre_hook -> module(state_dict) -> post_hook,post_hook 先注册证明调用顺序与注册顺序无关;post_hook 检查 state_dict 已包含模型参数,证明 module 在 pre 和 post 之间执行 | | test_register_state_dict_pre_hook_called | 验证 pre_hook 在 state_dict 时被调用,接收到正确的 prefix 参数 | | test_register_state_dict_pre_hook_with_module | 验证 pre_hook 接收到的 module 参数就是当前模型实例 | | test_register_state_dict_pre_hook_remove | 验证 handle.remove() 后 pre_hook 不再触发 | | test_register_state_dict_post_hook_called | 验证 post_hook 在 state_dict 后被调用,接收到正确的 prefix 参数 | | test_register_state_dict_post_hook_with_module | 验证 post_hook 接收到的 module 参数就是当前模型实例 | | test_register_state_dict_post_hook_remove | 验证 handle.remove() 后 post_hook 不再触发 | # 【资料变更】 torch.jit.ScriptModule.register_load_state_dict_pre_hook、torch.jit.ScriptModule.register_state_dict_post_hook API昇腾支持,但是在文档中并无描述,因此需要增加。 其他API昇腾支持,且在文档中有描述,无需添加。 文档修改PR链接:https://gitcode.com/Ascend/pytorch/pull/35840 # 【接口变更】 不涉及 # 【功能验证】 | 接口 | 状态 | 说明 | |------|------|------| | torch.jit.ScriptModule.register_full_backward_hook | 不可用 | 调用时抛出 RuntimeError | | torch.jit.ScriptModule.register_full_backward_pre_hook | 可用 | 正常注册并触发,支持修改 grad_output、prepend 顺序控制、handle 移除 | | torch.jit.ScriptModule.register_load_state_dict_pre_hook | 可用 | 在 load_state_dict 前触发,可接收 module 参数,支持 handle 移除 | | torch.jit.ScriptModule.register_load_state_dict_post_hook | 可用 | 在 load_state_dict 后触发,可接收 module 参数,支持 handle 移除 | | torch.jit.ScriptModule.register_state_dict_pre_hook | 可用 | 在 state_dict 前触发,可接收 module 参数,支持 handle 移除 | | torch.jit.ScriptModule.register_state_dict_post_hook | 可用 | 在 state_dict 后触发,可接收 module 参数,支持 handle 移除 | 测试日志 ``` ======================================== Python代码多环境测试开始 测试脚本: /root/torch-2.11/test_script_module_hooks.py 测试时间: Fri Apr 24 06:37:57 AM UTC 2026 ======================================== 检测到已激活的虚拟环境,先取消激活... ---------------------------------------- 测试环境: torch-2.7.1 虚拟环境: /root/torch-2.7.1/.venv/bin/activate 日志文件: /root/torch-2.11/logs/test_2.7.1_20260424_063757.log ---------------------------------------- 测试环境: torch-2.7.1 退出码: 0 状态: 成功 ✅ 详细日志: /root/torch-2.11/logs/test_2.7.1_20260424_063757.log 完成测试: torch-2.7.1 (退出码: 0) ---------------------------------------- 测试环境: torch-2.8 虚拟环境: /root/torch-2.8/.venv/bin/activate 日志文件: /root/torch-2.11/logs/test_2.8_20260424_063757.log ---------------------------------------- 测试环境: torch-2.8 退出码: 0 状态: 成功 ✅ 详细日志: /root/torch-2.11/logs/test_2.8_20260424_063757.log 完成测试: torch-2.8 (退出码: 0) ---------------------------------------- 测试环境: torch-2.9 虚拟环境: /root/torch-2.9/.venv/bin/activate 日志文件: /root/torch-2.11/logs/test_2.9_20260424_063757.log ---------------------------------------- 测试环境: torch-2.9 退出码: 0 状态: 成功 ✅ 详细日志: /root/torch-2.11/logs/test_2.9_20260424_063757.log 完成测试: torch-2.9 (退出码: 0) ---------------------------------------- 测试环境: torch-2.10 虚拟环境: /root/torch-2.10/.venv/bin/activate 日志文件: /root/torch-2.11/logs/test_2.10_20260424_063757.log ---------------------------------------- 测试环境: torch-2.10 退出码: 0 状态: 成功 ✅ 详细日志: /root/torch-2.11/logs/test_2.10_20260424_063757.log 完成测试: torch-2.10 (退出码: 0) ---------------------------------------- 测试环境: torch-2.11 虚拟环境: /root/torch-2.11/.venv/bin/activate 日志文件: /root/torch-2.11/logs/test_2.11_20260424_063757.log ---------------------------------------- 测试环境: torch-2.11 退出码: 0 状态: 成功 ✅ 详细日志: /root/torch-2.11/logs/test_2.11_20260424_063757.log 完成测试: torch-2.11 (退出码: 0) ======================================== 测试完成总结 总测试环境数: 5 完成时间: Fri Apr 24 06:39:05 AM UTC 2026 成功测试数: 5 失败测试数: 0 所有详细日志保存在: /root/torch-2.11/logs 主日志文件: /root/torch-2.11/logs/test_results_20260424_063757.log ======================================== ``` pytorch 2.12 ``` ../root/.local/share/uv/python/cpython-3.12.13-linux-aarch64-gnu/lib/python3.12/multiprocessing/popen_fork.py:66: DeprecationWarning: This process (pid=3985006) is multi-threaded, use of fork() may lead to deadlocks in the child. self.pid = os.fork() [W515 03:02:03.790319610 NPUCachingAllocator.cpp:199] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) [W515 03:02:11.756102926 IscloseKernelNpu.cpp:34] Warning: Device do not support double dtype of rtol and atol now, dtype cast repalce with float. (function operator()) .................... ---------------------------------------------------------------------- Ran 21 tests in 18.055s OK ``` # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!3582114 天前
!10958 Add test files: test_flop_counter/test_jit_autocast/test_jit_fuser/... Merge pull request !10958 from yuhaiyan/master-dev3 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!3598112 天前
!10958 Add test files: test_flop_counter/test_jit_autocast/test_jit_fuser/... Merge pull request !10958 from yuhaiyan/master-dev3 2 年前
!22454 Fix test_matmul_npu Merge pull request !22454 from dilililiwhy/fix_test_matmul_npu 10 个月前
!8912 Synchronize the different test cases for v2.2.0. Merge pull request !8912 from yuhaiyan/master-dev1 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!3598112 天前
!12772 Delete the URLs in code. Merge pull request !12772 from yuhaiyan/master-dev2 1 年前
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!337141 个月前
!21353 Add test_native_mha.py. Merge pull request !21353 from 刘嘉巍/master 11 个月前
[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!3598112 天前
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!320602 个月前
!7605 Add UT files Merge pull request !7605 from yuhaiyan/master-dev1 2 年前
[fix]add getMemoryFraction attribute for torch._C Co-authored-by: weixin_47897441<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !30619 merge master into master [fix]add getMemoryFraction attribute for torch._C Created-by: weixin_47897441 Commit-by: weixin_47897441 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > (如有)请关联需求文档/issue链接 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 : torch._C不支持_npu_getMemoryFraction - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1、NPUCachingAllocator中新增getMemoryFraction方法及虚函数声明,Module中注册_npu_getMemoryFraction绑定; 2、在torch_npu.npu和torch_npu.npu.memory中实现并暴露get_per_process_memory_fraction接口,支持指定设备,调用底层 C++ 接口; 3、新增该接口的测试用例; 4、将该接口及底层Cpp绑定加入Dynamo追踪规则,完成适配。 # 【资料变更】 > 不涉及 # 【接口变更】 > 否 # 【功能验证】 > UT用例测试通过:python test_npu.py -v -k test_get_per_process_memory_fraction ![image.png](https://raw.gitcode.com/user-images/assets/7404318/dd7cc124-b3b1-47d1-ab15-ad3798b33115/image.png 'image.png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!306192 个月前
[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通过 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/97941307-5dcc-4588-9bc3-dd968506ae68/image.png 'image.png') 本地验证ut通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ✓] 代码注释完备,正确记录错误日志 - [ ✕] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!366495 天前
!20986 Refactoring device_count Merge pull request !20986 from huangyunlong/2.7ct 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!3598112 天前
add record_stream sanitizer Co-authored-by: bellatan<tanmei2@huawei.com> Co-authored-by: hb_hubin<hubin79@huawei.com> # message auto-generated for no-merge-commit merge: !34841 merge record_stream_sanitizer into master add record_stream sanitizer Created-by: bellatan Commit-by: bellatan;hb_hubin 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测试用例看护,并补充测试自验证截图 本地验证 1. test/npu/test_sanitizer.py ![image.png](https://raw.gitcode.com/user-images/assets/7404318/db51597e-f6bf-4b34-8ba1-170ba8bb5bde/image.png 'image.png') 2. test/npu/test_sanitizer_record_stream.py ![image.png](https://raw.gitcode.com/user-images/assets/7404318/630b87e8-dc9c-4c9a-a2d4-932b9ad18dca/image.png 'image.png') 3. test/test_npu_sanitizer.py ![image.png](https://raw.gitcode.com/user-images/assets/7404318/ecb4d1f1-aef9-4b9b-a082-75ff16991064/image.png 'image.png') 4. test/test_sanitizer_pluggable_allocator.py ![image.png](https://raw.gitcode.com/user-images/assets/7404318/ffa87f39-c755-41fe-8176-9cb38cd73a09/image.png 'image.png') 5. ci结果 ·UT_ARM_A2_Part_01:test/test_npu_sanitizer.py,pass ![image.png](https://raw.gitcode.com/user-images/assets/7404318/d5fb5242-cb11-435d-ae2b-36960a9522f8/image.png 'image.png') ·UT_ARM_A2_Part_02:test/npu/test_sanitizer.py,pass;test/test_sanitizer_pluggable_allocator.py pass ![1778915605465.png](https://raw.gitcode.com/user-images/assets/7404318/243673b4-b5b0-4c5d-8c21-3d22f84cce82/1778915605465.png '1778915605465.png') ·UT_ARM_A2_Part_03:test/npu/test_sanitizer_record_stream.py,pass ![1778915660126.png](https://raw.gitcode.com/user-images/assets/7404318/b1e2f979-f4f7-4f24-b4b9-b1987de33677/1778915660126.png '1778915660126.png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!3484112 天前
!9845 update test_trace_rules.py for v2.3 and skip a failed test case. Merge pull request !9845 from yuhaiyan/master-dev4 2 年前
!12772 Delete the URLs in code. Merge pull request !12772 from yuhaiyan/master-dev2 1 年前
!12235 UPdate test_ops_gradients and test_ops_fwd_gradients of pt24 Merge pull request !12235 from 张向龙3/ops_grad_24 1 年前
!10484 Add test files. Merge pull request !10484 from yuhaiyan/master-dev5 2 年前
!8912 Synchronize the different test cases for v2.2.0. Merge pull request !8912 from yuhaiyan/master-dev1 2 年前
!7765 [UT] add official source testcase for test_out_dtype_op Merge pull request !7765 from 张伟康/pta_master_dev 2 年前
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测试用例看护,并补充测试自验证截图 ![image (4).png](https://raw.gitcode.com/user-images/assets/7404318/01eda919-bd1c-415a-b9bc-76cb268cc1d1/image__4_.png 'image (4).png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!370921 天前
[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通过 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/97941307-5dcc-4588-9bc3-dd968506ae68/image.png 'image.png') 本地验证ut通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ✓] 代码注释完备,正确记录错误日志 - [ ✕] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!366495 天前
!8330 Delete the public URL in code Merge pull request !8330 from yuhaiyan/master-dev6 url fixed url fixed fixed fixed fixed 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!3598112 天前
!12609 add test_sparse.py Merge pull request !12609 from huangyunlong/2.4sparse 1 年前
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_sparseaten::_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:1to_sparse 结果的 device 和数值一致性。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。 # 【功能验证】 - 已在 v2.7.1 环境完成 torch_npu 编包并安装验证,torch_npu.__version__2.7.1.post5。 - 已确认 aten::_to_sparseaten::_to_sparse.sparse_dimPrivateUse1 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!359461 天前
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!321401 个月前
!12178 Update test_tensor_creation_ops of pt2.4 Merge pull request !12178 from 张向龙3/creation_ops_24 1 年前
[feat]TensorTo support preserve_format consistent with GPU Co-authored-by: chenshuai<chenshuai81@huawei.com> # message auto-generated for no-merge-commit merge: !35355 merge cherry-pick-mr-34696-1778549007272-auto into master [feat]TensorTo support preserve_format consistent with GPU Created-by: culechan Commit-by: culechan;chenshuai Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1、NPU上tensorto支持preserve_format模式。行为逻辑上对齐pytorch原生框架 2、增加preserve_format模式相关的测试用例 # 【资料变更】 不涉及,原生API表格中未体现这部分内容 # 【接口变更】 Tensor.to默认使用且支持preserve_format模式 # 【功能验证】 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/26dfe926-6f3c-4124-9680-486ed681e868/image.png 'image.png') ![image.png](https://raw.gitcode.com/user-images/assets/7404318/a46d3e66-4a4c-4f9f-9531-78b30d665b58/image.png 'image.png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!3535519 天前
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!273715 个月前
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用例失败 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/5f0c285f-6871-454e-bc01-3c4e20c37a0a/image.png 'image.png') **根因**: 重构前 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 ``` **现象**: ![image.png](https://raw.gitcode.com/user-images/assets/7404318/57e68133-cb8b-4949-880d-7d84282a0b36/image.png 'image.png') **根因分析**: 旧版 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 ``` **现象**: ![image.png](https://raw.gitcode.com/user-images/assets/7404318/e5562a37-524e-4a8e-b790-4b341b8e1e49/image.png 'image.png') **根因分析**: 旧版顶层有: ```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 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/42508ae7-20ae-4a14-a05d-e48cf4a674cb/image.png 'image.png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!367033 天前
!13891 add ParallelTcpStore and register to rendezvous Merge pull request !13891 from 叶子凡/master_TCP 1 年前
!10598 Delete the URL in code. Merge pull request !10598 from yuhaiyan/master-dev7 2 年前
!12165 Update test_type_promotion of pt2.4 Merge pull request !12165 from 张向龙3/prom_24 1 年前
!12150 Update test_unary_ufuncs of pt2.4 Merge pull request !12150 from 张向龙3/unary_ufunc_24 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!253087 个月前
README.md

简介

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

  1. 报错:"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

  2. test_public_bindings.py 用例的功能

    该用例是为了校验接口的公开规范性,如果该用例报错,请确认报错的接口是否要公开,并按照报错的提示进行修改。