| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
attention/ffn的aicpu算子提供torch_npu._afd的调用方式 Co-authored-by: panweicheng<panweicheng@huawei.com> # message auto-generated for no-merge-commit merge: !28845 merge master into master attention/ffn的aicpu算子提供torch_npu._afd的调用方式 Created-by: pwc10490 Commit-by: panweicheng 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!28845 | 7 个月前 | |
[fix]import_all_patch Co-authored-by: cuiduo<cuiduo1@huawei.com> # message auto-generated for no-merge-commit merge: !35445 merge master into master [fix]import_all_patch Created-by: cuiduo Commit-by: cuiduo Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 删除部分MLIR与triton,dvm等重复的patch > 将inductort的init阶段修改至_TorchCompileInductorWrapper的init阶段,避免部分patch无法加载的问题,并对3条分支下不通的patch做区分 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 已通过UT用例 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35445 | 3 个月前 | |
HOST内存统计API对齐社区 Co-authored-by: luanchaowei<luanchaowei3@huawei.com> # message auto-generated for no-merge-commit merge: !29057 merge master into master HOST内存统计API对齐社区 Created-by: luanchaowei Commit-by: luanchaowei 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**: 1.torch_npu.npu. empty_pin_memory_cache()更名为torch_npu.npu.host_empty_cache() 2.torch_npu.npu.pin_memory_stats()更名为torch_npu.npu.host_memory_stats() 3.删除torch_npu.npu.pin_memory_allocated()和torch_npu.npu.pin_memory_reserved() 4.补齐torch_npu.npu.host_memory_stats()其他指标 5.新增 torch_npu.npu.host_memory_stats_as_nested_dict() torch_npu.npu.reset_accumulated_host_memory_stats() torch_npu.npu. reset_peak_host_memory_stats() **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!29057 | 7 个月前 | |
| 1 年前 | ||
| 2 年前 | ||
[Feature] transfer_to_npu adapt cuda_default_generators Co-authored-by: l30044004<louyujing@huawei.com> # message auto-generated for no-merge-commit merge: !34215 merge master into master [Feature] transfer_to_npu adapt cuda_default_generators Created-by: louyujing Commit-by: l30044004 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> https://gitcode.com/Ascend/pytorch/issues/1789 - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) torch.cuda.default_generators在NPU上需要迁移为torch_npu.npu.default_generators,且必须是设备init完成之后 使用torch_npu.npu._lazy_call的方式,在设备init完成之后,才使patch生效 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34215 | 3 个月前 | |
[Feature]rename head file and add cmake for libtorch_npu | 2 年前 | |
fix: fix from blob bug Co-authored-by: luochao60<luochao60@huawei.com> # message auto-generated for no-merge-commit merge: !30841 merge pta_fix_from_blob_20260212 into master fix: fix from blob bug Created-by: luochao60 Commit-by: luochao60 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > (如有)请关联需求文档/issue链接 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列 > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 修复 torch_npu/csrc/aten/common/from_blob.cpp 中 TensorMaker::computeStorageSize() 计算 storage size 时对 storage_offset_ 的处理 bug:原代码将 storage_offset_(按元素数计)直接累加到字节大小上,缺少 * itemsize,导致非 float32 类型或带偏移的 tensor 计算出的 storage size 偏小,from_blob 创建的 tensor storage 不足。修复后两处分支均改为 storage_size += storage_offset_.value() * itemsize;。 2. 修复 torch_npu/csrc/npu/Module.cpp 中 _weak_ref_tensor 实现:原实现通过 t.data_ptr() + t.sizes() + t.strides() 调用 from_blob 构造新 tensor,丢失了原 tensor 的 storage_offset 信息,且当原 tensor 是 view(带 offset 或非平凡 stride)时,新 tensor 的 storage 会被错误地按视图形状重新计算,与原 storage 不一致。修复方式:基于原 tensor 的完整 storage().mutable_data() 与 storage().nbytes() / element_size() 调用 from_blob 构造新 tensor(覆盖完整 storage),随后通过 set_sizes_and_strides 与 set_storage_offset 还原原 tensor 的视图信息,确保弱引用 tensor 的 storage、sizes、strides、offset 与原 tensor 完全一致。 3. 测试用例重构与新增: - 将原本散落在 test/cpp_extensions/extension.cpp 中的 from_blob 相关测试(check_from_blob/check_from_blob_strides/check_from_blob_delete)迁移到独立的 test/cpp_extensions/test_from_blob.cpp,按 at_npu::native::from_blob 接口能力分门别类组织。 - test/cpp_extensions/setup.py 注册新的扩展模块 torch_test_cpp_extension.npu_from_blob。 - test/cpp_extensions/test/test_cpp_extensions_aot.py 新增 TestFromBlob 测试类,覆盖 basic / deleter / strides / storage_offset / storage_offset_2d / storage_offset_dtype / storage_offset_contiguous / non_owning / clone 等场景;test_storage_sizes 增加 @SupportedDevices(['Ascend910B', 'Ascend910C']) 限制。 - test/npu/test_npu_format.py 新增 test_weak_ref_tensor_with_storage_offset 用例,构造带非平凡 stride 与 storage_offset 的 view,验证 _weak_ref_tensor 返回的 tensor 在 size、stride、storage_offset、storage().nbytes() 与数值上都与原 tensor 一致。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及" 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及" 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤 > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 1. C++ 扩展用例 test/cpp_extensions/test/test_cpp_extensions_aot.py::TestFromBlob:覆盖 at_npu::native::from_blob 在 basic、自定义 deleter、显式 strides、带 storage_offset、二维带 offset、不同 dtype、contiguous 标志、non-owning 语义、clone 后数据正确性等场景,验证修复后 storage 计算正确。 2. Python 用例 test/npu/test_npu_format.py::TestNPUFormat::test_weak_ref_tensor_with_storage_offset:构造 view_shape=[2,1,8,64]、view_strides=[1536,0,192,1]、view_offset=128 的 strided view,验证 _weak_ref_tensor 保持 size/stride/offset/storage 字节数一致且数值相等。 3. UT 已随 PR 一同提交,本地自验证通过。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!30841 | 4 个月前 | |
Skip failing torch official TestCase tests and disable unsupported test cases Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> Co-authored-by: yuhaiyan8<yuhaiyan8@h-partners.com> # message auto-generated for no-merge-commit merge: !32140 merge cherry-pick-mr-32139-1774073503832-auto into master Skip failing torch official TestCase tests and disable unsupported test cases Created-by: yuhaiyan Commit-by: yuhaiyan;yuhaiyan8 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 暂时跳过失败用例 2. 已提单跟进修复 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32140 | 4 个月前 | |
test(distributed/checkpoint): Add StorageWriter storage_meta API tests Co-authored-by: Jwerr<19166910919@163.com> # message auto-generated for no-merge-commit merge: !35323 merge test-StorageWriter-api-master into master test(distributed/checkpoint): Add StorageWriter storage_meta API tests Created-by: Jwerr Commit-by: Jwerr Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 关联 Issue:#1895 PyTorch 社区缺少对 torch.distributed.checkpoint.StorageWriter.storage_meta(实际类路径:torch.distributed.checkpoint.storage.StorageWriter.storage_meta)的直接 API 级测试,且未覆盖 NPU。本 PR 在 test/distributed/checkpoint/test_StorageWriter_api.py 补齐单卡 + 多卡 NPU 用例。 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 一、API功能说明 torch.distributed.checkpoint.StorageWriter.storage_meta是 torch.distributed.checkpoint.StorageWriter 基类下的可选钩子,父类默认返回 None,子类可按需覆写并返回 torch.distributed.checkpoint.metadata.StorageMeta。 torch.distributed.checkpoint.metadata.StorageMeta 用于描述 checkpoint 存储元信息,包含 checkpoint_id、save_id、load_id、modules 等字段。其中 checkpoint_id 表示存储位置 ID,save_id 表示本次保存 UUID,modules 默认为空列表。 在保存流程中,writer.storage_meta() 返回的 torch.distributed.checkpoint.metadata.StorageMeta 会通过 torch.distributed.checkpoint.save 透传给 torch.distributed.checkpoint.planner.SavePlanner.set_up_planner(state_dict, storage_meta=...),用于保存规划阶段感知 writer 侧元数据。 二、测试文件 test_StorageWriter_api.py 验证内容 1. 基类默认行为验证 定义 _MinimalStorageWriter 作为 torch.distributed.checkpoint.storage.StorageWriter 最小实现类,仅实现抽象方法,不覆写 torch.distributed.checkpoint.storage.StorageWriter.storage_meta,验证: * torch.distributed.checkpoint.storage.StorageWriter.storage_meta 可调用; * 父类默认 storage_meta() 返回 None。 2. FileSystemWriter 覆写行为验证 通过 torch.distributed.checkpoint.FileSystemWriter 验证真实 writer 的 storage_meta 返回值: * 返回值类型为 torch.distributed.checkpoint.metadata.StorageMeta; * checkpoint_id 与初始化 checkpoint 目录一致; * save_id 为合法 UUID; * modules 默认为空列表; * reset(checkpoint_id=new_dir) 后 checkpoint_id 更新,save_id 变化。 3. 保存流程验证 通过 torch.distributed.checkpoint.save 验证 storage_meta 在实际保存流程中的可用性: * 使用 NPU Tensor 执行 torch.distributed.checkpoint.save(..., no_dist=True) 后,writer.storage_meta() 仍返回合法 torch.distributed.checkpoint.metadata.StorageMeta; * 空 state_dict 保存后,writer.storage_meta() 仍保持有效; * save -> reset -> save 后 save_id 发生变化,验证 writer 生命周期更新有效。 4. SavePlanner 透传验证 定义 _CapturingPlanner 继承 torch.distributed.checkpoint.default_planner.DefaultSavePlanner,在 set_up_planner 中捕获 storage_meta,验证: * torch.distributed.checkpoint.save 会将 writer.storage_meta() 返回值透传给 torch.distributed.checkpoint.planner.SavePlanner.set_up_planner; * planner 捕获到的 checkpoint_id、save_id 与 writer.storage_meta() 保持一致。 5. 多 NPU 分布式验证 TestStorageMetaDistributed 继承 torch.testing._internal.distributed._shard.sharded_tensor.ShardedTensorTestBase,通过 torch_npu.testing.common_distributed.with_comms 初始化 HCCL 进程组,并通过 torch_npu.testing.common_distributed.skipIfUnsupportMultiNPU(2) 限定 2 卡 NPU 环境运行,验证: * rank 0 创建共享 checkpoint 目录,并通过 torch.distributed.broadcast_object_list 广播给其他 rank; * 分布式 torch.distributed.checkpoint.save 后,各 rank 的 checkpoint_id 通过 torch.distributed.all_gather_object 收集并保持一致; * 分布式 save -> reset -> save 后 save_id 发生变化; * 分布式保存后 writer.storage_meta() 仍返回 torch.distributed.checkpoint.metadata.StorageMeta,且 save_id 为合法 UUID。 三、NPU适配 torch.distributed.checkpoint.storage.StorageWriter.storage_meta 和 torch.distributed.checkpoint.metadata.StorageMeta 均属于 Python 层 checkpoint 元数据抽象,不涉及 NPU 算子、NPU kernel、设备内存管理或 HCCL 通信协议本身,因此 API 本身无需针对 NPU 修改。 本 PR 主要在测试用例层面验证 NPU 场景可用性: * 单卡用例继承 torch_npu.testing.testcase.TestCase,使用 torch.Tensor.npu() 构造 NPU Tensor 后进入 torch.distributed.checkpoint.save 流程; * 多卡用例通过 torch_npu.testing.common_distributed.with_comms 初始化 HCCL 进程组; * 通过 torch_npu.testing.common_distributed.skipIfUnsupportMultiNPU(2) 限定多 NPU 环境,避免设备数量不足时误失败; * 通过 torch.distributed.broadcast_object_list 保证各 rank 使用同一 checkpoint 目录; * 通过 torch.distributed.all_gather_object 验证 checkpoint_id 跨 rank 一致; * 测试结束后通过 destroy_pg 释放分布式进程组资源。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 在2.7.1 2.9.0 2.10.0 2.11.0 2.12.0以及master版本上执行该用例,均通过,本分支对应master日志如下: I0511 13:42:19.353000 130119 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:895] Started process 0 with pid 130263 I0511 13:42:19.355000 130119 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:895] Started process 1 with pid 130264 I0511 13:42:30.185000 130263 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:973] Process 0 skipping test test_storage_meta_checkpoint_id_consistency_across_ranks for following reason: Multi-NPU 2 condition not satisfied I0511 13:42:30.322000 130264 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:973] Process 1 skipping test test_storage_meta_checkpoint_id_consistency_across_ranks for following reason: Multi-NPU 2 condition not satisfied sI0511 13:42:33.087000 130119 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:895] Started process 0 with pid 130483 I0511 13:42:33.088000 130119 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:895] Started process 1 with pid 130484 I0511 13:42:43.797000 130484 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:973] Process 1 skipping test test_storage_meta_returned_in_distributed_save for following reason: Multi-NPU 2 condition not satisfied I0511 13:42:43.938000 130483 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:973] Process 0 skipping test test_storage_meta_returned_in_distributed_save for following reason: Multi-NPU 2 condition not satisfied sI0511 13:42:46.624000 130119 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:895] Started process 0 with pid 130675 I0511 13:42:46.625000 130119 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:895] Started process 1 with pid 130676 I0511 13:42:57.504000 130675 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:973] Process 0 skipping test test_storage_meta_save_id_changes_after_reset_distributed for following reason: Multi-NPU 2 condition not satisfied I0511 13:42:57.625000 130676 pytorch-2.12.0-env/lib/python3.10/site-packages/torch/testing/_internal/common_distributed.py:973] Process 1 skipping test test_storage_meta_save_id_changes_after_reset_distributed for following reason: Multi-NPU 2 condition not satisfied s.../root/work/pytorch-2.12.0-env/lib/python3.10/site-packages/torch/distributed/checkpoint/utils.py:485: UserWarning: torch.distributed is disabled, unavailable or uninitialized, assuming the intent is to save in a single process. return func(*args, **kwargs) .[W511 13:43:04.696461912 NPUCachingAllocator.cpp:199] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator()) ... ---------------------------------------------------------------------- Ran 10 tests in 45.440s OK (skipped=3) # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35323 | 3 个月前 | |
[sync] PR-34962: add testcase test_guard_control for dynamo tests. Co-authored-by: rmch<chenruimin2@huawei.com> # message auto-generated for no-merge-commit merge: !35011 merge sync-pr34962-v2.10.0-0507-to-master into master [sync] PR-34962: add testcase test_guard_control for dynamo tests. Created-by: ascend-ds-bot Commit-by: rmch Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/34962 ### 2. Original pull request related issue(s): ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[9c39a7df](https://gitcode.com/Ascend/pytorch/commit/9c39a7df118f645f7661a7eeda50f9e426e81c62)|2026-05-07 17:02:17 +0800 CST|add testcase test_guard_control for dynamo tests.<br><br>Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com><br>| See merge request: Ascend/pytorch!35011 | 3 个月前 | |
| 2 年前 | ||
| 1 年前 | ||
test(fx): add tests for graph codegen api Co-authored-by: nannan-2026<1794949109@qq.com> # message auto-generated for no-merge-commit merge: !34465 merge test-fx-codegen-api-master into master test(fx): add tests for graph codegen api Created-by: nannan-2026 Commit-by: nannan-2026 Merged-by: ascend-robot Description: # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 关联 issue:https://gitcode.com/Ascend/pytorch/issues/1637 # 【修改方案】 本 PR 新增 torch.fx 代码生成相关 API 的单元测试,覆盖如下 API: - torch.fx.Graph.python_code - torch.fx.graph.PythonCode - torch.fx.Graph.set_codegen 具体修改内容: 1. 新增 test/test_fx_codegen_api.py 测试文件。 2. 增加 test_graph_python_code_returns_python_code 用例,验证 Graph.python_code("self") 返回对象类型为 PythonCode,并校验返回对象包含 src、globals 字段。 3. 增加 test_graph_set_codegen 用例,验证 Graph.set_codegen 设置自定义 CodeGen 后,GraphModule 可重新编译并正常执行。 4. 该组 API 属于 torch.fx Python 层代码生成接口,不涉及新增 NPU 算子实现。 # 【资料变更】 不涉及。 本 PR 仅新增测试用例,不修改资料文档。如后续确认 torch.fx.graph.PythonCode 在 native_apis 文档中缺失,将单独提交 docs PR 补充。 # 【接口变更】 不涉及。 本 PR 不修改客户可见接口,不修改 API 行为,仅新增测试用例验证现有 API 兼容性。 # 【功能验证】 测试场景: 1. 验证 torch.fx.Graph.python_code 可正常生成 PythonCode。 2. 验证 torch.fx.graph.PythonCode 对象包含 src 和 globals 字段。 3. 验证 torch.fx.Graph.set_codegen 设置自定义 CodeGen 后,GraphModule 可重新编译并正常执行。 测试命令: TORCH_DEVICE_BACKEND_AUTOLOAD=0 python test/test_fx_codegen_api.py -v 测试结果: test_graph_python_code_returns_python_code (__main__.TestFXCodegenAPI.test_graph_python_code_returns_python_code) ... ok test_graph_set_codegen (__main__.TestFXCodegenAPI.test_graph_set_codegen) ... ok Ran 2 tests in 0.168s OK 说明: 该 API 为 torch.fx Python 层代码生成接口,不涉及 NPU 算子计算。本次测试主要验证 API 功能行为与 PyTorch 原生保持一致。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34465 | 3 个月前 | |
| 2 年前 | ||
add test for nn.Module.npu() Co-authored-by: zf_zhang<sjzz0306@outlook.com> # message auto-generated for no-merge-commit merge: !35161 merge test-nn-module-npu-master into master add test for nn.Module.npu() Created-by: zf_zhang Commit-by: zf_zhang Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">https://gitcode.com/Ascend/pytorch/issues/1888?ref=&did=3951326#tid-3951326</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> pytorch社区的test_nn.py中没有torch.nn.Module.npu的测试用例文件,故修改test/nn/test_nn_api.py这个测试用例文件,用于验证这个api的正确性 - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 用例设计原则 本次验证结合官方用例复用与自定义用例补充的方式,遵循 “最小化、核心化、针对性” 原则,核心思路为: 补充缺失用例:针对torch.nn.Module.npu这个缺失用例,我们设计了精简且详细的测试用例,覆盖了其核心功能 聚焦核心功能:我们验证了这个 API 的基础操作以及功能,确保结果反映 API 本身适配状态; 轻量化设计:单个测试方法仅验证一个核心功能点,逻辑清晰、执行高效,便于问题定位。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 在master 版本上执行该用例,测试通过,日志如下: root@aa02efd9993a:/home/test# python /home/test/pytorch-v271/test/nn/test_nn_api.py -v TestNNModuleAPIs.test_npu test_npu (__main__.TestNNModuleAPIs.test_npu) Checks that moving a module (with both parameters and buffers) to NPU via to("npu") or .npu() correctly places all tensors on the NPU device. ... ok ---------------------------------------------------------------------- Ran 1 test in 2.078s OK # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35161 | 3 个月前 | |
[sync] PR-34238: [feat] support PYTORCH_NPU_ALLOC_CONF: per_process_memory_fraction Co-authored-by: ffmh<fengminghao2@huawei.com> # message auto-generated for no-merge-commit merge: !35472 merge sync-pr34238-v2.11.0_device_alloc_conf_ppmf-to-master into master [sync] PR-34238: [feat] support PYTORCH_NPU_ALLOC_CONF: per_process_memory_fraction Created-by: ascend-ds-bot Commit-by: ffmh Merged-by: ascend-robot Description: ### 1. Origin pull request: https://gitcode.com/Ascend/pytorch/merge_requests/34238 ### 2. Original pull request related issue(s): https://gitcode.com/Ascend/pytorch/issues/1796 https://gitcode.com/Ascend/pytorch/issues/1837 ### 3. Original pull request related commit(s): | Sha | Datetime | Message | |---|---|---| |[2192500c](https://gitcode.com/Ascend/pytorch/commit/2192500c7c6cea10d297beab3943881d7e50333d)|2026-05-09 18:25:18 +0800 CST|fix test case<br>| |[12dd3694](https://gitcode.com/Ascend/pytorch/commit/12dd36948537a5e5457be1d9d5313c37e8914363)|2026-05-09 18:25:17 +0800 CST|refactor allowed_memory_maximum according to cuda caching allocator<br>| |[92c06b95](https://gitcode.com/Ascend/pytorch/commit/92c06b95e74b7e4109d7251f24486895df7e094c)|2026-05-09 18:25:17 +0800 CST|support PYTORCH_NPU_ALLOC_CONF: per_process_memory_fraction<br>| See merge request: Ascend/pytorch!35472 | 3 个月前 | |
Skip failing torch official TestCase tests and disable unsupported test cases Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> Co-authored-by: yuhaiyan8<yuhaiyan8@h-partners.com> # message auto-generated for no-merge-commit merge: !32140 merge cherry-pick-mr-32139-1774073503832-auto into master Skip failing torch official TestCase tests and disable unsupported test cases Created-by: yuhaiyan Commit-by: yuhaiyan;yuhaiyan8 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 暂时跳过失败用例 2. 已提单跟进修复 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32140 | 4 个月前 | |
Skip failing torch official TestCase tests and disable unsupported test cases Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> Co-authored-by: yuhaiyan8<yuhaiyan8@h-partners.com> # message auto-generated for no-merge-commit merge: !32140 merge cherry-pick-mr-32139-1774073503832-auto into master Skip failing torch official TestCase tests and disable unsupported test cases Created-by: yuhaiyan Commit-by: yuhaiyan;yuhaiyan8 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 暂时跳过失败用例 2. 已提单跟进修复 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32140 | 4 个月前 | |
[feat]profiler move task_time soc_pmu Co-authored-by: hehongzhe<935062458@qq.com> # message auto-generated for no-merge-commit merge: !34918 merge movem into master [feat]profiler move task_time soc_pmu 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] 需求 - [ ] 问题单 - [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1814 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1、新增移动task_time_*.csv,文件名称为task_time.csv 2、新增移动soc_pmu_*.csv,文件名称为soc_pmu.csv # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 打开l2_cahce=True进行数据采集,完成后查看ASCEND_PROFILER_OUTPUT  预期文件正常生成 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34918 | 3 个月前 | |
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 个月前 | |
Skip failing torch official TestCase tests and disable unsupported test cases Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> Co-authored-by: yuhaiyan8<yuhaiyan8@h-partners.com> # message auto-generated for no-merge-commit merge: !32140 merge cherry-pick-mr-32139-1774073503832-auto into master Skip failing torch official TestCase tests and disable unsupported test cases Created-by: yuhaiyan Commit-by: yuhaiyan;yuhaiyan8 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 暂时跳过失败用例 2. 已提单跟进修复 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32140 | 4 个月前 | |
[test] compat(test): adapt test cases for torch 2.10/2.11 cross-version compatibility Co-authored-by: chz34<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !34505 merge compat/master-test into master [test] compat(test): adapt test cases for torch 2.10/2.11 cross-version compatibility Created-by: c_34 Commit-by: chz34 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 基于多版本分支归一的方案,对应完成测试用例的修改 [#1688](https://gitcode.com/Ascend/pytorch/issues/1688) # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) compat(test): adapt test cases for torch 2.10/2.11 and Python 3.10/3.11+ compatibility Fix import typo MultiProcContinousTest -> MultiProcContinuousTest in pipelining tests and remove the unused TEST_MULTIGPU import from the CUDA module. Add the legacy flat cutedsl_grouped_gemm path back to test_public_bindings private_allowlist so it is exempted on torch 2.10/2.11 where the package restructure hasn't happened. Introduce per-version disabled-tests files (.pytorch-disabled-tests-2.10.json / -2.11.json) and update get_failed_ut_from_log.py to auto-select the right file via torch_npu._compat.version.CURRENT_VERSION. Add --torch parameter documentation to README, CONTRIBUTING, and ci/docker/README. Normalize Enum class signatures in test_compatibility.py to strip the boundary=None parameter added by Python 3.11+ via EnumMeta.__call__, ensuring schema comparisons remain consistent across Python 3.10 and 3.11+. # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” Add --torch description in README.md, CCONTRIBUTE.md, ci/docker/README.md # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34505 | 4 个月前 | |
【feat】NPUAffinityController support multiple rangs of affinity cpu core Co-authored-by: zhaoyu<nanzhaogang@qq.com> # message auto-generated for no-merge-commit merge: !34407 merge Affinity into master 【feat】NPUAffinityController support multiple rangs of affinity cpu core Created-by: zhaoyu65 Commit-by: zhaoyu Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 [#1816](https://gitcode.com/Ascend/pytorch/issues/1816) - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 1、修改内容总体 本次 commit 的核心目的是让 **NPUAffinityController 支持绑定多个不连续的 CPU 核范围**。同时修改了lintrunner工具扫描出来的代码规范问题。 主要技术变更: - 将数据结构从 CoreIdRange {start, end} 改为 CoreIdList = std::set<CoreId>,支持离散/多段 CPU 核集合,set容器符合语义,不存在重复值 - 支持解析查出来的多段CPU亲和段 - 对GetAffinityCPUInfo.cpp和NPUAffinityController.cpp重构,优化函数圏复杂度,将cpp内部调用函数使用namespace或static关键词封装, --- ## 2、各文件修改的内容和目的 | 文件 | 修改内容 | 目的 | |------|----------|------| | **NPUAffinityController.h** | 将 CoreIdRange 结构体替换为 CoreIdList = std::set<CoreId>,新增 SetThreadAffinity(const CoreIdList) 接口 | 数据结构重构,支持多核集合 | | **NPUAffinityController.cpp** | 重构核心绑定逻辑:解析配置支持 npu0:0-1,npu0:4-9 多段格式;新增 formatCoreRange() 输出函数;重构 parseDeviceCoreRange() 解析多段范围 | 核心实现支持多段 CPU 核绑定 | | **GetAffinityCPUInfo.cpp** | 将 parseAffinityCPU() 改为 parseAffinityCores(),支持逗号分隔的多段范围;重构 GetExclusiveAffinityCPU() 的核分配逻辑 | DCMI 接口层适配新数据结构,避免重复初始化 | | **GetAffinityCPUInfo.h** | 简化接口,对其他cpp文件只保留 GetAffinityCores(int card_id)接口 | 接口统一 | | **Module.cpp** | Python 绑定增加对 PyList 参数的解析,支持python内部接口侧传入 [0, 1, 4, 5] 格式的核列表 | Python API 支持新参数类型 | | **affinity.py** | _set_thread_affinity() 支持 List[int] 或 List[List[int]] 参数,如 [[0,5], [8,10]] | Python 层 API 扩展 | | **torch_npu_schema.json** | 更新签名 Union[List[int], List[List[int]], NoneType] | 类型提示更新 | | **test_affinity.py** | 新增加多段CPU核相关测试用例 | 新增用例 | --- ## 3、修改后的影响 ### 功能增强 - **用户可配置多段 CPU 核范围**:如 CPU_AFFINITY_CONF='1,npu0:0-3,npu0:8-15',同一设备可绑定不连续的核,取并集 - **API 更灵活**:set_thread_affinity() 新增接受 [[0,5], [8,10]] 格式参数的功能 ### 行为变化 - 环境变量 CPU_AFFINITY_CONF 同一设备多次指定核范围会合并(如 npu0:0-1,npu0:4-9 绑定核 0,1,4,5,6,7,8,9) ### 代码改进 - 新增 formatCoreRange() 函数统一输出格式(如 0-3,8-15) - 代码结构更清晰:解析函数拆分为 parseNpuAffineMode()、parseLazyBindMode()、parseForceMode()、parseDeviceCoreRange() --- # 【资料变更】 在后续2.7.1分支的PR中修改 # 【接口变更】 CPU_AFFINITY_CONF环境变量和set_thread_affinity()接口变更方案已通过SEG例会评审,兼容旧版本; # 【功能验证】 自测OK  验证环境变量CPU_AFFINITY_CONF bash #!/bin/bash # 设置环境变量 export ASCEND_PROCESS_LOG_PATH=$(pwd) export ASCEND_GLOBAL_LOG_LEVEL=0 echo -e 'import torch\na=torch.tensor([1],device="npu")\nb=a+1\n' > add.py # 定义配置和期望值数组 configs=( "1,npu_affine:1,npu0:0-5" "1,npu_affine:1,npu0:0-5,npu1:6-7,npu2:8-8,npu2:10-11,npu0:12-19" "1,npu_affine:1,npu0:0-5,npu1:10-13,npu0:4-7" ) values=( "0-5" "0-5,12-19" "0-7" ) run_test() { local index=$1 local conf=$2 local expected_val=$3 export CPU_AFFINITY_CONF="$conf" # 清理旧日志,确保获取的是本次运行的日志 rm -rf debug/ # 执行测试脚本 python add.py # 检查 python 执行是否成功,可选 if [ $? -ne 0 ]; then echo "[ERROR] Index $index: python add.py failed." >> result.log return 1 fi # 提取 affinity 值 # 使用 find 避免 glob 匹配不到文件时的报错,或者保留原来的 glob 但确保目录存在 local log_file log_file=$(find debug/plog -name "*.log" 2>/dev/null | head -1) if [ -z "$log_file" ]; then echo "[ERROR] Index $index: No log file found in debug/plog/" >> result.log return 1 fi local affinity_line affinity_line=$(grep "Device 0 set acl_thread affinity to" "$log_file" 2>/dev/null | head -1) if [ -z "$affinity_line" ]; then echo "[ERROR] Index $index: Affinity line not found in log." >> result.log return 1 fi # 提取 "affinity to" 后面的具体值 local affinity_value # sed 提取最后一个非空字段,或者根据具体日志格式调整 affinity_value=$(echo "$affinity_line" | sed -n 's/.*affinity to \([^ ]*\).*/\1/p') # 去除可能的首尾空白字符 (trim) affinity_value=$(echo "$affinity_value" | xargs) # 比较实际值与期望值 if [ "$affinity_value" == "$expected_val" ]; then echo "测试环境变量 CPU_AFFINITY_CONF $conf: 的结果为:SUCCESS (Actual: ${affinity_value} == Expected: ${expected_val})" else echo "测试环境变量 CPU_AFFINITY_CONF $conf: 的结果为:FAIL (Actual: ${affinity_value} != Expected: ${expected_val})" fi } # 循环遍历配置 # 使用 C 风格的 for 循环以便同时获取索引 for ((i=0; i<${#configs[@]}; i++)); do run_test "$i" "${configs[$i]}" "${values[$i]}" done echo "All tests completed." 测试结果为:所有用例都通过  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34407 | 3 个月前 | |
| 1 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
TORCH MAIN SYNC: switch to release candidate of torch 2.12 update Co-authored-by: chansinging<chenxingying2@huawei.com> Co-authored-by: Chansinging<1183520536@qq.com> # message auto-generated for no-merge-commit merge: !35103 merge main_sync_0509 into master TORCH MAIN SYNC: switch to release candidate of torch 2.12 update Created-by: chansinging Commit-by: Chansinging;chansinging Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 同步社区演进,例行更新 lintrunner规避,见[issue](https://gitcode.com/Ascend/pytorch/issues/1865) # 【修改方案】 出包参考社区改动,https://github.com/pytorch/pytorch/pull/177570/ # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 本地A3服务器和ci流水线已跑通测试  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35103 | 3 个月前 | |
| 1 年前 | ||
[test] compat(test): adapt test cases for torch 2.10/2.11 cross-version compatibility Co-authored-by: chz34<chenhaozhe1@huawei.com> # message auto-generated for no-merge-commit merge: !34505 merge compat/master-test into master [test] compat(test): adapt test cases for torch 2.10/2.11 cross-version compatibility Created-by: c_34 Commit-by: chz34 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 基于多版本分支归一的方案,对应完成测试用例的修改 [#1688](https://gitcode.com/Ascend/pytorch/issues/1688) # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) compat(test): adapt test cases for torch 2.10/2.11 and Python 3.10/3.11+ compatibility Fix import typo MultiProcContinousTest -> MultiProcContinuousTest in pipelining tests and remove the unused TEST_MULTIGPU import from the CUDA module. Add the legacy flat cutedsl_grouped_gemm path back to test_public_bindings private_allowlist so it is exempted on torch 2.10/2.11 where the package restructure hasn't happened. Introduce per-version disabled-tests files (.pytorch-disabled-tests-2.10.json / -2.11.json) and update get_failed_ut_from_log.py to auto-select the right file via torch_npu._compat.version.CURRENT_VERSION. Add --torch parameter documentation to README, CONTRIBUTING, and ci/docker/README. Normalize Enum class signatures in test_compatibility.py to strip the boundary=None parameter added by Python 3.11+ via EnumMeta.__call__, ensuring schema comparisons remain consistent across Python 3.10 and 3.11+. # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” Add --torch description in README.md, CCONTRIBUTE.md, ci/docker/README.md # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 不涉及 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34505 | 4 个月前 | |
| 2 年前 | ||
TORCH MAIN SYNC: switch to release candidate of torch 2.12 update Co-authored-by: chansinging<chenxingying2@huawei.com> Co-authored-by: Chansinging<1183520536@qq.com> # message auto-generated for no-merge-commit merge: !35103 merge main_sync_0509 into master TORCH MAIN SYNC: switch to release candidate of torch 2.12 update Created-by: chansinging Commit-by: Chansinging;chansinging Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 同步社区演进,例行更新 lintrunner规避,见[issue](https://gitcode.com/Ascend/pytorch/issues/1865) # 【修改方案】 出包参考社区改动,https://github.com/pytorch/pytorch/pull/177570/ # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 本地A3服务器和ci流水线已跑通测试  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35103 | 3 个月前 | |
| 2 年前 | ||
| 1 年前 | ||
| 2 年前 | ||
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 个月前 | |
feat(autocast): 支持float32作为自动混合精度计算的数据类型 Co-authored-by: leland17<lileliao@foxmail.com> # message auto-generated for no-merge-commit merge: !30512 merge master into master feat(autocast): 支持float32作为自动混合精度计算的数据类型 Created-by: leland17 Commit-by: leland17 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > (如有)请关联需求文档/issue链接 issue:[支持float32作为自动混合精度计算的数据类型](https://gitcode.com/Ascend/pytorch/issues/1537) - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 当前现状with autocast(device="npu", dtype=torch.float32)暂时不支持按照float32的精度获取结果。同liwei有过详细的讨论方案,并且确定了如下的支持思路 在autocast_utils.py中支持float32的数据类型支持。 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 bash cd ${pytorch}/test && python -m unittest test_autocast.TestAutocastNPUfp32 新增4个用例场景,验证暂无问题  整体test_autocast.py的用例执行结果  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!30512 | 6 个月前 | |
| 1 年前 | ||
| 1 年前 | ||
| 2 年前 | ||
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
add group_type=2 meta tests and negative cases for npu_grouped_matmul Co-authored-by: XianglongZeng<zengxianglong1@huawei.com> # message auto-generated for no-merge-commit merge: !34656 merge master into master add group_type=2 meta tests and negative cases for npu_grouped_matmul Created-by: probiotics_53 Commit-by: XianglongZeng Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 ## 1. meta 层(fake tensor)测试 | 用例ID | 场景 | split_item | group_type | 验证要点 | |---|---|---|---|---| | meta_g2_1 | K轴分组 fp16 单单单 | 2 | 2 | 输出为 3D shape=(num_groups, M, N) | | meta_g2_2 | K轴分组 fp16 单单单 | 3 | 2 | 输出为 3D shape=(num_groups, M, N) | ## 2.异常场景看护用例 | 测试文件 | 用例名称 | 测试内容 | |---|---|---| | test/test_fake_tensor.py | test_npu_grouped_matmul_meta_invalid_group_type | group_type=1/3/100 应抛出 group_type only supports 错误 | # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】    # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34656 | 4 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Co-authored-by: xiemingda1002<xiemingda1002@163.com> # message auto-generated for no-merge-commit merge: !34071 merge add-test-hub-help-api-master into master test(hub): add test cases for torch.hub.help and torch.hub._get_torch_home APIs Created-by: xiemingda1002 Commit-by: xiemingda1002 Merged-by: ascend-robot Description: # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1703**</font>\ - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 一、API 功能说明 torch.hub.help 和 torch.hub._get_torch_home 是 PyTorch hub 模块中用于文档查询和路径管理的辅助 API,功能说明如下: 1. torch.hub.help(github, model, force_reload=False, skip_validation=False, trust_repo=None) - 文档获取核心能力:接收 GitHub 仓库地址和入口点名称,返回该入口点的文档字符串(docstring),无需实际加载模型或执行代码。 - 远程仓库解析核心能力:支持 "owner/repo[:branch]" 格式的仓库地址,自动解析并获取 hubconf.py 中定义的入口点函数的文档。 - 安全机制支持:通过 skip_validation 参数可跳过 GitHub API 验证(避免 rate limit),trust_repo 参数控制仓库信任策略(False/True/check/None)。 - 无状态调用:多次调用 help 不会产生副作用,不修改缓存状态,不影响后续 load 等操作,不下载仓库代码。 - 返回值灵活性:返回字符串类型文档或 None(若入口点函数未定义 docstring),支持用户预览模型使用说明。 - 典型用途:在加载模型前查看入口点的参数说明、使用示例、依赖信息等。 2. torch.hub._get_torch_home() - 路径解析核心能力:根据环境变量 TORCH_HOME 或默认路径 ~/.cache/torch 确定 torch home 目录。 - 环境变量优先级机制:优先读取 TORCH_HOME 环境变量,若未设置则依次检查 XDG_CACHE_HOME/torch、~/.cache/torch。 - 内部 API 特性:作为 get_dir() 的底层实现,不直接暴露给用户,但可通过 hub 模块访问(用于测试或调试)。 - 路径标准化处理:返回的路径经过 os.path.expanduser 处理,支持 ~ 符号展开,确保路径可用性。 - 返回值:字符串类型路径,非空且为绝对路径。 上述 API 均为纯 Python 层实现,不涉及张量计算,仅负责文档查询和路径解析。 二、测试文件 test/test_hub_api.py 完整验证该 API 的原因 本测试文件针对 PyTorch 社区原生 test/test_hub.py 覆盖不足的 torch.hub.help / _get_torch_home API 进行补充验证,确保昇腾 NPU 环境下功能完整可用: 1. torch.hub.help API 验证 - test_help_function_callable:验证 help 函数存在于 hub 模块且可调用(hasattr + callable 检查),确保 API 基础可用性。 - test_help_returns_none_without_docstring:严格验证 help 函数在入口点无 docstring 时返回 None。使用 mock 本地仓库进行测试,无需外部网络依赖。 - test_help_returns_docstring_with_content:严格验证 help 函数在入口点有 docstring 时返回有效的字符串内容。使用 mock 本地仓库进行测试,检查返回值类型为 str、非空、且包含预期关键字 "EfficientNet"。 2. torch.hub._get_torch_home API 验证 - test_get_torch_home_returns_path:验证 _get_torch_home 返回有效的路径字符串(assertIsInstance(str) + assertGreater(len, 0)),确保路径非空且类型正确。 - test_get_torch_home_with_env_variable:验证 TORCH_HOME 环境变量能正确影响返回路径,使用 tempfile.TemporaryDirectory 创建临时目录作为测试路径,覆盖自定义路径场景。测试后恢复原始环境变量状态(os.environ.pop 或 restore),避免污染其他测试。 3. 测试隔离性保障 - setUp 机制:TestHubHelp 类在 setUp 中创建 mock 本地仓库目录,写入 hubconf.py 文件,包含有/无 docstring 的两个入口点函数。 - tearDown 机制:每个测试后清理临时目录,确保测试用例间无状态污染。 - 独立性设计:两个测试类(TestHubHelp、TestHubGetTorchHome)独立,无共享状态。 - 零外部依赖:使用 unittest.mock.patch 模拟 _get_cache_or_reload,避免对 GitHub 外部仓库的依赖,测试更快、更可靠,适合 CI 环境。 测试完整性 所有用例覆盖 API 的基础功能验证、接口存在性检查、环境变量交互、测试隔离性保障,完整覆盖昇腾 NPU 适配所需的最小功能集合。 三、昇腾 NPU 适配说明(解释为什么无需 NPU 适配) torch.hub.help 和 torch.hub._get_torch_home 均具备硬件无关性、纯 Python 层实现、无底层算子依赖三大核心特征,决定了其无需针对昇腾 NPU 做适配,具体分析: 1. 纯 Python 层抽象,无硬件相关逻辑 - help API 硬件无关性:仅负责解析远程仓库的 hubconf.py 并提取文档字符串,是「文档查询」的纯 Python 抽象接口,不涉及任何硬件相关的计算、存储、通信逻辑。 - _get_torch_home API 硬件无关性:仅负责读取环境变量和构建路径字符串,依赖 os.path 模块进行路径处理,无任何硬件相关的逻辑或依赖。 - 设备无关设计:两个 API 的核心逻辑与 CPU/GPU/NPU 等硬件架构完全解耦,在任意硬件环境下行为一致。 2. 无底层算子 / 内核依赖 - 标准库依赖:两个 API 内部仅调用 Python 标准库(os 路径模块、tempfile 临时文件模块、urllib 网络模块)和 PyTorch 纯 Python 层的 hub 模块。 - 无硬件扩展依赖:未依赖 CUDA/NPU 等硬件相关的扩展库、内核函数或底层驱动。 - help 的远程解析机制:基于 GitHub URL 和 Python import 机制,与硬件架构无关。 - _get_torch_home 的路径处理机制:基于 os.path.expanduser 和 os.getenv,纯文件系统操作。 3. 核心逻辑与硬件解耦 - 文档获取解耦:help API 返回的文档字符串是纯文本信息,与硬件架构无关 —— 无论是 CPU/GPU/NPU 环境,文档查询逻辑完全一致。 - 路径解析解耦:_get_torch_home 返回的路径是通用文件系统路径,不包含任何硬件相关字段(如设备 ID、内存地址),昇腾 NPU 环境下可直接复用。 - 无张量操作:两个 API 均不涉及张量的创建、计算或迁移,测试用例中无 tensor 相关代码,无需 NPU 设备支持。 结论 torch.hub.help 和 torch.hub._get_torch_home 均是「硬件无关的纯 Python 层抽象」,核心逻辑不耦合任何特定硬件。测试用例无需导入 torch_npu,API 本身无需适配修改,可直接复用。 # 【资料变更】 刷新2.7.1版本下有多个版本资料。 1、torch.hub._get_torch_home API该API昇腾支持,但是在文档中并无描述,因此需要增加。 文档修改PR链接:https://gitcode.com/Ascend/pytorch/pull/34365 # 【接口变更】 不涉及 # 【功能验证】 测试文件路径:test/test_hub_api.py 本地验证结果:  所有测试用例执行通过。torch.hub.help 和 torch.hub._get_torch_home API 核心功能验证正常。 两个 API 均为纯 Python 层实现,不涉及张量操作,无需 NPU 设备适配。测试用例无需导入 torch_npu,API 本身可在任意硬件环境稳定运行。验证结果表明,torch.hub.help 和 torch.hub._get_torch_home 在昇腾 NPU 环境下功能正常可用,无需修改源码。 # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签:test(hub) - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34071 | 4 个月前 | |
| 2 年前 | ||
fix: skip test_index_put_accumulate_large_tensor Co-authored-by: zhanw_coding<zhanwang@huawei.com> # message auto-generated for no-merge-commit merge: !31414 merge master into master fix: skip test_index_put_accumulate_large_tensor Created-by: zhanw_coding Commit-by: zhanw_coding Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 门禁A1机器cann8.5.0 AsStrided124 算子报错 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!31414 | 5 个月前 | |
fix(nn): fix test for jit api: torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32402 merge fixtest-jit-api-master into master fix(jit): fix test for jit api: torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load Created-by: dinglaiping Commit-by: dinglaiping Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1597**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 2.7.1及以上版本提示additional_module_tests、new_module_tests和module_tests找不到,要把additional_module_tests换成get_all_nn_module_tests并且删除new_module_tests和module_tests,最后在调用的时候使用get_all_nn_module_tests()。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 整体结论: 本次验证基于torch-npu 官方test_jit.py用例全量复用的方式,在完成最小化的文件、代码、环境适配后,于 NPU环境下完成torch.jit.script、torch.jit.trace、torch.jit.save、torch.jit.load四个核心 API 的全量验证,所有指定的测试方法均执行成功。验证结果表明,torch-npu 官方 JIT 用例可完整覆盖四个 API 的核心功能,使用官网用例完成 NPU 适配验证已足够;四个 API 在 NPU环境下的基础能力、协同逻辑均正常可用,完全满足 NPU 场景下模型编译优化、序列化部署、跨设备迁移、推理执行的实际业务需求。 1. torch.jit.script:官方用例中函数重复脚本化操作正常,脚本化模型的序列化 / 反序列化无数据丢失,NPU 设备下编译后模型的参数、设备属性与原模型保持一致,编译优化逻辑正常生效; 2. torch.jit.trace:官方用例中追踪化过程可完整保留模型的 train/eval 状态,字典类型可正常作为示例输入完成追踪,NPU 设备下追踪化模型的前向传播执行正常,输出结果与原模型一致; 3. torch.jit.save:官方用例中模型可成功保存至 zip 压缩包格式,保存过程中可完整保留 NPU 设备信息与模型全状态(参数、缓冲区、计算图),序列化过程无数据遗漏或损坏; 4. torch.jit.load:官方用例中可成功还原模型保存时的 NPU 设备信息,模型中自定义方法可正常导入并调用,zip 压缩包格式的模型可正确解析,加载后模型可直接在 NPU 上推理,执行结果与保存前模型一致。 运行日志: root@hostname-fqv42:~/torchnpuapi/torch-npu/2.7.1/pytorch/test# python -m unittest test_jit.TestJit.test_restore_device test_jit.TestJit.test_import_method test_jit.TestJit.test_torch_load_zipfile_check test_jit.TestScript.test_repeated_script_on_function test_jit.TestJit.test_script_fn_pkl test_jit.TestJit.test_trace_retains_train test_jit.TestFrontend.test_dictionary_as_example_inputs_for_jit_trace -v monkeytype is not installed. Skipping tests for Profile-Directed Typing test_restore_device (test_jit.TestJit.test_restore_device) ... ok test_import_method (test_jit.TestJit.test_import_method) ... ok test_torch_load_zipfile_check (test_jit.TestJit.test_torch_load_zipfile_check) ... ok test_repeated_script_on_function (test_jit.TestScript.test_repeated_script_on_function) ... ok test_script_fn_pkl (test_jit.TestJit.test_script_fn_pkl) ... ok test_trace_retains_train (test_jit.TestJit.test_trace_retains_train) ... ok test_dictionary_as_example_inputs_for_jit_trace (test_jit.TestFrontend.test_dictionary_as_example_inputs_for_jit_trace) ... ok ---------------------------------------------------------------------- Ran 7 tests in 0.104s OK root@hostname-fqv42:~/torchnpuapi/torch-npu/2.7.1/pytorch/test# # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32402 | 5 个月前 | |
test(jit):add test for onednn_fusion_enabled Co-authored-by: qq_42437014<yandj5@163.com> # message auto-generated for no-merge-commit merge: !34166 merge test-onednn_fusion_enabled into master test(jit):add test for onednn_fusion_enabled Created-by: qq_42437014 Commit-by: qq_42437014 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 [[Usage]: torch.jit.onednn_fusion_enabled API的测试用例缺失](https://gitcode.com/Ascend/pytorch/issues/1710) > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 本次变更为**新增单元测试文件**, 补齐 torch.jit.onednn_fusion_enabled 及配套 API torch.jit.enable_onednn_fusion 的测试覆盖。 **新增文件**:test/test_jit_api.py **测试用例设计**: | 测试方法 | 验证点 | |---------|--------| | test_onednn_fusion_enabled_api_exists | API 存在且可调用,返回值类型为 bool | | test_onednn_fusion_enable_disable_roundtrip | enable_onednn_fusion(True/False) 设置后,onednn_fusion_enabled() 返回值同步变化;执行结束后恢复原始状态 | **设计原则**: - **聚焦核心**:仅验证 API 的调用契约(存在性、返回值类型、状态设置/读取的配对行为),不测试 oneDNN 后端的实际融合效果。 - **无硬件依赖**:该 API 本身不涉及张量计算,测试用例无需依赖 NPU 或 GPU,可在任意环境下验证 API 的基础可用性。 - **环境自适应**:通过 original_state 记录并恢复原始开关状态,避免对同一进程中的其他测试产生副作用。 - **符合社区规范**:继承 TestCase,使用 run_tests 作为主入口,断言使用 self.assertIsInstance / self.assertEqual。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 **测试命令**: bash cd pytorch/test python test_jit_api.py -v **验证结果**: root@560aba985731:/test/pytorch/test#python test_jit_api.py -v python test_jit_api.py -v test_onednn_fusion_enable_disable_roundtrip (__main__.TestOneDNNJitAPI.test_onednn_fusion_enable_disable_roundtrip) ... ok test_onednn_fusion_enabled_returns_bool (__main__.TestOneDNNJitAPI.test_onednn_fusion_enabled_returns_bool) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.008s OK **验证结论**: 两个测试用例均通过,API 在 NPU 环境下可正常调用,状态设置与查询行为符合预期。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34166 | 3 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 1 年前 | ||
| 2 年前 | ||
test: add test for multiprocessing Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com> # message auto-generated for no-merge-commit merge: !32107 merge master into master test: add test for multiprocessing Created-by: VnOcean Commit-by: huangyunlong2022 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 [[Usage]: test 目录下 torch.multiprocessing 的 Array、get_start_method、set_start_method等测试用例缺失。](https://gitcode.com/Ascend/pytorch/issues/1584?ref=&did=3810729#tid-3810729) > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 ## 设计原则 该测试用例的设计遵循了三个核心原则:聚焦核心、贴合场景、轻量化。 ## 核心思路 测试用例的核心思路围绕跨进程数据共享与通信展开,通过五个典型场景验证多进程编程的正确性: 1. 共享内存模式测试Value和Array时,创建子进程对共享数据进行修改,主进程验证修改结果,直观展示了多进程间数据共享的基本原理——共享内存在不同进程地址空间中的可见性。 2. 管道通信模式测试Pipe时,构建了双向通信场景:子进程发送多种类型数据(字符串、整数、列表),父进程接收验证;随后测试请求-响应模式,验证了管道作为双向通信通道的可靠性。 3. 管理器模式测试展示了比共享内存更高级的抽象,通过Manager创建共享列表、字典和命名空间,子进程的修改自动同步到主进程,体现了管理器服务进程作为代理的同步机制。 4. 张量规约测试特别针对NPU场景,验证了PyTorch张量在多进程环境下的序列化与反序列化能力,确保深度学习模型中的张量数据可以跨进程高效传递。 5. 多进程编程的核心本质是在独立进程地址空间之间,通过序列化、共享内存或代理服务等方式,建立安全可靠的数据交换通道,同时保持进程的独立性和并发执行能力。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 用例验证结果: python test_multiprocessing_api.py -v test_array (\__main__.TestMultiprocessingAPIs.test_array) Test Array API ... ok test_get_set_start_method (__main__.TestMultiprocessingAPIs.test_get_set_start_method) Test get_start_method and set_start_method APIs ... ok test_manager (__main__.TestMultiprocessingAPIs.test_manager) Test Manager API ... ok test_pipe (__main__.TestMultiprocessingAPIs.test_pipe) Test Pipe API ... ok test_reductions (__main__.TestMultiprocessingAPIs.test_reductions) Test reductions API ... ok test_value (__main__.TestMultiprocessingAPIs.test_value) Test Value API ... ok ---------------------------------------------------------------------- Ran 6 tests in 1.304s OK # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32107 | 5 个月前 | |
| 2 年前 | ||
add_test Co-authored-by: sunhaolun<sunhaolun3@huawei.com> # message auto-generated for no-merge-commit merge: !33714 merge master into master add_test Created-by: sunhaolun Commit-by: sunhaolun Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 为以下API增加用例功能 Tensor.copy_ Tensor.narrow torch.cat torch.chunk torch._chunk_cat # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增文件 test_cat.py test_chunk.py test_chunk_cat.py test_copy_.py test_narrow.py # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33714 | 4 个月前 | |
| 1 年前 | ||
[feat] add nestedtensor backend Co-authored-by: culechan<chenshuai81@huawei.com> # message auto-generated for no-merge-commit merge: !30982 merge cherry-pick-mr-30981-1771989871865-auto into master [feat] add nestedtensor backend Created-by: culechan Commit-by: culechan Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > (如有)请关联需求文档/issue链接 - [ ] 需求 - [x] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 创建Nestedtensor相关的后端,参考quantized后端的实现,因为二者较为类似,因此在文件代码自动生成逻辑部分做了合并重构。 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增已适配UT测试用例看护,并补充测试自验证截图  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!30982 | 5 个月前 | |
fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential Co-authored-by: dinglaiping<1016581171@qq.com> # message auto-generated for no-merge-commit merge: !32060 merge fixtest-nn-api-master into master fix(nn): fix test for nn api: torch.nn.ParameterDict, torch.nn.ParameterList, torch.nn.Sequential Created-by: dinglaiping Commit-by: dinglaiping Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**https://gitcode.com/Ascend/pytorch/issues/1585**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] issue/工单 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1. 2.6.0版本提示skipIfMps找不到,要换成skipIfMPS。 2. 2.7及以上版本skipIfMps找不到,换成skipIfMPS;new_module_tests找不到,需要把导入new_module_tests改成导入get_new_module_tests并在调用的地方换成get_new_module_tests();tf32_on_and_off找不到,删掉导入,并在调用tf32_is_not_fp32()的地方换成调用torch.cuda.is_tf32_supported() # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 整体结论: 本次验证通过修复官网test_nn.py用例文件,验证3个API,功能正常: ParameterDict:官方用例中键值对索引、新增、删除、遍历等操作均正常,容器内所有参数设备统一为npu:0,无设备漂移问题; ParameterList:官方用例中数字索引、append新增、遍历等操作均正常,参数设备一致性与长度校验均通过,有序管理能力正常; Sequential:官方用例中getitem/setitem/delitem/append/insert/extend/pop等所有核心操作均正常执行,操作后子模块设备均保持为npu:0,动态扩展与元素管理能力完整。 运行日志: [root@hostname-fqv42 torchnpuapi]# docker exec -it test bash root@hostname-fqv42:/home# cd /root/torchnpuapi root@hostname-fqv42:~/torchnpuapi# python -m unittest test_nn_npu27.TestNN.test_ParameterList test_nn_npu27.TestNN.test_ParameterDict test_nn_npu27.TestNN.test_Sequential_getitem test_nn_npu27.TestNN.test_Sequential_setitem test_nn_npu27.TestNN.test_Sequential_delitem test_nn_npu27.TestNN.test_Sequential_append test_nn_npu27.TestNN.test_Sequential_insert test_nn_npu27.TestNN.test_Sequential_extend test_nn_npu27.TestNN.test_Sequential_pop -v test_ParameterList (test_nn_npu27.TestNN.test_ParameterList) ... ok test_ParameterDict (test_nn_npu27.TestNN.test_ParameterDict) ... ok test_Sequential_getitem (test_nn_npu27.TestNN.test_Sequential_getitem) ... ok test_Sequential_setitem (test_nn_npu27.TestNN.test_Sequential_setitem) ... ok test_Sequential_delitem (test_nn_npu27.TestNN.test_Sequential_delitem) ... ok test_Sequential_append (test_nn_npu27.TestNN.test_Sequential_append) ... ok test_Sequential_insert (test_nn_npu27.TestNN.test_Sequential_insert) ... ok test_Sequential_extend (test_nn_npu27.TestNN.test_Sequential_extend) ... ok test_Sequential_pop (test_nn_npu27.TestNN.test_Sequential_pop) ... ok ---------------------------------------------------------------------- Ran 9 tests in 0.057s OK root@hostname-fqv42:~/torchnpuapi# # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32060 | 5 个月前 | |
| 2 年前 | ||
[fix]add getMemoryFraction attribute for torch._C Co-authored-by: weixin_47897441<wuyouqi1@h-partners.com> # message auto-generated for no-merge-commit merge: !30619 merge master into master [fix]add getMemoryFraction attribute for torch._C Created-by: weixin_47897441 Commit-by: weixin_47897441 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > (如有)请关联需求文档/issue链接 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 : torch._C不支持_npu_getMemoryFraction - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1、NPUCachingAllocator中新增getMemoryFraction方法及虚函数声明,Module中注册_npu_getMemoryFraction绑定; 2、在torch_npu.npu和torch_npu.npu.memory中实现并暴露get_per_process_memory_fraction接口,支持指定设备,调用底层 C++ 接口; 3、新增该接口的测试用例; 4、将该接口及底层Cpp绑定加入Dynamo追踪规则,完成适配。 # 【资料变更】 > 不涉及 # 【接口变更】 > 否 # 【功能验证】 > UT用例测试通过:python test_npu.py -v -k test_get_per_process_memory_fraction  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!30619 | 5 个月前 | |
add torch.npu.memory._set_allocator_settings(only support expandable_segments) and testcases Co-authored-by: zhaoyu<nanzhaogang@qq.com> # message auto-generated for no-merge-commit merge: !25488 merge alloctor into master add torch.npu.memory._set_allocator_settings(only support expandable_segments) and testcases Created-by: zhaoyu65 Commit-by: zhaoyu 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 feature **What does this PR do / why do we need it**: 1、增加torch_npu.npu.memory.\_set\_allocator\_settings接口,仅支持expandable_segments:True或expandable_segments:False场景。 2、增加对应的测试用例。 **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!25488 | 10 个月前 | |
| 1 年前 | ||
host allocator support pinned_use_background_threads Co-authored-by: zhaoyu<nanzhaogang@qq.com> # message auto-generated for no-merge-commit merge: !28786 merge background_thread into master host allocator support pinned_use_background_threads Created-by: zhaoyu65 Commit-by: zhaoyu 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 feature **What does this PR do / why do we need it**: host allocator 支持背景线程 **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!28786 | 7 个月前 | |
[bugfix] Add proper handling for view and factory function for csan, and supplement the corresponding test cases. Co-authored-by: chenkun<chenkun82@huawei.com> # message auto-generated for no-merge-commit merge: !26406 merge cherry-pick-mr-26401-1762829831101-auto into master [bugfix] Add proper handling for view and factory function for csan, and supplement the corresponding test cases. Created-by: kuhn7 Commit-by: chenkun Merged-by: ascend-robot Description: **What type of PR is this?** bug **What does this PR do / why do we need it**: 增加 ArgumentHander.parse_input() 缺失的 is_factory 参数, 并补充了相应的看护用例。 **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**: 开源社区对应改动如下: https://github.com/pytorch/pytorch/commit/c4ed03cea17d2ec9b09427786627bba479f4cb6b See merge request: Ascend/pytorch!26406 | 9 个月前 | |
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 1 年前 | ||
| 2 年前 | ||
| 1 年前 | ||
Skip failing torch official TestCase tests and disable unsupported test cases Co-authored-by: yuhaiyan<yuhaiyan8@huawei.com> Co-authored-by: yuhaiyan8<yuhaiyan8@h-partners.com> # message auto-generated for no-merge-commit merge: !32140 merge cherry-pick-mr-32139-1774073503832-auto into master Skip failing torch official TestCase tests and disable unsupported test cases Created-by: yuhaiyan Commit-by: yuhaiyan;yuhaiyan8 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. 暂时跳过失败用例 2. 已提单跟进修复 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!32140 | 4 个月前 | |
| 2 年前 | ||
| 1 年前 | ||
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 个月前 | |
refactor for torch_npu init module. Co-authored-by: bellatan<tanmei2@huawei.com> # message auto-generated for no-merge-commit merge: !35338 merge torch_npu_init_refactor into master refactor for torch_npu init module. 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] 重构优化 - [ ] 资料更新 # 【修改方案】 本 PR 对 torch_npu 初始化链路进行重构,将原先集中在 torch_npu/__init__.py 中的初始化逻辑拆分到 _init 目录下的多个职责模块中,形成“**顶层编排 + 子模块分阶段执行 + 内部能力统一收口**”的结构。重构后,torch_npu/__init__.py 不再承载大量具体业务初始化细节,只负责固定初始化时序。各类具体能力分别由 _check_device_conflict、_load_core_modules、_register_components、_apply_patches、_enable_optional_features、_initialize_runtime_lifecycle 等内部函数承接。 ## 一、核心修改 ### 1. 重构 torch_npu/__init__.py 顶层初始化入口 重构后的初始化流程如下: python def _initialize(): _check_device_conflict() _load_core_modules() _register_components() _apply_patches() _enable_optional_features() _initialize_runtime_lifecycle() 顶层入口主要负责: 1. 维护 __all__; 2. 在 import torch 前关闭 TORCH_DEVICE_BACKEND_AUTOLOAD,避免 PyTorch 后端自动加载导致循环依赖; 3. 提前导入 torch_npu.utils.patch_getenv,用于捕获初始化阶段的环境变量访问; 4. 按固定顺序调用各初始化阶段入口; 5. 保留 _autoload() 作为 PyTorch 后端自动加载入口,用于恢复 TORCH_DEVICE_BACKEND_AUTOLOAD。 --- ### 2. 新增 _init 目录: 目录结构如下: text torch_npu/_init/ __init__.py common/ warning_utils.py core/ _exports.py module_loader.py optional_features.py runtime_lifecycle.py patches/ __init__.py api_patches.py asd_patches.py distributed_patches.py dynamo_patches.py monkey_patches.py npu_patches.py patch_manager.py profiler_patches.py warning_patches.py registry/ __init__.py backend.py distributed.py dynamo.py registry_manager.py --- ### 3. 通过 _check_device_conflict() 处理前置设备冲突检查 **_check_device_conflict()**:负责最早期的设备冲突检查,避免 NPU 与其他 accelerator 同时启用。该接口属于初始化内部逻辑,不作为 public API 暴露。 --- ### 4. 通过 _load_core_modules() 统一管理核心模块加载、注册副作用和顶层 API 导出 _load_core_modules() 将原先散落在 torch_npu/__init__.py 中的模块导入、底层 _C 子模块准备、基础 runtime 支撑模块初始化、导入即注册副作用以及顶层 API 导出统一收口。该阶段主要负责: 1. 加载 torch_npu 初始化所需的核心模块; 2. 统一准备 _C child submodules; 3. 初始化 logging、profiler、distributed 等基础组件; 4. 在 _C 准备完成后进行 torch_npu.npu 导入检查; 5. 加载需要通过 import 触发注册副作用的 Python 模块; 6. 导出 torch_npu 顶层 public API。 具体包括: * _C 子模块初始化:统一创建并注册 _profiler、_distributed_c10d、_cd、_logging、_flops_count 等 _C child submodules,保证业务 Python 模块只消费这些子模块,不再各自创建。 * torch_npu.npu 导入检查:在 _C 子模块完成准备后再检查 torch_npu.npu 导入状态,既保留对底层依赖缺失的友好报错,又避免 _C 未就绪时提前 import torch_npu.npu 导致循环导入。 * 导入副作用模块加载:统一加载需要通过 import 触发注册副作用的模块,例如 aclnn、optim、afd、custom ops、op_plugin、meta registrations 等,避免注册类副作用散落在初始化流程中。 * 顶层 API 导出:通过 export_all 将 torch_npu 顶层公开 API 统一导出到 globals() 和 __all__ 中,保证 public API 行为与旧版兼容。 * lazy Python API:对 HiFloat8Tensor、erase_stream、matmul_checksum 等接口采用 lazy export,保证接口可见但不在 import 阶段立即加载对应模块,减少循环导入风险。 * NPU custom ops:将 torch.ops.npu 下的公开算子导出到 torch_npu 顶层,并保留 torch.<op> deprecated wrapper。 * dtype symbols:将 _C._cd.DType 中的 dtype 符号导出到 torch_npu 顶层。 --- ### 5. 通过 _register_components() 统一管理框架集成注册 _register_components() 负责 backend 和 framework integration 注册,将原先散落在顶层入口中的 NPU backend、distributed、Dynamo、RPC、Inductor 等注册逻辑统一收口。通过该阶段统一收口后,框架集成注册逻辑不再散落在顶层 __init__.py 中,后续新增集成能力时可直接在 registry 目录下维护。该阶段主要负责: * NPU backend 注册:将 PyTorch PrivateUse1 backend 映射为 NPU,并注册 torch.npu 设备模块和相关方法。 * distributed backend 注册:注册 HCCL、LCCL backend,保证 NPU distributed 能力可用。 * Dynamo 注册:注册 Dynamo backend、NPU device interface 和 trace rules,保证 NPU 能接入 Dynamo 编译链路。 * RPC 注册:注册 NPU RPC backend,保证 RPC 场景下 NPU backend 可用。 * Inductor lightweight override 注册:只注册轻量级 NPU device op override,避免 import 阶段提前加载 heavy module。 * 默认 gradient device type 配置:保持 checkpoint 等场景下默认设备类型与旧行为兼容。 --- ### 6. 通过 _apply_patches() 统一管理 patch 注册与执行 引入集中式 patch 管理机制,统一收口原先散落在初始化入口中的 patch 逻辑。顶层入口 _apply_patches() 负责触发 patch 发现、注册和执行,具体由 PatchManager 承接。_apply_patches() 主要完成以下工作: 1. **patch 分组注册**:各组件 patch 按 group 注册,例如 monkey、api、distributed、dynamo、profiler、npu、warning、asd 等。 2. **内置 patch 自动发现**:PatchManager 会自动扫描 _init/patches 下符合命名规则的 patch 模块。模块被导入后,内部 patch 会完成注册。 3. **固定 patch 执行顺序**:patch group 按默认顺序执行,避免 import 顺序变化导致 patch 行为漂移。 4. **支持自定义 patch 顺序**:PatchManager 支持调整 patch group 执行顺序,便于测试或特殊场景扩展。 5. **异常钩子统一处理**:全局异常钩子由 PatchManager.run() 统一处理,便于初始化失败和运行时异常场景的集中管理。 --- ### 7. 通过 _enable_optional_features() 统一管理可选运行时能力 将 sanitizer、交互式模式配置、transfer_to_npu 等可选能力统一收口到 _enable_optional_features(),避免可选逻辑散落在顶层初始化入口。该阶段主要包括: python _enable_sanitizer_if_needed() _configure_interactive_mode() _enable_transfer_to_npu_if_needed() 具体说明: * sanitizer:仅在用户显式配置 TORCH_NPU_SANITIZER 时启用; * interactive mode:在交互式命令行环境中自动设置相关运行配置,并给出 warning 提示; * transfer_to_npu:通过 TORCH_TRANSFER_TO_NPU 控制是否启用,对非法配置进行显式报错。 --- ### 8. 通过 _initialize_runtime_lifecycle() 统一管理 runtime 生命周期 _initialize_runtime_lifecycle() 专门负责最终 C++ extension 初始化屏障和进程退出阶段的 shutdown hook 注册。该阶段主要包括: * extension finalize:调用 torch_npu._C._initExtension() 完成最终 C++ extension 绑定。该阶段放在核心模块加载、框架注册、API 导出和 patch 执行之后,保证 Python 侧初始化准备完成后再进入最终 extension barrier。 * shutdown hook 注册:负责注册进程退出阶段的 NPU 资源清理逻辑,包括设备同步、distributed 资源析构、异常处理和其他 runtime 清理流程。 --- ## 三、重构目的和收益 本次重构的目标是把 torch_npu 初始化从“单文件集中式副作用堆叠”调整为“阶段化、组件化、可维护”的初始化框架。主要收益包括: 1. **顶层入口更清晰** torch_npu/__init__.py 只保留初始化编排,不再堆叠大量具体 import、注册、patch 和 shutdown 逻辑。 2. **初始化顺序更稳定** _C 子模块和基础 runtime 支撑能力统一由 _load_core_modules 准备,降低循环导入和 _C 未就绪时提前访问的风险。 3. **组件职责更清楚** 模块加载、框架注册、API 导出、patch、可选功能、runtime 生命周期分别由不同接口承接。 4. **patch 更易维护** 各组件 patch 可以在自己的文件中维护,由 PatchManager 自动发现和统一执行,减少顶层冲突。 5. **支持后续扩展** 新增初始化能力时,只需放到对应处理的接口 或 patch group 中,不需要继续膨胀 __init__.py。 6. **便于问题定位** 初始化链路被拆成明确阶段,出现问题时可以快速判断是模块加载、注册、导出、patch、optional feature 还是 runtime lifecycle 阶段异常。 --- ## 四、兼容性说明 本次重构保持以下兼容性: 1. import torch_npu 行为保持兼容; 2. 顶层公开 API 保持兼容; 3. __version__ 仍从 torch_npu.version 导出。 --- ## 五、PatchManager 机制说明 本 PR 引入 PatchManager,用于统一管理 torch_npu 初始化阶段的 patch 注册与执行。原先 patch 逻辑集中在 torch_npu/__init__.py 中,和初始化流程、模块导入、框架注册逻辑混在一起,导致顶层文件过重,也不利于各组件独立维护。本次重构后,patch 逻辑从顶层入口中解耦,由 _apply_patches() 作为顶层入口触发执行,具体注册、发现、排序、幂等保护由 PatchManager 管理。 PatchManager 主要支持以下能力: 1. patch 按 group 分组注册; 2. 内置 patch 模块自动发现; 3. patch 按固定顺序执行; 4. patch 执行具备幂等保护; 5. 支持组件自行维护 patch module; 6. 支持按 group 执行,为后续按需使能 patch 打基础; 7. 支持自定义 patch 顺序,便于测试和问题定位。 整体机制如下: text 组件 patch 文件自注册 ↓ PatchManager 自动发现/加载 ↓ 按 group 统一管理 ↓ 按固定顺序执行 ↓ 幂等保护,避免重复 patch --- ### 场景一:新增 torch_npu 内置 patch 如果新增的是 torch_npu 内置 patch,例如 distributed patch、profiler patch、NPU API patch、warning patch、ASD patch 等,可以直接放到:torch_npu/_init/patches/ 目录下,并按 group 注册。 示例: python from torch_npu._init.patches.patch_manager import PatchManager @PatchManager.register_patch("profiler") def apply_profiler_patch(): ... 使用方式: text 1. 在 _init/patches 下新增或修改对应 *_patches.py 文件; 2. 在文件中通过 @PatchManager.register_patch(group) 注册 patch; 3. import torch_npu 时,由 _apply_patches() 统一触发; 4. PatchManager 自动发现并按 group 顺序执行。 --- ### 场景二:组件自行维护 patch module 如果某个组件自己的目录下新加了patch 文件,通过 patch module 注册机制接入。 示例: python PatchManager.register_patch_module("torch_npu.some_component.some_patches") 组件自己的 patch 文件中仍然使用 group 注册: python from torch_npu._init.patches.patch_manager import PatchManager @PatchManager.register_patch("some_component") def apply_some_component_patch(): ... 使用方式: text 1. 组件在自己的目录中维护 patch 文件; 2. 通过 register_patch_module 注册该 patch module; 3. module 被导入后,内部 patch 自动注册到 PatchManager; 4. 后续仍由 PatchManager 统一排序和执行。 适用场景: text 组件有独立维护边界; patch 逻辑不适合放到中心化 patches 目录; 后续组件可能独立演进、迁移或删除。 --- ### 场景三:按 group 执行 patch,用于测试或后续按需使能 PatchManager 支持按 group 执行 patch。当前默认初始化路径仍执行全部注册 patch,后续也可按需使能。 示例: python PatchManager.apply_registered_patches("distributed") 使用方式: text 1. 指定需要执行的 patch group; 2. PatchManager 只执行该 group 下已注册的 patch; 3. 已执行过的 patch 不会重复执行; 4. 可用于单独验证某一类 patch 的行为。 适用场景: text 只验证 distributed patch; 只执行 profiler patch; 排查某一类 patch 对初始化流程的影响; 后续通过环境变量控制某个 patch group 是否启用。 如果需要调整 patch group 顺序,也可以使用: python PatchManager.set_patch_order([ "monkey", "api", "distributed", ]) 适用场景: text 测试 patch 顺序; 排查 patch 依赖问题; 特殊构建或实验场景调整 patch 执行顺序。 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 新增 TestTorchNpuBootstrap 初始化专项测试,覆盖以下场景: 1. test_01_import_order_compatibility 验证 import torch_npu、import torch; import torch_npu、import torch_npu; import torch、重复 import torch_npu 等不同导入顺序保持兼容。 2. test_02_import_state_snapshot 验证 import torch_npu 后的初始化状态,包括 torch.npu 注册、Tensor/Module.npu 方法生成、_C child submodules 准备、旧版初始化副作用模块加载、非预期模块不 eager import、顶层关键属性可访问等。 3. test_03_public_exports_snapshot 验证顶层 public API 导出行为,包括 lazy Python APIs、torch.ops.npu public ops、deprecated torch.<op> alias、dtype symbols 等导出保持兼容。 4. test_04_framework_registration_snapshot 验证框架集成注册行为,包括 Dynamo NPU device interface、Dynamo backend、Inductor lightweight device op override、distributed backend、RPC backend 等注册保持生效。 5. test_05_runtime_lazy_init_semantics 验证 import 阶段不触发 NPU runtime lazy init,查询类 API 不触发完整 runtime 初始化,真实 runtime API 和显式 torch_npu.npu.init() 能正常触发 lazy init。 6. test_06_component_behavior_snapshot 验证关键组件行为保持兼容,包括 patch_getenv 生效、ASD detector 兼容 API、AFD 通过 torch_npu._afd 暴露、torch_npu._C._afd 不暴露、AFD ops 可访问等。 7. test_07_distributed_patch_behavior 验证 distributed patch 行为保持兼容,包括 distributed 内部函数替换、public API alias、rendezvous/launcher patch、FSDP 相关 patch 等。 新增测试用例本地验证通过。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35338 | 3 个月前 | |
| 2 年前 | ||
| 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 | 11 个月前 | |
| 2 年前 | ||
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 年前 | ||
[Fix] Remove the outer monkey-patch of torch.save to support JIT compilation Co-authored-by: dinghongzou<zoudinghong3@huawei.com> # message auto-generated for no-merge-commit merge: !34981 merge fix/test_torchscript_functions_not_supported-master into master [Fix] Remove the outer monkey-patch of torch.save to support JIT compilation Created-by: Windwindzzz Commit-by: dinghongzou 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能力等内容) **问题:** Jit.script报错:Unknown type name 'object'  当导入 torch_npu 时,它会将 torch.save 替换为自定义的 save 函数。然而,TorchScript 编译器在编译这个自定义函数时会走通用编译路径,并因 obj: object 类型注解而报错 Unknown type name 'object'。为了解决这个问题,我们将原有的针对 torch.save 的 patch 逻辑下沉至其内部函数 _legacy_save,从而将 patch 的目标由 torch.save 调整为 _legacy_save。 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 自验证社区用例通过 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34981 | 3 个月前 | |
| 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 用例的功能
该用例是为了校验接口的公开规范性,如果该用例报错,请确认报错的接口是否要公开,并按照报错的提示进行修改。