| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
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_config_copy | 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 年前 | |
feat add c_shim_npu Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com> # message auto-generated for no-merge-commit merge: !35375 merge 2.13shim into master feat add c_shim_npu 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能力等内容) 继承社区inductor_fallback_ops,生成npu支持的stable abi,包括NPU,CompositeExplicitAutograd,CompositeExplicitAutogradNonFunctional,CompositeImplicitAutograd等dispatchkey 1、生成at::npu::ops调用供aoti_torch_npu_ops调用,包括Register{dispatchkey}.cpp中的实现和ops_{dispatchkey}_dispatch.h的声明 2、生成c_shim_npu.h和c_shim_npu.cpp,支持aoti_torch_npu_ops等算子接口 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35375 | 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 个月前 | |
test: add staging api npu tests Co-authored-by: zj<2943168611@qq.com> # message auto-generated for no-merge-commit merge: !35465 merge test/master-staging-api-npu into master test: add staging api npu tests Created-by: zjucn Commit-by: zj Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [x] issue/工单: https://gitcode.com/Ascend/pytorch/issues/1897 本 PR 覆盖以下 API: - torch.distributed.checkpoint.staging.AsyncStager - torch.distributed.checkpoint.staging.AsyncStager.should_synchronize_after_execute - torch.distributed.checkpoint.staging.AsyncStager.stage - torch.distributed.checkpoint.staging.AsyncStager.synchronize_staging - torch.distributed.checkpoint.staging.BlockingAsyncStager - torch.distributed.checkpoint.staging.BlockingAsyncStager.stage - torch.distributed.checkpoint.staging.BlockingAsyncStager.synchronize_staging 问题背景和 API 功能说明见 issue。本 PR 不修改 torch-npu 生产代码,仅新增 test_staging_api.py,用于验证 DCP staging API 在 NPU tensor 场景下的可用性。 # 【修改方案】 ## 一、总体方案 PyTorch 社区已有分布式 checkpoint 测试主要通过 torch.distributed.checkpoint.async_save 端到端流程间接覆盖 staging 行为。本 PR 在 torch-npu 侧补充 staging API 专项测试,重点验证 NPU tensor 经过 DCP staging 后能够形成稳定的 CPU staged state dict,并可继续通过 DCP 文件系统 writer 完成异步保存和加载。 测试实现遵循以下原则: - 使用真实 NPU tensor 作为输入,不 mock DCP staging 内部逻辑。 - 直接调用 BlockingAsyncStager.stage(),验证 NPU 到 CPU staging 行为。 - 使用同一个 BlockingAsyncStager 实例连续 staging,验证 cached staging buffer 复用。 - 使用 FileSystemWriter.stage() 覆盖文件系统 writer 继承 BlockingAsyncStager 的真实路径。 - 使用 torch.distributed.checkpoint.async_save 和 torch.distributed.checkpoint.load 覆盖保存加载端到端链路。 - 使用自定义 writer 验证 should_synchronize_after_execute 与 synchronize_staging() 的调用关系。 - 用例保持轻量,不引入分布式初始化和多进程依赖,使测试目标聚焦在本 PR 涉及的 staging API。 ## 二、用例覆盖 本 PR 新增的测试文件为 test_staging_api.py。用例覆盖如下: ### 1. test_async_stager_protocol_defaults 覆盖 torch.distributed.checkpoint.staging.AsyncStager、torch.distributed.checkpoint.staging.AsyncStager.should_synchronize_after_execute、torch.distributed.checkpoint.staging.AsyncStager.stage 和 torch.distributed.checkpoint.staging.AsyncStager.synchronize_staging。 该用例构造最小 stager 实现,验证: - 对象可被 runtime protocol 识别为 AsyncStager。 - 默认 should_synchronize_after_execute 返回 True。 - 默认 stage() 抛出 NotImplementedError。 - 默认 synchronize_staging() 返回 None。 PyTorch 2.9.0 起 AsyncStager protocol 新增 close(),测试中的最小实现类提供该方法,以兼容不同版本的 runtime protocol 判断。 ### 2. test_blocking_async_stager_stage_npu_tensor_to_cpu_snapshot 覆盖 torch.distributed.checkpoint.staging.BlockingAsyncStager.stage。 该用例构造包含顶层和嵌套 NPU tensor 的 state dict,调用 BlockingAsyncStager.stage() 后验证: - staged tensor 位于 CPU。 - staged tensor 数值与 staging 时刻的源 NPU tensor 一致。 - 修改原始 NPU tensor 后,staged CPU tensor 不受影响。 该用例验证 BlockingAsyncStager.stage() 在 NPU 输入下的 CPU staging 和 checkpoint 快照语义。 ### 3. test_blocking_async_stager_cached_reuses_cpu_buffer 覆盖 torch.distributed.checkpoint.staging.BlockingAsyncStager.stage(cache_staged_state_dict=True)。 该用例使用同一个 BlockingAsyncStager 实例连续 staging 两份 NPU tensor,验证: - 两次返回的 staged tensor 复用同一 CPU buffer。 - 第二次 staging 后,CPU buffer 中的数据被更新为最新 NPU tensor 数据。 该用例验证 cached staging buffer 在 NPU 到 CPU 拷贝场景下的正确性。 ### 4. test_blocking_async_stager_sync_noop_and_property 覆盖 torch.distributed.checkpoint.staging.BlockingAsyncStager、torch.distributed.checkpoint.staging.AsyncStager.should_synchronize_after_execute 和 torch.distributed.checkpoint.staging.BlockingAsyncStager.synchronize_staging。 该用例验证: - BlockingAsyncStager 满足 AsyncStager 协议。 - BlockingAsyncStager.should_synchronize_after_execute 返回 False。 - BlockingAsyncStager.synchronize_staging() 为 no-op,并返回 None。 该用例验证阻塞式 staging 实现与 AsyncStager 协议的同步语义一致。 ### 5. test_filesystem_writer_stage_sets_copy_ahead_zero 覆盖 FileSystemWriter.stage() 与 BlockingAsyncStager.stage() 的组合路径。 该用例显式设置 per_thread_copy_ahead=1024 后调用 FileSystemWriter.stage(),验证: - per_thread_copy_ahead 被置为 0。 - 返回的 staged tensor 位于 CPU。 - staged tensor 数值与输入 NPU tensor 一致。 该用例验证文件系统 writer 在 async staging 场景下使用 CPU staged 数据路径。 ### 6. test_async_save_npu_state_dict_with_filesystem_writer 覆盖 torch.distributed.checkpoint.async_save、FileSystemWriter、BlockingAsyncStager.stage() 和 torch.distributed.checkpoint.load 的完整链路。 该用例分别测试 cache_staged_state_dict=False 和 cache_staged_state_dict=True,验证: - NPU tensor 可通过 DCP async_save 异步保存。 - 保存完成后可通过 DCP load 加载回 NPU 目标 tensor。 - 加载后的 tensor 数值与源 NPU tensor 一致。 该用例验证默认文件系统 writer 下的真实 DCP NPU 保存加载路径。 ### 7. test_async_save_converts_stateful_object 覆盖 torch.distributed.checkpoint.async_save 在 staging 前对 Stateful 对象的转换路径。 该用例定义实现 state_dict() 和 load_state_dict() 的对象,对象内部持有 NPU tensor,验证: - Stateful 对象可直接传给 async_save。 - 对象内部 NPU tensor 可被 staging 并保存。 - 加载后可恢复到新的对象中,且数值一致。 该用例验证 Stateful 对象与 DCP staging 调用链在 NPU tensor 场景下可用。 ### 8. test_async_save_calls_synchronize_when_stager_requests_it 覆盖 torch.distributed.checkpoint.staging.AsyncStager.should_synchronize_after_execute 与 torch.distributed.checkpoint.staging.AsyncStager.synchronize_staging 的调用关系。 该用例自定义 FileSystemWriter,将 _synchronize_after_execute 设为 True,并记录 synchronize_staging() 是否被调用。测试验证: - async_save 启动后台保存任务后会调用 synchronize_staging()。 - 保存 future 可正常完成。 该用例验证自定义 stager 请求同步时,async_save 能正确执行同步 hook。 ## 三、NPU 适配说明 本 PR 的 NPU 适配重点是验证 DCP staging API 在真实 NPU tensor 输入下的行为。 具体适配点如下: - 使用 torch.arange(...).to(device_type)、torch.ones(...).to(device_type) 和 torch.full(...).to(device_type) 构造 NPU tensor。 - 直接验证 NPU tensor 可通过 BlockingAsyncStager.stage() staging 到 CPU。 - 验证 staged CPU tensor 与原始 NPU tensor 解耦,避免后续训练修改影响 checkpoint 数据。 - 验证 cached staging buffer 可在多次 NPU 到 CPU staging 中复用并正确更新。 - 验证 FileSystemWriter.stage() 会在 async staging 场景下关闭 per_thread_copy_ahead。 - 验证 DCP.async_save + FileSystemWriter + DCP.load 能保存并恢复 NPU tensor。 - 验证 Stateful 对象内部 NPU tensor 可经 DCP staging 调用链保存和恢复。 为什么不需要修改 API: - AsyncStager 和 BlockingAsyncStager 是 DCP Python 层协议和默认实现,接口本身不绑定具体设备后端。 - NPU 适配风险集中在 NPU tensor 到 CPU staging、cached buffer 复用以及 FileSystemWriter 与 async_save 调用链是否可用。 - 本 PR 通过新增测试覆盖这些风险点,无需修改 torch-npu 生产代码或 API 签名。 ## 四、跨版本兼容说明 经对比 PyTorch 2.7.1、2.9.0、2.10.0、2.11.0 以及 master,本 PR 覆盖的七个 API 核心行为保持兼容,无需新增额外测试分支。 版本差异和本 PR 处理如下: - PyTorch 2.7.1 中,AsyncStager.stage 返回普通 STATE_DICT_TYPE。本 PR 测试覆盖该返回形式。 - PyTorch 2.9.0 起,AsyncStager.stage 返回类型扩展为普通 state dict 或 future;BlockingAsyncStager.stage 仍返回普通 staged state dict,本 PR 测试无需变化。 - PyTorch 2.9.0 起,AsyncStager.synchronize_staging 被标记为 deprecated,但该方法仍存在并保持同步 hook 语义。本 PR 继续验证该 API 的现有行为。 - PyTorch 2.9.0 起,AsyncStager protocol 新增 close()。测试中的最小 stager 实现提供 close(),保证 runtime protocol 判断在不同版本上兼容。 - PyTorch 2.9.0 起新增 DefaultStager、StagingOptions、AsyncSaveResponse 等 API;这些 API 不属于本 PR 覆盖范围,因此本 PR 不新增对应测试。 - PyTorch 2.10.0、2.11.0、2.12.0 和 master 相比 2.9.0,在本 PR 覆盖的七个 API 上未发现需要额外处理的公共语义变化。 # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 在 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 版本上执行 test_staging_api.py 测试,均通过。 bash $ python test_staging_api.py ........ ---------------------------------------------------------------------- Ran 8 tests in 5.361s OK # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35465 | 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 test for Tracer.getattr Co-authored-by: m0_45651774<2759927519@qq.com> # message auto-generated for no-merge-commit merge: !35414 merge test-fx-Tracer-getattr-master into master test(fx): add test for Tracer.getattr Created-by: m0_45651774 Commit-by: m0_45651774 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260512 --> # 【API功能】 **API:** torch.fx.Tracer.getattr **功能:** Tracer.getattr 是 PyTorch FX 符号追踪(Symbolic Tracing)过程中的核心钩子函数之一,它充当了 Python 对象属性访问与 FX 计算图节点之间的桥梁。torch.fx.Tracer.getattr 的主要职责是在追踪(Trace)阶段,拦截对 nn.Module 实例属性的访问操作,并将其转化为计算图(Graph)中的一个 get_attr 节点。在 PyTorch FX 的设计中,Tracer 通过重写 Python 的属性访问机制,确保当代码尝试读取模型的权重(如 self.linear.weight)、偏置或子模块时,不会直接返回底层的 Tensor 或 Module 对象,而是返回一个代表该值的符号代理(Proxy)。 # 【用例完整性】 经 PyTorch 社区代码检索,v2.7.1/v2.8.0/v2.9.0/v2.10.0/v2.11.0/master均无torch.fx.Tracer.getattr 测试用例覆盖,因此需要新增 torch-npu 自有用例。 # 【修改方案】 对目标 API 进行现状核查,确认在当前v2.7.1/v2.8.0/v2.9.0/v2.10.0/v2.11.0已实际支持,不需要补齐底层实现,本 PR 仅补充torch.fx.Tracer.getatt的测试用例至test/fx/test_fx_tracer_transformer_api.py。 # 【版本说明】 经 PyTorch 社区代码检索,v2.7.1/v2.8.0/v2.9.0/v2.10.0/v2.11.0均存在该API # 【NPU适配分析】 - **职责**:在符号追踪过程中,处理模型代码对属性(如 self.submodule.weight 或 self.layers.__len__)的访问。决定该属性是直接返回原始值(视为常量),还是记录为图中的 get_attr 节点。 - **实现层次**:该方法属于 Tracer 类的 Python 成员函数,其逻辑由 PyTorch 框架在 Python 层完成(例如通过 super().getattr() 调用默认行为或用户自定义的 is_leaf_module 判断)。 - **设备无关性**:getattr 操作的对象是 torch.nn.Module 或 Python 对象,并不直接接触 torch.Tensor 的底层设备内存。即使访问的张量位于 NPU 上,getattr 也只是获取该张量的属性元信息(如 .shape, .dtype)或子模块引用,不涉及 NPU 侧的 kernel 执行或内存传输。 torch.fx.Tracer.getattr属于纯 Python 框架层面的操作,不需要进行 NPU 适配。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 torch.fx.Tracer.getattr测试用例路径:test/fx/test_fx_tracer_transformer_api.py **验证环境** - 对应版本:torch-npu 2.7.1、2.8.0、2.9.0、2.10.0、2.11.0 - 操作系统:openEuler22.03 - CANN 软件版本:8.5.0 - 安装的软件版本:torch、torch-npu 2.7.1~2.11.0 验证结果:  结果说明:测试用例执行通过。 注意:测试结果图中的test_fx_Tracer_getattr.py文件内容已添加到test/fx/test_fx_tracer_transformer_api.py文件。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35414 | 3 个月前 | |
test(jit):add test for ScriptFunction,ScriptFunction.get_debug_state,ScriptFunction.save,and ScriptFunction.save_to_buffer Co-authored-by: fengwu154<1067935138@qq.com> # message auto-generated for no-merge-commit merge: !35412 merge test-torch-jit-ScriptFunction-master into master test(jit):add test for ScriptFunction,ScriptFunction.get_debug_state,ScriptFunction.save,and ScriptFunction.save_to_buffer Created-by: fengwu154 Commit-by: fengwu154 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 https://gitcode.com/Ascend/pytorch/issues/1904 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. ** get_debug_state 适配** - 使用 PyTorch 内置的 enable_profiling_mode_for_profiling_tests() 上下文强制启用 profiling executor。 - 执行两次函数(一次 profile,一次 optimize),确保优化计划生成。 - 通过 GRAPH_EXECUTOR 常量判断执行器模式,非 profiling 模式自动跳过测试。 2. **save 适配** - API 签名仅接受字符串路径,因此使用 tempfile.TemporaryDirectory 创建临时文件,避免对文件系统的污染。 3. **save_to_buffer 适配** - 验证返回类型为 bytes,并通过 io.BytesIO 模拟文件流加载,与保存前输出一致。 - **原测试缺口**:test_jit.py 虽大量使用 ScriptFunction,但缺少对其类型、save_to_buffer 及 save 直接路径的专门测试;get_debug_state 仅在特定测试中偶现调用,未系统验证。 - **新增覆盖**: - 类型断言:确保 @torch.jit.script 生成的函数为 torch.jit.ScriptFunction 实例。 - 调试状态:验证在 profiling 模式下两次执行后可获得有效状态对象。 - 序列化闭环:通过 save_to_buffer → load 和 save(file) → load 验证序列化后语义等价。 - **边界适配**:get_debug_state 通过 @unittest.skipIf(GRAPH_EXECUTOR != ProfilingMode.PROFILING, ...) 仅在有 profiling 执行器的环境中运行,避免内部断言错误。 - 新增测试文件 test/jit/test_jit_ScriptFunction.py。 - 实现 4 个测试用例,覆盖 ScriptFunction 类型、调试状态获取、内存序列化与文件序列化。 - 使用条件跳过(@unittest.skipIf)适配不同执行器模式(profiling / simple / legacy)。 - 不依赖外部文件,所有测试可在任意环境运行。 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 root@devserver-fae-mirrors:/home/aicc/wf/api/2.7.1/pytorch/test# python test_jit_ScriptFunction.py .... ---------------------------------------------------------------------- Ran 4 tests in 10.120s OK 覆盖版本: v2.7.1 v2.9.0 v2.10.0 v2.11.0 v2.12.0 master # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35412 | 3 个月前 | |
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 个月前 | |
【inductor】decoupling akg and mlir Co-authored-by: kkjocker<hexuanyu1@huawei.com> # message auto-generated for no-merge-commit merge: !35551 merge master into master 【inductor】decoupling akg and mlir Created-by: kkjocker Commit-by: kkjocker Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> https://gitcode.com/Ascend/pytorch/issues/1962 解耦mlir和akg kernel/scheduling **kernel** SchedulerNode(s) │ ▼ create_fx_from_snodes_by_traced_graph │ ▼ torch.fx.GraphModule (gm) │ ▼ NpuMetaKernel.__init__ │ ▼ codegen_kernel() ├─ scalarize_tensor_ops_on_scalars ├─ FX → MLIR (stateless_fx_import) ├─ run_mlir_pipeline() └─ return Torch IR text ** scheduling** NpuMetaScheduling ┌─────────────────────────────────────────────┐ │ 调度无关逻辑(统一) │ │ │ │ - SchedulerNode[] → FX Graph │ │ - call_args / mutated_indices计算 │ │ - kernel name / hash / cache key │ │ - traced_graph_dump / fallback dump │ │ │ │ ───────────────────────────────────────── │ │ backend 相关逻辑(子类 override) │ │ │ │ - kernel_type │ │ - select_tiling │ │ - _get_kernel_prefix() │ │ - _get_compile_api() │ │ - _handle_default / auto_fallback │ │ - _prepare_kernel_meta │ └─────────────────────────────────────────────┘ 核心修改: 1、AKG和MLIR代码路径拆开,kernel和scheduling都继承NpuMetaKernel和NpuMetaScheduling,Compiler继承MetaCompiler 2、define_kernel统一存下torch ir,后续ir转换在compiler位置进行,以便直接对接精度工具 3、公共操作放至meta_kernel.py和meta_compiler.py,包括自动fallback、去除死节点和运行时参数归一化、非连续tensor处理等操作 # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 - [x] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) # 【资料变更】 > “不涉及” # 【接口变更】 > “不涉及” # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 重构后算子和e2e加速比:  # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35551 | 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 个月前 | |
test: remove test_lr_scheduler_verbose_deprecation_warning Co-authored-by: 21xiu<caixiuxiu1@huawei.com> # message auto-generated for no-merge-commit merge: !35141 merge master into master test: remove test_lr_scheduler_verbose_deprecation_warning 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/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > GPU版本已删除verbose测试,删除用例test_lr_scheduler_verbose_deprecation_warning # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35141 | 3 个月前 | |
[torch_master]修复cann_export中找不到msprof二进制文件日志提示问题 Co-authored-by: yuliangbin<y1416490440@163.com> # message auto-generated for no-merge-commit merge: !34190 merge fix_tid into master [torch_master]修复cann_export中找不到msprof二进制文件日志提示问题 Created-by: yu_liangbin Commit-by: yuliangbin 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/1894 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\ > 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容) 1.使用Profiler解析过程中,如果msprof的二进制文件找不到,当前校验会在os.stat()时抛出异常,如果msprof的二进制文件不存在,后续的权限校验其实无意义,因此权限校验的前提时msprof的二进制文件存在,所以要在权限校验前判断msprof的二进制文件是否存在,存在即校验,反之不校验; 2.cleancode修改 # 【资料变更】 > 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及” 不涉及 # 【接口变更】 > 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及” 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 source CANN包,且把msprof的二进制文件删除, 预期结果:  抛出msprof二进制文件找不到ERROR打屏,而非os.stat的错误 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!34190 | 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 个月前 | |
[feat]TensorTo support preserve_format consistent with GPU Co-authored-by: chenshuai<chenshuai81@huawei.com> # message auto-generated for no-merge-commit merge: !35355 merge cherry-pick-mr-34696-1778549007272-auto into master [feat]TensorTo support preserve_format consistent with GPU Created-by: culechan Commit-by: culechan;chenshuai Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1、NPU上tensorto支持preserve_format模式。行为逻辑上对齐pytorch原生框架 2、增加preserve_format模式相关的测试用例 # 【资料变更】 不涉及,原生API表格中未体现这部分内容 # 【接口变更】 Tensor.to默认使用且支持preserve_format模式 # 【功能验证】   # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35355 | 3 个月前 | |
test: remove test_lr_scheduler_verbose_deprecation_warning Co-authored-by: 21xiu<caixiuxiu1@huawei.com> # message auto-generated for no-merge-commit merge: !35141 merge master into master test: remove test_lr_scheduler_verbose_deprecation_warning 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/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > GPU版本已删除verbose测试,删除用例test_lr_scheduler_verbose_deprecation_warning # 【资料变更】 > 不涉及 # 【接口变更】 > 不涉及 # 【功能验证】 > 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\ > 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35141 | 3 个月前 | |
【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 年前 | ||
Update to v2.13.0 Co-authored-by: Chansinging<1183520536@qq.com> # message auto-generated for no-merge-commit merge: !35159 merge main_sync_20260510 into master Update to v2.13.0 Created-by: chansinging Commit-by: Chansinging Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 - [ ] 需求 - [ ] 问题单 - [x] issue/工单 [版本升级](https://gitcode.com/Ascend/pytorch/issues/1923) - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 社区演进和版本升级 # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】  # 【CheckList】 - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35159 | 3 个月前 | |
| 2 年前 | ||
| 1 年前 | ||
| 1 年前 | ||
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 年前 | ||
[feat]TensorTo support preserve_format consistent with GPU Co-authored-by: chenshuai<chenshuai81@huawei.com> # message auto-generated for no-merge-commit merge: !35355 merge cherry-pick-mr-34696-1778549007272-auto into master [feat]TensorTo support preserve_format consistent with GPU Created-by: culechan Commit-by: culechan;chenshuai Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1、NPU上tensorto支持preserve_format模式。行为逻辑上对齐pytorch原生框架 2、增加preserve_format模式相关的测试用例 # 【资料变更】 不涉及,原生API表格中未体现这部分内容 # 【接口变更】 Tensor.to默认使用且支持preserve_format模式 # 【功能验证】   # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!35355 | 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 个月前 | |
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 个月前 | |
| 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 个月前 | |
| 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 年前 | ||
Added new possible value "platform" for option "host_sys" Co-authored-by: ArisovaAnastasiia<nasaris2406@gmail.com> # message auto-generated for no-merge-commit merge: !33837 merge master into master Added new possible value "platform" for option "host_sys" Created-by: ArisovaAnastasiia Commit-by: ArisovaAnastasiia Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>\ > <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [ ] 问题单 - [ ] issue/工单 https://gitcode.com/Ascend/pytorch/issues/1869 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 > Added new possible valuse for **host-sys** option in ExperimentalConfig: -host-sys=**platform**. This value wil enabled platform analisys. (It is a next future changes) # 【资料变更】 > No changes were made # 【接口变更】 > Added new possible valuse for **host-sys** option in ExperimentalConfig: -host-sys=**platform**. This value wil enabled platform analisys. (It is a next future changes) # 【功能验证】 > Manual testing # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!33837 | 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 用例的功能
该用例是为了校验接口的公开规范性,如果该用例报错,请确认报错的接口是否要公开,并按照报错的提示进行修改。