| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
[sync] PR-36230: skip ci failed testcase Co-authored-by: XianglongZeng<zengxianglong1@huawei.com> # message auto-generated for no-merge-commit merge: !36269 merge sync-pr36230-v2.7-to-v2.10.0 into v2.10.0 [sync] PR-36230: skip ci failed testcase Created-by: ascend-ds-bot Commit-by: XianglongZeng Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/36230 ### 2. Original pull request related issue(s): ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[06ebea14](https://gitcode.com/Ascend/pytorch/commit/06ebea1424fc0c8334ab9dc002922f441039eb97)|2026-05-20 20:44:39 +0800 CST|skip ci failed testcase<br>| See merge request: Ascend/pytorch!36269 | 3 个月前 | |
support_list_and_move_npu_meta_registration | 2 个月前 | |
[v2.10.0][bugfix]CI error:acl header missing fix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !36837 merge apply-acl-fix-v2.10.0 into v2.10.0 [v2.10.0][bugfix]CI error:acl header missing fix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2137 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 门禁ut不是基于门禁编包代码执行,而是拉取新代码,头文件在编包执行过程中才会从acl_src复制到原本头文件路径acl下。导致门禁ut调用build_stub.sh报错头文件找不到。 修复方案: 1、在门禁执行入口文件ci/access_control_test.py增加头文件复制策略,从当前安装torch_npu路径下复制头文件到工作区代码三方库下acl下 2、修改三个ut中的编译依赖相对路径确保能找到对应头文件 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 门禁通过,ut通过  本地验证ut通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ✓] 代码注释完备,正确记录错误日志 - [ ✕] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36837 | 3 个月前 | |
fix: lintrunner --all-files --take NEWLINE -a Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35873 merge v2.10.0_lintrunner into v2.10.0 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/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 执行: lintrunner --all-files --take NEWLINE -a 修复换行符,不影响代码逻辑。 2. 屏蔽两个分布式用例,已提issue,给对应接口人跟踪。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35873 | 3 个月前 | |
| 2 年前 | ||
将test_mish、test_silu等skip掉的用例重新补回来 Co-authored-by: xiaoqi-zhou<zhouxiaoqi9@h-partners.com> # message auto-generated for no-merge-commit merge: !33585 merge transfer_v2.10.0 into v2.10.0 将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!33585 | 3 个月前 | |
[Feature]rename head file and add cmake for libtorch_npu | 2 年前 | |
Support allocator trace tracker in NPU caching allocator Co-authored-by: zzhongmin<zhongmin23@huawei.com> # message auto-generated for no-merge-commit merge: !38687 merge v2.10.0_tratra into v2.10.0 Support allocator trace tracker in NPU caching allocator Created-by: zzhongmin Commit-by: zzhongmin Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 将 NPU Caching Allocator 对齐到上游 CUDA 实现,补齐 Allocator Trace Tracker 回调机制,并将 mempool 关联方式从间接反查改为直接存储。 1. 新增 AllocatorTraceTracker 回调机制(NPUCachingAllocator.h + .cpp) - 新增 AllocatorTraceTracker 类型、虚方法、trace_trackers_ 成员、公共接口层转发及便捷函数,与 CUDA 接口对齐 2. record_trace 支持 tracker 回调分发(NPUCachingAllocator.cpp) - 入口条件改为 !record_history && trace_trackers_.empty(),构造 TraceEntry 后遍历 trace_trackers_ 调用回调 3. TraceEntry 新增 mempool_ 字段(NPUCachingAllocator.h) - 构造函数新增 MempoolId_t mempool = {0, 0} 参数,新增 MempoolId_t mempool_ 成员 4. PrivatePool 改为直接存储 mempool ID(NPUCachingAllocator.cpp) - 新增 id 成员,构造函数接受 MempoolId_t id - 新增 BlockPool::owner_MempoolId() 方法 - 新增 create_or_incref_pool / get_private_pool,重构 beginAllocateToPool / endAllocateToPool 5. 所有 record_trace 调用点补齐 mempool_id 参数(NPUCachingAllocator.cpp) - 8 处调用点传入 block->pool->owner_MempoolId() 6. NPUWorkspaceAllocator 补齐 TraceEntry 构造参数(NPUWorkspaceAllocator.cpp) - 3 处构造补齐 MempoolId_t{0, 0} 7. NPUPluggableAllocator 补齐接口(NPUPluggableAllocator.h + .cpp) - 新增 attachAllocatorTraceTracker override,TORCH_CHECK(false) 拒绝调用 8. 新增测试 - C++ 扩展注册回调统计 SEGMENT_ALLOC/FREE 事件,Python 测试验证两种场景下回调正确触发 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 test/npu/test_allocator_trace_tracker.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38687 | 2 个月前 | |
trans npuformat cast from aclop to aclnn and fix 1d npu format cast fallback Co-authored-by: shawnylee233<lixiangyi1@huawei.com> # message auto-generated for no-merge-commit merge: !38287 merge sync-pr38058-1D_format_cast-to-v2.10.0 into v2.10.0 trans npuformat cast from aclop to aclnn and fix 1d npu format cast fallback Created-by: shawnylee233 Commit-by: shawnylee233 Merged-by: ascend-robot Description: 同步pr:https://gitcode.com/Ascend/pytorch/pull/38058 See merge request: Ascend/pytorch!38287 | 2 个月前 | |
skip sub-comm creation when global process group was reinit'd and fix p2p longname err Co-authored-by: limuan<liyijie16@huawei.com> # message auto-generated for no-merge-commit merge: !38995 merge comm_p2p_v2.10.0 into v2.10.0 skip sub-comm creation when global process group was reinit'd and fix p2p longname err Created-by: limuan Commit-by: limuan Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 HCCLUdi在rootinfo场景下的P2P通信中,被覆盖为groupname,导致hccl算子拼接后hcclUdi和hcclCommname后,字符超长,拼接后名字:groupbfa08d29a349dccf55aaf7ea17c96695164d8ba6_p2p_0_1_groupbfa08d29a349dccf55aaf7ea17c96695164d8ba6_p2p_0_1 修复方案:Udi仅在rankfiletable场景下,被覆盖为groupname # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 ut用例通过:  pp并行时,正常拉起训练  Udi正常更新:  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38995 | 2 个月前 | |
【bugfix】npugraph_ex.scope.limit_core_num增加默认参数stream Co-authored-by: wangkai<wangkai579@huawei.com> # message auto-generated for no-merge-commit merge: !38935 merge v2.10.0 into v2.10.0 【bugfix】npugraph_ex.scope.limit_core_num增加默认参数stream Created-by: mihudan Commit-by: wangkai Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2445 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 torchair仓合入PR:【refeat】limit_core_num控核支持单算子和可选参数streamhttps://gitcode.com/Ascend/torchair/pull/3181 资料修改: 【doc】limit_core_num支持可选参数streamhttps://gitcode.com/Ascend/torchair/pull/3227 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” ex资料修改已合入 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” npugraph_ex接口增加默认参数,ex资料修改已合入,组内已检视 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 已增加传入stream参数场景  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38935 | 2 个月前 | |
| 2 年前 | ||
| 1 年前 | ||
test(fx): add testcases for torch.fx.experimental.symbolic_shapes APIs v2.10.0 Co-authored-by: xuanzhi-2026<814906706@qq.com> # message auto-generated for no-merge-commit merge: !36804 merge test-symbolic-shapes-api-v2.10.0 into v2.10.0 test(fx): add testcases for torch.fx.experimental.symbolic_shapes APIs v2.10.0 Created-by: xuanzhi-2026 Commit-by: xuanzhi-2026 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【任务背景】 本 PR 对应 pytorch-vllm 开源实习项目中的 Torch-NPU API 一致性对齐任务,公开 issue: https://gitcode.com/Ascend/pytorch/issues/1628 本 PR 是 v2.10.0 分支的用例补齐 PR,目标是补齐 torch.fx.experimental.symbolic_shapes 下 5 个 API 的直接验证用例。同组交付 PR 如下: - v2.7.1 用例:https://gitcode.com/Ascend/pytorch/pull/36792 - v2.9.0 用例:https://gitcode.com/Ascend/pytorch/pull/36799 - v2.10.0 用例:https://gitcode.com/Ascend/pytorch/pull/36804 - v2.11.0 用例:https://gitcode.com/Ascend/pytorch/pull/36815 - v2.12.0 用例:https://gitcode.com/Ascend/pytorch/pull/36818 - master 用例:https://gitcode.com/Ascend/pytorch/pull/36820 - 资料支持状态:https://gitcode.com/Ascend/pytorch/pull/36822 # 【API 功能介绍】 | API | 功能说明 | | --- | --- | | torch.fx.experimental.symbolic_shapes.ShapeEnv.size_hint | 对确定的符号表达式或 sympy 表达式求可用于动态 shape guard/约束判断的整型 hint;allow_none 控制无法求值时是否允许返回 None。 | | torch.fx.experimental.symbolic_shapes.ShapeEnv.suppress_guards | ShapeEnv 提供的上下文管理器,用于在局部代码块内临时抑制 guard 记录,避免辅助求值过程额外生成 guards。 | | torch.fx.experimental.symbolic_shapes.ShapeEnvSettings | ShapeEnv 的配置数据结构,保存动态 shape 相关开关,例如 scalar output、dynamic output shape、duck shape、deferred runtime assert 等行为配置。 | | torch.fx.experimental.symbolic_shapes.StatefulSymbolicContext | 带状态的符号上下文,保存 tensor_source 以及 ShapeEnv/source/symbol 的缓存,用于同一张量符号化过程中的符号复用。 | | torch.fx.experimental.symbolic_shapes.StatelessSymbolicContext | 无状态符号上下文,记录 dynamic_sizes、dynamic_strides、constraint_sizes、constraint_strides 等输入元信息,用于创建符号尺寸时描述动态维约束。 | # 【上游社区测试情况】 已基于当前分支基线检索 test 目录中的相关覆盖情况: - 上游/基线中存在部分间接覆盖,例如 StatelessSymbolicContext 在 dynamo export/subclass 场景中被使用,ShapeEnvSettings 出现在 public API allowlist 中。 - 未发现覆盖本任务 5 个 API 的集中直接 UT,尤其缺少 ShapeEnv.size_hint、ShapeEnv.suppress_guards、ShapeEnvSettings 字段构造、StatefulSymbolicContext/StatelessSymbolicContext 默认状态的直接行为断言。 - 因此本任务按 issue 要求在 torch-npu test/fx 目录新增自写 UT,而不是搬运现有上游 patch。 # 【修改方案 / 用例开发思路】 在 test/fx/test_symbolic_shapes_api.py 中新增 5 个直接测试用例: 1. test_shape_env_size_hint:构造 ShapeEnv,验证 sympy.Integer(8) 可返回 size hint 8,并检查签名中包含 expr、allow_none,且 allow_none 默认值为 False。 2. test_shape_env_suppress_guards:验证 ShapeEnv.suppress_guards() 可作为上下文管理器使用,并在上下文内完成 size_hint 求值。 3. test_shape_env_settings:通过 dataclasses.fields 获取当前版本支持字段,只对当前版本存在的字段构造 ShapeEnvSettings,保证跨版本稳定;随后断言配置值可正确保留。 4. test_stateless_symbolic_context:以 DimDynamic.DUCK 构造 StatelessSymbolicContext,验证 dynamic_sizes、默认 dynamic_strides、constraint_sizes、constraint_strides。 5. test_stateful_symbolic_context:以 ConstantSource("x") 构造 StatefulSymbolicContext,验证 tensor_source、空 symbol cache 和动态维配置。 # 【完备性分析】 - 本 PR 覆盖了 5 个目标 API 的可访问性、核心调用路径、关键返回值、构造参数、默认字段与上下文管理器行为。 - 这 5 个 API 属于 torch.fx.experimental.symbolic_shapes 的 Python 层符号 shape 元信息/上下文能力,不涉及新增 NPU 算子,也不改变跨仓接口或运行时计算逻辑。 - 当前结论:需要新增测试用例,已在本 PR 完成;不需要新增 API 功能实现,不需要新增 NPU kernel,不需要新增资料以外的接口说明。 - 同组 PR 已覆盖 v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0 和 master;资料支持状态由 PR 36822 单独补齐。 # 【资料变更】 不涉及。本 PR 仅补充测试用例;资料支持状态已通过独立资料 PR 提交: https://gitcode.com/Ascend/pytorch/pull/36822 # 【接口变更】 不涉及。未修改跨仓接口或客户可见接口行为。 # 【功能验证】 验证新增 5 个目标 API 测试用例,执行命令如下: ~~~bash cd /workspace/user_data python3 torch-npu-v2.10.0/test/fx/test_symbolic_shapes_api.py \ TestSymbolicShapesAPI.test_shape_env_size_hint \ TestSymbolicShapesAPI.test_shape_env_suppress_guards \ TestSymbolicShapesAPI.test_shape_env_settings \ TestSymbolicShapesAPI.test_stateless_symbolic_context \ TestSymbolicShapesAPI.test_stateful_symbolic_context ~~~ 执行结果如下: ~~~text ..... ---------------------------------------------------------------------- Ran 5 tests in 0.033s OK ~~~ # 【测试效果 / 日志说明】 - 5 个目标 API 用例全部通过。 - 新增用例为 Python 层 symbolic shape 行为验证,测试过程中不依赖新增 NPU 算子实现。 - 当前 PR 已通过 GitCode CI 标签检查:ci-pipeline-passed、docs-ci-pipeline-success。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36804 | 2 个月前 | |
test(jit): add ScriptModule API alignment test cases [v2.10.0] Co-authored-by: TensorLake<l.wenjie@foxmail.com> # message auto-generated for no-merge-commit merge: !37635 merge test/script-module-npu-v2-10-0 into v2.10.0 test(jit): add ScriptModule API alignment test cases [v2.10.0] Created-by: TensorLake Commit-by: TensorLake Merged-by: ascend-robot Description: ## 【合入来源】 Fork: TensorLake/torch-npu 分支: test/script-module-npu-v2-10-0 → Ascend/pytorch:v2.10.0 ## 【修改方案】 本 PR 为 [#1861](https://gitcode.com/Ascend/pytorch/issues/1861) 的交付。社区用例情况:已在 PyTorch 官方社区 pytorch/test/jit/ 下搜索 ScriptModule 相关测试,无针对这 19 个 API 的独立测试用例,因此自行编写测试用例。 ### 一、API 功能说明及行为分类 torch.jit.ScriptModule 通过 torch.jit.script() 创建,返回 RecursiveScriptModule 实例。其方法可见性由双层机制控制: 1. RecursiveScriptModule 自己定义的方法(如 save()、extra_repr()) 2. _compiled_methods_allowlist 白名单中的 nn.Module 方法(如 train()、to()、state_dict()) 3. 不满足以上两条的方法被 _make_fail 替换,调用即抛 RuntimeError("xxx is not supported on ScriptModules") 本测试使用 torch.jit.script() 作为 canonical 创建方式,正确验证 allowlist 机制的行为。按实测行为将 19 个 API 分为 4 类: **第一类:allowlist 内正常工作(11 个)** | API | 来源 | 行为说明 | |-----|------|---------| | train(mode) | 白名单 | 设置训练模式,返回 self,递归传播到子模块 | | eval() | 白名单 | 等价于 train(False),返回 self | | zero_grad(set_to_none) | 白名单 | 清零所有参数梯度 | | float() | 白名单 | 将参数/buffer 转为 float32,返回 self,递归传播 | | double() | 白名单 | 将参数/buffer 转为 float64。NPU 不支持 float64,自动降级为 float32 | | to(dtype/device) | 白名单 | 支持多参数形式,递归传播 | | type(dst_type) | 白名单 | 转换 dtype | | state_dict(...) | 白名单 | 返回 OrderedDict,支持 prefix=、destination=、keep_vars= 参数 | | save(f, _extra_files) | RSM 自定义 | 委托 C++,无返回值。支持 _extra_files 附加文件 | | save_to_buffer() | RSM 自定义 | 序列化到 bytes 并返回 | | extra_repr() | RSM 自定义 | 返回 "original_name=..." 格式字符串 | **第二类:_make_fail 封杀(5 个,与 CPU/GPU 行为一致)** | API | 异常消息(assertRaisesRegex 匹配) | |-----|-----------------------------------| | requires_grad_() | "requires_grad_ is not supported on ScriptModules" | | to_empty() | "to_empty is not supported on ScriptModules" | | xpu() | "xpu is not supported on ScriptModules" | | get_buffer() | "get_buffer is not supported on ScriptModules" | | set_submodule() | "set_submodule is not supported on ScriptModules" | **第三类:torch-npu 拦截(3 个)** | API | CPU 行为 | NPU 行为 | |-----|---------|---------| | share_memory() | 正常工作 | RuntimeError: "share_memory is not supported in npu" | | register_module() | RuntimeError(PyTorch 限制) | RuntimeError(torch-npu 先拦截) | | register_parameter() | RuntimeError(PyTorch 限制) | RuntimeError(torch-npu 先拦截) | 注:share_memory 在 GPU/CUDA 上为 **no-op**(官方文档明确),NPU 行为与 GPU 不一致。 **第四类:PyTorch 内部未完成实现(1 个)** | API | 行为 | |-----|------| | set_extra_state() | RuntimeError: "should never be called" | ### 二、测试文件说明 新增文件:test/jit/test_script_module.py,共 67 个测试用例,按功能语义分为 10 个测试类: - TestScriptModuleTrainEval(11 个):train/eval 默认状态、显式设置、返回值验证、往返切换、NPU 验证、子模块递归传播 - TestScriptModuleZeroGrad(5 个):无梯度不报错、梯度清零、set_to_none 语义、set_to_none=False 清零、backward→zero_grad→backward 链路 - TestScriptModuleTo(9 个):dtype/device/device+dtype/dtype_keyword/string_device/no_args 多形式、返回值验证、子模块传播 - TestScriptModuleFloatDouble(7 个):float 转换/传播、double 转换/NPU float64 降级 float32/传播 - TestScriptModuleType(4 个):float32 正常路径、float64 降级路径、NPU 验证、int32 异常 - TestScriptModuleStateDict(7 个):参数/buffer 包含、值匹配、NPU 设备验证、prefix/destination/keep_vars 参数形式 - TestScriptModuleSave(6 个):save/load 往返、参数保留、返回 None、NPU 验证、_extra_files、save_to_buffer - TestScriptModuleExtraRepr(3 个):返回字符串、original_name 模式、NPU 验证 - TestScriptModuleShareMemory(4 个):CPU 返回 self/makes_shared/幂等、NPU assertRaisesRegex 拦截 - TestScriptModuleMetadata(7 个):register_module/register_parameter NPU 拦截、set_submodule _make_fail、get_buffer _make_fail - TestScriptModuleUnsupported(4 个):requires_grad_/to_empty/xpu _make_fail、set_extra_state 未完成实现 所有可预测异常的 API 均使用 assertRaisesRegex 精确匹配异常信息内容。 ### 三、NPU 适配说明 - 所有涉及张量的测试均在 NPU 设备上运行 - NPU 不支持 float64,double()/to(torch.float64)/type(torch.float64) 自动降级为 float32 - share_memory 在 NPU 上被拦截(GPU 为 no-op,行为不一致,已在测试中标注) - _make_fail 封杀的 5 个 API 在所有设备上行为一致 ## 【资料变更】 经检查 docs/zh/native_apis/ 下各版本路径,已有记录的 API 18/19。set_submodule 缺失,已通过独立文档 PR 提交。 ## 【接口变更】 不涉及 ## 【功能验证】 测试文件:test/jit/test_script_module.py 测试环境:torch 2.10.0 + torch_npu 2.10.0 + NPU 910B3(CANN 8.5.0) ``` test_extra_repr_contains_original_name (__main__.TestScriptModuleExtraRepr.test_extra_repr_contains_original_name) ... ok test_extra_repr_on_npu (__main__.TestScriptModuleExtraRepr.test_extra_repr_on_npu) ... ok test_extra_repr_returns_str (__main__.TestScriptModuleExtraRepr.test_extra_repr_returns_str) ... ok test_double_converts_params (__main__.TestScriptModuleFloatDouble.test_double_converts_params) ... [W604 11:34:32.815442779 compiler_depend.ts:164] Warning: Device do not support double dtype now, dtype cast replace with float. (function operator()) ok test_double_on_npu_fallback_to_float32 (__main__.TestScriptModuleFloatDouble.test_double_on_npu_fallback_to_float32) ... ok test_double_returns_self (__main__.TestScriptModuleFloatDouble.test_double_returns_self) ... ok test_float_converts_params (__main__.TestScriptModuleFloatDouble.test_float_converts_params) ... ok test_float_on_npu (__main__.TestScriptModuleFloatDouble.test_float_on_npu) ... ok test_float_propagates_to_submodules (__main__.TestScriptModuleFloatDouble.test_float_propagates_to_submodules) ... ok test_float_returns_self (__main__.TestScriptModuleFloatDouble.test_float_returns_self) ... ok test_get_buffer_unsupported (__main__.TestScriptModuleMetadata.test_get_buffer_unsupported) ... ok test_get_buffer_unsupported_nonexistent (__main__.TestScriptModuleMetadata.test_get_buffer_unsupported_nonexistent) ... ok test_get_buffer_unsupported_on_nested (__main__.TestScriptModuleMetadata.test_get_buffer_unsupported_on_nested) ... ok test_register_module_raises_on_npu (__main__.TestScriptModuleMetadata.test_register_module_raises_on_npu) ... ok test_register_parameter_raises_on_npu (__main__.TestScriptModuleMetadata.test_register_parameter_raises_on_npu) ... ok test_set_submodule_nested_raises (__main__.TestScriptModuleMetadata.test_set_submodule_nested_raises) ... ok test_set_submodule_raises (__main__.TestScriptModuleMetadata.test_set_submodule_raises) ... ok test_save_and_load (__main__.TestScriptModuleSave.test_save_and_load) ... ok test_save_on_npu (__main__.TestScriptModuleSave.test_save_on_npu) ... ok test_save_preserves_output (__main__.TestScriptModuleSave.test_save_preserves_output) ... ok test_save_returns_none (__main__.TestScriptModuleSave.test_save_returns_none) ... ok test_save_to_buffer (__main__.TestScriptModuleSave.test_save_to_buffer) ... ok test_save_with_extra_files (__main__.TestScriptModuleSave.test_save_with_extra_files) ... ok test_share_memory_cpu_idempotent (__main__.TestScriptModuleShareMemory.test_share_memory_cpu_idempotent) ... ok test_share_memory_cpu_makes_shared (__main__.TestScriptModuleShareMemory.test_share_memory_cpu_makes_shared) ... ok test_share_memory_cpu_returns_self (__main__.TestScriptModuleShareMemory.test_share_memory_cpu_returns_self) ... ok test_share_memory_on_npu_raises (__main__.TestScriptModuleShareMemory.test_share_memory_on_npu_raises) ... ok test_state_dict_contains_buffers (__main__.TestScriptModuleStateDict.test_state_dict_contains_buffers) ... ok test_state_dict_contains_params (__main__.TestScriptModuleStateDict.test_state_dict_contains_params) ... ok test_state_dict_keep_vars (__main__.TestScriptModuleStateDict.test_state_dict_keep_vars) ... ok test_state_dict_on_npu (__main__.TestScriptModuleStateDict.test_state_dict_on_npu) ... ok test_state_dict_values_match (__main__.TestScriptModuleStateDict.test_state_dict_values_match) ... ok test_state_dict_with_destination (__main__.TestScriptModuleStateDict.test_state_dict_with_destination) ... ok test_state_dict_with_prefix (__main__.TestScriptModuleStateDict.test_state_dict_with_prefix) ... ok test_to_device (__main__.TestScriptModuleTo.test_to_device) ... ok test_to_device_and_dtype (__main__.TestScriptModuleTo.test_to_device_and_dtype) ... ok test_to_dtype (__main__.TestScriptModuleTo.test_to_dtype) ... ok test_to_dtype_keyword (__main__.TestScriptModuleTo.test_to_dtype_keyword) ... ok test_to_no_args_returns_self (__main__.TestScriptModuleTo.test_to_no_args_returns_self) ... ok test_to_npu_and_dtype (__main__.TestScriptModuleTo.test_to_npu_and_dtype) ... ok test_to_propagates_to_submodules (__main__.TestScriptModuleTo.test_to_propagates_to_submodules) ... ok test_to_returns_self (__main__.TestScriptModuleTo.test_to_returns_self) ... ok test_to_string_device (__main__.TestScriptModuleTo.test_to_string_device) ... ok test_eval_on_npu (__main__.TestScriptModuleTrainEval.test_eval_on_npu) ... ok test_eval_propagates_to_submodules (__main__.TestScriptModuleTrainEval.test_eval_propagates_to_submodules) ... ok test_eval_returns_self (__main__.TestScriptModuleTrainEval.test_eval_returns_self) ... ok test_eval_sets_training_false (__main__.TestScriptModuleTrainEval.test_eval_sets_training_false) ... ok test_train_default_is_training (__main__.TestScriptModuleTrainEval.test_train_default_is_training) ... ok test_train_eval_roundtrip (__main__.TestScriptModuleTrainEval.test_train_eval_roundtrip) ... ok test_train_on_npu (__main__.TestScriptModuleTrainEval.test_train_on_npu) ... ok test_train_propagates_to_submodules (__main__.TestScriptModuleTrainEval.test_train_propagates_to_submodules) ... ok test_train_returns_self (__main__.TestScriptModuleTrainEval.test_train_returns_self) ... ok test_train_set_false (__main__.TestScriptModuleTrainEval.test_train_set_false) ... ok test_train_set_true_explicit (__main__.TestScriptModuleTrainEval.test_train_set_true_explicit) ... ok test_type_float32 (__main__.TestScriptModuleType.test_type_float32) ... ok test_type_float64 (__main__.TestScriptModuleType.test_type_float64) ... ok test_type_int32_raises (__main__.TestScriptModuleType.test_type_int32_raises) ... ok test_type_on_npu (__main__.TestScriptModuleType.test_type_on_npu) ... ok test_requires_grad_unsupported (__main__.TestScriptModuleUnsupported.test_requires_grad_unsupported) ... ok test_set_extra_state_raises (__main__.TestScriptModuleUnsupported.test_set_extra_state_raises) ... ok test_to See merge request: Ascend/pytorch!37635 | 2 个月前 | |
[sync] PR-37317: delete-skip Co-authored-by: l00881990<lixinyu68@huawei.com> # message auto-generated for no-merge-commit merge: !38579 merge sync-pr37317-delete-skip-to-v2.10.0 into v2.10.0 [sync] PR-37317: delete-skip Created-by: ascend-ds-bot Commit-by: l00881990 Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/37317 ### 2. Original pull request related issue(s): https://gitcode.com/Ascend/pytorch/issues/2177 ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[7bcf1299](https://gitcode.com/Ascend/pytorch/commit/7bcf12998a95e594482810ce4b8d93a20fb64782)|2026-06-01 15:41:27 +0800 CST|delete-skip<br>| See merge request: Ascend/pytorch!38579 | 2 个月前 | |
[new memconfig] add max_non_split_rounding_mb and release_lock_on_npumalloc Co-authored-by: xuyun15<xuyun15@huawei.com> # message auto-generated for no-merge-commit merge: !38777 merge 20260615_mem_config_v2.10.0 into v2.10.0 [new memconfig] add max_non_split_rounding_mb and release_lock_on_npumalloc Created-by: xuyun15 Commit-by: xuyun15 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 与torch社区一致,补充对应的配置到分支即可。 ### 1. Feature 核心工作机制 本 PR 为 NPU Caching Allocator 新增两个可配置项: - ** max_non_split_rounding_mb**:将空闲块选择逻辑中硬编码的 kLargeBuffer(20MB)取整阈值替换为可配置值。用户可通过环境变量或运行时 API 调整该阈值,控制大块分配时的内存浪费容忍度。该配置委托给 c10 基类 AcceleratorAllocatorConfig 管理。 - **release_lock_on_npumalloc**:在 NPU 内存分配(AclrtMallocAlign32)期间释放分配器互斥锁,允许其他线程并发执行分配器操作,提升多线程场景下的并发性能。利用 c10::make_scope_exit 实现 RAII 式的锁恢复,保证异常安全。 ### 2. 核心调用路径 - **配置解析**:PYTORCH_NPU_ALLOC_CONF / _set_allocator_settings() → NPUAllocatorConfig::parseArgs() → AcceleratorAllocatorConfig::parseMaxNonSplitRoundingSize() / NPUAllocatorConfig::parseReleaseLockOnNpuMalloc() - **取整阈值使用**:get_free_block() → NPUAllocatorConfig::max_non_split_rounding_size() → 块选择判断 - **锁释放使用**:alloc_block() → NPUAllocatorConfig::release_lock_on_npumalloc() → lock.unlock() → AclrtMallocAlign32 → scope_exit → lock.lock() ### 3. 核心数据结构 - AcceleratorAllocatorConfig::max_non_split_rounding_size_:std::atomic<size_t>,存储取整阈值(字节),默认 20MB - NPUAllocatorConfig::m_release_lock_on_npumalloc:bool,是否在 malloc 期间释放锁,默认 false - c10::scope_exit:RAII 作用域守卫,析构时自动执行回调 ### 4. 用户使用 - 配置如下:参数含义与社区一致/或者使用export PYTORCH_NPU_ALLOC_CONF环境变量的方式 - torch.npu.memory._set_allocator_settings("max_split_size_mb:50,max_non_split_rounding_mb:30") - `torch.npu.memory._set_allocator_settings("release_lock_on_npumalloc:True") # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38777 | 2 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
[v2.10.0] cherry-pick v2.7.1_fix_ut: remove unskip Co-authored-by: ffmh<fengminghao2@huawei.com> # message auto-generated for no-merge-commit merge: !37617 merge v2.10.0_fix_ut into v2.10.0 [v2.10.0] cherry-pick v2.7.1_fix_ut: remove unskip Created-by: ffmh Commit-by: ffmh Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) Cherry-pick de67e68db from v2.7.1_fix_ut 移除 test/optim/test_fused_optimizers.py 中 3 处 @unittest.skip("Temporarily skipping") 装饰器,重新启用以下测试用例: 1. test_unscale 2. test_simple_model_train_dynamic 3. test_simple_model_train_static # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及" 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及" 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 重新启用 test_fused_optimizers.py 中被跳过的 3 个测试用例,验证 NPU 上 fused optimizer 的 unscale 和 dynamic/static training 功能正常。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37617 | 2 个月前 | |
test(package): add testcase for PackageExporter additional APIs Co-authored-by: PAGEMRW<985608880@qq.com> # message auto-generated for no-merge-commit merge: !37842 merge test-package-exporter-additional-api-v2.10.0 into v2.10.0 test(package): add testcase for PackageExporter additional APIs Created-by: PAGEMRW Commit-by: PAGEMRW Merged-by: ascend-robot Description: # 【合入来源】 - 问题单 PyTorch 社区用例对以下 torch.package.PackageExporter API 缺少充分且直接的验证: torch.package.PackageExporter.add_dependency torch.package.PackageExporter.all_paths torch.package.PackageExporter.close torch.package.PackageExporter.dependency_graph_string torch.package.PackageExporter.get_unique_id torch.package.PackageExporter.register_intern_hook 因此新增 test_package_exporter_additional_api.py 测试文件,用于验证上述 6 个 API 的正确性,并补充异常路径验证,覆盖显式依赖添加、依赖图路径查询、依赖图字符串输出、唯一 ID 生成、intern hook 注册/移除、PackageExporter 正常关闭及重复关闭异常等场景。 # 【修改方案】 一、API 功能说明 1. torch.package.PackageExporter.add_dependency 是 PyTorch torch.package.PackageExporter 中用于手动向包导出器依赖图添加模块依赖的 API,核心功能如下: 依赖图补充能力:接收指定模块名,并根据用户预先配置的 extern、intern、mock、deny 等规则,将该模块加入 PackageExporter 的依赖分析流程。 规则驱动处理:模块最终是被打包进 archive、作为外部依赖记录、替换为 mock 模块,还是被拒绝,取决于导出器中已有的依赖匹配规则。 递归依赖分析支持:当 dependencies=True 时,会进一步分析该模块源码中的 import 依赖,并将相关依赖继续纳入处理。 手动依赖声明:适用于测试或特殊打包场景中显式补充某个模块依赖,避免完全依赖 save_module、save_pickle 等接口的自动扫描。 纯 Python 打包辅助:该 API 主要操作模块依赖关系和导出规则,不涉及张量计算,也不要求运行在 NPU/GPU 设备上。 2. torch.package.PackageExporter.all_paths 是 PyTorch PackageExporter 中用于查询两个模块之间依赖路径的调试分析 API,核心功能如下: 依赖路径追踪:接收源模块 src 和目标模块 dst,返回从 src 到 dst 的所有依赖路径。 DOT 图格式输出:返回结果为 DOT 格式字符串,可用于 Graphviz 等工具可视化依赖子图。 依赖原因定位:常用于分析某个模块为什么会被 PackageExporter 作为依赖引入,帮助定位间接 import 链路。 子图级别查看:相比完整依赖图,该 API 只关注指定源模块到目标模块之间的路径,便于缩小调试范围。 静态调试属性:该 API 只读取和展示 PackageExporter 内部依赖图信息,不会执行实际模型计算或张量运算。 3. torch.package.PackageExporter.close 是 PyTorch PackageExporter 中用于结束打包并将 package 写入目标位置的收尾 API,核心功能如下: 包写出能力:将前面通过 save_module、save_pickle、save_text、save_binary、save_source_string 等接口收集到的代码、对象和资源正式写入文件系统或二进制 IO 对象。 导出流程终止:调用 close() 后,PackageExporter 进入关闭状态,后续再调用保存、依赖添加等导出相关接口将不再合法。 上下文管理器等价:通常推荐使用 with PackageExporter(...) as exporter 的形式自动触发关闭逻辑,避免忘记手动调用 close()。 规则完整性检查:在关闭阶段会完成打包收尾检查,例如未解析依赖、非法依赖或未匹配规则可能在关闭时触发异常。 资源释放作用:用于确保底层 zip/package 归档结构被完整写入并释放相关写入资源。 4. torch.package.PackageExporter.dependency_graph_string 是 PyTorch PackageExporter 中用于输出完整包依赖图的调试 API,核心功能如下: 完整依赖图查看:返回当前 PackageExporter 已记录的 package 依赖关系图。 字符串化输出:返回值为字符串形式的依赖图表示,可直接打印到控制台或写入日志文件。 打包调试支持:用于观察哪些模块被纳入依赖图、模块之间存在怎样的依赖关系。 与局部路径分析互补:all_paths(src, dst) 适合查看两个模块之间的路径,而 dependency_graph_string() 适合查看整体依赖结构。 无副作用查询:该 API 只读取依赖图状态,不会修改打包内容,也不涉及张量或设备相关操作。 5. torch.package.PackageExporter.get_unique_id 是 PyTorch PackageExporter 中用于生成包内唯一标识符的辅助 API,核心功能如下: 唯一 ID 生成:返回一个字符串 ID,并保证该 ID 在当前 package 导出过程中只会被分配一次。 避免命名冲突:常用于生成临时模块名、资源路径或中间文件名,防止与已有模块和资源发生冲突。 自定义打包支持:在自定义 __reduce_package__ 等高级打包逻辑中,可用该 API 为动态生成的资源分配唯一名称。 包内范围唯一:其唯一性主要保证在当前 PackageExporter 管理的 package 内成立,不用于全局分布式唯一标识。 轻量级工具属性:该 API 只生成字符串标识,不涉及依赖扫描、文件写入或张量运算。 6. torch.package.PackageExporter.register_intern_hook 是 PyTorch PackageExporter 中用于注册 intern 模块匹配回调函数的 API,核心功能如下: intern 回调注册:向导出器注册一个 hook,当某个模块匹配 intern() 规则并准备被打包进 package 时,该 hook 会被触发。 自定义处理能力:hook 函数可接收 exporter 和 module_name,从而在模块被 intern 时执行额外逻辑,例如记录日志、统计模块、补充资源或检查模块名。 多 hook 顺序执行:支持注册多个 intern hook,并按照注册顺序依次调用,便于组合多个自定义处理逻辑。 可移除句柄支持:注册后会返回 RemovableHandle,后续可通过 handle.remove() 移除该 hook。 打包流程扩展点:该 API 提供对 PackageExporter 内部模块处理流程的扩展能力,适合测试 hook 调用顺序、移除机制和模块匹配行为。 二、测试文件 test_package_exporter_additional_api.py 完整验证该 API 的原因 `` 该测试用例针对 torch.package.PackageExporter.add_dependency、torch.package.PackageExporter.all_paths、torch.package.PackageExporter.dependency_graph_string、torch.package.PackageExporter.get_unique_id、torch.package.PackageExporter.register_intern_hook 和 torch.package.PackageExporter.close 六个 API,从显式依赖处理、异常依赖处理、依赖图路径查询、依赖图字符串输出、唯一标识生成、Hook 注册与移除机制、包写入闭环、重复关闭异常等维度进行直接验证,具体体现在: 1. 对 add_dependency API 的验证 显式依赖添加验证 test_add_dependency:通过创建 PackageExporter,并直接调用 add_dependency("math") 手动加入 math 模块依赖,验证 API 能够将指定模块加入 PackageExporter 的依赖分析流程。测试通过 dependency_graph.nodes 校验 math 已被加入依赖图节点,说明 add_dependency 能够正确记录显式添加的依赖。随后关闭 exporter,并使用 PackageImporter 从内存 package 中重新加载 math 模块,验证导入结果与系统原生 math 模块一致,说明显式添加的依赖不仅在导出阶段被正确记录,也能在导入阶段保持正确解析。 不存在模块异常路径验证 test_add_dependency_nonexistent_module_raises:通过 add_dependency("nonexistent_module_for_package_exporter_test") 手动添加一个不存在的模块依赖,并在 exporter.close() 阶段断言抛出 PackagingError。该测试验证 add_dependency 对非法/不可解析模块依赖的处理符合预期:依赖可以先进入导出器依赖处理流程,但最终关闭打包时会进行完整性检查并暴露打包错误,避免生成包含无效依赖的 package。 2. 对 all_paths API 的验证 依赖路径查询验证 test_all_paths:手动向 dependency_graph 中添加 a -> b、b -> c、a -> d 三条边,然后调用 all_paths("a", "c") 查询从 a 到 c 的依赖路径。测试断言结果中包含 "a" -> "b" 和 "b" -> "c",说明 API 能够正确返回目标路径上的依赖边;同时断言结果中不包含 "a" -> "d",说明 API 不会错误返回与目标节点 c 无关的分支路径。该测试覆盖了依赖图路径提取的正确性和无关路径过滤能力。 3. 对 dependency_graph_string API 的验证 依赖图字符串输出验证 test_dependency_graph_string:通过向 dependency_graph 中添加 a -> b 依赖边,再调用 dependency_graph_string() 获取完整依赖图字符串。测试断言结果中包含 digraph G,验证其输出符合 DOT 图格式;同时断言结果中包含 "a" -> "b",验证依赖图中的实际边关系能够被正确序列化输出。该测试说明该 API 能够将 PackageExporter 内部依赖图转换为可读、可调试的字符串表示。 4. 对 get_unique_id API 的验证 唯一标识生成验证 test_get_unique_id:连续三次调用 get_unique_id(),并分别断言返回值为 "0"、"1"、"2"。该测试验证了 API 能够在同一个 PackageExporter 实例内生成单调递增且不重复的字符串 ID,说明其可用于包内临时资源、模块名或自定义打包逻辑中的唯一命名需求。同时,连续调用场景也验证了内部计数状态能够被正确维护。 5. 对 register_intern_hook API 的验证 Hook 注册与触发验证 test_register_intern_hook:定义 intern_hook 回调函数,并通过 register_intern_hook 注册到 PackageExporter 中。随后调用 save_source_string("foo", "VALUE = 1", dependencies=False) 保存源码模块,触发模块 intern 流程。测试最终断言 interned_modules 等于 ["foo"],说明当模块被打包进 package 时,已注册的 intern hook 能够被正确调用,并且能够接收到正确的模块名参数。 Hook 移除机制验证 test_register_intern_hook_remove:注册 intern hook 后,立即调用返回句柄的 remove() 方法移除该 hook,再保存 foo 模块。测试断言 interned_modules 为空列表,说明被移除的 hook 不会继续触发。该测试进一步覆盖了 register_intern_hook 返回句柄的有效性,以及 hook 注册后可撤销的边界行为,避免回调残留或误触发。 6. 对 close API 的验证 包写入闭环验证 test_close:先通过 save_source_string("foo", "VALUE = 3", dependencies=False) 向 package 中写入源码模块,再调用 close() 完成导出收尾。随后重置 BytesIO 指针,并使用 PackageImporter 从内存 package 中重新导入 foo 模块,断言 foo.VALUE 等于 3。该测试验证了 close() 能够正确完成 package 的最终写入、归档结构封装和资源收尾,使导出的内容能够被后续 PackageImporter 正常加载。 重复关闭异常路径验证 test_close_twice_raises:创建 PackageExporter 后先执行一次 close() 完成关闭,再次调用 close() 时断言抛出异常。该测试验证 close() 关闭状态管理符合预期,PackageExporter 在完成导出后不会允许重复关闭或重复写入,从而避免资源状态异常、归档结构重复收尾等问题。 7. 测试完整性与隔离性保障 该测试文件使用 BytesIO 作为内存 package 载体,避免依赖外部文件系统,保证测试过程轻量、独立、可重复。每个测试用例均重新创建 PackageExporter 实例,分别构造独立的依赖图、hook 列表或 package 内容,避免不同 API 测试之间发生状态污染。部分测试使用 with PackageExporter(buffer) as exporter 的上下文管理方式,覆盖自动 close 场景;test_close 显式调用 close(),覆盖手动关闭场景;test_add_dependency_nonexistent_module_raises 和 test_close_twice_raises 分别覆盖依赖解析失败与重复关闭两个异常分支。由于这些 API 主要属于 torch.package 的 Python 层打包、依赖管理和导出流程,不涉及实际张量计算或 NPU 算子执行,因此无需额外构造 NPU 张量,也无需额外进行张量迁移适配。 三、NPU 适配 torch.package.PackageExporter.add_dependency、torch.package.PackageExporter.all_paths、torch.package.PackageExporter.close、torch.package.PackageExporter.dependency_graph_string、torch.package.PackageExporter.get_unique_id 和 torch.package.PackageExporter.register_intern_hook 均属于 torch.package 模块中的 Python 层打包、依赖管理、调试分析和 Hook 扩展类 API,不涉及张量计算、算子执行或设备调度逻辑,因此无需针对昇腾 NPU 做额外适配,具体分析如下: 1. 纯 Python 层打包流程 API,无硬件相关计算逻辑 - add_dependency API:主要用于手动向 PackageExporter 的依赖图中添加模块依赖,并根据 extern、intern、mock、deny 等规则处理模块归属,核心逻辑是 Python 模块依赖分析和打包规则匹配,不涉及 Tensor 运算或 NPU 算子调用;新增的不存在模块用例验证的是打包阶段异常检查,也不涉及设备逻辑。 - all_paths API:仅用于查询 PackageExporter 内部依赖图中两个模块之间的依赖路径,返回 DOT 格式字符串,属于依赖图调试分析能力,不涉及任何设备侧计算。 - dependency_graph_string API:用于将当前依赖图字符串化输出,便于观察模块之间的依赖关系,本质是读取并序列化 Python 层依赖图结构,与 NPU 硬件无关。 - get_unique_id API:仅用于在当前 PackageExporter 实例内生成唯一字符串 ID,属于轻量级命名辅助工具,不涉及依赖扫描、文件执行、张量创建或设备迁移。 - register_intern_hook API:用于注册模块 intern 过程中的 Python 回调函数,核心逻辑是 hook 注册、触发和移除,不依赖任何底层硬件能力。 - close API:用于完成 package 的最终写入和资源收尾,将已保存的源码、对象或资源写入目标 package 中,属于文件/字节流归档写出逻辑;新增的重复 close 用例验证的是 Python 对象关闭状态管理,也不涉及 NPU 计算图或算子执行。 2. 无底层算子 / 内核 / NPU Runtime 依赖 - 这 6 个 API 的核心功能集中在 PackageExporter 的模块依赖管理、依赖图维护、包内容写入、唯一 ID 生成以及 hook 机制上,均运行在 Python 解释器和 PyTorch 打包框架层面。 - 测试过程中使用的 BytesIO、PackageExporter、PackageImporter、dependency_graph 等对象均属于 Python 层对象或 PyTorch package 管理结构,不会调用 torch_npu 的算子、NPU kernel、NPU 内存管理接口或设备通信接口。 - 测试用例即使在 torch-npu 迁移环境下执行,也仅验证 torch.package 的打包、导入和依赖图逻辑,不触发任何 NPU 设备侧行为。 3. 核心逻辑与硬件设备解耦 - 依赖管理解耦:add_dependency、all_paths 和 dependency_graph_string 操作的是模块依赖图,依赖关系来自 Python import 规则和 PackageExporter 的打包策略,与 CPU/GPU/NPU 设备类型无关。 - 打包写入解耦:close API 负责将 package 内容写入内存 buffer 或文件系统,其正确性取决于归档结构和资源写入完整性,而不是底层计算设备。 - Hook 机制解耦:register_intern_hook 触发的是 Python 回调函数,测试关注 hook 是否被正确注册、调用和移除,不涉及任何硬件执行路径。 - 唯一标识生成解耦:get_unique_id 仅维护 PackageExporter 内部计数状态并返回字符串 ID,不包含设备判断、张量分配或算子派发逻辑。 4. 无需构造 NPU 张量的原因 - 本测试文件覆盖的 6 个 API 均不以 Tensor 作为输入,也不返回 Tensor 结果。 - 测试逻辑主要包括模块依赖声明、异常依赖关闭检查、依赖图边关系查询、字符串输出校验、hook 调用验证、package 写入与重新导入验证、重复关闭异常验证。 - 因此,按照“涉及张量的用例尽可能运行在 NPU 上”的原则,本测试文件不存在需要迁移到 NPU 的张量对象,也无需额外添加 .npu() 或 .to(device_type) 操作。 - 若强行构造 NPU 张量,反而会引入与被测 API 无关的设备依赖,降低测试的针对性和最小化原则。 综上,torch.package.PackageExporter.add_dependency、all_paths、close、dependency_graph_string、get_unique_id 和 register_intern_hook 均属于硬件无关的 Python 层 package 导出与依赖管理 API。其功能正确性主要取决于 PackageExporter 内部依赖图、打包规则、hook 机制、异常状态管理和归档写入逻辑,不依赖昇腾 NPU 的算子、内存或运行时能力。因此在 torch-npu 适配中无需修改 API 本身,也无需构造 NPU 张量,可直接复用 PyTorch 社区逻辑进行验证。 # 【资料变更】 > 不涉及 已检查文档,https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 下面各个版本均已记录这些 API 支持情况,因此不需要提交 PR 修改资料。 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配 UT 测试用例看护,并补充测试自验证截图 在 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 版本上执行该用例,均通过,日志如下: ` root@c18d5a0da657:/workspace/pytorch29/test/package# python -m unittest -v test_package_exporter_additional_api test_add_dependency (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_add_dependency) ... ok test_add_dependency_nonexistent_module_raises (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_add_dependency_nonexistent_module_raises) ... ok test_all_paths (test_package_exporter_additional_api.TestPackageExporterAdditionalAPI.test_all_paths) ... ok test_close (test_package_exporter_additional_api.TestPackageExporter See merge request: Ascend/pytorch!37842 | 2 个月前 | |
[test]profiler fix uttest Co-authored-by: hehongzhe<935062458@qq.com> # message auto-generated for no-merge-commit merge: !38680 merge te10 into v2.10.0 [test]profiler fix uttest Created-by: hhz0 Commit-by: hehongzhe 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/2347 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 之前删除函数没有删除对应ut测试用例,补充删除 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38680 | 2 个月前 | |
AI assist developer for python dt master Co-authored-by: aksksks<mengzichao@h-partners.com> # message auto-generated for no-merge-commit merge: !26538 merge master into master AI assist developer for python dt master Created-by: aksksks Commit-by: aksksks Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!26538 | 9 个月前 | |
test update ut Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com> # message auto-generated for no-merge-commit merge: !37773 merge 2.10ut1 into v2.10.0 test update ut Created-by: huangyunlong2022 Commit-by: huangyunlong2022 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) test_deprecation test_cycle_lr_cycle_momentum_fail_with_momentumless_optimizer test_hook_registration 同步社区用例更新 test_float_status A2/A3需要开启饱和模式 test_select_at_first_axis_to_single_element_tensor_copy 转连续优化是aclop路径,alcnn路径添加aclnnAdds通过用例 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37773 | 2 个月前 | |
test: enable test_constant_pad_nd_with_negative Co-authored-by: 21xiu<caixiuxiu1@huawei.com> # message auto-generated for no-merge-commit merge: !38533 merge cherry-pick-mr-38532-1781505597756-auto into v2.10.0 test: enable test_constant_pad_nd_with_negative Created-by: xiu_21 Commit-by: 21xiu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 放开测试用例test_constant_pad_nd_with_negative # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38533 | 2 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
refactor: replace hard-coded dispatch with Registry + Template Method for NPU Graph op handlers Co-authored-by: suhaibo<suhaibo1@huawei.com> # message auto-generated for no-merge-commit merge: !31273 merge v2.10.0 into v2.10.0 refactor: replace hard-coded dispatch with Registry + Template Method for NPU Graph op handlers Created-by: suhaibo Commit-by: suhaibo 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能力等内容) 1. 拓展aclgraph update功能,支持自定义算子注册update能力,避免侵入式修改pta源码 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” <span style="color:#0066cc;">新增register_npu_graph_handler和NpuGraphOpHandler对外接口</span> # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!31273 | 5 个月前 | |
| 1 年前 | ||
fix: lintrunner --all-files --take NEWLINE -a Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !35873 merge v2.10.0_lintrunner into v2.10.0 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/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 执行: lintrunner --all-files --take NEWLINE -a 修复换行符,不影响代码逻辑。 2. 屏蔽两个分布式用例,已提issue,给对应接口人跟踪。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35873 | 3 个月前 | |
| 2 年前 | ||
test update ut Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com> # message auto-generated for no-merge-commit merge: !32257 merge 2.10ut into v2.10.0 test update ut Created-by: huangyunlong2022 Commit-by: huangyunlong2022 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 更新ut # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32257 | 5 个月前 | |
| 2 年前 | ||
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
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!26731 | 9 个月前 | |
[sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 Co-authored-by: yuanqi1104<yuanqi13@huawei.com> # message auto-generated for no-merge-commit merge: !38702 merge sync-pr38602-yuanqi_add_torch_npu_testcases-to-v2.10.0 into v2.10.0 [sync] PR-38602: 新增torch_npu.npu.are_compatible_impl_enabled和torch_npu.npu.get_amp_supported_dtype接口的测试用例。 Created-by: ascend-ds-bot Commit-by: yuanqi1104 Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/38602 ### 2. Original pull request related issue(s): https://gitcode.com/Ascend/pytorch/issues/2402 ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[3481c54f](https://gitcode.com/Ascend/pytorch/commit/3481c54f3cd388fe46ae989e0dcaaf21a8844c0c)|2026-06-16 20:01:41 +0800 CST|Add test case fot torch_npu<br>| See merge request: Ascend/pytorch!38702 | 2 个月前 | |
| 1 年前 | ||
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33715 merge v2.10.0 into v2.10.0 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!33715 | 4 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33715 merge v2.10.0 into v2.10.0 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!33715 | 4 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33715 merge v2.10.0 into v2.10.0 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!33715 | 4 个月前 | |
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: !36746 merge v2.10.0 into v2.10.0 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.so 的 aclrtGetSocName() 接口获取 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!36746 | 3 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33715 merge v2.10.0 into v2.10.0 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!33715 | 4 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
test update ut Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com> # message auto-generated for no-merge-commit merge: !37773 merge 2.10ut1 into v2.10.0 test update ut Created-by: huangyunlong2022 Commit-by: huangyunlong2022 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) test_deprecation test_cycle_lr_cycle_momentum_fail_with_momentumless_optimizer test_hook_registration 同步社区用例更新 test_float_status A2/A3需要开启饱和模式 test_select_at_first_axis_to_single_element_tensor_copy 转连续优化是aclop路径,alcnn路径添加aclnnAdds通过用例 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37773 | 2 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test(fx): add CustomBuiltin test cases for v2.10.0. Co-authored-by: jingkai-2026<jingkai@isrc.iscas.ac.cn> # message auto-generated for no-merge-commit merge: !35582 merge custom-test-v2.10.0 into v2.10.0 test(fx): add CustomBuiltin test cases for v2.10.0. Created-by: jingkai-2026 Commit-by: jingkai-2026 Merged-by: ascend-robot Description: https://gitcode.com/Ascend/pytorch/issues/1630 ## 上游社区(PyTorch 官方)测试覆盖情况分析 ### torch.fx.Graph / torch.fx.Graph.__init__ - **社区测试文件**: test/test_fx.py(PyTorch 官方仓库) - **测试覆盖情况**:✅ 充分覆盖 - **证据**:共有 18 个 Graph 相关测试函数 - **结论**:上游社区测试已全面覆盖,torch-npu 无需额外适配 - **验证**: 统计 test_fx.py 中 Graph 相关的测试函数数量 grep -c "def test.*[Gg]raph" /workspace/pytorch/test/test_fx.py 查看具体是哪些测试函数 grep "def test.*[Gg]raph" /workspace/pytorch/test/test_fx.py | head -20 统计 GraphModule 相关的测试 grep -c "def test.*GraphModule" /workspace/pytorch/test/test_fx.py 统计 Graph 类被使用的次数(证明被广泛测试) grep -c "torch.fx.Graph" /workspace/pytorch/test/test_fx.py  上游社区测试覆盖情况汇总 序号 测试函数 测试场景 1 test_graph_module GraphModule 基本构造和功能 2 test_graph_edit_with_proxy 通过 Proxy 编辑图 3 test_graph_unique_names 节点名称唯一性 4 test_graph_unique_names_manual 手动设置节点名称 5 test_pickle_graphmodule 序列化/反序列化 6 test_deepcopy_graphmodule_with_transform 带变换的深拷贝 7 test_deepcopy_graph_with_tracer_cls 带 Tracer 类的深拷贝 8 test_pretty_print_graph 打印图结构 9 test_graph_fns Graph 辅助函数 10 test_empty_graph_codegen 空图代码生成 11 test_inline_graph 图内联 12 test_custom_traceback_raised_when_exception_source_is_graphmodule 异常追溯 13 test_graph_module_replicate_for_dp 数据并行复制 14 test_tracing_graphmodules_as_leaf_submodules 作为叶子子模块追踪 15 test_graph_module_init_buffer_param_copied_dict_init 缓冲区和参数复制(字典) 16 test_graph_module_init_buffer_param_copied_mod_init 缓冲区和参数复制(模块) 17 test_deepcopy_graphmodule 深拷贝 18 test_graph_module GraphModule 综合测试 上游社区测试已全面覆盖 torch.fx.Graph 的核心功能 __init__ 通过 30 次 torch.fx.Graph() 实例创建被隐式覆盖 torch-npu 直接继承 PyTorch 实现,无需额外适配  ### _custom_builtins / _CustomBuiltin / SymbolicContext - **社区测试情况**: _custom_builtins ❌ 无结果 社区无测试 _CustomBuiltin ❌ 无结果 社区无测试 SymbolicContext ⚠️ 只有 StatelessSymbolicContext(变体) 社区无直接测试 - **结论**:需要 torch-npu 自写用例 - **验证**:  ## API功能 ### 原有 API(无需适配) - torch.fx.Graph:PyTorch FX图模式的核心数据结构,用于构建和表示计算图 - torch.fx.Graph.__init__:Graph类的构造函数,初始化空的图结构 ### 本次新增测试的 API - **torch.fx.graph._custom_builtins.items()**:返回PyTorch FX图模块中内置函数的字典视图。这些内置函数在图追踪时被识别为特殊操作,不会被递归展开。返回值为 dict_items 类型,包含7个预注册的内置函数,每个键为函数名(str),值为 _CustomBuiltin 实例。 - **torch.fx.graph._CustomBuiltin**:表示FX图中的一个内置函数占位符。它是一个类,实例化后代表一个被注册为内置操作的函数对象,在图追踪过程中作为原子操作处理。模块归属为 torch.fx.graph。 - **torch.fx.experimental.symbolic_shapes.SymbolicContext**:符号形状推导的上下文类。可无参实例化,配合 StatelessSymbolicContext 等变体在导出或追踪过程中传递和管理符号形状信息。模块归属为 torch.fx.experimental.symbolic_shapes。 ## 用例完备性说明 PyTorch社区在test_fx.py、test_export.py等文件中已有丰富的Graph/GraphModule测试用例,覆盖图的创建、节点操作、符号追踪等核心功能。这些用例均为框架层逻辑测试,不涉及TEST_CUDA/TEST_PRIVATEUSE1等硬件强相关分支。 **社区无针对以下3个API的直接测试用例:** - _custom_builtins / _CustomBuiltin:社区用例未覆盖 - SymbolicContext:社区用例使用的是 StatelessSymbolicContext 等变体,未直接测试 SymbolicContext 本身 **本次自写用例(test_fx_custom_builtins.py)覆盖5个测试方法:** | 测试方法 | 验证内容 | |---------|---------| | test_custom_builtins_items | 验证 _custom_builtins.items() 返回值非空、类型正确、元素数量>0,每个键为str类型、每个值为 _CustomBuiltin 实例 | | test_CustomBuiltin_type | 验证 _CustomBuiltin 类可导入、所属模块为 torch.fx.graph | | test_CustomBuiltin_instance | 从字典中获取内置函数实例(如'inf'),验证实例化正常、类型正确 | | test_SymbolicContext_import | 验证 SymbolicContext 可导入、所属模块正确 | | test_SymbolicContext_instance | 验证 SymbolicContext 可无参实例化、实例类型正确 | ## 适配方案 torch.fx为框架层图模式API,与底层设备算子完全解耦。在NPU环境下导入torch_npu后直接可用,无需任何代码修改。新增测试用例同样无需适配,可直接在NPU环境运行。 ## 运行结果 在NPU环境下测试通过: - torch.fx.Graph() 创建成功 - torch.fx.Graph.__init__() 正常工作 - **新增5个测试用例全部通过**  ## 文档检查 已检查 docs/api/torch_npu_apis.md: - torch.fx.Graph 和 torch.fx.Graph.__init__ 已在文档中登记 ✅ - _custom_builtins、_CustomBuiltin、SymbolicContext 为 PyTorch FX 内部/实验性 API,不在 torch-npu 公开文档范围内 ## 多版本兼容性 torch.fx核心架构自PyTorch 1.8引入后保持稳定,推断在2.7.1 ~ 2.12.0及master分支行为一致,均无需适配。 See merge request: Ascend/pytorch!35582 | 3 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Co-authored-by: xiemingda1002<xiemingda1002@163.com> # message auto-generated for no-merge-commit merge: !34080 merge add-test-hub-help-api-v2.10.0 into v2.10.0 test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Created-by: xiemingda1002 Commit-by: xiemingda1002 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1703**</font>\ - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 一、API 功能说明 torch.hub.help 和 torch.hub._get_torch_home 是 PyTorch hub 模块中用于文档查询和路径管理的辅助 API,功能说明如下: 1. torch.hub.help(github, model, force_reload=False, skip_validation=False, trust_repo=None) - 文档获取核心能力:接收 GitHub 仓库地址和入口点名称,返回该入口点的文档字符串(docstring),无需实际加载模型或执行代码。 - 远程仓库解析核心能力:支持 "owner/repo[:branch]" 格式的仓库地址,自动解析并获取 hubconf.py 中定义的入口点函数的文档。 - 安全机制支持:通过 skip_validation 参数可跳过 GitHub API 验证(避免 rate limit),trust_repo 参数控制仓库信任策略(False/True/check/None)。 - 无状态调用:多次调用 help 不会产生副作用,不修改缓存状态,不影响后续 load 等操作,不下载仓库代码。 - 返回值灵活性:返回字符串类型文档或 None(若入口点函数未定义 docstring),支持用户预览模型使用说明。 - 典型用途:在加载模型前查看入口点的参数说明、使用示例、依赖信息等。 2. torch.hub._get_torch_home() - 路径解析核心能力:根据环境变量 TORCH_HOME 或默认路径 ~/.cache/torch 确定 torch home 目录。 - 环境变量优先级机制:优先读取 TORCH_HOME 环境变量,若未设置则依次检查 XDG_CACHE_HOME/torch、~/.cache/torch。 - 内部 API 特性:作为 get_dir() 的底层实现,不直接暴露给用户,但可通过 hub 模块访问(用于测试或调试)。 - 路径标准化处理:返回的路径经过 os.path.expanduser 处理,支持 ~ 符号展开,确保路径可用性。 - 返回值:字符串类型路径,非空且为绝对路径。 上述 API 均为纯 Python 层实现,不涉及张量计算,仅负责文档查询和路径解析。 二、测试文件 test/test_hub_api.py 完整验证该 API 的原因 本测试文件针对 PyTorch 社区原生 test/test_hub.py 覆盖不足的 torch.hub.help / _get_torch_home API 进行补充验证,确保昇腾 NPU 环境下功能完整可用: 1. torch.hub.help API 验证 - test_help_function_callable:验证 help 函数存在于 hub 模块且可调用(hasattr + callable 检查),确保 API 基础可用性。 - test_help_returns_none_without_docstring:严格验证 help 函数在入口点无 docstring 时返回 None。使用 mock 本地仓库进行测试,无需外部网络依赖。 - test_help_returns_docstring_with_content:严格验证 help 函数在入口点有 docstring 时返回有效的字符串内容。使用 mock 本地仓库进行测试,检查返回值类型为 str、非空、且包含预期关键字 "EfficientNet"。 2. torch.hub._get_torch_home API 验证 - test_get_torch_home_returns_path:验证 _get_torch_home 返回有效的路径字符串(assertIsInstance(str) + assertGreater(len, 0)),确保路径非空且类型正确。 - test_get_torch_home_with_env_variable:验证 TORCH_HOME 环境变量能正确影响返回路径,使用 tempfile.TemporaryDirectory 创建临时目录作为测试路径,覆盖自定义路径场景。测试后恢复原始环境变量状态(os.environ.pop 或 restore),避免污染其他测试。 3. 测试隔离性保障 - setUp 机制:TestHubHelp 类在 setUp 中创建 mock 本地仓库目录,写入 hubconf.py 文件,包含有/无 docstring 的两个入口点函数。 - tearDown 机制:每个测试后清理临时目录,确保测试用例间无状态污染。 - 独立性设计:两个测试类(TestHubHelp、TestHubGetTorchHome)独立,无共享状态。 - 零外部依赖:使用 unittest.mock.patch 模拟 _get_cache_or_reload,避免对 GitHub 外部仓库的依赖,测试更快、更可靠,适合 CI 环境。 测试完整性 所有用例覆盖 API 的基础功能验证、接口存在性检查、环境变量交互、测试隔离性保障,完整覆盖昇腾 NPU 适配所需的最小功能集合。 三、昇腾 NPU 适配说明(解释为什么无需 NPU 适配) torch.hub.help 和 torch.hub._get_torch_home 均具备硬件无关性、纯 Python 层实现、无底层算子依赖三大核心特征,决定了其无需针对昇腾 NPU 做适配,具体分析: 1. 纯 Python 层抽象,无硬件相关逻辑 - help API 硬件无关性:仅负责解析远程仓库的 hubconf.py 并提取文档字符串,是「文档查询」的纯 Python 抽象接口,不涉及任何硬件相关的计算、存储、通信逻辑。 - _get_torch_home API 硬件无关性:仅负责读取环境变量和构建路径字符串,依赖 os.path 模块进行路径处理,无任何硬件相关的逻辑或依赖。 - 设备无关设计:两个 API 的核心逻辑与 CPU/GPU/NPU 等硬件架构完全解耦,在任意硬件环境下行为一致。 2. 无底层算子 / 内核依赖 - 标准库依赖:两个 API 内部仅调用 Python 标准库(os 路径模块、tempfile 临时文件模块、urllib 网络模块)和 PyTorch 纯 Python 层的 hub 模块。 - 无硬件扩展依赖:未依赖 CUDA/NPU 等硬件相关的扩展库、内核函数或底层驱动。 - help 的远程解析机制:基于 GitHub URL 和 Python import 机制,与硬件架构无关。 - _get_torch_home 的路径处理机制:基于 os.path.expanduser 和 os.getenv,纯文件系统操作。 3. 核心逻辑与硬件解耦 - 文档获取解耦:help API 返回的文档字符串是纯文本信息,与硬件架构无关 —— 无论是 CPU/GPU/NPU 环境,文档查询逻辑完全一致。 - 路径解析解耦:_get_torch_home 返回的路径是通用文件系统路径,不包含任何硬件相关字段(如设备 ID、内存地址),昇腾 NPU 环境下可直接复用。 - 无张量操作:两个 API 均不涉及张量的创建、计算或迁移,测试用例中无 tensor 相关代码,无需 NPU 设备支持。 结论 torch.hub.help 和 torch.hub._get_torch_home 均是「硬件无关的纯 Python 层抽象」,核心逻辑不耦合任何特定硬件。测试用例无需导入 torch_npu,API 本身无需适配修改,可直接复用。 # 【资料变更】 刷新2.7.1版本下有多个版本资料。 1、torch.hub._get_torch_home API该API昇腾支持,但是在文档中并无描述,因此需要增加。 文档修改PR链接:https://gitcode.com/Ascend/pytorch/pull/34365 # 【接口变更】 不涉及 # 【功能验证】 测试文件路径:test/test_hub_api.py 本地验证结果:  所有测试用例执行通过。torch.hub.help 和 torch.hub._get_torch_home API 核心功能验证正常。 两个 API 均为纯 Python 层实现,不涉及张量操作,无需 NPU 设备适配。测试用例无需导入 torch_npu,API 本身可在任意硬件环境稳定运行。验证结果表明,torch.hub.help 和 torch.hub._get_torch_home 在昇腾 NPU 环境下功能正常可用,无需修改源码。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签:test(hub) - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34080 | 4 个月前 | |
| 2 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
fix(nn): fix test for jit api: torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32400 merge fixtest-jit-api-2.10.0 into v2.10.0 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!32400 | 5 个月前 | |
[feat] Add test cases for verifying torch.jit.ScriptModule hook API on NPU Co-authored-by: hmoji<ha_m@foxmail.com> # message auto-generated for no-merge-commit merge: !34411 merge v2.10.0 into v2.10.0 [feat] Add test cases for verifying torch.jit.ScriptModule hook API on NPU Created-by: hxm_ Commit-by: hxm_;hmoji 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_module(RecursiveScriptModule 实例)作为 C++ 侧代理。编译过程只迁移参数/子模块/缓冲区的存储,不替换类上的方法,也不影响 hook 相关属性(torch.jit.ScriptModule ._backward_hooks、torch.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!34411 | 3 个月前 | |
| 2 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
| 2 年前 | ||
Add unit test for compile and cpu api in torch.jit.ScriptModule Co-authored-by: Sunhuan<1685880687@qq.com> # message auto-generated for no-merge-commit merge: !38168 merge fix-v2.10.0 into v2.10.0 Add unit test for compile and cpu api in torch.jit.ScriptModule Created-by: qq_43890555 Commit-by: Sunhuan Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2293**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 - torch.jit.ScriptModule 的 cpu() 方法继承自 nn.Module 实现,本次基于通用卷积网络模型完成脚本化转换,验证 ScriptModule 从 NPU 迁移至 CPU 设备的能力 - torch.compile 接口搭配 backend="npu" 对 ScriptModule 推理链路进行编译优化验证,模型由 torch.jit.script 生成 ## API功能介绍 **cpu()** 功能:将 ScriptModule 模型的所有参数、缓冲区迁移至 CPU 设备,就地修改模型。 **语法** python script_model.cpu() **特点** - 就地执行,不生成新模型实例; - 迁移后模型参数、缓冲区设备类型统一为 CPU; - 支持跨设备(NPU → CPU)迁移场景。 **使用场景** - 模型跨设备部署、多设备调度、CPU 侧推理验证、模型统一存储与分发 **torch.compile()** 功能:对模型计算图做编译优化,结合昇腾 NPU 后端完成算子融合、常量折叠、内存复用等优化,提升推理性能。 **语法** python opt_model = torch.compile(model, backend="npugraph_ex", fullgraph=True, dynamic=False) **特点** - 首次执行触发编译,后续推理复用优化后计算图; - 原生适配昇腾 NPU 硬件,充分利用硬件算力; - 兼容 TorchScript 模型,不破坏 ScriptModule 原有属性与能力。 **使用场景** - 昇腾 NPU 环境下固定输入形态的在线推理、离线批量数据处理、高吞吐服务化部署,适用于 CNN 等计算图规整的模型。 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38168 | 2 个月前 | |
| 1 年前 | ||
| 2 年前 | ||
fix: unskip test_reductions test case in test_multiprocessing_api.py Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !37694 merge sync-pr36359-v2.10.0 into v2.10.0 fix: unskip test_reductions test case in test_multiprocessing_api.py Created-by: wuyouqi1 Commit-by: wuyouqi1 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. test/test_multiprocessing_api.py 中 test_reductions 用例在验证 NPU tensor 时,调用了 reduce_tensor + rebuild_npu_tensor 进行同进程内重建比较。 2. rebuild_npu_tensor 内部通过 aclIpcOpenMemHandle/aclIpcOpenEventHandle 导入 IPC handle,该机制设计用于跨进程共享 NPU 内存,同进程内 import 会触发驱动错误(drvRetCode=17),导致用例失败。 3. 将 NPU tensor 重建验证改为跨进程方式:主进程 reduce_tensor 导出 handle,通过 Queue 传给子进程,子进程 rebuild_npu_tensor 重建后返回数据,主进程比较。子进程返回 .tolist() 避免 resource_sharer 连接断开问题。 4. 删除原有 @unittest.skip 装饰器,改为 @unittest.skipUnless(get_cann_version(module="DRIVER") >= "25.3.rc1", ...) 条件跳过。NPU IPC reduce/rebuild 依赖 driver >= 25.3.rc1,低版本 driver 自动跳过该用例。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 - 测试场景:test_multiprocessing_api.py 中 test_reductions 用例 - 测试方法:pytest 单元测试 - 验证结果:PASS # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37694 | 2 个月前 | |
| 2 年前 | ||
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33715 merge v2.10.0 into v2.10.0 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!33715 | 4 个月前 | |
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32059 merge fixtest-nn-api-2.10.0 into v2.10.0 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 test210 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!32059 | 5 个月前 | |
| 2 年前 | ||
[fix][2.10.0]add getMemoryFraction attribute for torch._C Co-authored-by: weixin_47897441<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !30795 merge v2.10.0 into v2.10.0 [fix][2.10.0]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  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!30795 | 5 个月前 | |
[v2.10.0][bugfix]CI error:acl header missing fix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !36837 merge apply-acl-fix-v2.10.0 into v2.10.0 [v2.10.0][bugfix]CI error:acl header missing fix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2137 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 门禁ut不是基于门禁编包代码执行,而是拉取新代码,头文件在编包执行过程中才会从acl_src复制到原本头文件路径acl下。导致门禁ut调用build_stub.sh报错头文件找不到。 修复方案: 1、在门禁执行入口文件ci/access_control_test.py增加头文件复制策略,从当前安装torch_npu路径下复制头文件到工作区代码三方库下acl下 2、修改三个ut中的编译依赖相对路径确保能找到对应头文件 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 门禁通过,ut通过  本地验证ut通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ✓] 代码注释完备,正确记录错误日志 - [ ✕] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36837 | 3 个月前 | |
| 1 年前 | ||
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 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: !37095 merge searchsorted_testcase_v2.10.0 into v2.10.0 test(reductions): note NPU/XLA skip searchsorted non-contiguous UserWarning check. Created-by: Margaret_wangrui Commit-by: Margaret_wangrui Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/1910 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) values_3d_permute = values_3d.permute(2, 1, 0).to(torch.int32) boundaries_permute = values_3d.permute(2, 1, 0).to(torch.float64) values_3d_permute和boundaries_permute在torch_npu中是连续的,不应该在用例中去捕获非连续告警信息 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 .png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37095 | 2 个月前 | |
[v2.10.0][bugfix]CI error:acl header missing fix Co-authored-by: Dring<17737727613@163.com> # message auto-generated for no-merge-commit merge: !36837 merge apply-acl-fix-v2.10.0 into v2.10.0 [v2.10.0][bugfix]CI error:acl header missing fix Created-by: Dring Commit-by: Dring Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2137 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 门禁ut不是基于门禁编包代码执行,而是拉取新代码,头文件在编包执行过程中才会从acl_src复制到原本头文件路径acl下。导致门禁ut调用build_stub.sh报错头文件找不到。 修复方案: 1、在门禁执行入口文件ci/access_control_test.py增加头文件复制策略,从当前安装torch_npu路径下复制头文件到工作区代码三方库下acl下 2、修改三个ut中的编译依赖相对路径确保能找到对应头文件 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 门禁通过,ut通过  本地验证ut通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ✓] 代码注释完备,正确记录错误日志 - [ ✕] 代码实现进行了返回值、空指针等校验 - [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36837 | 3 个月前 | |
fix: support quantized NPU flip dispatch Co-authored-by: hz893<zhanghao491@huawei.com> # message auto-generated for no-merge-commit merge: !36070 merge fix_quantized_flip_v2.10.0_20260519 into v2.10.0 fix: support quantized NPU flip dispatch Created-by: hz893 Commit-by: hz893 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 https://gitcode.com/Ascend/pytorch/issues/2207 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 在 QuantizedPrivateUse1 的 codegen 注册中补充 aten::flip,使量化 NPU tensor 能命中 torch_npu 的 quantized helper。 2. 新增 quantized_flip helper:per-tensor 量化场景对 int_repr() 调用普通 NPU aten::flip,复用现有 op_plugin::flip -> aclnnFlip 数据翻转路径,再用原 scale/zero_point 重建 affine quantized tensor。 3. 对齐 CPU/CUDA 行为:sub-byte 量化 dtype 保持不支持报错;per-channel 量化保持 Setting strides is possible only on uniformly quantized tensor 报错。 4. 新增 per-channel quantized flip 报错回归测试。 # 【资料变更】 不涉及。 # 【接口变更】 不涉及。 # 【功能验证】 1. v2.7.1 环境执行 bash ci/build.sh --python=3.11,编译成功并生成 wheel。 2. v2.7.1 环境执行 python -m pytest test_shape_ops.py -v -k test_flip_npu_float32,结果:1 passed。 3. v2.7.1 环境执行 python -m pytest --import-mode=importlib test/test_shape_ops.py -v -k "test_flip_per_channel_quantized_error or test_flip_npu_float32",结果:2 passed。 4. 验证普通 float NPU flip backward 与 CPU 在 dims=(0,)、(1,)、(0, 1)、() 下 forward/grad 均一致;验证 quantized flip 的 autograd 状态和错误行为与 CPU 一致。 5. v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 源分支均执行 git diff --check,无异常。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36070 | 2 个月前 | |
[Fix] Fix static check errors detected by SPACES Co-authored-by: huangjingwei<huangjingwei4@huawei.com> # message auto-generated for no-merge-commit merge: !36365 merge v2.10.0_lintrunner into v2.10.0 [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!36365 | 3 个月前 | |
| 2 年前 | ||
run_once_fix Co-authored-by: 1479518308<cuiduo1@huawei.com> # message auto-generated for no-merge-commit merge: !38396 merge v2.10.0 into v2.10.0 run_once_fix Created-by: cuiduo Commit-by: 1479518308 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 > run_once在inductor目录下有多处不同的定义,但实现功能是一致的,进行整理 # 【资料变更】 >不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 已通过UT # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38396 | 2 个月前 | |
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: !32139 merge cherry-pick-mr-32138-1774073465134-auto into v2.10.0 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!32139 | 4 个月前 | |
| 2 年前 | ||
[feat]TensorTo support preserve_format consistent with GPU Co-authored-by: chenshuai<chenshuai81@huawei.com> # message auto-generated for no-merge-commit merge: !35351 merge cherry-pick-mr-34696-1778548794156-auto into v2.10.0 [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模式 # 【功能验证】   # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35351 | 3 个月前 | |
Update test_torch.py Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> # message auto-generated for no-merge-commit merge: !27371 merge master-dev2 into master Update test_torch.py Created-by: yuhaiyan Commit-by: yuhaiyan Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!27371 | 8 个月前 | |
fix lazy_init and api export Co-authored-by: bellatan<tanmei2@huawei.com> # message auto-generated for no-merge-commit merge: !36705 merge v2.10.0_torch_npu_init_refactor into v2.10.0 fix lazy_init and api export Created-by: bellatan Commit-by: bellatan Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 **问题1**:test/test_npu.py的test_lazy_init用例失败  **根因**: 重构前 torch_npu/__init__.py 中,先做 accelerator 冲突检查,即_check_device_conflict 接口调用,再 import torch_npu.npu、torch_npu.utils 等内部模块,不会触发 NPU device count 提前枚举 重构后 torch_npu/__init__.py 中,先调用了_check_device_conflict 接口,再 import torch_npu.npu、torch_npu.utils 等内部模块,_check_device_conflict 接口调用顺序被延后,调用 _get_accelerator() 时 NPU backend 状态已经被拉起,触发底层设备探测,导致 _npu_getDeviceCount() 提前枚举真实设备数 8。 **解决** : 在 torch_npu/__init__.py 中,保持和重构前一样的调用顺序,即_check_device_conflict 接口调用提前到所有的 import 之前。 **问题2**:缺失子模块导出的 API: python torch_npu.asd.checksum torch_npu.utils.syncbatchnorm **现象**:  **根因分析**: 旧版 torch_npu/__init__.py 是一个大顶层初始化脚本,里面直接写了很多顶层 import: python from torch_npu.asd.checksum import _matmul_checksum as matmul_checksum import torch_npu.utils.syncbatchnorm 这些 import 会产生父包属性挂载副作用: python torch_npu.asd.checksum torch_npu.utils.syncbatchnorm 重构后初始化逻辑被拆分到 _init/core/module_loader.py、_exports.py 等模块中,部分旧版顶层 import 副作用没有恢复,因此这些子模块路径在 import torch_npu 后不可见。 **解决方案**: 在 _load_registration_modules() 中补充子模块父包属性: python import torch_npu.asd.checksum # noqa: F401 import torch_npu.utils.syncbatchnorm # noqa: F401 **问题3**:顶层属性缺失 API python torch_npu.ParallelStore torch_npu._ShardedGradScaler **现象**:  **根因分析**: 旧版顶层有: python from torch_npu._C._distributed_c10d import ParallelStore from torch_npu.npu.amp.sharded_grad_scaler import _ShardedGradScaler 因此旧版支持: python torch_npu.ParallelStore torch_npu._ShardedGradScaler 重构后 _distributed_c10d 子模块初始化逻辑被集中到 C 扩展子模块初始化流程中,但没有把 ParallelStore 恢复到 torch_npu 顶层,导致旧版顶层访问路径缺失。_ShardedGradScaler 只在 distributed patch 逻辑中局部 import: python def _apply_sharded_grad_scaler_patch(torch): from torch.distributed.fsdp import sharded_grad_scaler from torch_npu.npu.amp.sharded_grad_scaler import _ShardedGradScaler sharded_grad_scaler.ShardedGradScaler = _ShardedGradScaler 这能保证 patch 行为一致,但没有恢复旧版顶层属性torch_npu._ShardedGradScaler **解决方案**: 在 _exports.py 中补 legacy 顶层属性: python def _export_distributed_apis(globals_dict): """ Export legacy distributed-related top-level APIs. Rule: - torch_npu._C._distributed_c10d.ParallelStore -> torch_npu.ParallelStore - torch_npu.npu.amp.sharded_grad_scaler._ShardedGradScaler -> torch_npu._ShardedGradScaler Note: These APIs are kept for compatibility and should not be added to __all__. """ from torch_npu._C._distributed_c10d import ParallelStore from torch_npu.npu.amp.sharded_grad_scaler import _ShardedGradScaler globals_dict["ParallelStore"] = ParallelStore globals_dict["_ShardedGradScaler"] = _ShardedGradScaler # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 test/test_torch_npu_init.py 新增对应的测试项本地验证pass,CI pass  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36705 | 2 个月前 | |
| 1 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
[fix] add _npu_dtype_cast_backward sharding strategy Co-authored-by: zqwenn<zhangqiongwen@huawei.com> # message auto-generated for no-merge-commit merge: merge master_npu_dtype_cast_backsard_register_sharding into master [fix] add _npu_dtype_cast_backward sharding strategy Created-by: zqwenn Commit-by: zqwenn Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!25308 | 10 个月前 | |
test(utils): add checkpoint API coverage tests on NPU Co-authored-by: Jinfan Liu<1300083451@qq.com> # message auto-generated for no-merge-commit merge: !37238 merge test-utils-checkpoint-weak-npu-2.10.0 into v2.10.0 test(utils): add checkpoint API coverage tests on NPU Created-by: JfanLiu Commit-by: Jinfan Liu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2026**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> [x] issue/工单 # 【修改方案】 一、API功能说明 本 PR 补充 torch.utils.checkpoint 弱覆盖 API 的直接验证用例: - torch.utils.checkpoint.SelectiveCheckpointContext:selective checkpoint policy function 接收的上下文对象,用于区分 forward/recompute 阶段;2.12.0 起还可携带 op_output。 - torch.utils.checkpoint.detach_variable:reentrant checkpoint 内部用于 detach 输入 Tensor 并保持 requires_grad 状态的辅助函数。 二、测试用例完备性说明 PyTorch 官方社区 test/test_autograd.py 已通过 checkpoint 调用链间接覆盖上述 API,但缺少直接、聚焦的 API 行为断言。本 PR 按 1.3 类补充 torch-npu 自定义测试文件 test/test_utils_checkpoint_api.py。 1. torch.utils.checkpoint.detach_variable 直接覆盖: - test_detach_variable_keeps_device_and_requires_grad 直接调用 torch.utils.checkpoint.detach_variable((x, y, marker))。 - x 和 y 均为 NPU Tensor,覆盖返回 Tensor 保持 NPU device、requires_grad 与原输入一致、grad_fn 被断开并成为 leaf Tensor,非 Tensor 对象透传。 - test_detach_variable_rejects_non_tuple_input 覆盖非 tuple 输入的 RuntimeError 分支。 2. torch.utils.checkpoint.SelectiveCheckpointContext 直接覆盖: - test_selective_checkpoint_context_direct_attributes 直接实例化 torch.utils.checkpoint.SelectiveCheckpointContext,断言对象类型和 is_recompute 属性;对支持 op_output 的版本,额外断言 op_output 指向 NPU Tensor 输出。 - test_selective_checkpoint_context_passed_to_policy_fn 通过 create_selective_checkpoint_contexts + checkpoint(..., use_reentrant=False, context_fn=...) 捕获 policy_fn 收到的 ctx,断言 forward/recompute 两阶段均收到 SelectiveCheckpointContext,并验证上下文来自 NPU Tensor 的 selective checkpoint 运行路径。 上述新增用例把原来的调用链弱覆盖补充为直接 API 行为覆盖;其中涉及 Tensor 的路径均使用 torch.accelerator.current_accelerator() 获取 NPU 设备并在 NPU Tensor 上执行。 三、NPU适配方案 1. API 源码无需修改:torch.utils.checkpoint.SelectiveCheckpointContext 与 torch.utils.checkpoint.detach_variable 均复用 PyTorch Python 层实现,不新增 NPU kernel,不改变接口语义。 2. 测试新增路径:新增 test/test_utils_checkpoint_api.py,文件聚焦 checkpoint API 直接行为,可后续扩展同模块 API。 3. 分支提交范围:新增测试文件提交到 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 以及 master。 四、变更文件 - test/test_utils_checkpoint_api.py # 【资料变更】 > 已检查资料支持情况,结论如下: > > checkpoint: > - 公开 API,在文档中记录:torch.utils.checkpoint.CheckpointPolicy、torch.utils.checkpoint.SelectiveCheckpointContext、torch.utils.checkpoint.create_selective_checkpoint_contexts、torch.utils.checkpoint.set_checkpoint_debug_enabled。对应资料 PR:https://gitcode.com/Ascend/pytorch/merge_requests/36231 > - 内部函数,不在文档中记录:torch.utils.checkpoint.detach_variable。 # 【接口变更】 > 不涉及。API 源码无修改,不新增、删除或变更对外接口。 # 【功能验证】 > 已在 2.10.0 对应 torch-npu 环境执行新增用例,结果如下;master 使用 2.12.0 验证环境执行。 ## 验证环境 - 操作系统:Ubuntu / Linux aarch64 - 昇腾硬件:910B2 - CANN 软件版本:8.3.RC1 - 验证环境: - 2.7.1:torch 2.7.1+cpu / torch-npu 2.7.1.post3 - 2.9.0:torch 2.9.0+cpu / torch-npu 2.9.0.post1 - 2.10.0:torch 2.10.0+cpu / torch-npu 2.10.0rc3 - 2.11.0:torch 2.11.0+cpu / torch-npu 2.11.0rc1 - 2.12.0 / master 验证:torch 2.12.0+cpu / torch-npu 2.12.0.rc1 ## 运行命令与结果 bash python test/test_utils_checkpoint_api.py Ran 4 tests in 1.568s OK # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37238 | 2 个月前 | |
test(utils): add data worker API coverage tests on NPU Co-authored-by: Jinfan Liu<1300083451@qq.com> # message auto-generated for no-merge-commit merge: !37244 merge test-utils-data-weak-npu-2.10.0 into v2.10.0 test(utils): add data worker API coverage tests on NPU Created-by: JfanLiu Commit-by: Jinfan Liu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/2027**</font> > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> [x] issue/工单 # 【修改方案】 一、API功能说明 本 PR 补充 torch.utils.data worker/control 弱覆盖 API 的直接验证用例: - torch.utils.data.dataloader._MultiProcessingDataLoaderIter - torch.utils.data.dataloader._InfiniteConstantSampler - torch.utils.data._utils.worker.ManagerWatchdog - torch.utils.data._utils.worker._IterableDatasetStopIteration - torch.utils.data._utils.worker._ResumeIteration - torch.utils.data._utils.signal_handling._set_worker_signal_handlers - torch.utils.data._utils.signal_handling._remove_worker_pids 上述 API 属于 DataLoader 多进程 iterator、IterableDataset 采样控制、worker 存活检查、worker 控制消息以及 worker 信号/pid 管理逻辑。 二、测试用例完备性说明 PyTorch 官方社区 test/test_dataloader.py 已通过 DataLoader 多进程用例覆盖上述 API 的调用链,但缺少对部分内部对象和控制消息的直接行为断言。本 PR 按 1.3 类补充 torch-npu 自定义测试文件 test/test_utils_data_api.py。 1. torch.utils.data.dataloader._MultiProcessingDataLoaderIter 直接覆盖: - test_multiprocessing_dataloader_iter_type_and_shutdown 构造 num_workers=1 的 DataLoader,显式断言 iter(loader) 是 _MultiProcessingDataLoaderIter,并验证 next(iterator) 返回预期 batch,最后调用 _shutdown_workers() 覆盖正常关闭路径。 2. torch.utils.data.dataloader._InfiniteConstantSampler 直接覆盖: - test_infinite_constant_sampler_yields_none 直接实例化 _InfiniteConstantSampler,并断言连续 yield None,覆盖 IterableDataset 无限索引采样器的核心行为。 3. torch.utils.data._utils.worker.ManagerWatchdog 直接覆盖: - test_manager_watchdog_reports_parent_alive 直接构造 ManagerWatchdog,并断言正常父进程场景 is_alive() 为 True。 4. torch.utils.data._utils.worker._IterableDatasetStopIteration / torch.utils.data._utils.worker._ResumeIteration 直接覆盖: - test_worker_control_message_fields 直接构造两个 dataclass 控制消息,断言 worker_id、seed 字段和 repr 内容,覆盖 worker 耗尽通知与 persistent worker 恢复消息的对象行为。 5. torch.utils.data._utils.signal_handling._set_worker_signal_handlers / torch.utils.data._utils.signal_handling._remove_worker_pids 直接覆盖: - test_worker_signal_handlers_and_pid_cleanup 直接调用 _set_worker_signal_handlers,并通过 _set_worker_pids 注册当前 pid 后调用 _remove_worker_pids 清理,覆盖 C 侧 worker signal handler 初始化和 worker pid registry 清理入口的正常路径。 本文件验证的是 DataLoader worker/control 面 API。为避免把验证目标混入 NPU IPC 和 worker 子进程设备 Tensor 传输,本新增用例中的多进程 DataLoader 使用 Python 字符串 payload,不在 worker 子进程返回 NPU Tensor;原 DataLoader NPU Tensor payload 路径已由 test_upstream 中单进程 DataLoader/collate 用例覆盖。 三、NPU适配方案 1. API 源码无需修改:上述 API 是 torch.utils.data 的 Python/C++ 控制面入口,不新增 NPU kernel,不改变接口语义。 2. 测试新增路径:新增 test/test_utils_data_api.py,文件聚焦 worker/control API 直接行为,可后续扩展同模块 API。 3. 分支提交范围:新增测试文件提交到 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 以及 master。 四、变更文件 - test/test_utils_data_api.py # 【资料变更】 > 已检查资料支持情况,结论如下: > > dataloader: > - 公开 API,在文档中记录:torch.utils.data.DataLoader、torch.utils.data._utils.collate.collate。对应资料 PR:https://gitcode.com/Ascend/pytorch/merge_requests/36233 > - 内部函数/类,不在文档中记录:DataLoader iterator、worker、signal handling、persistent worker 相关内部对象。 # 【接口变更】 > 不涉及。API 源码无修改,不新增、删除或变更对外接口。 # 【功能验证】 > 已在 2.10.0 对应 torch-npu 环境执行新增用例,结果如下;master 使用 2.12.0 验证环境执行。 ## 验证环境 - 操作系统:Ubuntu / Linux aarch64 - 昇腾硬件:910B2 - CANN 软件版本:8.3.RC1 - 验证环境: - 2.7.1:torch 2.7.1+cpu / torch-npu 2.7.1.post3 - 2.9.0:torch 2.9.0+cpu / torch-npu 2.9.0.post1 - 2.10.0:torch 2.10.0+cpu / torch-npu 2.10.0rc3 - 2.11.0:torch 2.11.0+cpu / torch-npu 2.11.0rc1 - 2.12.0 / master 验证:torch 2.12.0+cpu / torch-npu 2.12.0.rc1 ## 运行命令与结果 bash python test/test_utils_data_api.py Ran 5 tests in 1.284s OK # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37244 | 2 个月前 | |
fix(npu): register QuantizedPrivateUse1 view/ravel/flatten for test_view_ops. Co-authored-by: Margaret_wangrui<wangrui178@huawei.com> # message auto-generated for no-merge-commit merge: !36700 merge v2.10.0_view_0524 into v2.10.0 fix(npu): register QuantizedPrivateUse1 view/ravel/flatten for test_view_ops. Created-by: Margaret_wangrui Commit-by: Margaret_wangrui Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2082 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 **问题简述:** 将 PyTorch 上游 test/test_view_ops.py 切换到 torch_npu 执行时,test_ravel_npu、test_flatten_npu 在处理 torch._empty_affine_quantized(..., quint8, device=npu) 量化张量时报错: text NotImplementedError: Could not run 'aten::view' with arguments from the 'Quantizednpu' backend 浮点 NPU 张量(PrivateUse1)可正常 view;量化 NPU 张量(QuantizedPrivateUse1)缺少对应 kernel 注册。 --- # 【修改方案】 本 PR 为 **QuantizedPrivateUse1** 补齐 shape / copy 相关 dispatch,并与 op-plugin stride_copy 修复配合,使量化 NPU 张量上的 view / ravel / flatten 语义与上游用例一致。 **组件交互关系:** text test_ravel_npu / test_flatten_npu(量化 quint8 on NPU) │ ▼ TensorShape.cpp(torch_npu) QuantizedPrivateUse1 注册:view / ravel / contiguous / clone / empty* / _copy_from │ ├─► MetaData 不匹配时 clone 物化(NPUStorageDesc 与 view shape 对齐) │ ▼ TensorFactories.cpp(torch_npu) NPUNativeFunctions::clone(quant):int_repr + npu_stride_copy_out │ ▼ AsStridedKernelNpu.cpp(op-plugin,子模块 071a046) 小 nbytes int_repr stride_copy 稳定走 AsStrided **具体实现:** 1. **torch_npu/csrc/aten/common/TensorShape.cpp(+312 行)** - 通过 TORCH_LIBRARY_IMPL(aten, QuantizedPrivateUse1, m) 注册:view、as_strided、ravel、contiguous、clone、empty_like、empty.memory_format、empty_strided、_copy_from。 - 实现 npu_quantized_view_symint:基于 infer_size + computeStride,经 alias_with_sizes_and_strides_npu 构造 QTensorImpl view;stride 不兼容且可展平为 rank-1 时走 clone + view。 - 实现 npu_quantized_ravel:aten::contiguous → view(-1),避免 composite reshape 在 NPU 量化张量上短路。 - 实现 npu_quantized_contiguous:除 is_contiguous() 外检查行主 stride,必要时 clone 物化。 - npu_quantized_view_materialize_if_storage_desc_mismatch:当 MetaDataAreMatch(q)==false 时对 view 结果 clone(Contiguous)。 - NPUNativeFunctions::as_strided 增加量化分支,构造 QTensorImpl view。 2. **torch_npu/csrc/aten/common/TensorFactories.cpp(+202 行)** - 增强 NPUNativeFunctions::clone 量化路径:empty_like + SetDesc + int_repr stride_copy。 - MetaDataAreMatch 异常(如 transpose、view 后 storage desc 不一致)时,CPU int_repr staging + H2D 物化。 - stride_copy 后 int_repr slab 传播与 canonical 缓冲对齐(npu_quantized_clone_write_int_repr_payload)。 3. **test/test_view_ops.py** - 量化 NPU 张量不再强制 flat._base is src(允许 NPUStorageDesc 不匹配时的物化拷贝路径)。 - 修正 is_quantized / is_npu 为属性访问(非可调用方法)。 **变更规模:** text test/test_view_ops.py | 5 +- torch_npu/csrc/aten/common/TensorFactories.cpp | 202 +++ torch_npu/csrc/aten/common/TensorShape.cpp | 312 +++ --- # 【资料变更】 不涉及。 --- # 【接口变更】 不涉及跨代码仓或客户面可见的公开 API 变更。 **内部说明(ATen dispatch 层,非 Python 公开接口):** | 算子 | Dispatch Key | 变更类型 | |------|--------------|----------| | view / as_strided / ravel / contiguous / clone | QuantizedPrivateUse1 | 新增 kernel 注册 | | empty_like / empty.memory_format / empty_strided / _copy_from | QuantizedPrivateUse1 | 新增 kernel 注册 | 用户可见行为变化:NPU 上 quint8 等量化张量可正常执行 view、ravel、flatten(此前为 NotImplementedError)。 --- # 【功能验证】 **环境要求:** 已编译安装 torch_npu;NPU 设备可用。 **测试步骤:** bash python test/test_view_ops.py -v -k test_ravel_npu python test/test_view_ops.py -v -k test_flatten_npu **覆盖场景:** | 场景 | 验证点 | |------|--------| | 连续量化张量 5×5×5×5 | ravel() / flatten(0,-1) 与 view(-1) 一致 | | 空 shape 0×2×3、3×0×2 | numel=0 时 shape 与 view 链正确 | | 转置 + ravel(nc=True) | 非连续路径 contiguous().view(-1) 与 ravel() 一致 | | 多组 flatten 维度 | (0,2)、(1,2)、(-2,-1) 等与 view(-1) 展开顺序一致 | | 浮点 NPU 回归 | 同一用例文件中浮点张量路径不受影响 | **UT 看护:** - [x] 适配 test/test_view_ops.py(量化 NPU _base 断言放宽、is_quantized/is_npu 属性修正) **自验证:** 请在合入前补充 NPU 环境执行上述命令的通过截图或 CI 流水线链接。   --- # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!36700 | 3 个月前 | |
Update onnx_test_common.py Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> # message auto-generated for no-merge-commit merge: merge master-dev1 into master Update onnx_test_common.py Created-by: yuhaiyan Commit-by: yuhaiyan Merged-by: ascend-robot Description: <!-- Thanks for sending a pull request! --> **What type of PR is this?** > Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line: > > /kind bug > /kind task > /kind feature **What does this PR do / why do we need it**: **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: Fixes #<issue number>, or Fixes (paste link of issue). --> Fixes # **Special notes for your reviewers**: See merge request: Ascend/pytorch!25485 | 10 个月前 | |
| 2 年前 | ||
【bugfix】npugraph_ex.scope.limit_core_num增加默认参数stream Co-authored-by: wangkai<wangkai579@huawei.com> # message auto-generated for no-merge-commit merge: !38935 merge v2.10.0 into v2.10.0 【bugfix】npugraph_ex.scope.limit_core_num增加默认参数stream Created-by: mihudan Commit-by: wangkai Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/2445 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 torchair仓合入PR:【refeat】limit_core_num控核支持单算子和可选参数streamhttps://gitcode.com/Ascend/torchair/pull/3181 资料修改: 【doc】limit_core_num支持可选参数streamhttps://gitcode.com/Ascend/torchair/pull/3227 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” ex资料修改已合入 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” npugraph_ex接口增加默认参数,ex资料修改已合入,组内已检视 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 已增加传入stream参数场景  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!38935 | 2 个月前 | |
| 2 年前 | ||
| 2 年前 |
简介
test目录为PTA相关的测试用例。
安装依赖
pip3 install -r requirements.txt
补全脚本
该操作需要联网
cd test
bash get_synchronized_files.sh
通过以上操作,会自动补齐testfiles_synchronized.txt和testfolder_synchronized.txt中的文件或文件夹。
跳过失败用例
export DISABLED_TESTS_FILE=./unsupported_test_cases/.pytorch-disabled-tests.json
如果不是在test目录下运行测试用例,需要传入.pytorch-disabled-tests.json的绝对路径。
执行方式
执行单个测试脚本
运行以test开头的文件。以test_autocast.py为例:
方式一:
python test_autocast.py
方式二:
python run_test.py -i test_autocast
说明:部分以test开头的脚本不是直接运行的脚本,比如jit中的测试脚本是通过test_jit.py执行的。
执行具体的用例
通过-k参数传入具体的用例名。以test_autocast.py为例:
方式一:
python test_autocast.py -v -k test_autocast_nn_fp32
方式二:
python run_test.py -v -i test_autocast -- -k test_autocast_nn_fp32
执行全量UT的方式
# 进入到test目录的上一级
cd ../
运行非分布式全量用例:
python ci/access_control_test.py --all
运行分布式全量用例:
python ci/access_control_test.py --distributed
FAQ
-
报错:"dictionary changed size during interation".
如果python 环境是3.8.1版本,报错在unitest/case.py中,可考虑是sys.modules被修改导致的。第三方包可能会有对sys.modules的修改,比如beartype。 此问题为python 3.8.1版本/3.9.0版本的已知bug,可按照 https://github.com/python/cpython/issues/73806 中修改方式修改,将
for v in sys.modules.values()改为for v in list(sys.modules.values())可用于复现问题的用例:
python test_jit.py -v -k test_annotated_empty_dict -
test_public_bindings.py 用例的功能
该用例是为了校验接口的公开规范性,如果该用例报错,请确认报错的接口是否要公开,并按照报错的提示进行修改。