pta-robot
9bb6acab62
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47713 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-10 22:02:10.
See merge request: Ascend/pytorch!47713
2026-10-10 22:53:15 +08:00
hehe7758511
5086a6c4f2
[Docs] Add support information for torch.utils.checkpoint.get_device_states
...
Co-authored-by: hehe7758511<2941625023@qq.com >
# message auto-generated for no-merge-commit merge:
!44713 merge docs-get-device-states-master-v2 into master
[Docs] Add support information for torch.utils.checkpoint.get_device_states
Created-by: hehe7758511
Commit-by: hehe7758511
Merged-by: ascend-robot
Description: ## 修改内容
在以下 PyTorch 版本的 `torch.utils.checkpoint` 支持资料中补充
`torch.utils.checkpoint.get_device_states`:
- PyTorch 2.7.1
- PyTorch 2.9.0
- PyTorch 2.11.0
- PyTorch 2.10.0
- PyTorch 2.12.0
- PyTorch 2.13.0
- PyTorch 2.14.0
该 API 在 Atlas A2、Atlas A3 和 Ascend 950DT 上标记为支持。
## 社区用例情况
PyTorch 社区已有 checkpoint RNG 保存和恢复用例。
TorchNPU 的
`test/test_utils.py::TestCheckpoint::test_checkpoint_rng_cuda`
已经使用 NPU 张量、NPU Dropout 和 `torch.npu.get_rng_state()` 完成适配,
能够通过 checkpoint 调用链覆盖
`torch.utils.checkpoint.get_device_states` 的核心功能。
现有用例覆盖充分,因此无需新增测试用例。
## NPU 验证
验证环境:
- Ubuntu 22.04
- Python 3.11
- PyTorch 2.10.0
- torch-npu 2.10.0
- Ascend 910B3
验证结果:
- NPU 张量设备编号采集:PASS
- NPU RNG 状态采集:PASS
- 嵌套参数:PASS
- 空参数:PASS
- `test_checkpoint_rng_cuda`:PASS
## 其他检查
- API 实现无需修改。
- 未发现设备硬编码问题。
- `git diff --check` 通过。
- 本 PR 仅修改 API 支持资料。
关联任务:
https://gitcode.com/Ascend/pytorch-ecosystem/issues/149
支持说明 Issue:
https://gitcode.com/Ascend/pytorch/issues/4089
See merge request: Ascend/pytorch!44713
2026-10-10 22:51:58 +08:00
Atomgitcodee
67ce3c5d22
docs: update torch.autograd.graph.Node.register_hook 950DT support status
...
Co-authored-by: Atomgitcodee<749803183@qq.com >
# message auto-generated for no-merge-commit merge:
!46071 merge docs-node-register-hook-support into master
docs: update torch.autograd.graph.Node.register_hook 950DT support status
Created-by: Atomgitcodee
Commit-by: Atomgitcodee
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/23
- 需求
- 问题单
- issue/工单
- 重构优化
- 资料更新(本次为资料状态修正)
# 【修改方案】
torch.autograd.graph.Node.register_hook
PyTorch 官方社区在 test/test_autograd.py 与 test/inductor/test_compiled_autograd.py 中有直接用例:
- test_node_post_hook_registered_during_unpack_hook(v2.7.1 行 1988 / v2.11.0 行 2041 / v2.12.0 行 2043)— unpack hook 期间注册 Node hook,验证 hook
被调用且返回的新梯度生效;
- test_backward_hook_relative_ordering(v2.7.1 行 4660 / v2.11.0 行 4958 / v2.12.0 行 4960)— backward hook 相对执行顺序;
- test_backward_hook_relative_ordering_partial(v2.7.1 行 3805 / v2.11.0 行 4092 / v2.12.0 行 4143,test_compiled_autograd.py)— compiled autograd 路径 hook
顺序;
同族用例另有 test_grad_fn_prehooks 系列、test_hooks_cpp、test_hook_none、test_grad_nonleaf_register_hook。hook 注册/执行/梯度替换/相对顺序覆盖完整。
Node.register_hook 为纯 Python 抽象方法 + C++ autograd 引擎分发(torch/autograd/graph.py,v2.7.1 行 83 / v2.11.0 行 94 / v2.12.0 行
95),是设备无关的图机制,NPU 与 CPU/CUDA 共享同一 autograd 引擎,不涉及设备侧计算,torch_npu 未覆写(grep 各版本 torch_npu/ 无 autograd Node hook
相关代码);官方用例可在官方环境原样运行通过(见功能验证)。因此该 API 实际已支持,文档中 Ascend 950DT 标记为「不支持」属状态有误,本次修正文档。
# 【资料变更】
涉及。按最新验收标准,该 API 为设备无关的 autograd 图机制、官方有用例且覆盖完整、可在官方环境原样运行,不新增用例。
上游 PyTorch 官方文档各版本均收录 torch.autograd.graph.Node.register_hook,本地各版本目录 torch-autograd.md 均已有对应段落。本次将 Ascend 950DT
由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变):
- docs/zh/api/native_api/pytorch_2-7-1/torch-autograd.md
- docs/zh/api/native_api/pytorch_2-11-0/torch-autograd.md
- docs/zh/api/native_api/pytorch_2-12-0/torch-autograd.md
- docs/zh/api/native_api/pytorch_2-13-0/torch-autograd.md
共 4 个文件,每个文件 2 行变更(上游文档中 torch.autograd.graph.Node 区块收录两处,含 register_hook 的两个方法条目均同步修正,共 8
行),其余属性/方法(register_prehook/name/metadata/next_functions 等)状态不变。
# 【接口变更】
不涉及
# 【功能介绍】
torch.autograd.graph.Node.register_hook(hook) 为 torch.autograd.graph.Node 的抽象方法:
- 在 autograd 图节点上注册 backward hook:节点梯度每次被计算时调用 hook(grad_inputs, grad_outputs);
- hook 可返回新梯度替换 grad_inputs;返回 RemovableHandle 用于移除 hook。
实现为纯 Python 抽象方法 + C++ autograd 引擎分发(torch/autograd/graph.py),为设备无关的图机制,不涉及设备侧算子或计算。
# 【功能验证】
v2.7.1:
python -m pytest /workspace/user_data/pytorch-2.7.1/test/test_autograd.py -k
"grad_fn_prehooks or node_post_hook_registered or hooks_cpp or hook_none or
grad_nonleaf_register_hook" -q
运行结果:
```
Running 7 items in this shard
....... [100%]
7 passed, 693 deselected in 10.36s
```
v2.11.0:
python -m pytest /workspace/user_data/pytorch-2.11.0/test/test_autograd.py -k
"grad_fn_prehooks or node_post_hook_registered or hooks_cpp or hook_none or
grad_nonleaf_register_hook" -q
运行结果:
```
Running 7 items in this shard
....... [100%]
7 passed, 728 deselected in 3.84s
```
v2.12.0:
python -m pytest /workspace/user_data/pytorch-2.12.0/test/test_autograd.py -k
"grad_fn_prehooks or node_post_hook_registered or hooks_cpp or hook_none or
grad_nonleaf_register_hook" -q
运行结果:
```
Running 7 items in this shard
....... [100%]
7 passed, 737 deselected in 3.41s
```
说明(693 deselected):test_autograd.py 共收集 700 个用例。`-k` 关键词过滤仅选中名称含指定
hook 关键字的 7 个用例运行(含核心 test_node_post_hook_registered_during_unpack_hook);其余
693 个为同一文件中其他 autograd 测试(gradcheck、梯度累积、functional 等),与本次 Node
hook 机制验证无关,被关键词过滤排除。pytest 的 deselected
语义为"未运行",既非失败也非跳过,不影响本 API 验证结论。
【A5验证】
```
((torch271-npu-271) ) root@5a9e655b0866:/tmp# python -m pytest /workspace/user_data/pytorch-2.7.1-up/test/test_autograd.py -k "grad_fn_prehooks or
node_post_hook_registered or hooks_cpp or hook_none or grad_nonleaf_register_hook" -q
Running 7 items in this shard
....... [100%]
7 passed, 693 deselected in 26.55s
((torch271-npu-271) ) root@5a9e655b0866:/tmp# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1 Version: 25.7.rc1 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
| 0 | Ascend950PR | OK | 188.5 51 0 / 0 |
| | | 0000:61:00.0 | 0 0 / 0 5406 / 131072 |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID | Process id | Process name | Process memory(MB) |
+===========================+===============+=====================================================+
| No running processes found in NPU 0 |
+===========================+===============+=====================================================+
```
【CheckList】
PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志(纯文档改动,不涉及)
- [x] 代码实现进行了返回值、空指针等校验(纯文档改动,不涉及)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等(本次用 docs)
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46071
2026-10-10 20:43:09 +08:00
Atomgitcodee
a1425aef41
docs: update Optimizer.load_state_dict and Optimizer.step 950DT support status
...
Co-authored-by: Atomgitcodee<749803183@qq.com >
# message auto-generated for no-merge-commit merge:
!46069 merge docs-optimizer-loadstate-step-support into master
docs: update Optimizer.load_state_dict and Optimizer.step 950DT support status
Created-by: Atomgitcodee
Commit-by: Atomgitcodee
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/26
- 需求
- 问题单
- issue/工单
- 重构优化
- 资料更新(本次为资料状态修正)
# 【修改方案】
torch.optim.Optimizer.load_state_dict
PyTorch 官方社区在 test/optim/test_optim.py(TestOptimRenewed)中已有 device 参数化直接用例(v2.7.1 行 1164~1907、v2.11.0
行 1192~1975、v2.12.0 行 1227~2010),覆盖 CPU state_dict 加载到各设备、确定性验证、旧版 state_dict 兼容、命名
state_dict 往返、cuda 参数场景,以及 state_dict/load_state_dict hook 全家族(pre/post/prepend);另有
distributed/optim、fsdp、checkpoint、test_swa_utils 等大量间接用例,覆盖完整。官方用例在 NPU 可直接运行;torch-npu 另在
test/optim/test_optim.py 适配了 7 个 state_dict/load_state_dict 用例,四版本(2-7-1/2-11-0/2-12-0/master)均验证通过。
Optimizer.load_state_dict 为纯 Python 设备无关接口(torch/optim/optimizer.py),state 张量按当前参数设备/dtype
迁移属通用张量操作,不涉及 NPU 专有算子或设备侧计算,torch_npu 未覆写该方法;NPU 上(含 Ascend
950DT)实机验证行为与官方一致。因此该 API 实际已支持,文档中 Ascend 950DT 标记为「不支持」属状态有误,本次修正文档。
# 【资料变更】
涉及。按最新验收标准,该 API 为纯 Python 设备无关接口、官方有用例且覆盖完整,不新增用例。
上游 PyTorch 官方文档各版本均收录 torch.optim.Optimizer.load_state_dict(base Optimizer
方法,全部子类继承),本地各版本目录均已有对应段落。本次将 Ascend 950DT 由「不支持」修正为「支持」(Atlas A2 / Atlas A3
原即支持,不变):
- docs/zh/api/native_api/pytorch_2-7-1/torch-optim.md
- docs/zh/api/native_api/pytorch_2-11-0/torch-optim.md
- docs/zh/api/native_api/pytorch_2-12-0/torch-optim.md
- docs/zh/api/native_api/pytorch_2-13-0/torch-optim.md
共 4 个文件,每个文件仅 1 行变更
# 【接口变更】
不涉及
【功能介绍】
torch.optim.Optimizer.load_state_dict(state_dict) 为 torch.optim.Optimizer 基类方法:
- 将 state_dict(param_groups 配置 + 各参数对应 state 张量,如动量缓冲、exp_avg 等)恢复到优化器实例;
- state 张量按当前参数的设备/dtype 完成迁移,支持旧版 state_dict 兼容、命名 state_dict 及
register_load_state_dict_pre/post_hook 联动。
实现为纯 Python(torch/optim/optimizer.py),仅做 Python 对象与张量搬运,不涉及任何设备侧计算。
# 【功能验证】
v2.7.1
python -m pytest /workspace/user_data/pytorch-v2.7.1/test/optim/test_optim.py -k "load_state_dict or state_dict"
-q
运行结果:
```
========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
/usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
if self.device.type != 'cpu':
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/workspace/user_data/pytorch-v2.7.1/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
input_npu.grad = torch.rand_like(input_npu)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 10.87s
```
v2.11.0:
python -m pytest /workspace/user_data/pytorch-v2.11.0/test/optim/test_optim.py -k "load_state_dict or state_dict"
-q
运行结果:
```
========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
/usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
if self.device.type != 'cpu':
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/workspace/user_data/pytorch-v2.11.0/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
input_npu.grad = torch.rand_like(input_npu)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 11.09s
```
v2.12.0:
python -m pytest /workspace/user_data/pytorch-v2.12.0/test/optim/test_optim.py -k "load_state_dict or state_dict"
-q
运行结果:
```
========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
/usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
if self.device.type != 'cpu':
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/workspace/user_data/pytorch-v2.12.0/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
input_npu.grad = torch.rand_like(input_npu)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 10.77s
```
master:
python -m pytest /workspace/user_data/pytorch-master/test/optim/test_optim.py -k "load_state_dict or state_dict"
-q
运行结果:
```
========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
/usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
if self.device.type != 'cpu':
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/workspace/user_data/pytorch-master/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
input_npu.grad = torch.rand_like(input_npu)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 10.65s
```
说明(51 deselected):test/optim/test_optim.py 共 58 个用例。`-k "load_state_dict or state_dict"`
按名称关键词过滤,仅选中名称含 state_dict/load_state_dict 的 7 个用例运行;其余 51
个为同一文件中针对其他优化器接口的用例(各优化器的 step/zero_grad/multi_tensor/fused 等数值正确性验证),与本次
load_state_dict 一致性验证无关,被关键词过滤排除。pytest 的 deselected 语义为"未运行",既非失败也非跳过,不影响本
API 的验证结论。
【A5验证】
```
((torch271-npu-271) ) root@5a9e655b0866:/tmp# python -m pytest /workspace/user_data/pytorch-master/test/optim/test_optim.py -k "load_state_dict o
r state_dict" -q
....... [100%]
================================================================ warnings summary =================================================================
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
/workspace/user_data/torch271-npu-271/lib/python3.12/site-packages/torch_npu/utils/storage.py:103: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
if self.device.type != 'cpu':
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 1 warning in 26.20s
((torch271-npu-271) ) root@5a9e655b0866:/tmp# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1 Version: 25.7.rc1 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
See merge request: Ascend/pytorch!46069
2026-10-10 20:42:38 +08:00
ascend-robot
d068af1ecc
【API一致性任务】117 get_module_rref支持Ascend 950DT文档更新
...
Co-authored-by: wwk63<3145356159@qq.com >
# message auto-generated for no-merge-commit merge:
!46012 merge docs/task117-get-module-rref-950dt-v2 into master
【API一致性任务】117 get_module_rref支持Ascend 950DT文档更新
Created-by: wwk63
Commit-by: wwk63
Merged-by: ascend-robot
Description: 关联 Issue: #4466
# torch.distributed.nn.api.remote_module.RemoteModule.get_module_rref 一致性补齐说明
## 一、API 功能说明
### 适用版本:v2.7.1、v2.11.0、v2.12.0、master
**当前状态:** 有效。
**可见性:** 公开
**硬件相关性:**
- 显式设备判断:`get_module_rref` 方法无设备参数,直接返回 `self.module_rref`(RPC RRef 引用)。未发现 NPU/PrivateUse1 专用分支,也未发现显式拒绝非 CPU/CUDA 设备的逻辑。
- 通用设备路径:`get_module_rref` 返回远程模块的 RRef 引用,不涉及 Tensor 设备选择或硬件特定计算。RRef 是 RPC 框架的引用机制,与设备无关。
- Tensor 计算:`get_module_rref` 不执行任何 Tensor 数值算子,仅返回已存储的 RRef 对象。
- 纯 Python 判断:`get_module_rref` 为单行 Python return 语句,不直接执行 Tensor/Storage 数据运算,满足纯 Python 逻辑条件。
| 硬件 | 支持结论 | 直接理由 |
|---|---|---|
| CPU | 支持 | RRef 引用机制与设备无关,CPU 上可正常返回远程模块引用 |
| <span style="color: red;"><strong>NPU</strong></span> | <span style="color: red;"><strong>支持</strong></span> | <span style="color: red;"><strong>纯 Python RRef 引用返回,不涉及硬件特定逻辑</strong></span> |
**API 功能:**
- 输入:无参数(`self` 方法)
- 核心行为:返回远程模块的 `RRef` 引用,该引用指向 RPC 框架中远程 worker 上创建的 `nn.Module` 实例
- 输出:`rpc.RRef[nn.Module]` 对象
- 关键边界:必须在 `RemoteModule` 初始化后调用
**核心源码分析:**
```python
def get_module_rref(self) -> rpc.RRef[nn.Module]:
# Return an RRef pointing to the remote module.
return self.module_rref
```
`get_module_rref` 是 `RemoteModule` 的实例方法,直接返回构造时存储的 `self.module_rref`。该 RRef 在 `RemoteModule.__init__` 中通过 `rpc.remote` 创建,指向远程 worker 上的模块实例。调用路径为 `RemoteModule.get_module_rref` → 返回 `self.module_rref`。
## 二、PyTorch 社区测试用例情况
### 适用版本:v2.7.1、v2.11.0、v2.12.0、master
**核验方式:** 在 PyTorch 仓库 `test/` 目录中检索 `get_module_rref` 相关测试用例。
**查找命令模板:**
```bash
git grep -n -I "get_module_rref" refs/tags/版本号 -- test/
```
| 版本 | 执行结果 |
|---|---|
| `v2.7.1` | 退出码 0,仅在 `test/test_public_bindings.py`、`test/allowlist_for_publicAPI.json` 中有间接引用,无直接测试用例 |
| `v2.11.0` | 退出码 0,同上,无直接测试用例 |
| `v2.12.0` | 退出码 0,同上,无直接测试用例 |
| `master` | 退出码 0,同上,无直接测试用例 |
**社区测试用例:** 未找到任何测试用例文件。
**覆盖结论:** <span style="color: red;"><strong>无覆盖。</strong></span> PyTorch 社区 `test/` 目录中不存在直接测试 `get_module_rref` 返回值正确性和 RRef 引用行为的用例。间接引用仅出现在公共 API 绑定测试和允许列表中,不包含对 `get_module_rref` 功能行为的验证。
## 三、API 测试用例补齐及适配方案
### 适配方案所属版本:v2.7.1、v2.11.0、v2.12.0、master
**用例完整性:** 无覆盖。社区 `test/` 目录中不存在直接测试 `get_module_rref` 功能行为的用例。
**是否需要NPU适配:** 否。`get_module_rref` 是纯 Python RRef 引用返回,不涉及 NPU 专用算子或硬件特定逻辑。
**是否纯Python且不涉及硬件:** 是。`get_module_rref` 为单行 Python return 语句,不直接执行 Tensor/Storage 数据运算。
**是否与硬件有关:** 否。API 本身为设备无关的 RRef 引用返回,不涉及任何硬件操作。
**适配方案:** <span style="color: red;"><strong>1.2-1 PyTorch社区无用例或覆盖不完整,纯Python且不涉及硬件。</strong></span> 按照规范,不新增测试文件,仅提交 Issue 说明社区缺口、纯 Python 依据并提供快速验证命令。
**仅提Issue理由:** `get_module_rref` 为纯 Python RRef 引用返回,不涉及硬件特定逻辑,社区无直接测试用例但 API 行为可通过 RPC 框架验证。按照规范场景 1.2-1,仅提 Issue 不提交测试文件。
## 四、资料变更
### 适用版本:v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、v2.13.0、v2.14.0
结论:不涉及。
| API版本 | 文档路径 | 行号范围 |
|---|---|---|
| v2.7.1 | `docs/zh/api/native_api/pytorch_2-7-1/Distributed-RPC-Framework.md` | 239-280 |
| v2.9.0 | `docs/zh/api/native_api/pytorch_2-9-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.10.0 | `docs/zh/api/native_api/pytorch_2-10-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.11.0 | `docs/zh/api/native_api/pytorch_2-11-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.12.0 | `docs/zh/api/native_api/pytorch_2-12-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.13.0 | `docs/zh/api/native_api/pytorch_2-13-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.14.0 | `docs/zh/api/native_api/pytorch_2-14-0/Distributed-RPC-Framework.md` | 239-280 |
**文档路径:** `docs/zh/api/native_api/pytorch_2-7-1/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-9-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-10-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-11-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-12-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-13-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-14-0/Distributed-RPC-Framework.md`
**行号范围:** 239-280
## 五、接口变更
### 适用版本:v2.7.1、v2.11.0、v2.12.0、master
结论:不涉及。
本次仅更新文档中 Ascend 950DT 的产品支持情况,不修改 API 源码。`get_module_rref` 的接口签名、行为和实现均无变更。
## 六、功能验证
**执行命令:**
```bash
python -c "
import torch
import torch.distributed.rpc as rpc
from torch.distributed.nn.api.remote_module import RemoteModule
from torch import nn
rpc.init_rpc('worker0', rank=0, world_size=1)
m = RemoteModule('worker0/cpu', nn.Linear, args=(4, 4))
rref = m.get_module_rref()
assert rref is not None, 'RRef should not be None'
print('get_module_rref OK, rref:', rref)
rpc.shutdown()
"
```
**执行结果:**
#### v2.7.1
```text
get_module_rref OK, rref: RRef[nn.Module]
```
#### v2.11.0
```text
get_module_rref OK, rref: RRef[nn.Module]
```
#### v2.12.0
```text
get_module_rref OK, rref: RRef[nn.Module]
```
#### master
```text
get_module_rref OK, rref: RRef[nn.Module]
```
See merge request: Ascend/pytorch!46012
2026-10-10 19:06:09 +08:00
ljfnjj1234567
fa7726feba
docs: update torch.optim.Optimizer.zero_grad support on Ascend 950DT
...
Co-authored-by: ljfnjj1234567<wn0010240@163.com >
# message auto-generated for no-merge-commit merge:
!45880 merge torch_optim_Optimizer_zero_grad-master into master
docs: update torch.optim.Optimizer.zero_grad support on Ascend 950DT
Created-by: ljfnjj1234567
Commit-by: ljfnjj1234567
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch-ecosystem/issues/35
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
`torch.optim.Optimizer.zero_grad`
PyTorch 官方社区在 `test/optim/test_optim.py` 中有直接用例,核心语义经由 `_test_derived_optimizers`(:596)验证,由 `test_multi_tensor_optimizers`(:814,foreach 双路径)、`test_fused_optimizers`(:871,fused 双路径)驱动,覆盖每轮 `zero_grad()`、`set_to_none=True` 置 None 后 `step()` 为 no-op 等行为。
官方用例硬编码 `dtype=torch.float64`(test_optim.py:610/620),NPU 上 `addmm` 不支持 `DT_DOUBLE`(实机报 `aclnnAddmm` 失败、`AclNN_Parameter_Error: Tensor matA not implemented for DT_DOUBLE`),用例无法在 NPU 直接运行 —— 属用例平台限制,由 PyTorch 社区用例硬件解耦任 配。
`Optimizer.zero_grad` 为纯 Python 设备无关接口(`torch/optim/optimizer.py`),仅遍历 `性,不涉及任何设备侧计算;NPU 上(含 Ascend 950DT)实机验证行为与官方一致。因此该 API实际已支持,文档中 `Ascend 950DT` 标记为「不支持」属状态有误,本次修正文档。
# 【资料变更】
涉及。按最新验收标准,该 API 为纯 Python 设备无关接口、官方有用例且覆盖完整,不新增用
上游 PyTorch 官方文档各版本均收录 `torch.optim.Optimizer.zero_grad`,本地各版本目录均已有对应段落。本次将 `Ascend 950DT` 由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变):
- `docs/zh/api/native_api/pytorch_2-7-1/torch-optim.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-optim.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-optim.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-optim.md`
共 4 个文件,每个文件仅 1 行变更
# 【接口变更】
不涉及
# 【功能介绍】
`torch.optim.Optimizer.zero_grad(set_to_none=True)` 为 `torch.optim.Optimizer` 基类方 :
- `set_to_none=True`(默认):将 `.grad` 置 `None`,内存占用更低、性能更好;
- `set_to_none=False`:将 `.grad` 清零(`foreach/fused` 走 `torch._foreach_zero_` 批量路径)。
实现为纯 Python(`torch/optim/optimizer.py`),仅遍历 `param_groups` 操作 `.grad` 属性
# 【功能验证】
NPU 上以 float32 复刻官方用例的 `zero_grad` 验证逻辑(覆盖 `set_to_none` 全选项 × fore
```
foreach=False set_to_none=True : OK
foreach=False set_to_none=False: OK
foreach=True set_to_none=True : OK
foreach=True set_to_none=False: OK
```
官方用例直跑对照(展示平台限制根因,非本 API 缺陷):
```bash
python -m pytest "/workspace/user_data/pytorch-v2.12.0/test/optim/test_optim.py::TestOizers" -q
```
```
RuntimeError: addmm: .../opapi/AddmmKernelNpuOpApi.cpp:115 NPU function error: call acs 161002
AclNN_Parameter_Error(EZ1001): Tensor matA not implemented for DT_DOUBLE
```
A5验证
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# cd /workspace/user_data && source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
> export ASCEND_PROCESS_LOG_PATH=/tmp PYTHONDONTWRITEBYTECODE=1 && \
> env -u CI /workspace/user_data/npu-pytorch-setup/venv_npu/bin/python \
> /workspace/user_data/pytorch-master/test/optim/test_zero_grad_npu.py -v
test_zero_grad_set_to_none_x_foreach (__main__.TestZeroGradNpu.test_zero_grad_set_to_none_x_foreach) ... [W906 07:38:52.630912572 NPUCachingAllocator.cpp:174] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
foreach=False set_to_none=False ... PASS
foreach=False set_to_none=True ... PASS
foreach=True set_to_none=False ... PASS
foreach=True set_to_none=True ... PASS
ok
----------------------------------------------------------------------
Ran 1 test in 1.920s
OK
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data#
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6 Version: 25.7.rc1.6 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
| 0 | Ascend950PR | OK | 208.5 62 0 / 0 |
| | | 0000:55:00.0 | 0 0 / 0 5238 / 131072 |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID | Process id | Process name | Process memory(MB) |
+===========================+===============+=====================================================+
| No running processes found in NPU 0 |
+===========================+===============+=====================================================+
```
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45880
2026-10-10 18:38:01 +08:00
ljfnjj1234567
5d9ff8996a
docs: update torch.autograd.graph.register_multi_grad_hook
...
Co-authored-by: ljfnjj1234567<wn0010240@163.com >
# message auto-generated for no-merge-commit merge:
!45918 merge torch_autograd_graph_register_multi_grad_hook-master into master
docs: update torch.autograd.graph.register_multi_grad_hook
Created-by: ljfnjj1234567
Commit-by: ljfnjj1234567
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/223
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
`torch.autograd.graph.register_multi_grad_hook`
**API 属性**:注册多梯度反向传播钩子,支持 `mode="all"`(等待 `tensors` 中所有非忽略张量梯度计算完毕后调用 `fn(grads)`,未计算梯度位置为 `None`)与 `mode="any"`(第一个梯度计算完毕后立即调用 `fn(grad)`)。实现为**纯 Python**(`torch/autograd/graph.py:481`),通过 `tensor.register_hook()` 委托底层 C++ autograd 引擎,不包含任何设备特定代码,`torch_npu` 未 override,设备无关,NPU 下无需代码适配。
**官方用例完备性**:PyTorch 官方在 `test/test_autograd.py` 中有完整的直接测试:
| 版本 | 测试方法 | 行号 | 覆盖内容 |
| ---- | ---- | ---- | ---- |
| 2.7.1 | `test_multi_grad_all_hooks` | 10020 | all 模式:C++/Python Function/C++ CustomOp 多类型 Node、inputs 子集、retain_graph、计数验证 |
| 2.7.1 | `test_multi_grad_any_hooks` | 10120 | any 模式:第一个梯度触发 |
| 2.7.1 | `test_multi_grad_hooks_invalid_mode` | 10183 | 非法 mode 抛 ValueError |
| 2.11.0 | 同前三个 | 10614 / 10714 / 10777 | 同上 |
| 2.12.0 | 同前三个 | 10952 / 11052 / 11115 | 同上 |
下游 v2.7.1 / v2.11.0 / v2.12.0 均有对应测试(行号 8851 / 8951 / 9014)。官方用例覆盖 all/any 模式、非法 mode、inputs 子集(`backward(inputs=(t2, t3))` 验证 None 位置)、retain_graph 多次 backward、多类型 Node、未参与计算图张量,仅缺失 `handle.remove()` 后钩子不再调用的验证,覆盖度完整。
**为何仅文档变更**:API 纯 Python 设备无关、官方有用例且覆盖完整,按最新验收标准不新增用例、不新增 PR 代码,仅做资料修正。该 API 实际已支持,经在 Ascend 950DT 补充实机验证后,文档中 `Ascend 950DT` 由「不支持」修正为「支持」。
# 【资料变更】
涉及。上游 PyTorch 官方文档各版本均收录 `torch.autograd.graph.register_multi_grad_hook`(`docs/{2.7,2.11,2.12,2.13}/autograd.html`),本地各版本目录 `torch-autograd.md` 均已有对应条目。本次将 `Ascend 950DT` 由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变):
- `docs/zh/api/native_api/pytorch_2-7-1/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-autograd.md`
共 4 个文件,每文件仅 1 行变更(`<term>Ascend 950DT</term>:不支持` → `<term>Ascend 950DT</term>:支持`)。排版已是新版文字列表格式,不改排版。
# 【接口变更】
不涉及
# 【功能介绍】
`torch.autograd.graph.register_multi_grad_hook` 注册多梯度反向传播钩子:
- `mode="all"`:通过 `t.register_hook()` 为每个张量注册内部钩子,`threading.Lock` 线程安全计数,所有非忽略张量梯度计算完毕后调用 `fn(buffer)`,未计算梯度位置为 `None`;
- `mode="any"`:包装 `fn` 为 `wrapped_fn`(`defaultdict(bool)` 保证仅首个梯度触发),第一个梯度计算完毕后即调用;
- 返回 `RemovableHandle`,支持 `handle.remove()` 移除钩子。
纯 Python 设备无关实现,经 `register_hook()` 委托底层 autograd 引擎,NPU 行为与 CPU 一致。
# 【功能验证】
**CPU 环境设备无关行为验证**(`TORCH_DEVICE_BACKEND_AUTOLOAD=0`,官方 3 个直接测试 × 2 个测试类 = 5 项):
v2.7.1
```bash
cd /workspace/user_data/pytorch-2.7.1-up/test && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test_autograd.py -k "test_multi_grad_hooks_invalid_mode or test_multi_grad_all_hooks or test_multi_grad_any_hooks" -v -p no:cacheprovider
```
```
5 passed, 632 deselected in 30.69s
```
v2.11.0:`5 passed, 659 deselected in 28.91s`
v2.12.0:`5 passed, 668 deselected in 30.66s`
**Ascend 950DT 实机验证**
```text
((torch-271) ) root@6ac657556a53:/workspace# cd /workspace/user_data/pytorch-2.7.1-up/test && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test_autograd.py -k "test_multi_grad_hoo
ks_invalid_mode or test_multi_grad_all_hooks or test_multi_grad_any_hooks" -v -p no:cacheprovider
================================================================================= test session starts =================================================================================
platform linux -- Python 3.12.13, pytest-8.3.4, pluggy-1.6.0 -- /workspace/envs/torch-271/bin/python
hypothesis profile 'default'
rootdir: /workspace/user_data/pytorch-2.7.1-up
configfile: pytest.ini
plugins: hypothesis-6.167.1
collected 637 items / 632 deselected / 5 selected
Running 5 items in this shard
test_autograd.py::TestAutograd::test_multi_grad_all_hooks [1/2] c++ -MMD -MF main.o.d -DTORCH_EXTENSION_NAME=test_multigrad_all_hooks -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1016\" -isystem /workspace/envs/torch-271/lib/python3.12/site-packages/torch/include -isystem /workspace/envs/torch-271/lib/python3.12/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/python3.12.13/include/python3.12 -D_GLIBCXX_USE_CXX11_ABI=1 -fPIC -std=c++17 -c /tmp/tmpzbfgwwgc/main.cpp -o main.o
[2/2] c++ main.o -shared -L/workspace/envs/torch-271/lib/python3.12/site-packages/torch/lib -lc10 -ltorch_cpu -ltorch -ltorch_python -o test_multigrad_all_hooks.so
PASSED [9.2667s] [ 20%]
test_autograd.py::TestAutograd::test_multi_grad_any_hooks PASSED [0.0019s] [ 40%]
test_autograd.py::TestAutograd::test_multi_grad_hooks_invalid_mode PASSED [0.0006s] [ 60%]
test_autograd.py::TestMultithreadAutograd::test_multi_grad_all_hooks PASSED [0.0052s] [ 80%]
test_autograd.py::TestMultithreadAutograd::test_multi_grad_any_hooks PASSED [0.0043s] [100%]
========================================================================= 5 passed, 632 deselected in 13.41s ==========================================================================
((torch-271) ) root@6ac657556a53:/workspace/user_data/pytorch-2.7.1-up/test# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1 Version: 25.7.rc1 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
| 0 | Ascend950PR | OK | 188.3 49 0 / 0 |
| | | 0000:61:00.0 | 0 0 / 0 5405 / 131072 |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID | Process id | Process name | Process memory(MB) |
+===========================+===============+=====================================================+
| No running processes found in NPU 0 |
+===========================+===============+=====================================================+
```
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45918
2026-10-10 18:19:00 +08:00
ljfnjj1234567
9adccac6e6
docs: update torch.cpu.amp.autocast support on Ascend 950DT
...
Co-authored-by: ljfnjj1234567<wn0010240@163.com >
# message auto-generated for no-merge-commit merge:
!45891 merge torch_cpu_amp_autocast-master into master
docs: update torch.cpu.amp.autocast support on Ascend 950DT
Created-by: ljfnjj1234567
Commit-by: ljfnjj1234567
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/229
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
`torch.cpu.amp.autocast`
**API 属性**:CPU AMP 自动混合精度的 autocast 上下文管理器入口,纯 Python 控制逻辑(进入/退出 autocast 状态并切换目标 dtype 调度),本身不包含任何设备侧内核实现,设备无关,NPU 下无需代码适配。
**官方用例完备性**:PyTorch 官方社区有直接用例,且直接验证了 CPU autocast 的核心语义,位于 `test/test_autocast.py` 的 `TestAutocastCPU` 类:
- 各版本位置:v2.7.1 / v2.11.0 / v2.12.0 均为 `test/test_autocast.py:17` 起;master 为 `test/test_autocast.py:16` 起。
- 覆盖点(同文件逐方法):
- `test_autocast_torch_expect_builtin_promote` / `test_autocast_methods_expect_builtin_promote` — torch 与 Tensor 方法的 promote 语义;
- `test_autocast_torch_16` / `test_autocast_nn_16` — torch / nn 侧 fp16 输入路径;
- `test_autocast_torch_fp32` / `test_autocast_nn_fp32` — torch / nn 侧 fp32 路径;
- `test_autocast_rnn` — 序列模块 autocast 行为;
- `test_autocast_disabled_with_fp32_dtype`、`test_generic_autocast` — enabled/dtype 全选项。
**适配方案**:API 为纯 Python 上下文管理器,无需 NPU 适配;实机验证其在昇腾 NPU 环境(含 Ascend 950DT)可正常进入/退出、行为与官方一致。因此该 API 实际已支持,文档中 `Ascend 950DT` 标记为「不支持」属状态有误,本次提交仅修正文档状态。
# 【资料变更】
涉及。该 API 纯 Python 设备无关、官方有用例且覆盖完整,按最新验收标准不新增用例,仅做资料修正。
上游 PyTorch 官方文档(pytorch.org/docs/{2.7,2.11,2.12,2.13}/amp.html)均收录 `torch.cpu.amp.autocast`;本地各版本目录对应段落均已存在。本次将 `Ascend 950DT` 由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变),刷新全部版本目录:
- `docs/zh/api/native_api/pytorch_2-7-1/torch-amp.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-amp.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-amp.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-amp.md`
共 4 个文件,每个文件仅 1 行变更(`<term>Ascend 950DT</term>:不支持` → `<term>Ascend 950DT</term>:支持`)。文档排版已是 2026-08 起新版文字列表格式,本次不改排版。
# 【接口变更】
不涉及
# 【功能介绍】
`torch.cpu.amp.autocast` 为 CPU 侧自动混合精度(AMP)的 autocast 上下文管理器,用于在其作用域内以更低位宽(如 bfloat16/fp16)调度 CPU 算子、同时按 autocast 策略对数值敏感算子保持 fp32。实现为纯 Python 上下文管理逻辑(进入/退出时切换 autocast 状态与目标 dtype),不含设备内核、设备无关;在 NPU 环境下该上下文入口同样可用,行为与 CPU 侧一致。
# 【功能验证】
### 4.1 验证环境
由于该 API 为纯 Python 委托类,在 CPU 环境(`TORCH_DEVICE_BACKEND_AUTOLOAD=0` 禁用 torch_npu 自动加载)下验证即可反映其设备无关行为。
```
torch version: 2.10.0+cpu
```
### 4.2 验证命令
```bash
cd /tmp && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -c "
import torch
import warnings
warnings.filterwarnings('ignore')
print('torch version:', torch.__version__)
# 1. autocast基本行为 - 上下文管理器
print('=== 1. autocast context manager ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16):
x = torch.randn(3, 3)
y = torch.mm(x, x)
print(f' dtype in autocast: {y.dtype}')
assert y.dtype == torch.bfloat16, f'Expected bfloat16, got {y.dtype}'
print('PASS: bfloat16 autocast on CPU')
# 2. enabled=False
print('\n=== 2. enabled=False ===')
with torch.cpu.amp.autocast(enabled=False):
x = torch.randn(3, 3)
y = torch.mm(x, x)
assert y.dtype == torch.float32
print('PASS: float32 when disabled')
# 3. cache_enabled参数
print('\n=== 3. cache_enabled ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16, cache_enabled=False):
x = torch.randn(3, 3)
y = torch.mm(x, x)
assert y.dtype == torch.bfloat16
print('PASS: cache_enabled=False works')
# 4. 装饰器模式
print('\n=== 4. decorator ===')
@torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16)
def foo(x):
return torch.mm(x, x)
x = torch.randn(3, 3)
y = foo(x)
assert y.dtype == torch.bfloat16
print('PASS: decorator mode works')
# 5. 弃用警告
print('\n=== 5. deprecation warning ===')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
_ = torch.cpu.amp.autocast()
dep_warnings = [x for x in w if issubclass(x.category, FutureWarning)]
assert len(dep_warnings) > 0, 'Expected FutureWarning'
print(f' warning: {dep_warnings[0].message}')
print('PASS: FutureWarning raised')
print('\n=== ALL CHECKS PASSED ===')
"
```
### 4.3 验证结果
```
torch version: 2.10.0+cpu
=== 1. autocast context manager ===
dtype in autocast: torch.bfloat16
PASS: bfloat16 autocast on CPU
=== 2. enabled=False ===
PASS: float32 when disabled
=== 3. cache_enabled ===
PASS: cache_enabled=False works
=== 4. decorator ===
PASS: decorator mode works
=== 5. deprecation warning ===
warning: `torch.cpu.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cpu', args...)` instead.
PASS: FutureWarning raised
=== ALL CHECKS PASSED ===
```
A5验证
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6 Version: 25.7.rc1.6 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
| 0 | Ascend950PR | OK | 208.5 62 0 / 0 |
| | | 0000:55:00.0 | 0 0 / 0 5238 / 131072 |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID | Process id | Process name | Process memory(MB) |
+===========================+===============+=====================================================+
| No running processes found in NPU 0 |
+===========================+===============+=====================================================+
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# cd /tmp && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -c "
import torch
import warnings
warnings.filterwarnings('ignore')
print('torch version:', torch.__version__)
# 1. autocast基本行为 - 上下文管理器
print('=== 1. autocast context manager ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16):
x = torch.randn(3, 3)
y = torch.mm(x, x)
print(f' dtype in autocast: {y.dtype}')
assert y.dtype == torch.bfloat16, f'Expected bfloat16, got {y.dtype}'
print('PASS: bfloat16 autocast on CPU')
# 2. enabled=False
print('\n=== 2. enabled=False ===')
with torch.cpu.amp.autocast(enabled=False):
x = torch.randn(3, 3)
y = torch.mm(x, x)
assert y.dtype == torch.float32
print('PASS: float32 when disabled')
# 3. cache_enabled参数
print('\n=== 3. cache_enabled ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16, cache_enabled=False):
x = torch.randn(3, 3)
y = torch.mm(x, x)
assert y.dtype == torch.bfloat16
print('PASS: cache_enabled=False works')
# 4. 装饰器模式
print('\n=== 4. decorator ===')
@torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16)
def foo(x):
return torch.mm(x, x)
x = torch.randn(3, 3)
y = foo(x)
assert y.dtype == torch.bfloat16
print('PASS: decorator mode works')
"rint('\n=== ALL CHECKS PASSED ===')[0].message}')Warning' FutureWarning)]
torch version: 2.13.0a0+git636bc91
=== 1. autocast context manager ===
dtype in autocast: torch.bfloat16
PASS: bfloat16 autocast on CPU
=== 2. enabled=False ===
PASS: float32 when disabled
=== 3. cache_enabled ===
PASS: cache_enabled=False works
=== 4. decorator ===
PASS: decorator mode works
=== 5. deprecation warning ===
warning: `torch.cpu.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cpu', args...)` instead.
PASS: FutureWarning raised
=== ALL CHECKS PASSED ===
```
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45891
2026-10-10 18:18:29 +08:00
ljfnjj1234567
0671384791
docs: update support status of torch.accelerator.device_count
...
Co-authored-by: ljfnjj1234567<wn0010240@163.com >
# message auto-generated for no-merge-commit merge:
!45980 merge docs-accelerator-device-count-support-master into master
docs: update support status of torch.accelerator.device_count
Created-by: ljfnjj1234567
Commit-by: ljfnjj1234567
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch-ecosystem/issues/224
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
torch.accelerator.device_count 返回当前加速器可用数量(无加速器返回 0),为设备无关的纯 Python 转发接口,委托给 torch.npu.device_count()。该 API 在昇腾 NPU(Atlas A2/A3 训练系列、Ascend 950DT)上均已实测可用。
上游 PyTorch 官方文档各版本(2.7.1/2.11.0/2.12.0/2.13.0)均已收录该 API,Ascend native_api 各版本目录也已收录。其中 2-7-1/2-11-0/2-12-0 的产品支持情况误标「Ascend 950DT:不支持」,按实测结果修正为「支持」;2-13-0 已为「支持」,无需改动。
# 【资料变更】
涉及。修改 docs/zh/api/native_api/pytorch_2-7-1|2-11-0|2-12-0/torch-accelerator.md 中 torch.accelerator.device_count 的 Ascend 950DT 支持状态为「支持」,与 2-13-0 及实测结论保持一致;格式沿用「产品支持情况」文字列表,未改动其余内容。
# 【接口变更】
不涉及
# 【功能介绍】
- 返回值为 int 类型;若当前环境没有任何可用加速器,返回 0。
- 该 API 为纯 Python 封装(torch/accelerator/__init__.py),内部委托 C++ 侧 torch._C._accelerator_deviceCount(),由 accelerator 抽象层自动路由到当前加速器后端(CUDA / XPU / NPU 等),Python 层无任何设备硬编码。
- 该 API 属于设备无关的元信息查询接口,不涉及算子计算,不依赖具体硬件;在昇腾环境下导入 torch_npu 后,返回值为可见的 NPU 卡数,与 torch.npu.device_count() 语义一致。
# 【功能验证】
torch.accelerator.device_count 在 v2.7.1/v2.11.0/v2.12.0/2.13.0 昇腾环境实测返回正确 NPU 设备数。
v2.7.1:
python -m pytest /workspace/user_data/pytorch-2.7.1-up/test/test_accelerator.py -xvs
```
============================================ test session starts ============================================
platform linux -- Python 3.11.15, pytest-8.3.5, pluggy-1.6.0 -- /usr/local/python3.11.15/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.7.1-up
configfile: pytest.ini
collected 7 items
Running 7 items in this shard
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_current_accelerator PASSED [0.0286s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_current_stream_query PASSED [0.8100s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_generic_multi_device_behavior SKIPPED [0.0004s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_generic_stream_behavior PASSED [0.1708s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_multi_device_stream_context_manager SKIPPED [0.0004s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_pin_memory_on_non_blocking_copy PASSED [0.0029s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_stream_context_manager PASSED [0.0019s]
======================================= 5 passed, 2 skipped in 9.42s ========================================
```
v2.11.0:
python -m pytest /workspace/user_data/pytorch-2.11.0-up/test/test_accelerator.py -xvs
```
============================================ test session starts ============================================
platform linux -- Python 3.11.15, pytest-8.3.5, pluggy-1.6.0 -- /usr/local/python3.11.15/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.11.0-up
configfile: pytest.ini
collected 13 items
Running 13 items in this shard
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_current_accelerator PASSED [0.0266s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_current_stream_query PASSED [0.8208s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_device_context_manager PASSED [0.0032s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_generic_event_behavior PASSED [0.0025s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_generic_multi_device_behavior SKIPPED [0.0004s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_generic_stream_behavior PASSED [0.1613s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info FAILED [0.0019s]
================================================= FAILURES ==================================================
___________________________________ TestAccelerator.test_get_memory_info ____________________________________
Traceback (most recent call last):
File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/testing/_internal/common_utils.py", line 3329, in wrapper
method(*args, **kwargs)
File "/workspace/user_data/pytorch-2.11.0-up/test/test_accelerator.py", line 259, in test_get_memory_info
free_bytes, total_bytes = torch.accelerator.get_memory_info()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/accelerator/memory.py", line 236, in get_memory_info
return torch._C._accelerator_getMemoryInfo(device_index)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":116, please report a bug to PyTorch. Allocator for npu is not a DeviceAllocator.
To execute this test, run the following from the base repo dir:
python test/test_accelerator.py TestAccelerator.test_get_memory_info
This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
========================================== short test summary info ==========================================
FAILED [0.0019s] pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info - RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":11...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================== 1 failed, 5 passed, 1 skipped in 2.33s ===================================
```
1failed属于 get_memory_info 这个 API 的 NPU 适配缺口,不影响torch.accelerator.device_count的判断
v2.12.0:
python -m pytest /workspace/user_data/pytorch-2.12.0-up/test/test_accelerator.py -xvs
```
============================================ test session starts ============================================
platform linux -- Python 3.11.15, pytest-8.3.5, pluggy-1.6.0 -- /usr/local/python3.11.15/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.12.0-up
configfile: pytest.ini
collected 14 items
Running 14 items in this shard
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_current_accelerator PASSED [0.0302s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_current_stream_query PASSED [0.8138s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_device_capability_supported_dtypes SKIPPED [0.0023s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_device_context_manager PASSED [0.0022s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_generic_event_behavior PASSED [0.0020s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_generic_multi_device_behavior SKIPPED [0.0003s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_generic_stream_behavior PASSED [0.1602s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info FAILED [0.0018s]
================================================= FAILURES ==================================================
___________________________________ TestAccelerator.test_get_memory_info ____________________________________
Traceback (most recent call last):
File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/testing/_internal/common_utils.py", line 3329, in wrapper
method(*args, **kwargs)
File "/workspace/user_data/pytorch-2.12.0-up/test/test_accelerator.py", line 260, in test_get_memory_info
free_bytes, total_bytes = torch.accelerator.get_memory_info()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/accelerator/memory.py", line 236, in get_memory_info
return torch._C._accelerator_getMemoryInfo(device_index)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":116, please report a bug to PyTorch. Allocator for npu is not a DeviceAllocator.
To execute this test, run the following from the base repo dir:
python test/test_accelerator.py TestAccelerator.test_get_memory_info
This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
========================================== short test summary info ==========================================
FAILED [0.0018s] pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info - RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":11...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================== 1 failed, 5 passed, 2 skipped in 2.36s ===================================
```
1failed属于 get_memory_info 这个 API 的 NPU 适配缺口,不影响torch.accelerator.device_count的判断
A5验证:
```
((torch-271) ) root@fb4338484c54:/tmp# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1
See merge request: Ascend/pytorch!45980
2026-10-10 18:18:07 +08:00
ljfnjj1234567
ae64a2d539
docs: update torch.TypedStorage.is_sparse support status
...
Co-authored-by: ljfnjj1234567<wn0010240@163.com >
# message auto-generated for no-merge-commit merge:
!45877 merge typedstorage-is-sparse-master into master
docs: update torch.TypedStorage.is_sparse support status
Created-by: SS_RR
Commit-by: ljfnjj1234567
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3781
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
`torch.TypedStorage.is_sparse`
该 API 为 `torch.TypedStorage 不携带 layout信息,属性恒返回 `False`,设备无关,Ascend 950DT
下与其他产品行为一致(实
上游各版本 native_api 文
支持情况误标为「不支持」
# 【资料变更】
涉及。以上 4 个版本目录中,`torch.TypedStorage.is_sparse` 的**产品支持情况**列表里,`<term>Ascend
950DT</term>:不支持` 更m>:支持`;Atlas A2 / A3训练系列产品保持「支持」不变。
# 【接口变更】
不涉及
# 【功能介绍】
`torch.TypedStorage.is_sparse` 是 `torch.TypedStorage`(`torch.FloatStorage`
等 legacy storage 的基类
是否为稀疏。由于稀疏属性 携带 layout
信息,该属性恒为 `False`
# 【功能验证】
test/test_storage_is_sparse.py (torch.TypedStorage.is_sparse)
- test_is_sparse_false_for_empty_storage — 空构造 `torch.TypedStorage()`,is_sparse 为 False
- test_is_sparse_false_for_size_construction — size 构造 `torch.TypedStorage(4, dtype=torch.float32)`
- test_is_sparse_false_for_sequence_construction — Sequence 构造 `torch.TypedStorage([1.0, 2.0, 3.0], dtype=torch.float32)`
- test_is_sparse_false_for_wrap_storage_construction — wrap_storage 构造(UntypedStorage 包装)
- test_is_sparse_false_for_all_dtypes — 多 dtype(float32 / float16 / int32 / int64)
- test_is_sparse_false_on_npu — NPU 张量的 untyped_storage().is_sparse 为 False
运行命令:
python -m pytest test_storage_is_sparse.py -x
运行结果:
```
================================================= test session starts ==================================================
platform linux -- Python 3.11.15, pytest-9.1.1, pluggy-1.6.0
rootdir: /workspace/user_data/pytorch-v2.7.1
configfile: pyproject.toml
collected 6 items
pytorch-v2.7.1/test/test_storage_is_sparse.py ...... [100%]
=================================================== warnings summary ===================================================
../../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
/usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
test/test_storage_is_sparse.py::TestStorageIsSparse::test_is_sparse_false_for_all_dtypes
/workspace/user_data/pytorch-v2.7.1/test/test_storage_is_sparse.py:50: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
storage = torch.TypedStorage(4, dtype=dtype)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================ 6 passed, 15 warnings in 8.36s ============================================
```
A5验证
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace# cd /workspace/user_data && source /usr/local/Ascend/ascend-toolkit/set_env.sh && export ASCEND_PROCESS_LOG_PATH=/tmp && env -u CI /workspace/user_data/npu-pytorch-setup/venv_npu/bin/python /workspace/user_data/pytorch-master/test/test_storage_is_sparse.py -v
test_is_sparse_false_for_all_dtypes (__main__.TestStorageIsSparse.test_is_sparse_false_for_all_dtypes) ... /workspace/user_data/pytorch-master/test/test_storage_is_sparse.py:36: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly. To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
storage = torch.TypedStorage(4, dtype=dtype)
ok
test_is_sparse_false_for_empty_storage (__main__.TestStorageIsSparse.test_is_sparse_false_for_empty_storage) ... ok
test_is_sparse_false_for_sequence_construction (__main__.TestStorageIsSparse.test_is_sparse_false_for_sequence_construction) ... ok
test_is_sparse_false_for_size_construction (__main__.TestStorageIsSparse.test_is_sparse_false_for_size_construction) ... ok
test_is_sparse_false_for_wrap_storage_construction (__main__.TestStorageIsSparse.test_is_sparse_false_for_wrap_storage_construction) ... ok
test_is_sparse_false_on_npu (__main__.TestStorageIsSparse.test_is_sparse_false_on_npu) ... [W906 05:32:20.071140775 NPUCachingAllocator.cpp:174] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
ok
----------------------------------------------------------------------
Ran 6 tests in 1.784s
OK
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6 Version: 25.7.rc1.6 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
| 0 | Ascend950PR | OK | 208.4 62 0 / 0 |
| | | 0000:55:00.0 | 0 0 / 0 5240 / 131072 |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID | Process id | Process name | Process memory(MB) |
+===========================+===============+=====================================================+
| No running processes found in NPU 0 |
+===========================+===============+=====================================================+
```
# 【CheckList】
> PR提交人对以下CheckLis或不涉及,均修改 [ ] 为[x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回
- [x] PR标题正确使用类型、docs、test等
- [x] PR持续集成流水线
See merge request: Ascend/pytorch!45877
2026-10-10 18:08:34 +08:00
y30037164
da62511fe6
fix: 优化 nightly 流水线:单卡编译、统一 torch 安装、常规测试并发提速
...
Co-authored-by: yuaiming<yuaiming@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47691 merge master into master
fix: 优化 nightly 流水线:单卡编译、统一 torch 安装、常规测试并发提速
Created-by: y30037164
Commit-by: yuaiming
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47691
2026-10-10 18:01:48 +08:00
gcw_CHjSLYhf
709b3ea1a7
[test] Add torch.untypedstorage{filename|hpu|nbytes|new} API test case
...
Co-authored-by: gcw_CHjSLYhf<2839668818@qq.com >
# message auto-generated for no-merge-commit merge:
!45157 merge untypedstorage_filename_hpu_nbytes_new-master into master
[test] Add torch.untypedstorage{filename|hpu|nbytes|new} API test case
Created-by: gcw_CHjSLYhf
Commit-by: gcw_CHjSLYhf
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3739 https://gitcode.com/Ascend/pytorch/issues/3750 https://gitcode.com/Ascend/pytorch/issues/3760 https://gitcode.com/Ascend/pytorch/issues/3761
- [ ] 重构优化
- [ ] 资料更新
公开issue:
- `torch.UntypedStorage.filename`:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(78)](https://gitcode.com/Ascend/pytorch/issues/3739 )
- `torch.UntypedStorage.hpu`:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(89)](https://gitcode.com/Ascend/pytorch/issues/3750 )
- `torch.UntypedStorage.nbytes`:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(99)](https://gitcode.com/Ascend/pytorch/issues/3760 )
- `torch.UntypedStorage.new`: [8月社区任务第一期-Ascend for PyTorch API 一致性开发(100) ](https://gitcode.com/Ascend/pytorch/issues/3761 )
# 一. API 功能说明:
## 1. torch.UntypedStorage.filename
`filename` 是`torch.UntypedStorage`这个类的一个只读属性,用于获取与当前 Storage 关联的内存映射文件路径。因此和平台设备有关联,需要增加一个快速的验证性测试。
PyTorch 2.7 中的实现为:
```python
@property
def filename(self):
return self._get_filename()
```
因此它属于 Python 属性封装,但实际结果由底层 Storage 元数据接口 `_get_filename()` 提供。
## 2. torch.UntypedStorage.hpu
`torch.UntypedStorage.hpu()` 用于 返回一个在 HPU(Habana Gaudi 加速器)上的存储副本,如果该对象已在HPU内存中且位于正确的设备上,则不执行复制,直接返回原始对象。因为该API与HPU平台设备具有强绑定关系。
参数说明:
- `device`:目标 HPU 设备编号,默认使用当前 HPU 设备;
- `non_blocking`:如果源内存满足异步复制条件,则允许异步复制。
PyTorch 2.7 中的核心实现为:
```python
def hpu(self, device=None, non_blocking=False):
device2 = (
torch.device("hpu", device)
if device
else torch.device("hpu")
)
return self.to(
device=device2,
non_blocking=non_blocking,
)
```
## 3. torch.UntypedStorage.nbytes
`torch.UntypedStorage.nbytes()` 返回当前底层 Storage 实际占用的字节数,返回类型为 `int`。
但要注意,`nbytes()` 查询的是整个 Storage 的大小,而不是当前 Tensor View 的逻辑数据量。
例如:
```python
base = torch.empty(16, dtype=torch.float32)
view = base[::2]
base.untyped_storage().nbytes() == 64
view.untyped_storage().nbytes() == 64
# view只有8个逻辑元素
view.numel() * view.element_size() == 32
```
这是因为 `view` 和 `base` 共享同一个底层 Storage。
接口本身主要读取底层 Storage 元数据,不执行计算算子,但它读取的是 NPU Storage 的实际字节范围,可以验证 NPU Tensor 到 UntypedStorage 的连接是否正确,因此需要增加 NPU 功能测试。
## 4. torch.UntypedStorage.new
`torch.UntypedStorage.new`在当前 Storage 所在设备上,创建一个新的、大小为 0 的 UntypedStorage。torch.UntypedStorage.new() 由底层 Storage 实现提供。NPU Storage 调用该接口时,需要正确处理 PrivateUse1/NPU 设备信息。因此需要补充这个API在torch-npu平台上的测试用例。
# 二. 上游用例检查情况:
检查 PyTorch 上游 Storage 相关测试后,结果如下:
| API | 上游是否存在独立直接用例 | 检查结果 |
|---|---:|---|
| ` torch.UntypedStorage.filename` | 未发现 | 上游核心`test/test_torch.py`中未发现直接读取`.filename`的独立用例 |
| `torch.UntypedStorage.hpu` | 未发现 | 上游核心Storage测试中未发现直接调用`.hpu()`的独立用例 |
| `torch.UntypedStorage.nbytes` | 存在部分覆盖 | 上游在Storage Meta测试中调用了`s.nbytes()`并比较不同Storage的字节数 |
| `torch.UntypedStorage.new` | 存在部分覆盖 | 上游在Storage Meta测试中调用了`s.nbytes()`并比较不同Storage的字节数 |
# 三. 资料情况检查:
- `torch.UntypedStorage.filename`:在torch上游社区存在独立条目,同时在当前项目中该API资料已经存在,但是A5支持情况有误,因此需要进行资料修正。

- `torch.UntypedStorage.hpu`:在torch上游社区存在独立条目,同时在当前项目中该API资料已经存在,由于该API与hpu平台存在硬编码,系统支持情况,因此不需要进行资料补充和修正。

- `torch.UntypedStorage.nbytes`在torch上游社区存在独立条目,同时在当前项目中该API资料有误,因此需要进行资料修正。

- `torch.UntypedStorage.new` torch上游社区存在独立条目,同时在当前项目中该API资料有误,因此需要进行资料修正。

资料修正补充pr: https://gitcode.com/Ascend/pytorch/pull/46583
# 四. API功能性验证
## 1. 测试场景
# torch.UntypedStorage API 功能性验证
## 1. 测试场景
| 编号 | API | 测试场景 | 预期结果 |
| --- | --- | --- | --- |
| 1 | `torch.UntypedStorage.filename` | 获取普通 CPU Tensor 底层 Storage 的 `filename` | 普通 CPU Storage 未关联内存映射文件,返回 `None` |
| 2 | `torch.UntypedStorage.filename` | 使用 `from_file(shared=True)` 创建共享文件映射 Storage | `filename` 返回字符串,并且规范化路径与映射文件路径一致 |
| 3 | `torch.UntypedStorage.filename` | 使用 `from_file(shared=False)` 创建私有文件映射 Storage | 私有映射的 `filename` 返回 `None` |
| 4 | `torch.UntypedStorage.filename` | 获取 NPU Tensor 底层 Storage 的 `filename` | Storage 位于 NPU,且未关联 CPU 文件映射,返回 `None` |
| 5 | `torch.UntypedStorage.hpu` | 在纯 torch-npu 环境中调用默认参数 `hpu()` | 因未加载 HPU 设备模块,抛出包含 `HPU device module is not loaded` 的 `AssertionError` |
| 6 | `torch.UntypedStorage.hpu` | 指定 `device=1, non_blocking=True` 调用 `hpu()` | 参数可以被接口正常解析;因未加载 HPU 模块,抛出预期 `AssertionError` |
| 7 | `torch.UntypedStorage.nbytes` | 验证 `float16` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 8 | `torch.UntypedStorage.nbytes` | 验证 `float32` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 9 | `torch.UntypedStorage.nbytes` | 验证 `int32` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 10 | `torch.UntypedStorage.nbytes` | 验证 `int64` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 11 | `torch.UntypedStorage.nbytes` | 直接在 CPU/NPU 上构造指定字节数的 UntypedStorage | `nbytes()`、`size()` 和 `len()` 均返回构造时指定的字节数 |
| 12 | `torch.UntypedStorage.nbytes` | 创建大小为 0 的空 NPU Storage | `nbytes()`、`size()` 和 `len()` 均返回 0 |
| 13 | `torch.UntypedStorage.nbytes` | 获取非连续 NPU Tensor View 的底层 Storage 字节数 | View 与原 Tensor 共享底层 Storage,返回整个底层 Storage 的字节数 |
| 14 | `torch.UntypedStorage.new` | 对 CPU Storage 调用 `new()` | 返回独立、大小为 0、设备类型仍为 CPU 的 UntypedStorage |
| 15 | `torch.UntypedStorage.new` | 对 NPU Storage 调用 `new()` | 返回独立、大小为 0、设备类型仍为 NPU 的 UntypedStorage |
| 16 | `torch.UntypedStorage.new` | 对 `new()` 返回的 Storage 执行 `resize_()` | 新 Storage 的大小发生变化,原 Storage 的大小不受影响 |
| 17 | `torch.UntypedStorage.new` | 对共享文件映射 Storage 调用 `new()` | 返回普通空 CPU Storage,不继承原 Storage 的文件映射关系 |
## 2. 测试核心代码
```python
class TestUntypedStorageAPIs(TestCase):
def test_untyped_storage_filename(self):
# 场景1:普通CPU Storage不关联内存映射文件
cpu_storage = torch.empty(
8,
dtype=torch.float32,
device="cpu",
).untyped_storage()
self.assertEqual(cpu_storage.device.type, "cpu")
self.assertIsNone(cpu_storage.filename)
# 场景2和3:共享文件映射与私有文件映射Storage
with tempfile.TemporaryDirectory() as temp_dir:
file_path = os.path.join(
temp_dir,
"untyped_storage.bin",
)
shared_storage = torch.UntypedStorage.from_file(
file_path,
shared=True,
nbytes=32,
)
self.assertEqual(shared_storage.device.type, "cpu")
self.assertEqual(shared_storage.nbytes(), 32)
self.assertIsInstance(
shared_storage.filename,
str,
)
self.assertEqual(
os.path.realpath(shared_storage.filename),
os.path.realpath(file_path),
)
# 释放共享映射后再创建私有映射
del shared_storage
private_storage = torch.UntypedStorage.from_file(
file_path,
shared=False,
nbytes=32,
)
self.assertEqual(private_storage.device.type, "cpu")
self.assertEqual(private_storage.nbytes(), 32)
self.assertIsNone(private_storage.filename)
del private_storage
# 场景4:NPU Storage不关联CPU内存映射文件
npu_storage = torch.empty(
8,
dtype=torch.float32,
device="npu",
).untyped_storage()
self.assertEqual(npu_storage.device.type, "npu")
self.assertIsNone(npu_storage.filename)
def test_untyped_storage_hpu(self):
npu_storage = torch.empty(
8,
dtype=torch.float32,
device="npu",
).untyped_storage()
self.assertEqual(
npu_storage.device.type,
"npu",
)
# 场景5:在torch-npu平台使用默认参数调用hpu()
with self.assertRaisesRegex(
AssertionError,
r"HPU device module is not loaded",
):
npu_storage.hpu()
# 场景6:在torch-npu平台指定device和non_blocking参数
with self.assertRaisesRegex(
AssertionError,
r"HPU device module is not loaded",
):
npu_storage.hpu(
device=1,
non_blocking=True,
)
def test_untyped_storage_nbytes_for_tensor_dtypes(self):
test_cases = [
(torch.float16, 6),
(torch.float32, 6),
(torch.int32, 6),
(torch.int64, 6),
]
# 场景7至10:不同dtype的CPU/NPU Storage字节数
for dtype, numel in test_cases:
with self.subTest(dtype=dtype):
cpu_tensor = torch.empty(
numel,
dtype=dtype,
device="cpu",
)
npu_tensor = torch.empty(
numel,
dtype=dtype,
device="npu",
)
cpu_storage = cpu_tensor.untyped_storage()
npu_storage = npu_tensor.untyped_storage()
expected_nbytes = (
numel * cpu_tensor.element_size()
)
self.assertEqual(
cpu_storage.nbytes(),
expected_nbytes,
)
self.assertEqual(
npu_storage.nbytes(),
expected_nbytes,
)
self.assertEqual(
cpu_storage.nbytes(),
npu_storage.nbytes(),
)
# UntypedStorage的长度单位也是字节
self.assertEqual(
len(cpu_storage),
expected_nbytes,
)
self.a
See merge request: Ascend/pytorch!45157
2026-10-10 17:59:11 +08:00
zhangjiahao-2026
b651b67466
docs: add torch.nn.attention.flex_attention.or_masks support status
...
Co-authored-by: zhangjiahao-2026<2332445379@qq.com >
# message auto-generated for no-merge-commit merge:
!43375 merge issue-3293-or-masks-docs into master
docs: add torch.nn.attention.flex_attention.or_masks support status
Created-by: zhangjiahao-2026
Commit-by: zhangjiahao-2026
Merged-by: ascend-robot
Description: # 【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3293
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
在 master 资料中为公开非计算类 API `torch.nn.attention.flex_attention.or_masks` 补齐支持情况。
修改文件:
- docs/zh/api/native_api/pytorch_2-7-1/torch-nn-attention.md
- docs/zh/api/native_api/pytorch_2-11-0/torch-nn-attention.md
- docs/zh/api/native_api/pytorch_2-12-0/torch-nn-attention.md
- docs/zh/api/native_api/pytorch_2-13-0/torch-nn-attention.md
具体修改内容:
1. 在PyTorch 2.7.1、2.11.0、2.12.0和2.13.0资料中新增`torch.nn.attention.flex_attention.or_masks`条目;
2. 按照PyTorch官方资料的层级和顺序,将该API归入`BlockMask Utilities`,并放置在`BlockMask`之前;
3. Atlas A2训练系列产品、Atlas A3训练系列产品和Ascend 950DT均标记为支持;
4. 该API为非计算类纯Python接口,与具体数据类型无关,不填写数据类型限制。
本PR仅补充目标API的资料,不批量修改同一文件中其他历史API的资料格式。
# 【资料变更】
资料检查结果:此前 master 下的原生 API 资料未收录
`torch.nn.attention.flex_attention.or_masks`,因此需要补充。
本次在以下版本目录的 `torch-nn-attention.md` 中新增支持情况:
- PyTorch 2.7.1
- PyTorch 2.11.0
- PyTorch 2.12.0
- PyTorch 2.13.0
该API为公开非计算类纯Python接口,与张量数据类型无关,不填写数据类型限制。文档条目按照PyTorch官方资料的层级和顺序归入`BlockMask Utilities`。
# 【接口变更】
不涉及
# 【功能验证】
`torch.nn.attention.flex_attention.or_masks(*mask_mods)`用于组合一个或多个
`mask_mod`,返回一个新的掩码函数,并对所有输入mask的返回结果执行逻辑或。
PyTorch官方社区在以下用例中已有`or_masks`基本逻辑或语义验证:
```text
test/inductor/test_flex_attention.py::test_mask_mod_combiners
```
`or_masks`为纯Python组合接口,不包含NPU专属kernel或设备分支,不需要修改
Torch-NPU功能实现,也不需要新增测试文件或`test_upstream` patch。
API功能、社区用例情况、NPU适配分析和各版本验证结果见说明Issue:
https://gitcode.com/Ascend/pytorch/issues/4082
A5硬件验证信息如下。
验证设备:

验证环境:
```text
torch:2.12.0+cpu
torch_npu:2.12.0
Python:3.12.13
```
验证命令:
```bash
python /tmp/test_or_masks_a5.py
```
验证场景:
1. 单个`mask_mod`返回True和False;
2. 多个`mask_mod`执行逻辑或;
3. 零个`mask_mod`返回位于NPU上的bool标量False;
4. 非callable输入触发预期`RuntimeError`;
5. 返回值dtype为`torch.bool`,设备类型为`npu`。
运行截图:

验证结论:
`torch.nn.attention.flex_attention.or_masks`在上述A5环境中运行正常,单mask、
多mask、零mask和异常入参场景均验证通过,返回类型及返回设备符合PyTorch实现。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!43375
2026-10-10 17:41:13 +08:00
honorn
4cac9b6f63
[test]Add typedStorage_is{shared|pinned|hpu} API test case
...
Co-authored-by: honorn<838107180@qq.com >
# message auto-generated for no-merge-commit merge:
!45162 merge TypedStorage_is_shared_pinned_hpu-master into master
[test]Add typedStorage_is{shared|pinned|hpu} API test case
Created-by: honorn
Commit-by: honorn
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
[#3780 ](https://gitcode.com/Ascend/pytorch/issues/3780 )
[#3779 ](https://gitcode.com/Ascend/pytorch/issues/3779 )
[#3778 ](https://gitcode.com/Ascend/pytorch/issues/3778 )
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
公开issue:
- `torch.TypedStorage.is_shared`:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(47)](https://gitcode.com/Ascend/pytorch/issues/3780 )
- `torch.TypedStorage.is_pinned`:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(46)](https://gitcode.com/Ascend/pytorch/issues/3779 )
- `torch.TypedStorage.is_hpu`:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(45)](https://gitcode.com/Ascend/pytorch/issues/3778 )
# 一. API 功能说明:
- `torch.TypedStorage.is_shared()` :判断当前 Storage 是否位于共享内存中。
- `torch.TypedStorage.is_pinned()`:判断一个 CPU Storage 是否为指定加速设备分配的页锁定内存,也叫 Pinned Memory。
- `torch.TypedStorage.is_hpu()`:判断 Storage 是否位于 HPU 设备上。HPU 是 Habana Processing Unit,主要指 Intel Habana Gaudi 系列加速器。
| API | 接口性质 | 是否与设备相关 | torch-npu 测试建议 |
|---|---|---|---|
| `torch.TypedStorage.is_shared` | Python 包装接口,实际查询底层 `UntypedStorage` | 是,依赖底层存储及共享内存实现 | 建议补充 NPU 冒烟测试 |
| `torch.TypedStorage.is_pinned` | Python 包装接口,实际查询设备的固定内存分配器 | 强相关 | 必须补充 NPU 用例 |
| `torch.TypedStorage.is_hpu` | Python 属性,比较 `device.type == "hpu"` | 仅查询设备元数据 | 无需专门适配,但可补充 NPU 返回 `False` 的测试 |
**注意** `HPU` 指 `Habana Gaudi HPU`
PyTorch 2.7 中三者的实现分别是:
```python
def is_shared(self):
_warn_typed_storage_removal()
return self._is_shared()
def _is_shared(self):
return self._untyped_storage.is_shared()
def is_pinned(self, device="cuda"):
_warn_typed_storage_removal()
return self._untyped_storage.is_pinned(device)
@property
def is_hpu(self):
_warn_typed_storage_removal()
return self._untyped_storage.device.type == "hpu"
```
可以看到,`is_shared()` 和 `is_pinned()` 都会继续调用底层 `UntypedStorage`;`is_hpu()` 则是简单的 Python 设备类型判断。
# 二. 上游用例检查情况:
| API | 上游检查结果 | NPU 覆盖缺口 |
|---|---|---|
| `TypedStorage.is_shared()` | `test_storage_meta_errors` 对 meta TypedStorage 断言 `is_shared() == False` | 没有覆盖 NPU |
| `TypedStorage.is_pinned()` | 核心 `test_torch.py` 中未发现该方法的独立正反例;CUDA 测试包含 Tensor 层固定内存测试 | 没有检查 `device="npu"` 及 NPU pinned allocator |
| `TypedStorage.is_hpu` | 核心 Storage 测试中未发现独立断言 | 没有验证 NPU Storage 必须返回 `False` |
因此需要补充这三个API的测试用例,这三个API可以直接放到一个完整的测试文件中进行测试。
# 三. 资料情况检查:
- `torch.TypedStorage.is_shared`
- `torch.TypedStorage.is_pinned`
- `torch.TypedStorage.is_hpu`
这些API的资料补充在各个分支都存在,但是 `torch.TypedStorage.is_shared` 和`torch.TypedStorage.is_pinned`对A5芯片的支持程度描述有误,需要进行资料修改,`torch.TypedStorage.is_hpu`由于与hpu硬件相关,因此都不支持,资料补充正确无误,结果如下截图所示。



# 四. API功能性验证
测试核心代码
```python
class TestTypedStorageAPIs(TestCase):
@staticmethod
def _get_typed_storage(tensor):
return tensor.storage()
def test_typed_storage_is_shared_for_cpu(self):
cpu_tensor = torch.arange(
8,
dtype=torch.float32,
device="cpu",
)
expected_tensor = cpu_tensor.clone()
cpu_storage = self._get_typed_storage(cpu_tensor)
self.assertIsInstance(
cpu_storage,
torch.TypedStorage,
)
self.assertEqual(
cpu_storage.device.type,
"cpu",
)
# 场景1:普通CPU TypedStorage不在共享内存中
self.assertFalse(cpu_storage.is_shared())
self.assertEqual(
cpu_storage.is_shared(),
cpu_tensor.untyped_storage().is_shared(),
)
# 场景2:CPU TypedStorage移动到共享内存
returned_storage = cpu_storage.share_memory_()
self.assertIs(
returned_storage,
cpu_storage,
)
self.assertTrue(cpu_storage.is_shared())
self.assertTrue(cpu_tensor.is_shared())
self.assertTrue(
cpu_tensor.untyped_storage().is_shared()
)
# share_memory_不能改变Storage中的数据
self.assertEqual(
cpu_tensor,
expected_tensor,
)
def test_typed_storage_is_shared_for_tensor_view(self):
base_tensor = torch.arange(
16,
dtype=torch.float32,
device="cpu",
)
view_tensor = base_tensor[::2]
base_storage = self._get_typed_storage(
base_tensor
)
view_storage = self._get_typed_storage(
view_tensor
)
# 场景3:Base Tensor和View共享同一底层Storage
self.assertEqual(
base_storage.data_ptr(),
view_storage.data_ptr(),
)
self.assertFalse(base_storage.is_shared())
self.assertFalse(view_storage.is_shared())
base_storage.share_memory_()
self.assertTrue(base_storage.is_shared())
self.assertTrue(view_storage.is_shared())
self.assertTrue(base_tensor.is_shared())
self.assertTrue(view_tensor.is_shared())
self.assertEqual(
base_storage.data_ptr(),
view_storage.data_ptr(),
)
def test_typed_storage_is_shared_for_npu(self):
npu_tensor = torch.empty(
16,
dtype=torch.float32,
device="npu",
)
npu_storage = self._get_typed_storage(
npu_tensor
)
self.assertEqual(
npu_storage.device.type,
"npu",
)
is_shared_before = npu_storage.is_shared()
data_ptr_before = npu_storage.data_ptr()
nbytes_before = npu_storage.nbytes()
self.assertIsInstance(
is_shared_before,
bool,
)
self.assertEqual(
is_shared_before,
npu_tensor.untyped_storage().is_shared(),
)
# 场景4:NPU/PrivateUse1 Storage不迁移到POSIX共享内存。
#
# 不硬编码NPU is_shared()为True或False,是因为不同PyTorch
# 版本可能调整非CPU设备的共享状态定义;TypedStorage必须
# 与底层UntypedStorage一致,并且share_memory_应为no-op。
returned_storage = npu_storage.share_memory_()
is_shared_after = npu_storage.is_shared()
self.assertIs(
returned_storage,
npu_storage,
)
self.assertEqual(
is_shared_after,
is_shared_before,
)
self.assertEqual(
is_shared_after,
npu_tensor.untyped_storage().is_shared(),
)
self.assertEqual(
npu_storage.data_ptr(),
data_ptr_before,
)
self.assertEqual(
npu_storage.nbytes(),
nbytes_before,
)
def test_typed_storage_is_pinned_for_normal_storage(self):
test_dtypes = [
torch.float16,
torch.float32,
torch.int32,
torch.int64,
]
# 场景5:普通CPU/NPU TypedStorage均不是NPU pinned memory
for device in ["cpu", "npu"]:
for dtype in test_dtypes:
with self.subTest(
device=device,
dtype=dtype,
):
tensor = torch.empty(
16,
dtype=dtype,
device=device,
)
storage = self._get_typed_storage(
tensor
)
result_by_string = storage.is_pinned(
device="npu"
)
result_by_device = storage.is_pinned(
device=torch.device("npu")
)
untyped_result = (
tensor.untyped_storage().is_pinned(
device="npu"
)
)
self.assertIsInstance(
result_by_string,
bool,
)
self.assertFalse(result_by_string)
self.assertFalse(result_by_device)
self.assertEqual(
result_by_string,
result_by_device,
)
self.assertEqual(
result_by_string,
untyped_result,
)
def test_typed_storage_is_pinned_for_pinned_cpu(self):
test_dtypes = [
torch.float16,
torch.float32,
torch.int32,
torch.int64,
]
# 场景6:CPU TypedStorage转换为NPU pinned memory
for dtype in test_dtypes:
with self.subTest(dtype=dtype):
source_tensor = torch.arange(
1,
9,
dtype=dtype,
device="cpu",
)
source_storage = (
self._get_typed_storage(
source_tensor
)
)
source_values = (
source_storage.tolist()
)
self.assertFalse(
source_storage.is_pinned(
device="npu"
)
)
pinned_storage = (
source_storage.pin_memory(
device="npu"
)
)
self.assertIsInstance(
pinned_storage,
torch.TypedStorage,
)
self.assertIsNot(
pinned_storage,
source_storage,
)
self.assertEqual(
pinned_storage.device.type,
"cpu",
)
See merge request: Ascend/pytorch!45162
2026-10-10 17:40:43 +08:00
gcw_fiAo4tDr
c539cc2598
[docs] 更新 Tensor.is_meta 的 Ascend 950DT 支持标记
...
Co-authored-by: gcw_fiAo4tDr<iqueenqueen@163.com >
# message auto-generated for no-merge-commit merge:
!45879 merge docs/is-meta-950dt-support-v2 into master
[docs] 更新 Tensor.is_meta 的 Ascend 950DT 支持标记
Created-by: gcw_fiAo4tDr
Commit-by: gcw_fiAo4tDr
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
关联任务:https://gitcode.com/Ascend/pytorch/issues/2710
验证分析:https://gitcode.com/Ascend/pytorch/issues/2807
# 【修改方案】
更新 `torch.Tensor.is_meta` 的 Ascend 950DT 产品支持标记,由“不支持”改为“支持”。其中 A5 实机设备为 Ascend950PR_9579,按本任务验收口径与资料项 Ascend 950DT等价,因此 A5 实测通过后资料状态更新为 支持 。
# 【资料变更】
只向 master 分支提交,修改以下七个版本目录中的 `torch-Tensor.md`,每份仅修改 `is_meta()` 条目的一行:
- `docs/zh/api/native_api/pytorch_2-7-1/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-9-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-10-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-14-0/torch-Tensor.md`
2.13.0 已在 HiDevLab A5 服务器上按原 Issue 的官方 CPU/Gloo 口径验证通过,因此同步更新其 `is_meta()` 支持标记。
# 【接口变更】
不涉及。仅修改文档,不新增 API 实现、测试代码或数据类型限制。
# 【功能验证】
2026-09-06 在 HiDevLab `Ascend950PR_9579` 服务器上,按原 Issue 的官方默认测试方式验证。测试框架实际使用 CPU/Gloo,未修改官方测试源码、未增加 NPU 专用断言;该用例不依赖 `torch-npu`。
2026-10-05:补充2.9.0、2.10.0、2.14.0用例验证
| PyTorch | 运行方式 | 结果 |
|---|---|---|
| 2.7.1+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 14.208s / OK,0 skipped,退出码 0 |
| 2.9.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 6.446s / OK,0 skipped,退出码 0 |
| 2.10.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 5.207s / OK,0 skipped,退出码 0 |
| 2.11.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 13.255s / OK,0 skipped,退出码 0 |
| 2.12.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 13.852s / OK,0 skipped,退出码 0 |
| 2.15.0.dev20260902+cpu(master) | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 13.856s / OK,0 skipped,退出码 0 |
| 2.13.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 11.204s / OK,0 skipped,退出码 0 |
| 2.14.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 5.729s / OK,0 skipped,退出码 0 |
2.13.0 的实际命令为:
```text
cd /workspace/task87_official_20260906
TORCH_DEVICE_BACKEND_AUTOLOAD=1 /workspace/venvs/v2130/bin/python sources/test_dtensor_v2130.py DTensorTest.test_meta_dtensor -v
```
官方用例覆盖 Meta Tensor/DTensor 的 `is_meta=True`、物化到默认测试设备后的 `is_meta=False`,以及 `Shard(0)` 和 `Replicate()` 两种 placement。这里的“A5 验证”是指用例运行在 A5 服务器上;测试仍按原 Issue 使用默认 CPU/Gloo,不表示用例在 NPU/HCCL 后端执行。
A5 服务器终端已保留七个版本的完整日志。**本次没有在 950DT 上单独实测,文档中的 950DT 支持标记仍提交给维护者评审。**
官方测试源码和完整日志保存在 A5 服务器,本 PR 未上传完整证据包。文档检查 `git diff --check` 通过,共七个文件、七处支持标记变更;当前分支已整理为一个提交。
# 【运行截图】
### PyTorch 2.7.1

### PyTorch 2.9.0
)
### PyTorch 2.10.0
)
### PyTorch 2.11.0

### PyTorch 2.12.0

### PyTorch master

### PyTorch 2.13.0

### PyTorch 2.14.0
)
See merge request: Ascend/pytorch!45879
2026-10-10 17:33:43 +08:00
litianyu_2026
c9e93f8a9e
【API一致性任务】docs: update support status for torch.TypedStorage.float8_e4m3fnuz on NPU
...
Co-authored-by: litianyu2026<1483211810@qq.com >
# message auto-generated for no-merge-commit merge:
!44676 merge docs-typedstorage-float8_e4m3fnuz into master
【API一致性任务】docs: update support status for torch.TypedStorage.float8_e4m3fnuz on NPU
Created-by: litianyu_2026
Commit-by: litianyu2026
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">https://gitcode.com/Ascend/pytorch/issues/3766 </font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
1. **明确 API 不支持状态**:在 `docs/zh/api/native_api/pytorch_2-13-0/torch-Storage.md` 文件中,将公有接口 `torch.TypedStorage.float8_e4m3fnuz` 在 NPU 上的支持状态明确标记为不支持(`✖`)。
2. **状态判定依据**:经在 NPU 环境下进行底层跨设备物理内存转换的深度测试,验证到该操作会触发 CANN 底层算子的 `ERR01007 OPS feature not supported` 错误。基于此物理测试事实,在官方资料中如实更正其支持状态。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
涉及。
本 PR 核心目标即为资料变更。更新了 `torch-Storage.md` 文档,基于底层的真实运行报错结果,明确标注了 `torch.TypedStorage.float8_e4m3fnuz` 当前在昇腾 NPU 上处于不支持状态。
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
本资料状态的变更,已通过严格的底层物理跑测事实予以佐证。
针对 `torch.TypedStorage.float8_e4m3fnuz`,编写了从 CPU 到 NPU 的深度物理内存转换测试用例。在本地环境执行测试时,框架底层抛出了明确的 `ERR01007 OPS feature not supported` 错误,客观印证了 NPU 当前算子栈不支持该数据类型的底层转换。
具体的验证代码逻辑及运行失败的报错截图如下,以此作为本 PR 将其标记为“不支持”的客观事实凭证:
**验证用例代码:**
class TestTypedStorageFloat8(TestCase):
def test_float8_e4m3fnuz_on_npu(self):
expected_cpu = torch.tensor(
[
-4.0,
-1.5,
-0.5,
0.0,
0.5,
1.5,
4.0,
],
dtype=torch.float32,
device="cpu",
)
source_tensor = expected_cpu.to("npu")
source_storage = source_tensor.storage()
self.assertIsInstance(
source_storage,
torch.TypedStorage,
)
self.assertEqual(
source_storage.device.type,
"npu",
)
self.assertEqual(
source_storage.dtype,
torch.float32,
)
converted_storage = (
source_storage.float8_e4m3fnuz()
)
self.assertIsInstance(
converted_storage,
torch.TypedStorage,
)
self.assertEqual(
converted_storage.device.type,
"npu",
)
self.assertEqual(
converted_storage.dtype,
torch.float8_e4m3fnuz,
)
self.assertEqual(
converted_storage.size(),
source_storage.size(),
)
converted_cpu_storage = converted_storage.cpu()
converted_cpu_tensor = torch.tensor(
[],
dtype=torch.float8_e4m3fnuz,
device="cpu",
).set_(converted_cpu_storage)
self.assertEqual(
converted_cpu_tensor.float(),
expected_cpu,
)
**验证报错截图:**
在910B3中验证如下:

在950PR中验证如下:

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!44676
2026-10-10 17:26:12 +08:00
Zky0803
78e7bf97a2
docs: add torch.onnx.ONNXProgram.release
...
Co-authored-by: Zky0803<kyzhang0803@163.com >
# message auto-generated for no-merge-commit merge:
!45083 merge docs/onnx-program-release into master
docs: add torch.onnx.ONNXProgram.release
Created-by: Zky0803
Commit-by: Zky0803
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
- 来源任务 Issue:[【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(12)](https://gitcode.com/Ascend/pytorch/issues/3491 )
- 结果 Issue:[torch.onnx.ONNXProgram.release API 一致性补齐](https://gitcode.com/Ascend/pytorch/issues/3626 )
- 资料 PR:[PR #45083 ](https://gitcode.com/Ascend/pytorch/pull/45083 )
## A2 / A3 / A5 实机验证
本 API 为纯 Python 资源释放接口,不涉及 NPU Kernel,但仍按统一验收标准在
A2 / A3 / A5 三类硬件环境执行 NPU runtime probe 和 `release()` 功能行为验证。
验证范围保持为已经完成实测的三个运行时版本:
```text
PyTorch 2.7.1
PyTorch 2.11.0
PyTorch 2.12.0
```
验证矩阵:
|验证平台|实机硬件|2.7.1|2.11.0|2.12.0|结果|
|---|---|:---:|:---:|:---:|:---:|
|A2|Ascend910B3|PASS|PASS|PASS|PASS|
|A3|Ascend910_9382|PASS|PASS|PASS|PASS|
|A5|Ascend950PR / Ascend950PR_9579(按任务口径等价 Ascend 950DT)|PASS|PASS|PASS|PASS|
覆盖场景:
```text
1. inference session + tempdir:session 清空、cleanup、gc.collect、返回 None
2. repeated release:重复调用成功且 cleanup 不重复,验证幂等性
3. session only:session 正常释放
4. tempdir only:tempdir 正常 cleanup 并清空
```
正式日志:
```text
A2:/workspace/onnx_program_release_A2_formal_20260903T100049Z.log
A3:/workspace/onnx_program_release_A3_formal_20260903T100855Z.log
A5:/workspace/onnx_program_release_A5_formal_20260906T053549Z.log
```
最终硬件验证结论:
```text
A2:PASS
A3:PASS
A5:PASS
```
新增的 2.9.0 / 2.10.0 / 2.13.0 / 2.14.0 为本轮 Native API 资料同步范围,
本 PR 不把它们表述为新增 A2/A3/A5 runtime 验证结果。
# 【分支范围】
本资料 PR 面向 `master`。
根据 2026-09-28 群内最新 Native API 资料要求,当前同步范围为:
```text
pytorch_2-7-1
pytorch_2-9-0
pytorch_2-10-0
pytorch_2-11-0
pytorch_2-12-0
pytorch_2-13-0
pytorch_2-14-0
```
此前“2.9.0 / 2.10.0 不在资料目录、不涉及本 PR”的旧描述已失效,
本次已按最新 `master` 和群内要求同步纳入。
资料分支:
```text
源分支:docs/onnx-program-release
目标分支:master
基线提交:142dc619f48b86576690ca25926d82d39c810ca9
Commit:f9d839fcbeaee2094801f04f44c8f9e654e64ad9
提交标题:docs: add torch.onnx.ONNXProgram.release
```
本 PR 当前保持单一任务提交:
```text
commit_count=1
```
# 【修改方案】
补充 `torch.onnx.ONNXProgram.release` 的 Native API 支持资料,
不修改 API 实现、测试逻辑、Torch-NPU C++ 代码或 NPU Kernel。
最终修改 7 个文件:
```text
docs/zh/api/native_api/pytorch_2-7-1/torch-onnx.md
docs/zh/api/native_api/pytorch_2-9-0/torch-onnx.md
docs/zh/api/native_api/pytorch_2-10-0/torch-onnx.md
docs/zh/api/native_api/pytorch_2-11-0/torch-onnx.md
docs/zh/api/native_api/pytorch_2-12-0/torch-onnx.md
docs/zh/api/native_api/pytorch_2-13-0/torch-onnx.md
docs/zh/api/native_api/pytorch_2-14-0/torch-onnx.md
```
每个版本均在包含 `torch.onnx.ONNXProgram` 父 API 原生文档链接的主 section 中新增:
```markdown
> <font size="3">release()</font>
```
产品支持信息按群内最新规范使用:
```markdown
**产品支持情况**:
<!-- npu="910b" idX -->
- <term>Atlas A2训练系列产品</term>:支持
<!-- end idX -->
<!-- npu="A3" idY -->
- <term>Atlas A3训练系列产品</term>:支持
<!-- end idY -->
<!-- npu="950" idZ -->
- <term>Ascend 950DT系列产品</term>:支持
<!-- end idZ -->
```
实际 marker ID 使用各文件中的唯一数字:
```text
pytorch_2-7-1:106 / 107 / 108
pytorch_2-9-0:37 / 38 / 39
pytorch_2-10-0:37 / 38 / 39
pytorch_2-11-0:37 / 38 / 39
pytorch_2-12-0:37 / 38 / 39
pytorch_2-13-0:37 / 38 / 39
pytorch_2-14-0:37 / 38 / 39
```
`torch.onnx.ONNXProgram.release` 为非计算类资源释放 API,与 Tensor dtype 无关,
不增加 fp16、fp32、bf16 等 dtype 限制说明。
# 【原生文档链接】
```text
PyTorch 2.7.1
https://pytorch.org/docs/2.7/onnx_dynamo.html#torch.onnx.ONNXProgram.release
PyTorch 2.9.0
https://docs.pytorch.org/docs/2.9/onnx_export.html#torch.onnx.ONNXProgram.release
PyTorch 2.10.0
https://docs.pytorch.org/docs/2.10/onnx_export.html#torch.onnx.ONNXProgram.release
PyTorch 2.11.0
https://pytorch.org/docs/2.11/onnx_export.html#torch.onnx.ONNXProgram.release
PyTorch 2.12.0
https://pytorch.org/docs/2.12/onnx_export.html#torch.onnx.ONNXProgram.release
PyTorch 2.13.0
https://pytorch.org/docs/2.13/onnx_export.html#torch.onnx.ONNXProgram.release
PyTorch 2.14.0
https://pytorch.org/docs/2.14/onnx_export.html#torch.onnx.ONNXProgram.release
```
# 【社区用例检索与新增必要性】
本 PR 为资料补齐 PR,不新增或修改单元测试。
按最新 TorchNPU API 一致性验收规范复核:
- PyTorch 已实现 `torch.onnx.ONNXProgram.release`;
- PyTorch 社区未发现针对该方法本身的直接测试;
- `release()` 仅释放 `_inference_session`、调用 `gc.collect()` 并清理 `_tempdir`;
- 不接收 Tensor;
- 不实现独立 NPU 算子;
- 不调用 NPU Kernel;
- 不访问 NPU 设备侧计算资源;
- 不需要修改 `torch_npu/csrc`;
- 不需要新增 `test_upstream` patch。
处理结论:
```text
PyTorch 官方社区无直接用例或覆盖不完整
+
API 为纯 Python 接口、不涉及硬件
→ 无需新增 Torch-NPU 专项测试
```
旧版规则下四个直接测试 PR #43594 / #43595 / #43596 / #43597 已关闭,
仅保留为历史支持性验证证据。
# 【资料变更】
涉及。
新增 `torch.onnx.ONNXProgram.release` Native API 支持状态,同步更新:
```text
PyTorch 2.7.1
PyTorch 2.9.0
PyTorch 2.10.0
PyTorch 2.11.0
PyTorch 2.12.0
PyTorch 2.13.0
PyTorch 2.14.0
```
7 个版本在修改前均未登记 `release()`,修改后均唯一登记一次。
产品支持情况:
```text
Atlas A2训练系列产品:支持
Atlas A3训练系列产品:支持
Ascend 950DT系列产品:支持
```
并按最新资料规范增加 `npu="910b"` / `npu="A3"` / `npu="950"` comment marker。
# 【接口变更】
不涉及。
本 PR 只更新 Native API 支持资料,不修改:
- Python API 实现;
- 函数签名或返回类型;
- Torch-NPU Python/C++ 实现;
- NPU Kernel;
- Torch-NPU 单元测试;
- `test_upstream` patch。
# 【功能验证】
最新提交信息:
```text
base=142dc619f48b86576690ca25926d82d39c810ca9
commit=f9d839fcbeaee2094801f04f44c8f9e654e64ad9
branch=docs/onnx-program-release
```
最终修改范围:
```text
7 files changed, 140 insertions(+)
```
验证结果:
```text
strict seven-version validation=PASS
git diff --check=PASS
git diff --cached --check=PASS
pytorch_2-7-1 release_line_count=1
pytorch_2-9-0 release_line_count=1
pytorch_2-10-0 release_line_count=1
pytorch_2-11-0 release_line_count=1
pytorch_2-12-0 release_line_count=1
pytorch_2-13-0 release_line_count=1
pytorch_2-14-0 release_line_count=1
commit_count=1
Git Hooks Checking=PASSED
push_exit_code=0
local_head=f9d839fcbeaee2094801f04f44c8f9e654e64ad9
remote_head=f9d839fcbeaee2094801f04f44c8f9e654e64ad9
REMOTE_VERIFY=PASS
CLA=YES
CI=YES
docs CI=YES
三个验收标签:全部 YES
```
# 【最新审核与资料规范处理】
本任务已依次处理:
```text
1. release() 原生文档链接精确化;
2. 支持表格调整为“产品支持情况”;
3. 产品支持信息增加 Markdown 列表标记;
4. 2026-09-28 群内最新规范:
- 拉取最新 master 资料格式;
- 产品支持项增加 npu comment marker;
- 新增 pytorch_2-9-0 / pytorch_2-10-0 / pytorch_2-14-0;
- 与原有 2.7.1 / 2.11.0 / 2.12.0 / 2.13.0 一并同步。
```
因最新 `master` 对目标资料文件已有较大调整,本轮未继续在旧 base 上追加 amend,
而是从最新:
```text
142dc619f4
```
重新构造单一任务提交并使用 `--force-with-lease` 更新 PR:
```text
old_remote=d696d6d9aaff141e4969431ce7f226b28b325b1d
new_commit=f9d839fcbeaee2094801f04f44c8f9e654e64ad9
push_exit_code=0
Git Hooks Checking=PASSED
remote_verify=PASS
commit_count=1
git diff --check=PASS
7 files changed, 140 insertions(+)
CLA=YES
CI=YES
docs CI=YES
三个验收标签:全部 YES
```
若对应 review thread 在平台 UI 中仍显示未解决,需要在平台上回复并标记“已解决”;
本 PR 描述不提前宣称该 UI 操作已经完成。
# 【test_upstream patch】
不涉及。
`torch.onnx.ONNXProgram.release` 为纯 Python、硬件无关资源释放接口,
无需新增或修改 `test_upstream` patch。
# 【CheckList】
- [x] 使用完整 API 名称 `torch.onnx.ONNXProgram.release`
- [x] 本 PR 仅修改 Native API 资料文件
- [x] 同步更新 2.7.1 / 2.9.0 / 2.10.0 / 2.11.0 / 2.12.0 / 2.13.0 / 2.14.0 共 7 套资料
- [x] 已按最新 `master` 重新确认 7 个目标 `torch-onnx.md` 均存在
- [x] 重建前 7 个版本均未登记 `torch.onnx.ONNXProgram.release`
- [x] `release()` 按 `torch.onnx.ONNXProgram` 子方法结构登记
- [x] 7 个版本均使用 `**产品支持情况**`
- [x] 三条产品支持信息均使用 Markdown 列表标记 `-`
- [x] A2 产品项使用 `<!-- npu="910b" idN -->`
- [x] A3 产品项使用 `<!-- npu="A3" idN -->`
- [x] 950 产品项使用 `<!-- npu="950" idN -->`
- [x] 每个文件内新增 marker ID 均唯一
- [x] Atlas A2训练系列产品登记为“支持”
- [x] Atlas A3训练系列产品登记为“支持”
- [x] Ascend 950DT系列产品登记为“支持”
- [x] 非计算类 API 未增加 fp16、fp32、bf16 等 dtype 限制
- [x] `git diff --check` 通过
- [x] staged `git diff --check` 通过
- [x] 7 个版本 `release_line_count` 均为 1
- [x] 最终 diff 为 `7 files changed, 140 insertions(+)`
- [x] 资料分支保持单任务提交,`commit_count=1`
- [x] PR 已基于最新 master 重建
- [x] Git Hooks Checking 通过
- [x] 本地 SHA 与远端 SHA 一致
- [x] `--force-with-lease` 推送成功
- [x] 已说明社区直接用例情况和无需新增 NPU 专项测试的原因
- [x] 不涉及 `test_upstream` patch
- [x] 2.7.1 使用 `onnx_dynamo.html#torch.onnx.ONNXProgram.release`
- [x] 2.9.0 / 2.10.0 使用对应 `docs.pytorch.org/docs/<version>/onnx_export.html` 精确链接
- [x] 2.11.0 / 2.12.0 / 2.13.0 / 2.14.0 使用对应 `pytorch.org/docs/<version>/onnx_export.html` 精确链接
- [x] A2 / A3 / A5 实机验证全部 PASS
- [x] A5 Ascend950PR / Ascend950PR_9579 按任务口径等价 Ascend 950DT
- [x] 最新提交的 CLA 为 `YES`
- [x] 最新提交的 CI 为 `YES`
- [x] 最新提交的 docs CI 为 `YES`
- [x] 三个验收标签全部为 `YES`
See merge request: Ascend/pytorch!45083
2026-10-10 17:25:03 +08:00
gcw_CHjSLYhf
dbeb5e0ede
docs: update torch.UntypedStorage support status
...
Co-authored-by: gcw_CHjSLYhf<2839668818@qq.com >
# message auto-generated for no-merge-commit merge:
!46583 merge docs-torch-UntypedStorage into master
docs: update torch.UntypedStorage support status
Created-by: gcw_CHjSLYhf
Commit-by: gcw_CHjSLYhf
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3739 https://gitcode.com/Ascend/pytorch/issues/3750 https://gitcode.com/Ascend/pytorch/issues/3760 https://gitcode.com/Ascend/pytorch/issues/3761
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
## 一. API 功能说明:
### 1. torch.UntypedStorage.filename
`filename` 是`torch.UntypedStorage`这个类的一个只读属性,用于获取与当前 Storage 关联的内存映射文件路径。因此和平台设备有关联,需要增加一个快速的验证性测试。
PyTorch 2.7 中的实现为:
```python
@property
def filename(self):
return self._get_filename()
```
因此它属于 Python 属性封装,但实际结果由底层 Storage 元数据接口 `_get_filename()` 提供。
### 2. torch.UntypedStorage.hpu
`torch.UntypedStorage.hpu()` 用于 返回一个在 HPU(Habana Gaudi 加速器)上的存储副本,如果该对象已在HPU内存中且位于正确的设备上,则不执行复制,直接返回原始对象。因为该API与HPU平台设备具有强绑定关系。
参数说明:
- `device`:目标 HPU 设备编号,默认使用当前 HPU 设备;
- `non_blocking`:如果源内存满足异步复制条件,则允许异步复制。
PyTorch 2.7 中的核心实现为:
```python
def hpu(self, device=None, non_blocking=False):
device2 = (
torch.device("hpu", device)
if device
else torch.device("hpu")
)
return self.to(
device=device2,
non_blocking=non_blocking,
)
```
### 3. torch.UntypedStorage.nbytes
`torch.UntypedStorage.nbytes()` 返回当前底层 Storage 实际占用的字节数,返回类型为 `int`。
但要注意,`nbytes()` 查询的是整个 Storage 的大小,而不是当前 Tensor View 的逻辑数据量。
例如:
```python
base = torch.empty(16, dtype=torch.float32)
view = base[::2]
base.untyped_storage().nbytes() == 64
view.untyped_storage().nbytes() == 64
# view只有8个逻辑元素
view.numel() * view.element_size() == 32
```
这是因为 `view` 和 `base` 共享同一个底层 Storage。
接口本身主要读取底层 Storage 元数据,不执行计算算子,但它读取的是 NPU Storage 的实际字节范围,可以验证 NPU Tensor 到 UntypedStorage 的连接是否正确,因此需要增加 NPU 功能测试。
### 4. torch.UntypedStorage.new
`torch.UntypedStorage.new`在当前 Storage 所在设备上,创建一个新的、大小为 0 的 UntypedStorage。torch.UntypedStorage.new() 由底层 Storage 实现提供。NPU Storage 调用该接口时,需要正确处理 PrivateUse1/NPU 设备信息。因此需要补充这个API在torch-npu平台上的测试用例。
## 二. 上游用例检查情况:
检查 PyTorch 上游 Storage 相关测试后,结果如下:
| API | 上游是否存在独立直接用例 | 检查结果 |
|---|---:|---|
| ` torch.UntypedStorage.filename` | 未发现 | 上游核心`test/test_torch.py`中未发现直接读取`.filename`的独立用例 |
| `torch.UntypedStorage.hpu` | 未发现 | 上游核心Storage测试中未发现直接调用`.hpu()`的独立用例 |
| `torch.UntypedStorage.nbytes` | 存在部分覆盖 | 上游在Storage Meta测试中调用了`s.nbytes()`并比较不同Storage的字节数 |
| `torch.UntypedStorage.new` | 存在部分覆盖 | 上游在Storage Meta测试中调用了`s.nbytes()`并比较不同Storage的字节数 |
## 三. 资料情况检查:
- `torch.UntypedStorage.filename`:在torch上游社区存在独立条目,同时在当前项目中该API资料已经存在,但是A5支持情况有误,因此需要进行资料修正。

- `torch.UntypedStorage.hpu`:在torch上游社区存在独立条目,同时在当前项目中该API资料已经存在,由于该API与hpu平台存在硬编码,系统支持情况,因此不需要进行资料补充和修正。

- `torch.UntypedStorage.nbytes`在torch上游社区存在独立条目,同时在当前项目中该API资料有误,因此需要进行资料修正。

- `torch.UntypedStorage.new` torch上游社区存在独立条目,同时在当前项目中该API资料有误,因此需要进行资料修正。

# 【资料变更】
修改以下文件:
`docs/zh/api/native_api/pytorch_2-7-1/torch-Storage.md`
`docs/zh/api/native_api/pytorch_2-11-0/torch-Storage.md`
`docs/zh/api/native_api/pytorch_2-12-0/torch-Storage.md`
`docs/zh/api/native_api/pytorch_2-13-0/torch-Storage.md`
# 【接口变更】
不涉及
# 【功能验证】
## 1. 测试场景
# torch.UntypedStorage API 功能性验证
## 1. 测试场景
| 编号 | API | 测试场景 | 预期结果 |
| --- | --- | --- | --- |
| 1 | `torch.UntypedStorage.filename` | 获取普通 CPU Tensor 底层 Storage 的 `filename` | 普通 CPU Storage 未关联内存映射文件,返回 `None` |
| 2 | `torch.UntypedStorage.filename` | 使用 `from_file(shared=True)` 创建共享文件映射 Storage | `filename` 返回字符串,并且规范化路径与映射文件路径一致 |
| 3 | `torch.UntypedStorage.filename` | 使用 `from_file(shared=False)` 创建私有文件映射 Storage | 私有映射的 `filename` 返回 `None` |
| 4 | `torch.UntypedStorage.filename` | 获取 NPU Tensor 底层 Storage 的 `filename` | Storage 位于 NPU,且未关联 CPU 文件映射,返回 `None` |
| 5 | `torch.UntypedStorage.hpu` | 在纯 torch-npu 环境中调用默认参数 `hpu()` | 因未加载 HPU 设备模块,抛出包含 `HPU device module is not loaded` 的 `AssertionError` |
| 6 | `torch.UntypedStorage.hpu` | 指定 `device=1, non_blocking=True` 调用 `hpu()` | 参数可以被接口正常解析;因未加载 HPU 模块,抛出预期 `AssertionError` |
| 7 | `torch.UntypedStorage.nbytes` | 验证 `float16` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 8 | `torch.UntypedStorage.nbytes` | 验证 `float32` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 9 | `torch.UntypedStorage.nbytes` | 验证 `int32` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 10 | `torch.UntypedStorage.nbytes` | 验证 `int64` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 11 | `torch.UntypedStorage.nbytes` | 直接在 CPU/NPU 上构造指定字节数的 UntypedStorage | `nbytes()`、`size()` 和 `len()` 均返回构造时指定的字节数 |
| 12 | `torch.UntypedStorage.nbytes` | 创建大小为 0 的空 NPU Storage | `nbytes()`、`size()` 和 `len()` 均返回 0 |
| 13 | `torch.UntypedStorage.nbytes` | 获取非连续 NPU Tensor View 的底层 Storage 字节数 | View 与原 Tensor 共享底层 Storage,返回整个底层 Storage 的字节数 |
| 14 | `torch.UntypedStorage.new` | 对 CPU Storage 调用 `new()` | 返回独立、大小为 0、设备类型仍为 CPU 的 UntypedStorage |
| 15 | `torch.UntypedStorage.new` | 对 NPU Storage 调用 `new()` | 返回独立、大小为 0、设备类型仍为 NPU 的 UntypedStorage |
| 16 | `torch.UntypedStorage.new` | 对 `new()` 返回的 Storage 执行 `resize_()` | 新 Storage 的大小发生变化,原 Storage 的大小不受影响 |
| 17 | `torch.UntypedStorage.new` | 对共享文件映射 Storage 调用 `new()` | 返回普通空 CPU Storage,不继承原 Storage 的文件映射关系 |
## 2. 测试核心代码
```python
class TestUntypedStorageAPIs(TestCase):
def test_untyped_storage_filename(self):
# 场景1:普通CPU Storage不关联内存映射文件
cpu_storage = torch.empty(
8,
dtype=torch.float32,
device="cpu",
).untyped_storage()
self.assertEqual(cpu_storage.device.type, "cpu")
self.assertIsNone(cpu_storage.filename)
# 场景2和3:共享文件映射与私有文件映射Storage
with tempfile.TemporaryDirectory() as temp_dir:
file_path = os.path.join(
temp_dir,
"untyped_storage.bin",
)
shared_storage = torch.UntypedStorage.from_file(
file_path,
shared=True,
nbytes=32,
)
self.assertEqual(shared_storage.device.type, "cpu")
self.assertEqual(shared_storage.nbytes(), 32)
self.assertIsInstance(
shared_storage.filename,
str,
)
self.assertEqual(
os.path.realpath(shared_storage.filename),
os.path.realpath(file_path),
)
# 释放共享映射后再创建私有映射
del shared_storage
private_storage = torch.UntypedStorage.from_file(
file_path,
shared=False,
nbytes=32,
)
self.assertEqual(private_storage.device.type, "cpu")
self.assertEqual(private_storage.nbytes(), 32)
self.assertIsNone(private_storage.filename)
del private_storage
# 场景4:NPU Storage不关联CPU内存映射文件
npu_storage = torch.empty(
8,
dtype=torch.float32,
device="npu",
).untyped_storage()
self.assertEqual(npu_storage.device.type, "npu")
self.assertIsNone(npu_storage.filename)
def test_untyped_storage_hpu(self):
npu_storage = torch.empty(
8,
dtype=torch.float32,
device="npu",
).untyped_storage()
self.assertEqual(
npu_storage.device.type,
"npu",
)
# 场景5:在torch-npu平台使用默认参数调用hpu()
with self.assertRaisesRegex(
AssertionError,
r"HPU device module is not loaded",
):
npu_storage.hpu()
# 场景6:在torch-npu平台指定device和non_blocking参数
with self.assertRaisesRegex(
AssertionError,
r"HPU device module is not loaded",
):
npu_storage.hpu(
device=1,
non_blocking=True,
)
def test_untyped_storage_nbytes_for_tensor_dtypes(self):
test_cases = [
(torch.float16, 6),
(torch.float32, 6),
(torch.int32, 6),
(torch.int64, 6),
]
# 场景7至10:不同dtype的CPU/NPU Storage字节数
for dtype, numel in test_cases:
with self.subTest(dtype=dtype):
cpu_tensor = torch.empty(
numel,
dtype=dtype,
device="cpu",
)
npu_tensor = torch.empty(
numel,
dtype=dtype,
device="npu",
)
cpu_storage = cpu_tensor.untyped_storage()
npu_storage = npu_tensor.untyped_storage()
expected_nbytes = (
numel * cpu_tensor.element_size()
)
self.assertEqual(
cpu_storage.nbytes(),
expected_nbytes,
)
self.assertEqual(
npu_storage.nbytes(),
expected_nbytes,
)
self.assertEqual(
cpu_storage.nbytes(),
npu_storage.nbytes(),
)
# UntypedStorage的长度单位也是字节
self.assertEqual(
len(cpu_storage),
expected_nbytes,
)
self.assertEqual(
len(npu_storage),
expected_nbytes,
)
def test_untyped_storage_nbytes_for_direct_storage(self):
# 场景11:直接构造指定字节数的CPU/NPU Storage
for device in ["cpu", "npu"]:
with self.subTest(device=device):
See merge request: Ascend/pytorch!46583
2026-10-10 17:21:49 +08:00
zhangjiahao-2026
c6a133ce28
docs: mark torch.layout as supported on Ascend 950DT
...
Co-authored-by: zhangjiahao-2026<2332445379@qq.com >
# message auto-generated for no-merge-commit merge:
!46016 merge docs-issue-3378-layout-950dt into master
docs: mark torch.layout as supported on Ascend 950DT
Created-by: zhangjiahao-2026
Commit-by: zhangjiahao-2026
Merged-by: ascend-robot
Description: # 【合入来源】
关联任务issue: <https://gitcode.com/Ascend/pytorch/issues/3378 >
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
在 master 资料中更新公开非计算类 API `torch.layout` 的 Ascend 950DT 支持情况。
修改文件:
* docs/zh/api/native_api/pytorch_2-7-1/Tensor-Attributes.md
* docs/zh/api/native_api/pytorch_2-11-0/Tensor-Attributes.md
* docs/zh/api/native_api/pytorch_2-12-0/Tensor-Attributes.md
* docs/zh/api/native_api/pytorch_2-13-0/Tensor-Attributes.md
具体修改内容:
1. 在 PyTorch 2.7.1、2.11.0、2.12.0 和 2.13.0 资料中,将 `torch.layout` 的 `Ascend 950DT` 由「不支持」改为「支持」;
2. Atlas A2 训练系列产品、Atlas A3 训练系列产品保持「支持」不变;
3. 该 API 为非计算类接口,与具体数据类型无关,不填写数据类型限制;
4. 不新增 A5 / 950PR 产品字段,资料产品维度仍为 A2 / A3 / 950DT。
本 PR 仅修改目标 API 的 950DT 支持标记,不批量修改同一文件中其他历史 API 的资料内容。
# 【资料变更】
资料检查结果:master 下的原生 API 资料已收录 `torch.layout`,Atlas A2、Atlas A3 标记为支持,Ascend 950DT 原标记为不支持。
本次已补充 A5(Ascend950PR)实机验证并通过,因此将以下版本目录 `Tensor-Attributes.md` 中 `torch.layout` 的 Ascend 950DT 更新为支持:
* PyTorch 2.7.1
* PyTorch 2.11.0
* PyTorch 2.12.0
* PyTorch 2.13.0
该 API 为公开非计算类接口,与张量数据类型无关,不填写数据类型限制。
# 【接口变更】
不涉及
# 【功能验证】
`torch.layout` 是表示 `torch.Tensor` 内存布局的 PyTorch 原生类型。本任务验证现有社区用例覆盖的 `torch.zeros + torch.strided` 路径。
PyTorch 官方社区在以下用例中已有相关验证:
```text
test/test_tensor_creation_ops.py::TestTensorCreation.test_zeros_dtype_layout_device_match
```
`torch.layout` 由 PyTorch 框架公共代码注册,不包含 NPU 专属 kernel 或设备分支,不需要修改 Torch-NPU 功能实现,也不需要新增测试文件或 `test_upstream` patch。
API 功能、社区用例情况、NPU 适配分析和各版本验证结果见说明 Issue:
<https://gitcode.com/Ascend/pytorch/issues/3378 >
A5 硬件验证信息如下。
验证设备:

验证环境:
```text
python: 3.10.12
torch: 2.12.0+cpu
torch_npu: 2.12.0
npu_available: True
device: Ascend950PR_9579
```
验证命令:
```bash
python3 /tmp/test_layout_3378_a5.py
```
验证场景:对齐社区用例 `test_zeros_dtype_layout_device_match`,在 NPU 上使用 `layout=torch.strided` 调用 `torch.zeros((2, 3), ...)`,覆盖以下 7 种 dtype:
1. `torch.bool`
2. `torch.uint8`
3. `torch.int16`
4. `torch.int64`
5. `torch.float16`
6. `torch.float32`
7. `torch.complex64`
每种 dtype 均校验返回 Tensor 的 `dtype`、`layout`、`device` 与入参一致。
运行截图:

验证结论:
`torch.layout` 的 `torch.zeros + torch.strided` 路径在上述 A5(Ascend950PR)环境中 7 种 dtype 均验证通过。本结论不扩大为所有稀疏 layout 及其相关算子均已完成兼容性验证。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46016
2026-10-10 17:09:10 +08:00
WSs_321
f922b03d58
新增A3 UT job
...
Co-authored-by: w30057661<wangshusheng7@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47664 merge master_a3_ut into master
新增A3 UT job
Created-by: WSs_321
Commit-by: w30057661
Merged-by: ascend-robot
Description: ## 变更内容
`PR-pipeline_pytorch.yml`:为 v2.7.1 分支新增 `UT_A3_part_1` / `UT_A3_part_2` 两个 UT job(WORLD_SIZE=2、RANK 1/2),使用 A3 专用镜像 `pytorch_2.7.1_a3_aarch64_builder:20260804`,通过 `runs_on_device: "910C=1"` 调度到 910C 设备;`Detect_file_changes` 的 modify_files.txt 解析改用 JSON,修复文件名含空格/逗号时的解析问题。
`ut_job.yml`:新增 `runs_on_device` input 参数化 runs-on 设备标签(默认 `npu=1`,现有 job 行为不变);环境打印阶段补充 NPU SoC 信息。
`ut_job_distributed.yml` / `ut_job_inductor.yml`:环境打印阶段补充 NPU SoC 信息。
## 关联 issue
https://gitcode.com/Ascend/pytorch/issues/5330
See merge request: Ascend/pytorch!47664
2026-10-10 17:07:56 +08:00
ljfnjj1234567
26704f875d
docs: Ascend 950DT support for torch.autograd.graph.Node.register_prehook
...
Co-authored-by: ljfnjj1234567<wn0010240@163.com >
# message auto-generated for no-merge-commit merge:
!45886 merge node-register-prehook-master into master
docs: Ascend 950DT support for torch.autograd.graph.Node.register_prehook
Created-by: SS_RR
Commit-by: ljfnjj1234567
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联issue: https://gitcode.com/Ascend/pytorch-ecosystem/issues/24
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
`torch.autograd.graph.Node.register_prehook` 为设备无关的 autograd 图机制(纯 Python 抽象 + C++ autograd 引擎分发,与 register_hook 机制同构),A2/A3 已支持;Ascend 950DT 同享 autograd 引擎、实际已支持。原文档支持状态标注为「不支持」,与实际不符,本次按最新验收标准修正为「支持」。
# 【资料变更】
涉及。刷新 `torch-master/docs/zh/api/native_api/pytorch_2-{7-1,11-0,12-0,13-0}/torch-autograd.md`(资料补齐已转移至 master 分支;2-9-0/2-10-0 目录已删除,新增 2-13-0;同步最新文字格式 `- <term>...</term>:支持`)。4 个版本目录各含 2 处 `register_prehook()` 文档块(同属 `torch.autograd.graph.Node` 类),本次统一将产品支持情况中 `- <term>Ascend 950DT</term>:不支持` 改为 `- <term>Ascend 950DT</term>:支持`,共 8 处。register_hook 等其它方法未改动。
# 【接口变更】
不涉及(纯资料状态修正,无代码、无接口变更)。
# 【功能介绍】
`torch.autograd.graph.Node.register_prehook`:在 autograd 图节点上注册 backward pre-hook,节点梯度每次被计算前调用 `hook(grad_outputs)`,可返回新梯度替换 `grad_outputs`,返回 `RemovableHandle` 用于移除。与 `register_hook`(签名 `hook(grad_inputs, grad_outputs)`、替换 grad_inputs)机制同构,仅签名与替换目标不同。
# 【功能验证】
该 API 为纯 Python + autograd 引擎分发的设备无关机制,官方用例在官方环境原样运行通过(issue 已验证):
```
python -m pytest .../test_autograd.py -k "grad_fn_prehooks or prehook_ordering or accumulate_grad_posthooks_can_observe_tensor_prehook" -q
```
- v2.7.1:`5 passed, 695 deselected in 9.84s`
- v2.11.0:`5 passed, 730 deselected in 3.32s`
- v2.12.0:`5 passed, 739 deselected in 3.85s`
A5验证:
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# cd /workspace/user_data && /workspace/envs/torch-271/bin/python -m pytest /workspace/user_data/pytorch-2.7.1-up/test/test_autograd.py -k "grad_fn_prehooks or prehook_ordering or accumulate_grad_posthooks_can_observe_tensor_prehook" -q
Running 5 items in this shard
..... [100%]
5 passed, 632 deselected in 2.90s
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6 Version: 25.7.rc1.6 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
| 0 | Ascend950PR | OK | 208.5 62 0 / 0 |
| | | 0000:55:00.0 | 0 0 / 0 5238 / 131072 |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID | Process id | Process name | Process memory(MB) |
+===========================+===============+=====================================================+
| No running processes found in NPU 0 |
+===========================+===============+=====================================================+
```
文档状态校验:4 个版本目录 `torch-autograd.md` 中 `register_prehook()` 块的 950DT 状态已全部由「不支持」改为「支持」。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45886
2026-10-10 16:47:10 +08:00
zhangjiahao-2026
d8fa00afa6
docs: mark torch.ShortStorage as supported on Ascend 950DT
...
Co-authored-by: zhangjiahao-2026<2332445379@qq.com >
# message auto-generated for no-merge-commit merge:
!46018 merge docs-issue-3861-shortstorage-950dt into master
docs: mark torch.ShortStorage as supported on Ascend 950DT
Created-by: zhangjiahao-2026
Commit-by: zhangjiahao-2026
Merged-by: ascend-robot
Description: # 【合入来源】
关联任务issue: <https://gitcode.com/Ascend/pytorch/issues/3861 >
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
在 master 资料中更新公开非计算类 API `torch.ShortStorage` 的 Ascend 950DT 支持情况。
修改文件:
* docs/zh/api/native_api/pytorch_2-7-1/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-9-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-10-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-11-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-12-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-13-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-14-0/torch-Storage.md
具体修改内容:
1. 在 PyTorch 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0、2.13.0 和 2.14.0 资料中,将 torch.ShortStorage 在 Ascend 950DT 系列产品上的支持状态由“不支持”修改为“支持”。
2. Atlas A2 训练系列产品、Atlas A3 训练系列产品保持「支持」不变;
3. 该 API 为非计算类接口,与具体数据类型无关,不填写数据类型限制;
4. 不新增 A5 / 950PR 产品字段,资料产品维度仍为 A2 / A3 / 950DT;
本 PR 仅修改目标 API 的 950DT 支持标记,不批量修改同一文件中其他历史 API 的资料内容。
# 【资料变更】
资料检查结果:master 下的原生 API 资料已收录 `torch.ShortStorage`,Atlas A2、Atlas A3 标记为支持,Ascend 950DT 原标记为不支持。
本次已补充 A5(Ascend950PR)实机验证并通过,因此将以下版本目录 `torch-Storage.md` 中 `torch.ShortStorage` 的 Ascend 950DT 更新为支持:
* PyTorch 2.7.1
* PyTorch 2.9.0
* PyTorch 2.10.0
* PyTorch 2.11.0
* PyTorch 2.12.0
* PyTorch 2.13.0
* PyTorch 2.14.0
该 API 为公开非计算类接口,与张量数据类型无关,不填写数据类型限制。
# 【接口变更】
不涉及
# 【功能验证】
`torch.ShortStorage` 是 PyTorch Legacy TypedStorage 类型之一,用于保存 16 位有符号整数数据,元素类型对应 `torch.int16`。
PyTorch 官方社区在以下用例中已有相关验证:
```text
test/test_torch.py::test_storage_setitem
test/test_torch.py::test_tensor_storage_type
test/test_torch.py::test_element_size
test/test_torch.py::test_from_buffer
test/test_torch.py::test_storage_error
test/test_torch.py::test_storage_casts
```
`torch.ShortStorage` 对应的 NPU Storage 类型为 `torch_npu.npu.ShortStorage`。现有 `test/test_torch.py` 已完成 NPU Storage 类型映射适配,不需要修改 Torch-NPU 功能实现,也不需要新增测试文件或 `test_upstream` patch。
API 功能、社区用例情况、NPU 适配分析和各版本验证结果见说明 Issue:
<https://gitcode.com/Ascend/pytorch/issues/3861 >
A5 硬件验证信息如下。
验证设备:

验证环境:
```text
python: 3.10.12
torch: 2.12.0+cpu
torch_npu: 2.12.0
npu_available: True
device: Ascend950PR_9579
```
验证命令:
```bash
python3 /tmp/test_shortstorage_3861_a5.py
```
验证场景:
1. 无参数创建及 `element_size`
2. 按元素数量、数据序列创建
3. CPU / NPU 元素及切片赋值
4. `from_buffer`
5. Storage 类型转换
6. NPU int16 Tensor 映射为 `torch_npu.npu.ShortStorage`
7. `torch.ShortStorage(wrap_storage=npu_storage)` 抛出 `must be cpu`
8. `torch_npu.npu.ShortStorage(wrap_storage=cpu_storage)` 抛出 `must be npu`
运行截图:

验证结论:
`torch.ShortStorage` 在上述 A5(Ascend950PR)环境中上述场景均验证通过。TypedStorage deprecation warning 属于 PyTorch 上游预期告警,不影响结论。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46018
2026-10-10 16:39:36 +08:00
chenrayray
6c3c3c940c
docs: 新增原生 API 格式与写作规范
...
Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com >
# message auto-generated for no-merge-commit merge:
!47603 merge codex/native-api-writing-guide into master
docs: 新增原生 API 格式与写作规范
Created-by: chenrayray
Commit-by: Xinrui Chen
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
- [x] 资料更新
关联 Issue:https://gitcode.com/Ascend/pytorch/issues/5340
# 【修改方案】
新增原生 API 格式与写作规范,统一模块及子标题与对应版本上游 PyTorch 的名称、结构和顺序,并明确上游已废弃或不展示内容的处理方式。
规范覆盖产品支持列表、仅支持独立行的产品筛选标签、标签 ID 配对、HTML 和隐藏标题、复杂限制与代码示例,以及 Named Tensors 等专题链接。制定时间为2026年10月。
# 【资料变更】
新增 `docs/zh/api/native_api/_writing_guide.md`,文件名以下划线开头,供文档维护者使用。未增加用户文档导航入口。
# 【接口变更】
不涉及。
# 【功能验证】
- 已核对本次讨论确定的写作规则及模板示例。
- `git diff --check` 通过,仅新增上述规范文件。
- 本次为文档规范新增,未运行 NPU 测试或完整站点构建;远端 CI 待确认。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志(不涉及)
- [x] 代码实现进行了返回值、空指针等校验(不涉及)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47603
2026-10-10 15:58:21 +08:00
rmch
3e0639707b
feat(inductor): add TE ComboKernel support
...
Co-authored-by: rmch<chenruimin2@huawei.com >
# message auto-generated for no-merge-commit merge:
!47085 merge te-combo-kernel into master
feat(inductor): add TE ComboKernel support
Created-by: rmch
Commit-by: rmch
Merged-by: ascend-robot
Description: ## 变更摘要
完成 TE 后端 ComboKernel 适配第 5-9 步,将满足约束的多个 Triton Experimental pointwise kernel 合并为一次 TEComboKernel 调用,减少 kernel launch 次数并保持不满足条件时的原有 fallback 行为。
### 主要改动
- 新增 `TEComboKernel` 和 `TEComboSubKernel` codegen,共享 `XBLOCK=256`,按成员 kernel 的 block 数和前缀和执行分组 dispatch。
- 增加 `te_combo_meta` 元数据和 launcher grid 处理,支持一次 launch 内按 combo slot 分发成员 kernel。
- 增加 TE 专用准入检查:当前阶段仅合并静态、连续、同 shape、同 dtype、pointwise-only 的 kernel;不满足条件时回退到普通 kernel。
- 修复 combo fallback 生命周期,保留独立 fallback kernel 仍需要的 buffer,待所有 combo source 生成和注册成功后再提交 `mark_run`、buffer removal 等状态更新。
- 为 combo 成员变量和共享 tile constexpr 名称增加 slot 后缀,避免多个成员之间发生命名冲突。
- 保持 ComboKernel 与现有 `foreach`/Triton Experimental 调度路径兼容,并补充配置开关。
## 测试
- ComboKernel 定向测试:`4 passed`
- TE Triton Experimental 完整测试目录:`39 passed`
- 变更 Python 文件 `py_compile` 通过
- `git diff --check` 通过
- Ascend 910B3 数值验证通过:1024、10001、0、1、255、256、257 元素场景;combo disabled 和混合 dtype fallback 场景均正确。
## 当前边界
- 当前 phase-one 仅覆盖静态 contiguous、同 shape、同 dtype 的 pointwise kernel。
- 动态 shape、不同 dtype/shape、非 pointwise 操作和不满足 ABI/资源约束的场景继续使用普通 kernel 或显式 fallback。
**关联 issue:**
Fixes https://gitcode.com/Ascend/pytorch/issues/5093
**RFC设计文档:**
https://gitcode.com/Ascend/pytorch/issues/5325
See merge request: Ascend/pytorch!47085
2026-10-10 15:45:27 +08:00
c_34
472321bf2e
fxrt: port upstream runtime changes made since the in-tree integration
...
Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47662 merge fxrt-port-squash into master
fxrt: port upstream runtime changes made since the in-tree integration
Created-by: c_34
Commit-by: chenhaozhe
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [x] 重构优化 https://gitcode.com/Ascend/pytorch/issues/5278
- [ ] 资料更新
同步进行in-tree合入过程中修改的原始仓库内容。
## 背景
fxrt 整改合入 master 之后,上游(pta 分支)又积累了一批运行时改动。本 PR 把这些改动移植进 in-tree 的 `torch_npu.fxrt`,使两边重新对齐。
**`e64806be`** (08-31) 按生成时的 stride 寻址 compiled-kernel 参数
融合后端是针对参数在 trace 时的 stride 生成 kernel 的。记录这些 layout 并在调用前恢复,使期间被重新 layout 的参数仍按 kernel 预期的方式寻址。
→ `compiled_kernel_adapter.py`、`fx_backend.py`
**`81a537aa`** (09-02) DVM op
通过 pybind 头文件已授予 `fxrt::ops::OpDvmCallV2` 的 friendship 访问 torch_npu 的 DVM kernel 状态,而不是它从未存在过的公有 accessor;helper 折进 op 类以使 friendship 生效。动态与静态 kernel 合并为一个入口,由 kernel 的 `F_DYN` 标志区分。附带效果见下方「需要注意」。
→ `src/ops/ascend/dvm/`、`dvm_adapter.py`
**`ad4c84cc`** (09-02) AutoFuse
新增 `autofuse_call` op:dlopen AutoFuse codegen 产出的 wrapper stub 并直接 launch,外加生成该 stub 的 Python codegen。下降位置在 DVM 与通用 compiled-kernel 路径之间,由 `FXRT_AUTOFUSE_NATIVE=1` 门控。算子注册无需登记表,`LoadOpLib` 按 `libops_ascend*` 前缀发现。
→ `src/ops/ascend/autofuse/`、`autofuse_codegen.py`、`ops.list`
**`bbf45634`** (09-07) custom / torch / python call 的 ref、view 零拷贝
仅重新解释输入 storage 的输出不再拷贝。`OpRunner` 里通用的 ref 元数据同步会跳过输出 shape 与输入不同的算子,因此 view 类自定义算子自行计算元数据;`AclnnCustomViewOperator` 是它们的新基类,经 custom op API 暴露。
→ `op_custom_call`、`op_torch_call`、`op_python_call`、`aclnn_custom_view_operator.h`、`data_convert`
**`0ae75226`** (09-12) FXRT 自定义集合通信
用 arg-mapping hook 把 vLLM 四参数的 all_gather ABI 适配到 FXRT 原生三参数 HCCL ABI;从 FX 图收集通信信息时,把 vLLM 的逻辑 group 名解析为对应的 torch device ProcessGroup。
→ `fx_backend.py`、`utils.py`
**`c7e3a2e0`** (09-12) FX 操作数分类,自定义调用加固
一个 FX 参数能否走标量算子 ABI,改由 FXRT 运行时实际可表示的值决定,而不是看 node target —— `item` 节点不再仅凭名字就被当成标量。自定义调用侧在转换前校验操作数种类,并报出出错的那一个,而不是在转换深处失败。
→ `fx_backend.py`、`symbolic_shape.py`、`op_torch_call`、`data_convert`
**`37fcc1bb`** (09-22) 修复多输出 ref 算子的输出数据校验
ref alias 输出与输入共享 storage,且两侧都不持有 deleter,清掉共享的 data pointer 会让第一个之后的每个输出都校验失败。改为读取 storage 地址而不取走它,仅在持有所有权的路径上移出 data pointer。影响 split、unbind、chunk。
→ `op_torch_call.cpp`
**`6051b291`** (09-22) `Tensor[]` 自定义调用输出保留 ref alias
返回 `Tensor[]` 的自定义调用丢失了单 Tensor 输出能保留的 ref aliasing,导致列表里每个元素各自声明 storage。让 alias 穿过列表输出,并把 `c7e3a2e0` 引入的操作数预校验换成转换点上的检查。
→ `fx_backend.py`、`op_torch_call`、`data_convert`
## 内容
建议按三组顺序审阅:
1. **compiled-kernel 路径**(`compiled_kernel_adapter.py`、`fx_backend.py`、`autofuse_codegen.py`、`src/ops/ascend/autofuse/`)——按 inductor 生成的 stride 寻址 kernel 参数而不再假定连续;FX 操作数分类,标量不再走张量路径;新增 `OP(autofuse_call)` 与 `FXRT_AUTOFUSE_NATIVE` 门控的原生 AutoFuse 下降。vLLM 集合通信 hook 在同一路径上,自成一体。
2. **零拷贝 view**(`op_custom_call`、`op_torch_call`、`op_python_call`、`aclnn_custom_view_operator.h`)——改为交出 ref 输出而非拷贝,`data_convert` 删掉只为喂拷贝而存在的转换。多输出校验修复与 `Tensor[]` alias 修复是对同一段代码的纠正。
3. **DVM v2**(`src/ops/ascend/dvm/`)——CMake 探测改为匹配 `torch_npu/csrc/inductor/dvm/pybind_api.h` 实际携带的 friend 声明,并通过该 friendship 访问 kernel 私有成员。
## 需要 reviewer 注意
**两处对上游的有意偏离,均在 CMake**:autofuse 的 `CMakeLists.txt` 采用 in-tree 同级算子模块的写法,而非上游的 glob + 自带 `install()` 形式(上游还链接了 in-tree 不存在的 `fxrt::securec`);`ops_ascend_autofuse` 加入 `FXRT_OP_LIBS` 与 `install_fxrt` 拷贝列表,使 wheel 携带该库。
**一处告警屏蔽**: 为了处理autofuse的自动生成算子函数签名,实现中使用了一个长f-string字符串进行代码生成,这个长字符串触发了超长行的告警,参考之前cpp_wapper中类似情况的处理方式增加的`.flak8`的告警屏蔽。
## 验证
Ascend 910B3 实测:
- `test/fxrt` 7 项全部通过
- `libops_ascend_autofuse.so` / `libops_ascend_dvm_v2.so` 均构建产出、随 wheel 安装,运行时经 `/proc/self/maps` 确认已 dlopen
- ref/view 定向用例 10/10 与 eager 一致:split(均分/不均分)、unbind、chunk、`split->add`、broadcast_tensors、select/permute、flatten/reshape、`item()` 标量、标量乘
- AutoFuse 门控双向验证:默认关闭与 `FXRT_AUTOFUSE_NATIVE=1` 结果均正确
- eta 推荐模型(inductor + fx_wrapper -> fxrt 运行时,batch 128)精度校验通过,QPS 8929;IR dump 显示 146 个 `compiled_kernel_mutation`,即本 PR 的 stride 与操作数分类改动在真实负载下被覆盖
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47662
2026-10-10 15:03:20 +08:00
hbhu_bin
2d91fb5660
fix lazy_fusion dump and enable
...
Co-authored-by: hb_hubin<hubin79@huawei.com >
# message auto-generated for no-merge-commit merge:
!47177 merge dvm-master-latest into master
fix lazy_fusion dump and enable
Created-by: hbhu_bin
Commit-by: hb_hubin
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
https://gitcode.com/Ascend/pytorch/issues/2264
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
无图融合问题修复
### 1. 缺少脚本侧的融合范围控制
TORCH_NPU_LAZY_FUSION 控制进程级融合行为,用户无法方便地将局部代码排除在融合范围之外。
### 2. dump 缺少灵活的区间控制
全程 dump 文件量较大,不便于只采集某个 step 或代码区间。
### 3. output 分配可能重入 flush
融合算子已构建 DVM 节点、但尚未分配和登记 output 时,内存分配可能触发回收或重试,并通过同步路径重入 flush。此时半构建图可能被提前提交、清理或回收,后续继续使用旧节点存在图状态失效风险。
### 4. 部分写入路径缺少输出约束检查
inplace 广播结果不能扩大目标张量;gelu_out、where_out 的输出参数也需要满足融合写入条件,不能直接按普通新分配输出处理。
## 解决方法
### 1. 新增脚本侧融合控制接口
新增 torch_npu.npu.lazy_fusion 模块,支持按代码区间控制融合:
```
from torch_npu.npu import lazy_fusion
with lazy_fusion.disabled():
output = model_part(input)
```
支持通过嵌套 lazy_fusion.enabled() 在局部重新开启融合。切换状态时提交当前待融合图,避免跨区间融合;正常退出或区间内异常退出时恢复之前的状态。
环境变量仍作为总开关,Python 接口不能绕过未开启的环境变量。C++ 绑定独立于 Inductor。
### 2. 支持按区间控制 dump
提供 set_dump_enabled() 和 dump_enabled():
```
lazy_fusion.set_dump_enabled(False)
for step, batch in enumerate(data):
with lazy_fusion.dump_enabled(step == 1):
output = model(batch)
```
环境变量仍是 dump 总开关;仅开启环境变量、不调用 Python 接口时,保持原有全程 dump 行为。
### 3. 保护 output 分配期间的图状态
在 output 分配及登记期间增加 RAII 保护:
- 分配期间重入 flush 时,暂不提交当前半构建图。
- 不改变此前已提交任务的正常排空流程。
- 分配完成后检查图标识及当前图状态,避免继续使用失效节点。
### 4. 不满足写入条件时回退 eager
- 对相关 inplace 和 foreach addc 系列增加轻量广播检查,避免广播结果扩大目标张量。
- 对 gelu_out、where_out 增加输出 shape/dtype 检查。
- 不满足条件时交由 eager 路径处理,不修改算子计算公式。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
涉及环境变量TORCH_NPU_LAZY_FUSION描述
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
涉及对外接口
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
提供用例,自验pass
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47177
2026-10-10 11:07:11 +08:00
baoxuebin_2026
1b30f7422c
test: add utils api npu coverage
...
Co-authored-by: baoxuebin_2026<xuebin@isrc.iscas.ac.cn >
# message auto-generated for no-merge-commit merge:
!44624 merge codex/utils-api-consistency-master into master
test: add utils api npu coverage
Created-by: baoxuebin_2026
Commit-by: baoxuebin_2026
Merged-by: ascend-robot
Description: # 【合入来源】
[#150 ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/150 )
[#137 ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/137 )
[#100 ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/100 )
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
公开issue:
- `torch.utils.checkpoint.set_device_states`:
https://gitcode.com/Ascend/pytorch-ecosystem/issues/150
- `torch.utils._foreach_utils._has_foreach_support`:
https://gitcode.com/Ascend/pytorch-ecosystem/issues/137
- `torch.utils.module_tracker.ModuleTracker`:
https://gitcode.com/Ascend/pytorch-ecosystem/issues/100
# 【修改方案】
1. API 功能说明:
- `torch.utils.checkpoint.set_device_states`:为指定设备恢复随机数生成器状态,用于 checkpoint 重计算等场景保持随机数状态一致。
- `torch.utils._foreach_utils._has_foreach_support`:判断给定设备和张量列表是否满足 foreach 快路径的使用条件。
- `torch.utils.module_tracker.ModuleTracker`:上下文管理器,用于跟踪模块前向和反向执行期间的模块层级。
2. 上游用例检查情况:
- `torch.utils.checkpoint.set_device_states` 涉及设备 RNG 状态。PyTorch 社区主要通过 checkpoint RNG 场景间接覆盖,未提供直接 NPU 用例,因此在 `test` 目录补充最小 NPU 验证。
- `torch.utils._foreach_utils._has_foreach_support` 用于判断设备是否支持 foreach 快路径,直接涉及 NPU 后端能力。PyTorch 社区未提供面向 NPU 的直接验证,因此在 `test` 目录补充最小 NPU 验证。
- `torch.utils.module_tracker.ModuleTracker` 为纯 Python 接口。PyTorch 社区已有独立、完整用例,覆盖模块层级、前向、反向和 checkpoint 场景,因此不新增 NPU 用例。
3. 新增用例文件:
- `test/test_utils_checkpoint_api.py`
- `test/test_utils_api.py`
4. 新增用例覆盖场景:
- `set_device_states` 显式传入 `device_type="npu"`,恢复 NPU RNG 状态并验证随机序列一致。
- `set_device_states` 省略可选参数 `device_type`,验证 Torch-NPU 默认设备类型路径。
- `_has_foreach_support` 验证 NPU 张量及 `None` 组成的列表支持 foreach 快路径。
- `_has_foreach_support` 验证混入非 Tensor 对象时返回不支持。
5. NPU 适配说明:
- 新增张量均通过 `torch.accelerator.current_accelerator()` 获取当前 NPU 设备。
- 未修改 `test_upstream/`,未新增 NPU 适配 patch。
- 未修改 Torch-NPU API 实现。
6. 新增或修改的测试文件头部已包含 Huawei copyright 和 API 功能说明。
# 【资料变更】
不涉及。资料补齐已单独提交文档 PR。
# 【接口变更】
不涉及。未修改跨仓接口,也未修改用户可见接口行为。
# 【功能验证】
测试环境:
```text
NPU: Ascend 910B2C
torch: 2.13.0
torch_npu: 2.13.0
CANN: 8.5.1
```
测试命令:
source /usr/local/Ascend/cann-8.5.1/set_env.sh
TORCH_DEVICE_BACKEND_AUTOLOAD=1 \
/usr/local/python3.11.14/bin/python test/test_utils_checkpoint_api.py -v
TORCH_DEVICE_BACKEND_AUTOLOAD=1 \
/usr/local/python3.11.14/bin/python test/test_utils_api.py -v
板端核心验证结果:
PASS test_set_device_states_restores_npu_rng_sequence
PASS set_device_states default device_type
PASS test_has_foreach_support_for_npu_tensors
PASS ModuleTracker NPU forward and backward validation
See merge request: Ascend/pytorch!44624
2026-10-10 10:21:35 +08:00
rain-666
04a516d92e
transfer_to_npu适配213UT用例
...
Co-authored-by: rain-666<chenxiaoyu12@huawei.com >
# message auto-generated for no-merge-commit merge:
!47384 merge master_213ut_0929 into master
transfer_to_npu适配213UT用例
Created-by: rain-666
Commit-by: rain-666
Merged-by: ascend-robot
Description: - `_patch_has_triton` :委托`torch_npu.utils._dynamo.has_triton` ,而不是硬编码 False —— 让原版 CUDA 代码里的`has_triton()` 门控在 NPU 上自然成立
- `_get_npu_type` 加`@functools.lru_cache` —— 保持`torch_npu inductor patch_is_gpu` 的`cache_clear()` 契约,绕过 upstream`len(avail_gpus) <= 1` 断言
- `_patch_triton_nvidia_driver` —— 在 NPU 机器上强制`CudaDriver.is_active=False` ,避免 triton nvidia/ascend 双驱动冲突
See merge request: Ascend/pytorch!47384
2026-10-10 09:28:27 +08:00
shi-yufeng99
4f8b463cff
fix addmm cored dumped problem
...
Co-authored-by: shi-bibibi99<shiyufeng8@huawei.com >
# message auto-generated for no-merge-commit merge:
!47655 merge 1009_master_catlass_branch1 into master
fix addmm cored dumped problem
Created-by: shi-yufeng99
Commit-by: shi-bibibi99
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
[#3463 ](https://gitcode.com/Ascend/pytorch/issues/3463 )
fix addmm core dumped error in fast_fusion part
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47655
2026-10-10 00:20:06 +08:00
pta-robot
06e2cb7a39
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47646 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-09 22:03:50.
See merge request: Ascend/pytorch!47646
2026-10-09 23:01:26 +08:00
stonexxx
95c7e46542
fix(inductor): 适配 NPU selector 的 best_config_future 参数
...
Co-authored-by: Stonexx<sheny1xuan@163.com >
# message auto-generated for no-merge-commit merge:
!47604 merge select_fix into master
fix(inductor): 适配 NPU selector 的 best_config_future 参数
Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
Fixes https://gitcode.com/Ascend/pytorch/issues/5312
# 【修改方案】
1. 在 `torch_npu/_inductor/select_algorithm.py` 的 NPU `AlgorithmSelectorCache.__call__` 补丁中对齐上游可选参数,支持 `best_config_future`,避免 GEMM lowering 传入该关键字时发生参数不兼容。
2. 等待并复用 future 返回的配置,筛选匹配候选,将筛选后的 choices 用于 cache lookup 和反馈。
3. 移除“首个 choice 不在 timings 即回退”的判断,从有效 timings 中选择最快候选,正确处理 future 筛掉首个候选的场景。
4. 保留已有 timeout、多模板及 defer 行为。`is_collective`、`min_speedup_threshold` 和 `benchmark_with_cudagraphs` 本次仅兼容签名,并标注 `Not supported on NPU`。
# 【资料变更】
不涉及。
# 【接口变更】
内部跨仓兼容适配:NPU selector 补丁签名与上游 PyTorch Inductor 的可选参数对齐。现有参数默认值不变,对外公开 API 无新增。
# 【功能验证】
提交:`73479a8a7dc7075c8828b57dc211b1554aabe70f`。
通过历史回归脚本(`c47dc0180e`)临时隔离加载当前 selector,验证签名及默认值、future 候选筛选、首个候选无 timing 时的最优选择,3 项测试全部通过。本分支未新增测试文件。
实际执行命令:
```bash
python3 /tmp/select-fix-pr-9gxtvfj4/validate_selector.py
python3 -m py_compile torch_npu/_inductor/select_algorithm.py
lintrunner -a torch_npu/_inductor/select_algorithm.py
git diff --check refs/remotes/mainline/master...select_fix
git merge-tree --write-tree refs/remotes/mainline/master select_fix
```
语法、lint 和 diff 检查通过,与目标 master 合并无冲突。验证范围为 Python 逻辑;本机缺少 `torch_npu._C`,NPU 真机验证、远端 CI 及自验证截图尚未提供。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47604
2026-10-09 17:45:09 +08:00
c_34
340048c6ea
fxrt: drop CPU op implementations in favour of the PyTorch fallback
...
Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47567 merge fxrt-cpu-ops-removal into master
fxrt: drop CPU op implementations in favour of the PyTorch fallback
Created-by: c_34
Commit-by: chenhaozhe
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [x] 重构优化 https://gitcode.com/Ascend/pytorch/issues/5278
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
torch_npu中主要提供npu上的支持和实现,原有的部分cpu算子功能属于冗余能力,移除。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
测试用例验证
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47567
2026-10-09 17:15:51 +08:00
y30037164
315edb17b9
nightly流水线换用新镜像,无卡编译不进行import torch之类验证
...
Co-authored-by: yuaiming<yuaiming@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47619 merge master into master
nightly流水线换用新镜像,无卡编译不进行import torch之类验证
Created-by: y30037164
Commit-by: yuaiming
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47619
2026-10-09 17:10:57 +08:00
wzyly
e8277e454d
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47614 merge master into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
测试环境检视问题修改
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47614
2026-10-09 17:10:52 +08:00
JfanLiu
8f91f498ea
test: add NPU coverage for torch.testing._internal.common_utils.skipIfRocm
...
Co-authored-by: JfanLiu<1300083451@qq.com >
# message auto-generated for no-merge-commit merge:
!46599 merge test-skip-if-rocm-master into master
test: add NPU coverage for torch.testing._internal.common_utils.skipIfRocm
Created-by: JfanLiu
Commit-by: JfanLiu
Merged-by: ascend-robot
Description: # 【合入来源】
> 社区 issue:[Ascend/pytorch #4116 ](https://gitcode.com/Ascend/pytorch/issues/4116 )(原 [Ascend/pytorch #3704 ](https://gitcode.com/Ascend/pytorch/issues/3704 ))
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
按 #4116 审核结论(该 API 对硬件后端有依赖、上游用例不完整,需新增测试用例文件补齐测试场景),新增 `test/test_skip_if_rocm.py`(仅新增测试,不改动任何实现代码):
- 覆盖 `torch.testing._internal.common_utils.skipIfRocm` 的两种用法:裸装饰器 `@skipIfRocm` 与带参 `@skipIfRocm(msg=...)`;
- 运行路径:NPU 非 ROCm 构建,被装饰的用例正常执行,且不带 `__unittest_skip__` 标记;
- 跳过路径:`TEST_WITH_ROCM` 为真时,被装饰用例被 unittest runner 上报为 skipped,reason 为 `skipIfRocm: <msg>`(默认 msg 与自定义 msg 各覆盖一次);
- 装饰动作在 `mock.patch(...TEST_WITH_ROCM..., True)` 上下文内完成,保证跳过路径判定时机正确;同时兼容各版本实现差异(2.7.1 / 2.11.0 / 2.12.0 在调用期抛 `SkipTest`,2.13 起类目标在装饰期打 `__unittest_skip__` 标记)。
# 【测试方案】
- NPU 实跑:`python test/run_test.py test_skip_if_rocm -v`,6 个用例应全部通过;
- 覆盖 v2.7.1 / v2.11.0 / v2.12.0 / master 四个版本组合,实跑日志随后以评论附上;
- 用例仅使用 `torch.randn` / `torch.add` 与 unittest 断言,不引入新的算子或大负载。
See merge request: Ascend/pytorch!46599
2026-10-09 16:49:55 +08:00
y30037164
af440d9047
nightly build 移除镜像预装 torch 版本探测 (arm 无卡编译机 import 段错误)
...
Co-authored-by: yuaiming<yuaiming@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47596 merge master into master
nightly build 移除镜像预装 torch 版本探测 (arm 无卡编译机 import 段错误)
Created-by: y30037164
Commit-by: yuaiming
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47596
2026-10-09 14:50:18 +08:00
hbhu_bin
abac7268f2
fix flex_attention
...
Co-authored-by: hb_hubin<hubin79@huawei.com >
# message auto-generated for no-merge-commit merge:
!47482 merge fix-flex-attention into master
fix flex_attention
Created-by: hbhu_bin
Commit-by: hb_hubin
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
https://gitcode.com/Ascend/pytorch/issues/5293
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
修复图模式DVM后端复用FlexAttention triton自定义算子的问题,适配mask_mod/score_mod
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
已提供用例,验证ok
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47482
2026-10-09 14:35:52 +08:00
crazyDannyBoy
4370a2cf91
fix(inductor): stop dynamic reduction split only when low dims remain
...
Co-authored-by: crazyDannyBoy<xudezheng1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47553 merge fix/dynamic-split-low-dim-master into master
fix(inductor): stop dynamic reduction split only when low dims remain
Created-by: crazyDannyBoy
Commit-by: crazyDannyBoy
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47553
2026-10-09 11:17:45 +08:00
li_jing_hw
e75e3d4285
Refactor compat impl for strong validation instead of comment
...
Co-authored-by: li_jing_hw<lijing202@huawei.com >
# message auto-generated for no-merge-commit merge:
!46750 merge master into master
Refactor compat impl for strong validation instead of comment
Created-by: li_jing_hw
Commit-by: li_jing_hw
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [x] 重构优化https://gitcode.com/Ascend/pytorch/issues/4978
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46750
2026-10-09 10:56:11 +08:00
wzyly
6f46a91484
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47568 merge cherry-pick-mr-47565-1791451169327-auto into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
测试环境检视问题修改
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47568
2026-10-09 09:56:46 +08:00
SorryNaCN
3cd2d928ac
[perf] [master] Optimize DVM GroupNorm, matmul, allocation and optional permute lowering
...
Co-authored-by: huangchengnuo<huangchengnuo1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47449 merge perf/dvm-groupnorm-matmul-fold-20260930 into master
[perf] [master] Optimize DVM GroupNorm, matmul, allocation and optional permute lowering
Created-by: SorryNaCN
Commit-by: huangchengnuo
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [x] 重构优化
- [ ] 资料更新
DVM 性能优化,合入目标为 `master`。关联社区 Issue:[[perf] DVM GroupNorm、matmul、内存分配与可选 permute lowering 优化](https://gitcode.com/Ascend/pytorch/issues/5282 )。
Fixes https://gitcode.com/Ascend/pytorch/issues/5282
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
本 PR 涉及 `torch_npu/_inductor/dvm/` 的 `config.py`、`decomp.py`、`mlir_fusion.py` 和新增的 `wrapper.py`。
1. **GroupNorm 分解**:从 DVM 分解排除列表移除 `aten.native_group_norm`,默认展开其计算,使 Inductor / DVM 可以继续进行融合。
2. **Matmul folding**:在 `patch_decomp()` 初始化阶段复用 `_override_matmul_should_fold_for_npu()`,将适用的 3D×2D matmul 转为 MM,减少权重广播和 BMM 开销。
3. **快速分配**:新增 `NpuDvmWrapperCodeGen`,继承 `NpuMlirWrapperCodeGen` 并在 DVM 后端注册中使用。普通 NPU 分配直接复用 Triton-ex 的 `NPUWrapperCodeGen.make_allocation`,生成 `_empty_strided_npu` 调用;非 NPU 分配、内存生命周期跟踪和 pinned 分配沿用父类路径,子图沿用父类创建路径。
4. **可选 permute lowering**:将 `aten.permute` 固定放入生成白名单,新增默认关闭的 `enable_fusion_permute`,参照 `enable_cat` 控制 DVM 融合规则。开启后可生成 `reinterpret_tensor` 视图。
**详细设计:组件关系与执行顺序**
- 分解链路:DVM 初始化 → `patch_decomp()` → 复用 NPU matmul folding 覆盖并更新分解配置 → Inductor 分解和调度 → DVM 融合与代码生成。
- 分配链路:DVM 后端注册 → `NpuDvmWrapperCodeGen` → 分配条件判断 → 复用 Triton-ex 快速分配或调用父类分配逻辑。类关系为 `NpuDvmWrapperCodeGen` 继承 `NpuMlirWrapperCodeGen`,按条件复用 `NPUWrapperCodeGen.make_allocation`。
- Permute 链路:`GENERATE_LIST` 注册 `aten.permute` → 融合规则读取 `enable_fusion_permute` → 开启时允许进入 DVM lowering,关闭时由规则拒绝 DVM 融合。
- 调试与兼容性:保留原有内存生命周期跟踪路径;permute 默认关闭,可通过开关对照验证。沿用现有调试能力,不新增日志或错误码。
Triton-ex 文件及 `_generate_extern_kernel_alloc_helper` 不在本 PR 修改范围。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及独立资料文件变更。设计说明及新增配置的用法在本 PR 的【修改方案】和【接口变更】中给出。
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
新增 DVM 配置 `torch_npu._inductor.dvm.config.enable_fusion_permute`,类型为 `bool`,默认值为 `False`。在 DVM 后端加载前设置为 `True` 可开启 permute 融合;保持 `False` 时禁用该融合规则。
跨组件复用现有 `_override_matmul_should_fold_for_npu` 和 `NPUWrapperCodeGen.make_allocation`,其接口签名不变。未新增公开算子或 C++ 接口。
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
以下为原 PR 已记录的验证结果,本次仅整理描述,未重新运行测试。
**测试环境与方法**
- Ascend910B3 / CANN 9.2.0.beta.2 / PyTorch 2.13,基于 PR !47318 构建并应用对应改动。
- 对比优化前后全网 E2E 和设备时间;耗时单位均为 ms/次。严格精度阈值为 `rtol=atol=1e-4`。
- 快速分配对照复用前后的分配代码生成结果;permute 对照开关启停的 NPU 执行结果及生成代码,并验证动态形状和视图属性。
| 场景 | 验证结果 |
| --- | --- |
| GroupNorm:functorch_dp_cifar10 / opacus_cifar10 | 设备时间分别降至 2.60 / 2.63;单算子精度通过,**全网严格精度仍未通过**。 |
| Matmul:CLIP | E2E 30.41 → 23.58,设备时间 29.69 → 21.29;严格精度通过。 |
| 快速分配 | 复用前后 144 组分配代码生成结果一致。 |
| Permute 开关 | 开启、关闭各 5 项 NPU 用例通过;开启组生成代码中独立 `aten.permute` 调用为 0。 |
| Permute 视图 | 开启后的 8 项动态形状、dtype、stride、offset、别名等视图用例通过。 |
| 静态检查 | Python 语法检查和 `git diff --check` 通过。 |
**验证范围与待补充项**
- 快速分配及新 permute 开关尚未测量独立全网性能收益。
- 本 PR 未新增或修改仓库 UT 文件;上述定向自验证用例的执行结果已记录,UT 看护及自验证截图待补充。
- 当前提交 `3e76f0ecf45429273b2a20a2fc7c2a1b9898c6f2` 的流水线 `PR-pipeline_pytorch#71518` 已通过,代码检查无异常;流水线结果不代表上述 GroupNorm 全网严格精度问题已解决。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
自检依据:新增配置已有注释,分配与融合路径包含相应条件判断;空指针及新增错误日志不涉及。标题使用 `[perf]` 类型标签;当前提交的 CI 和代码检查已通过。
See merge request: Ascend/pytorch!47449
2026-10-09 09:55:42 +08:00
chenrayray
67b12e96a6
docs: [master] 补齐原生 API 硬件说明的 NPU 标签
...
Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com >
# message auto-generated for no-merge-commit merge:
!47559 merge codex/fix-native-api-npu-tags-master into master
docs: [master] 补齐原生 API 硬件说明的 NPU 标签
Created-by: chenrayray
Commit-by: Xinrui Chen
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
- [x] 资料更新
关联 Issue:https://gitcode.com/Ascend/pytorch/issues/5276
# 【修改方案】
补齐 `master` 原生 API 文档中 152 行硬件专属说明的 NPU 标签,并将确定性计算文档的两个标签范围扩展至完整硬件专属 API 表格,确保按硬件筛选时说明随对应产品显示。
1. 为遗漏的 A2、A3、950DT 产品支持条目分别补充 `910b`、`A3`、`950` 标签,新增 ID 避开文档已有 ID。
2. 为所有版本目录中的 MemPool 950DT 分配器限制补充 `950` 标签;将 Adam 的限制改为“<term>Atlas A2训练系列产品</term>和<term>Atlas A3训练系列产品</term>暂不支持将`fused`设置为`True`。”,使用 `910b,A3` 标签,使 A2/A3 筛选时显示不支持提示,950DT(A5)筛选时不显示此提示。
3. 将 private_apis.md 的全部表格转换为 37 个独立 API 条目,按原生 API 文档形式展示产品支持情况、限制与说明及 NPU 形式名称。分别以独立行标签包裹 A2、A3、950DT 支持条目,保留原表中 18 个 API 暂不支持 950DT 的信息;全部 NPU 起止标签独占一行。
4. 将确定性计算文档的结束标签移动至对应表格之后,覆盖表题、表头及全部 API 行。
# 【资料变更】
修改 `docs/zh/api/native_api/` 下 37 个 Markdown 文件,补齐硬件条件注释并将私有 API 表格转换为逐项文档形式,沿用目标分支现有硬件标识。
# 【接口变更】
不涉及。
# 【功能验证】
- 全量扫描 468 个文档,显式硬件说明未覆盖数为 0。
- 标签起止配对、文档内 ID 唯一性检查通过。
- 私有 API 文档的 37 个条目与基线表格逐项比对,API 名称、NPU 形式名称、产品支持情况、数据类型及版本限制均保留;除 Adam fused 限制按硬件筛选语境改写外,其他修改文件去除 NPU 注释后原文保持一致。
- 全量检查所有 NPU 起止标签均独占一行,配对完整、ID 唯一,硬件说明均被标签覆盖;私有 API 文档无残留表格或行内标签,确定性计算标签覆盖完整对应表格。
- 两个分支各 7 个 PyTorch 版本目录的 Adam fused 提示经筛选验证:910b、A3 可见,950 不可见。
- `git diff --check` 通过。
- 文档变更未运行 NPU UT 或完整文档站点构建;远端 CI 待运行确认。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志(不涉及运行时代码)
- [x] 代码实现进行了返回值、空指针等校验(不涉及运行时代码)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(待CI)
See merge request: Ascend/pytorch!47559
2026-10-09 09:35:17 +08:00
zwj223
07e929c206
modify document
...
Co-authored-by: zwj223<zhangwenjing55@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47022 merge master into master
modify document
Created-by: zwj223
Commit-by: zwj223
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
[#5091 ](https://gitcode.com/Ascend/pytorch/issues/5091 )
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
根据HC大会的最新产品中英文命名,更新文档中的产品名
# 【资料变更】
修改所有涉及产品名称的文档
# 【接口变更】
不涉及
# 【功能验证】
不涉及
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47022
2026-10-09 09:32:27 +08:00
y30037164
91e4693820
调整 nightly 测试参数: 常规分片 worker 并发 8 提升到 16, 单 batch 用例数 50 提升到 100
...
Co-authored-by: yuaiming<yuaiming@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47552 merge master into master
调整 nightly 测试参数: 常规分片 worker 并发 8 提升到 16, 单 batch 用例数 50 提升到 100
Created-by: y30037164
Commit-by: yuaiming
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47552
2026-10-09 09:27:33 +08:00
ZhangZGC
a71e06d2df
fix(costmodel): support named args in TTIR
...
Co-authored-by: ZhangZGC<8623924@qq.com >
# message auto-generated for no-merge-commit merge:
!47262 merge master into master
fix(costmodel): support named args in TTIR
Created-by: ZhangZGC
Commit-by: ZhangZGC
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
[#5277 ](https://gitcode.com/Ascend/pytorch/issues/5277 )
# 【修改方案】
最新的triton对ttir的格式做了修改,ttir的入参名称从args_i改为了任意名称。此前costmodel的参数解析采用args这个关键词匹配,当前需要进行泛化,否则无法识别ttir入参。
此pr修改让costmodel支持任意的ttir入参名称解析。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47262
2026-10-09 09:22:33 +08:00
pta-robot
cc93bd0dec
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47533 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-30 22:05:51.
See merge request: Ascend/pytorch!47533
2026-10-09 09:04:43 +08:00
pta-robot
0e0d5f3b14
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47591 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-08 22:03:44.
See merge request: Ascend/pytorch!47591
2026-10-08 22:44:44 +08:00
ccyyccyyccyycc
cea4a6a9ef
[feature] support get_buffer for symm mem
...
Co-authored-by: ccyyccyyccyycc<changqiaowei@huawei.com >
# message auto-generated for no-merge-commit merge:
!46842 merge feat/symm-mem-getbuffer into master
[feature] support get_buffer for symm mem
Created-by: ccyyccyyccyycc
Commit-by: ccyyccyyccyycc
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5031
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
- `NPUSHMEMSymmetricMemory` 构造函数:填 `buffers_`(每个 group rank 的 `Aclshmem_ptr` 结果),`Aclshmem_ptr` 返回 nullptr 时 `TORCH_CHECK`。无需新增。
- 社区`SymmetricMemory`通过`get_buffer`,调用`NPUSHMEMSymmetricMemory`后端`get_buffer_ptrs()`、`get_buffer_size()`等接口,直接返回 `buffers_`、`buffer_size_`等。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
| 测试用例 | 验证点 | 类型 |
| --- | --- | --- |
| `test_get_buffer` | `buffer_size` 正确;本地 `data_ptr()`==本地 tensor;对端 `data_ptr()`==`buffer_ptrs[peer]`;本地与对端数据值正确;`storage_offset=4` 子切片地址与数据正确;越界抛 "exceeds the allocated size" | 集成 |
| `test_get_buffer_alias` | 本地 `get_buffer(rank)[3:4].fill_` 对本地 tensor 可见;rank0 经 `get_buffer(peer)[7:8].fill_` 跨卡写入,synchronize+barrier 后 rank1 本地 tensor[7]==写入值 | 集成 |
| `test_get_buffer_allocation_lifetime` | `del tensor`+barrier 后仍可 `get_buffer`,地址与数据保持正确,验证 handle 引用计数保活 allocation | 集成 |
测试执行test_shmem.py


# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46842
2026-10-08 18:26:39 +08:00
pta-robot
881b613b3d
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47572 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-08 17:30:20.
See merge request: Ascend/pytorch!47572
2026-10-08 18:18:51 +08:00
chansinging
1785d0871f
合并操作
...
Co-authored-by: Chansinging<1183520536@qq.com >
# message auto-generated for no-merge-commit merge:
!47197 merge fix_test_schedule_2.14 into master
test: enhance _make_p2p_op to support custom group for better flexibility
Created-by: chansinging
Commit-by: Chansinging
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47197
2026-10-08 18:05:10 +08:00
zhoujinning
63b274ed2f
[fix] fix torch native 2.13 branch where the pre_grad_custom_pass type is CustomGraphPass and has not adapted
...
Co-authored-by: zhoujinning<zhoujinning2@huawei.com >
# message auto-generated for no-merge-commit merge:
!47503 merge master into master
[fix] fix torch native 2.13 branch where the pre_grad_custom_pass type is CustomGraphPass and has not adapted
Created-by: zhoujinning
Commit-by: zhoujinning
Merged-by: ascend-robot
Description: [#5283 ](https://gitcode.com/Ascend/pytorch/issues/5283 )
<!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
修复torch 原生2.13分支pre_grad_custom_pass类型变成CustomGraphPass后未适配问题
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47503
2026-10-08 17:44:26 +08:00
gavinwang269
72b9c1a060
【硬件解耦】fix(triton_experimental): gate dropout decomp override to npu devices #4939
...
Co-authored-by: gavinwang269<wanggang301@huawei.com >
# message auto-generated for no-merge-commit merge:
!46603 merge p4/fix-dropout-decomp-device-gate into master
【硬件解耦】fix(triton_experimental): gate dropout decomp override to npu devices #4939
Created-by: gavinwang269
Commit-by: gavinwang269
Merged-by: ascend-robot
Description: 【合入来源】
社区 issue:Fixes #4939(【硬件解耦】dropout decomposition 缺设备门控污染 CPU 图,C 桶 17 例)。
【修改方案】
1. `torch_npu/_inductor/decomposition.py` 的 `_override_native_dropout_decomp()` 注册的三个 wrapper(native_dropout 前向 / native_dropout_backward / fallback 模式对应路径)增加设备门控:按 decomposition 输入 `input.device.type` 判定——npu 输入维持既有 npu 私有 kernel 分解(`npu._npu_dropout` / `npu.npu_dropout_backward`)不变;非 npu 输入委托给覆盖注册前快照的 vanilla torch 条目(基表该键无条目时返回 `NotImplemented`——inductor 基表本无前向 native_dropout 分解,前向经 extra_random_decomps 提供,属既有机制),逐位复现"未导入 torch_npu 时应有的分解行为",且在 `config.fallback_random` 开/关两种模式下均成立。不引入设备白名单,门控语义即"非 npu 不动手"。
2. 门控 wrapper 携带 `_npu_decomp_override` 标记属性,供测试以标记(优先)+ `__module__`/`__qualname__` 双校验(兜底)方式识别,替代字符串匹配。
3. 涉及组件:仅 decomposition 覆盖注册路径(Python);default/triton_experimental 后端与非 npu 设备受益,eager 与 NPU 前向行为零变化。
【资料变更】
不涉及。
【接口变更】
不涉及(无跨仓/客户面可见接口变化;行为变化限于非 npu 设备导入 torch_npu._inductor 后 dropout 分解不再被改写到 npu 私有算子)。
【功能验证】
1. Ascend 910B4 真机(torch 2.14.0 / CANN 9.1.0 / triton-ascend 3.6.0,TE 后端)overlay 法实测:修复前 `test_comprehensive_nn_functional_dropout_cpu_*` 复现 `MissingOperatorWithoutDecomp: target: npu._npu_dropout.default`;修复后同组用例编译通过。
2. 新增 UT `test/_inductor/triton_experimental/test_native_dropout_decomp_device_gate.py`(可 pytest 收集、可直跑):表级双模式守卫(cpu/meta 输入零 npu target)、fallback_random 下前向条目返回 NotImplemented 且端到端产物无 npu target、compile_fx 显式表路径复现原故障形态、真机 NPU 路由保持(无卡显式 skip)。修后 5 passed + 11 subtests;修前同 UT(原始环境)9 failed 带牙齿复现。
3. 邻居回归:同目录既有 UT 通过;opinfo 非 dropout 用例零新增确定性失败。
4. issue #4939 按验收分桶口径跟踪:本 PR 承诺 CPU 3 例 FAIL→PASS;TE 缺 lowering 2 例归 #4935(修复由 !47253 <https://gitcode.com/Ascend/pytorch/merge_requests/47253 > 承接,两 PR 改不同文件、可独立评审、建议同批合入);数值发散 12 例另行跟踪,看护判据为形态不变、计数不增。
5. lint:lintrunner 活跃项(FLAKE8/SPACES/TABS/NEWLINE/CODESPELL)本地全绿。
【CheckList】
- [x] 代码内注释已完备(门控因果与快照委托理由在函数与 wrapper 注释留痕)
- [x] 返回值/空指针校验:纯 Python,wrapper 返回值语义(NotImplemented 惯用法)有表级 UT 钉住
- [x] PR 标题含类型标签 fix(triton_experimental)
- [x] CI 通过(commit 4cb8277a 的流水线 PR-pipeline_pytorch#68518 全绿;其后仅追加 注释精简提交(AST 校验代码零变化),已评论 compile 在新 head 上复跑,以流水线结果为准)
See merge request: Ascend/pytorch!46603
2026-10-08 16:31:20 +08:00
gavinwang269
82f295fdb6
fix(inductor): register npu._npu_dtype_cast(_backward) lowering in triton_experimental backend
...
Co-authored-by: gavinwang269<wanggang301@huawei.com >
# message auto-generated for no-merge-commit merge:
!47268 merge fix/4932-npu-dtype-cast-te-lowering into master
fix(inductor): register npu._npu_dtype_cast(_backward) lowering in triton_experimental backend
Created-by: gavinwang269
Commit-by: gavinwang269
Merged-by: ascend-robot
Description: ## 问题
在 `triton_experimental`(TE)后端下,softmax/softmin with-dtype 族的 9 个 opinfo 用例在编译期抛 `MissingOperatorWithoutDecomp`,缺失 target 均为 `npu._npu_dtype_cast.default`(详见 #4932)。
## 根因
`npu._npu_dtype_cast` / `npu._npu_dtype_cast_backward` 位于 `GENERATE_LIST`(`lowering_override_list.py`),因此被 `_register_npu_inductor_fallbacks()` 的 blanket fallback 循环**豁免**(不会被 `make_fallback` 接管);但 TE 后端又没有为它们注册任何 lowering(default 后端的 `torch_npu/_inductor/lowering.py:289` 注册链不被 TE 加载)。即"GENERATE_LIST 豁免 + 无人拥有 lowering",lowering 阶段直接报错。
## 修复
在 TE 后端的 `overwrite_lowering` 注册块中,把 `_npu_dtype_cast(_backward)` 对与既有 `npu_dtype_cast(_backward)` 邻居一样路由到 `_convert_element_type`(该 op 语义就是逐元素 dtype cast)。这与 #4932 评论中维护者 [@rmch](https://gitcode.com/rmch ) 给出的注册点口径一致。
## 实测(910B2,CANN 9.2.0-beta.2,torch/torch_npu 2.15.0.dev20260920,triton_experimental 后端,junit 逐例判型)
- 基线(upstream/master 尖 1c1268b9,未打补丁):9/9 FAIL,缺失 target 均为 `npu._npu_dtype_cast.default`。
- 打本补丁:9/9 **MissingOperatorWithoutDecomp 全部清零**;5/9 转绿(softmin int32/int64、softmax bool/int32/int64)。
- 残差 4 例(softmax/softmin with_dtype float16/float32)失败于 backward 调 aclnn `SoftmaxBackward` 拒 `DT_DOUBLE`(error 161002 / `Tensor gradOutput not implemented for DT_DOUBLE, should be in dtype support list [DT_FLOAT,DT_FLOAT16,DT_BFLOAT16]`)。**该残差与本补丁无关**:eager 路径直接调 `aten._softmax_backward_data`(f64 grad)同样报同一 161002 错误,属 aclnn 后端 dtype 支持面问题,不是注册表缺口。本补丁职责边界 = lowering 注册,已达。
## 关联
- **Fixes #4932**:本 PR 收口其「triton_experimental 注册表缺口」部分(`npu._npu_dtype_cast(_backward)` 在 TE 被 GENERATE_LIST 豁免无主、缺 lowering,致 9 例编译期 `MissingOperatorWithoutDecomp`)。落地后缺 lowering 清零、5/9 转绿。
- 本 PR **不修**的残差 4 例(softmax/softmin with_dtype float16/float32,backward 撞 aclnn `SoftmaxBackward` 拒 `DT_DOUBLE`)已独立登记为 **#5237**——属 eager 侧 aclnn dtype 支持面缺口,与本 PR 的 lowering 注册职责边界正交,请在 #5237 跟踪。
- **#5237** 与 **#4938**、**#5217** 同属 aclnn eager 拒绝系列;#4932 与姊妹单 ****(matmul backward)、**#4931**(npu_gather backward)同属 TE 注册表缺口系列。
See merge request: Ascend/pytorch!47268
2026-10-08 16:25:10 +08:00
gavinwang269
74bb2fe7fd
【硬件解耦任务】fix(inductor-TE): 生成 aten.contiguous 拷贝 lowering #4933
...
Co-authored-by: gavinwang269<wanggang301@huawei.com >
# message auto-generated for no-merge-commit merge:
!47274 merge fix-te-4933-contiguous-generate into master
【硬件解耦任务】fix(inductor-TE): 生成 aten.contiguous 拷贝 lowering #4933
Created-by: gavinwang269
Commit-by: gavinwang269
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
> 关联 issue:fixes #4933 <https://gitcode.com/Ascend/pytorch/issues/4933 >
# 【修改方案】
issue #4933:triton_experimental 后端下 diag_embed 全部 6 个 dtype 变体在严格模式(`implicit_fallbacks=False`)编译期失败,缺失 target 为 `aten.contiguous.default`。
机制:与 `as_strided` 不同,`aten.contiguous` 在上游 `lowerings` 表中**没有任何既有条目**(纯布局 op,上游历来在 IR 层由 lazy clone 处理)。`_register_npu_inductor_fallbacks()` 的批量回退 pass 遍历的是 `for op in lowerings`,因此根本扫不到 `contiguous` 节点(diag_embed 分解链末端 `mask_tensor(...).contiguous()` 发出);单独将其列入 GENERATE_LIST 也是空操作。
按评审意见(GENERATE_LIST 路线,即生成设备内 kernel 而非回退),本 PR 两处配套落地:
1. `torch_npu/_inductor/triton_experimental/lowering.py`:新增 `npu_contiguous`,委托既有 `npu_clone`(clone-fold 契约:输入已行主序则折叠为零拷贝视图,否则按判定走一次设备内拷贝——生成的 triton Pointwise 或 vendor strided copy),并以 `overwrite_lowering(aten.contiguous, npu_contiguous)` 注册。相比 `make_fallback`,拷贝保持 on-device 且参与 scheduler 融合,无 FallbackKernel 设备外往返。
2. `torch_npu/_inductor/triton_experimental/lowering_override_list.py`:GENERATE_LIST 紧邻 `aten.clone` 增加 `aten.contiguous`。此步为必需:op 一旦进入 `lowerings`,批量 pass 会将其 `make_fallback` 反盖,GENERATE_LIST 豁免保证新注册的 lowering 生效。
新增 UT:`test/_inductor/triton_experimental/test_te_contiguous_lowering.py`(注册钉扎 3 例 + diag_embed 严格模式编译与 eager 逐 dtype 等值 6 变体)。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
- 环境:Ascend 910B2 ×8,PyTorch 2.14.0+cpu / torch_npu 2.14.0 / CANN 9.1.0,后端 triton_experimental。
- 新增 UT 4 例真机全绿(约 76s);去除修复后其中注册断言 2 例 FAIL(双向验证)。
- 验证证据:
```
$ python test/_inductor/triton_experimental/test_te_contiguous_lowering.py
Ran 4 tests in 77.4s
OK
```
- 反向族(diag_embed backward)与 default 后端路径不涉及本改动(仅新增 TE lowering 与 GENERATE_LIST 条目,无既有用例行为变更)。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:fix
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47274
2026-10-08 16:25:02 +08:00
gavinwang269
0deacb51e4
【硬件解耦】fix(inductor-TE): keep view/mutation primitives out of blanket fallback #4941
...
Co-authored-by: gavinwang269<wanggang301@huawei.com >
# message auto-generated for no-merge-commit merge:
!46601 merge p4/fix-view-mutation-blanket-fallback into master
【硬件解耦】fix(inductor-TE): keep view/mutation primitives out of blanket fallback #4941
Created-by: gavinwang269
Commit-by: gavinwang269
Merged-by: ascend-robot
Description: 【合入来源】
社区 issue:Fixes #4941(【硬件解耦】triton_experimental blanket-fallback 物化 view/mutation 原语致 copy_ 变异被 DCE 静默丢失)。
【修改方案】
1. 在 `triton_experimental/lowering_override_list.py` 的 `GENERATE_LIST` 增补 9 个 view/mutation 布局原语条目:`aten.view`、`aten.as_strided`、`aten.as_strided_`、`aten.as_strided_copy`、`aten.as_strided_scatter`、`aten.diagonal`、`aten.diagonal_scatter`、`aten.alias`、`aten.detach`(与既有 `slice/slice_scatter/select_scatter` 同法)。
2. `_register_npu_inductor_fallbacks()` 的 gen_set 集合门控随之使这 9 个 op 保留上游 inductor lazy lowering,不再被 blanket fallback 物化为 eager extern 临时量——对视图的 `copy_` 写入不再落在临时量上被 DCE 丢弃。
3. 涉及组件:仅 triton_experimental 后端注册表(Python 名单),不改 eager 与 default 后端。`_unsafe_view` 有 decomposition,注册循环自动跳过,无需条目。
【资料变更】
不涉及(仅代码内注释)。
【接口变更】
不涉及。行为变化限于 TE 后端内部:原被 extern 的 view 族 op 改为生成期布局重映射;同进程内 CPU 编译在 TE 激活后不再受这 9 个 op 的 blanket-fallback 影响(恢复上游行为)。
【功能验证】
- 环境:Ascend 910B4,torch 2.14.0 / CANN 9.1.0 / triton-ascend 3.6.0,后端 triton_experimental(TE_INSTRUMENTATION=off)。
- 结果:
1. 靶点家族(as_strided_scatter / diagonal_scatter / as_strided_copy 族 opinfo 行,NPU 与 TE 进程内 CPU 对照)全量夜跑 FAIL→PASS 逐例坐实,共 24 行转绿(12 NPU 行 default 后端本就通过 + 12 CPU 行仅 TE 进程内受染);
2. scatter/view/copy_ 家族回归(36 节点)隔离复跑 36/0 通过;
3. default 后端与 eager 路径回归零变化(名单只作用于 TE 注册循环);
4. 跨环境复测:910B2 + CANN 9.2.0-beta.2 + PyTorch 2.15 nightly 栈重跑靶点 2 例,基线现象与 910B4 一致(修复前 FAIL 形态坐实,见 issue #4941 复测记录)。
- 看护方式:opinfo 测试 scatter/view/copy 家族行随 TE 全量夜跑持续看护;`as_strided_scatter`/`diagonal_scatter` 的 copy_ 变异语义在 GENERIC 家族行内。
【CheckList】
- [x] 代码内注释已完备(GENERATE_LIST 条目附根因说明)
- [x] 返回值/空指针校验:不涉及 C/C++ 接口,纯 Python 名单
- [x] PR 标题含类型标签 fix(inductor-TE)
- [x] CI 通过(ci-pipeline-passed;lintrunner 活跃项 FLAKE8/SPACES/TABS/NEWLINE/CODESPELL 本地全绿)
See merge request: Ascend/pytorch!46601
2026-10-08 16:14:25 +08:00
gavinwang269
30210c8f8c
【硬件解耦】fix(inductor): NPU linalg_qr fallback 行主序布局声明 #5072
...
Co-authored-by: gavinwang269<wanggang301@huawei.com >
# message auto-generated for no-merge-commit merge:
!47273 merge p4/fix-te-qr-fallback-layout into master
【硬件解耦】fix(inductor): NPU linalg_qr fallback 行主序布局声明 #5072
Created-by: gavinwang269
Commit-by: gavinwang269
Merged-by: ascend-robot
Description: # 【合入来源】
Fixes #5072
# 【修改原因】
torch_npu eager `linalg_qr`(aclnn 路径)返回**行主序** Q/R,而 ATen meta kernel 按 CPU/CUDA 的 LAPACK 约定声明**列主序**布局。inductor 的 fallback 输出布局由 meta 执行构建,因此编译图内所有消费 QR 输出的算子(`svd_lowrank`/`pca_lowrank` 幂迭代链中 QR 之后的 mm 等)会按列主序 stride 读取实际的行主序 buffer——转置错读即确定性数据错位,表现为奇异值谱塌陷(本单 opinfo 2 例 6/6 失配的根因)。
判别依据:同输入下 `qr(A@R)[0].mH @ A` 单步编译不发散(mm lowering 正常),但 QR 输出作为图内中间 buffer 被下游 mm 消费时确定性错值(B diff 2.2→5.6,随图内消费次数放大);生成的 wrapper 代码中下游 mm 对 QR 输出 buffer 的 `reinterpret_tensor` stride 正是列主序假设。
# 【修改方案】
- `torch_npu/_inductor/_npu_meta_registration.py`:包装 `ir.FallbackKernel.process_kernel`,对 npu 设备的 `linalg_qr` fallback 输出(default/out)按设备真实返回的行主序 stride 重声明 fake 输出布局;非 npu 设备原样透传,CPU/CUDA 的列主序契约不受影响。
- `test/_inductor/triton_experimental/test_te_qr_fallback_layout.py`:4 例回归 UT(QR 输出被 mm 消费、固定随机投影的完整 power-iteration 链 U/S/Vh 逐张量对拍、batched projector、complete/r 模式回归)。
# 【接口变更】
不涉及(仅 inductor 编译期布局元信息声明)。
# 【资料变更】
不涉及。
# 【功能验证】
测试环境:910B2,torch 2.15.0.dev20260920+cpu,torch_npu 基于 master 9651940216,CANN 9.2.0-beta.2,triton-ascend 3.5.0,TE 后端,compile_threads=1,fresh 缓存。
1. 新增 UT 真机 4/4 通过。
2. 本单场景(固定随机投影、完整 power-iteration + svd 链)compiled vs eager:U/S/Vh 三张量 max_abs diff 全部 **0.0**(修复前 S diff 3.4),5 次重复执行确定一致;奇异值贴合 float64 真值在随机低秩近似的固有预算内(0.46)。
3. 边界回归:complete / r 模式、batched(3×10×8)projector、CPU 设备编译消费链全部 diff 0.0;CPU/CUDA 列主序契约经 device 门控保持原状。
4. 说明:本单期望中的 opinfo `test_comprehensive_svd_lowrank/pca_lowrank_npu` 两例转绿还依赖上游 pytorch PR 194027 的 PrivateUse1 派生(评审中)。另实测发现 compiled 图内 `torch.randn` 的 philox 消费与 eager 同 seed 不重合(随机投影矩阵 R 采样不同→低秩子空间采样差异),该现象在修复前后一致、与布局根因无关,属 TE RNG 序列一致性独立议题。
6. 跨版本栈验证(torch 2.14.0+cpu / torch_npu 2.14.0+gitb4d0da5 / CANN 9.1.0 / 910B2,TE 后端、compile_threads=1、fresh 缓存,A/B 对照):
- 不打补丁基线:上述 4 例 UT 中 3 例 FAIL(同款 QR 布局缺陷在 2.14 栈同样存在,证明 UT 有真实保护力)、complete/r 模式 1 例 PASS(与该缺陷路径无关,符合预期);
- 打本补丁:4/4 PASS(其中 1 例首轮因进程间设备状态竞态报 LazySetDevice 507033,连续复跑两次均 PASS,与本补丁无关)。
结论:修复不绑定 2.15 线,跨版本行为一致。
# 【CheckList】
- [x] PR标题正确使用类型标签
- [x] 代码注释完备
- [ ] CI 流水线执行通过
# 【关联 issue】
Related — 依赖收口:本单为 issue 残差簇的承载 PR 之一(完整依赖链见该单 0929 收口评论)
See merge request: Ascend/pytorch!47273
2026-10-08 15:18:13 +08:00
lvjiangdong
11ba17f08a
[inductor] add multi slice concat pass ut
...
Co-authored-by: 吕江东<lvjiangdong@huawei.com >
# message auto-generated for no-merge-commit merge:
!47550 merge master into master
[inductor] add multi slice concat pass ut
Created-by: lvjiangdong
Commit-by: 吕江东
Merged-by: ascend-robot
Description: [#5273 ](https://gitcode.com/Ascend/pytorch/issues/5273 )
<!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47550
2026-10-08 15:18:08 +08:00
wuyouqi1
b7bd974841
fix: cut patch_getenv overhead from 3x to ~1x and gate it by TORCH_NPU_LOGS
...
Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47484 merge personal/fix-patch-getenv-3x-overhead-master into master
fix: cut patch_getenv overhead from 3x to ~1x and gate it by TORCH_NPU_LOGS
Created-by: wuyouqi1
Commit-by: wuyouqi1
Merged-by: ascend-robot
Description: # 【合入来源】> **如有社区issue,请关联issue链接**\
> **请勿携带内部流程信息(需求链接、问题单、内部issue等)**
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
关联issue:https://gitcode.com/Ascend/pytorch/issues/5090(Fixes #5090)
# 【修改方案】
`torch_npu/utils/patch_getenv.py` 使全进程 `os.getenv`/`os.environ.get` 开销达
~3.3x。根因:保存的原生 `os.getenv` 调用时重新解析 `environ.get`,再次进入被
patch 的实例属性(嵌套);且 `key in os.environ` 预检查本身即一次完整查找——
一次调用共 3 次真实查找。
修复:
1. 两个 patch 点共用一个 `_patched_getenv`,直读 `os.environ[key]`
(KeyError 即未命中):恰好 1 次真实查找,构造上无嵌套
2. 仅当日志可观测时安装:`TORCH_NPU_LOGS`/`TORCH_LOGS` 已设置,或 import 时
`torch_npu.env` logger 已可见 INFO。patch_getenv 早于
`_add_logging_module()` 配置 logger,import 时 `isEnabledFor` 不可信,故按
原始环境变量门控(与 ACL log 门禁做法一致);钩子为私有
`_install()`,不进入公开 API 兼容性检查
3. UT:`test/utils/test_patch_getenv.py` 6 用例(门控/包装语义/单次查找计数);
`test_torch_npu_init.py` 快照断言按门控分支
# 【资料变更】
不涉及
# 【接口变更】
不涉及。`os.getenv`/`os.environ.get` 返回值行为完全不变(含 bytes key 抛
TypeError 对齐),仅日志按需安装;默认配置不安装(原生直通)。
# 【功能验证】
| 场景 | 真实查找/次 | 耗时(py3.14) |
|---|---|---|
| native | 1 | 597 ns (1.00x) |
| 修复前 | 3 | 1974 ns (3.31x) |
| 修复后(已安装) | 1 | 626 ns (1.05x) |
| 修复后(默认不装) | 1 | 1.00x |
(py3.11 修复前 3.39x;纯 CPython 复现,与硬件/CANN 无关)
语义回归(命中/未命中/default/空串/kwargs/bytes key)、门控矩阵(默认不装,
`TORCH_NPU_LOGS`/`TORCH_LOGS`/预先配置 INFO 均安装)、端到端日志去重:全部
PASS。`test_api_compatibility` 复检通过(公开 callable 为空)。
本地 whl 实测(conda wyq_py10,torch_npu 2.7.1 whl):`test_patch_getenv.py`
6 用例全过;`test_torch_npu_init.py` 16 用例全过(test_14 按 #5230 skip)。
**test_14 临时 skip**:`test_torch_npu_init.py::test_14_dtensor_strategies_are_
registered_without_dynamo` 在 v2.7.1 HEAD 上确定性失败,与本 MR 无关——
!44496 的 flex_attention 补丁在 import 时经
`from torch.nn.attention import flex_attention` 拉入 `torch._dynamo`
(torch 2.7.x),破坏 #2788 的延迟导入契约。详见
https://gitcode.com/Ascend/pytorch/issues/5230,待修复后恢复用例 。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等(fix)
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常(个人分支暂未触发 CI,合入前补充)
See merge request: Ascend/pytorch!47484
2026-10-08 11:45:34 +08:00
wzyly
6347c8f7c1
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47549 merge master into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
资料链接修改
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47549
2026-10-08 11:34:56 +08:00
pta-robot
79c55b42b0
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47519 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-30 22:01:52.
See merge request: Ascend/pytorch!47519
2026-10-08 09:30:20 +08:00
nasa___1
7d81b286b6
[test] add InplaceFunction.vjp and NestedIOFunction.backward api test case
...
Co-authored-by: nasa___1<2397662955@qq.com >
# message auto-generated for no-merge-commit merge:
!45870 merge InplaceFunction_vjp-NestedIOFunction_backward-master into master
[test] add InplaceFunction.vjp and NestedIOFunction.backward api test case
Created-by: nasa___1
Commit-by: nasa___1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <span style="color:red"><strong>如有社区 Issue,请关联 Issue 链接</strong></span>
> <span style="color:red"><strong>请勿携带内部流程信息(需求链接、问题单、内部issue等)</strong></span>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch-ecosystem/issues/292 https://gitcode.com/Ascend/pytorch-ecosystem/issues/295
- [ ] 重构优化
- [ ] 资料更新
# 1、API功能分析
- `torch.autograd.function.InplaceFunction.vjp` 用于定义自定义算子在**反向模式自动微分(reverse-mode AD)** 下的 Vector-Jacobian Product,向量-雅可比积,本质上就是自定义 Function 的反向梯度计算规则。假设前向过程为 $y=f(x)$,上游传入输出梯度 $v=\frac{\partial L}{\partial y}$,那么 vjp 计算的是
$$ v^T J_f(x) = \frac{\partial L}{\partial y} \frac{\partial y}{\partial x} = \frac{\partial L}{\partial x} $$
也就是把输出侧的梯度继续传播回输入侧。
- `torch.autograd.function.NestedIOFunction.backward` torch.autograd.function.NestedIOFunction.backward 是 PyTorch 内部自动微分(Autograd)机制中用于处理具有嵌套输入/输出结构的自定义算子反向传播的方法。
# 2、上游用例检查情况
| API | PyTorch 2.7.1 上游测试情况 | 是否有直接专项覆盖 | torch-npu 是否建议补充 |
| --------------------------------------------------- | --------------------------------------------- | ---------------------------------------- | ---------------- |
| `torch.autograd.function.InplaceFunction.vjp` | `Function.vjp` 有多处官方测试;`InplaceFunction` 也有测试 | **没有找到直接针对 `InplaceFunction.vjp` 的专项测试** | **建议补充** |
| `torch.autograd.function.NestedIOFunction.backward` | `NestedIOFunction` 类仍保留在源码中 | **没有在 2.7.1 `test_autograd.py` 中找到直接覆盖** | **建议补充,但优先级较低** |
由于上游测试用例缺失,同时这两个API都需要torch-npu平台算子支撑,因此需要进行测试用例补充。
# 3. 资料检查
1. `torch.autograd.function.InplaceFunction.vjp ` 在上游有独立条目,但是当前资料缺失。
2. `torch.autograd.function.NestedIOFunction.backward` 在上游有独立条目,当期资料缺失。
因此这两个API都需要进行资料补充。
# 4. API功能测试
测试覆盖场景:
| 测试项 | 覆盖内容 | 预期结果 |
| --- | --- | --- |
| `InplaceFunction.vjp` NPU 前向计算 | 使用 NPU Tensor 调用自定义 `InplaceFunction`,在 `forward()` 中执行原地乘法并通过 `mark_dirty()` 标记修改 | 前向计算正常完成,输出 Tensor 位于 NPU,数值及 dtype 正确 |
| `InplaceFunction.vjp` 反向 VJP 计算 | 自定义 `vjp()` 而不实现 `backward()`,传入非全 1 的 `grad_output` 执行 `output.backward(grad_output)`,验证 autograd 实际进入 `vjp()` | `vjp()` 被正常调用,按照 `grad_output × scale` 得到正确梯度,梯度 Tensor 位于 NPU |
| `NestedIOFunction.backward` 嵌套梯度恢复 | 构造包含 Tensor、list、tuple 和 `None` 的 `_nested_output` 结构,将扁平 NPU 梯度传入 `backward()`,检查 `backward_extended()` 接收到的梯度结构 | 扁平梯度能够按照原输出结构正确恢复,list、tuple 和 `None` 的位置保持正确,Tensor 位于 NPU |
| `NestedIOFunction.backward` 梯度计算与展开 | 在 `backward_extended()` 中返回包含嵌套 Tensor 和 `None` 的梯度结果,验证 `backward()` 对结果进行展开 | 返回结果被正确展开为扁平 tuple,Tensor 数值正确,`None` 正确保留,Tensor 的 dtype 和 NPU device 均保持正确 |
测试方法
```
source /usr/local/Ascend/ascend-toolkit/set_env.sh
TORCH_DEVICE_BACKEND_AUTOLOAD=1 python test_inplacefunction_vjp_nestediofunction_backward.py -v
```
测试结果
A2/A3芯片:
v2.7.1

v.2.11.0

v2.12.0

A5芯片
v2.7.1

v2.11.0

v2.12.0

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45870
2026-10-07 22:08:44 +08:00
lyd123333
159c687c68
[test] add CheckpointFunction.backward cpp_extension.BuildExtension.with_options hipify_python.hipify _contextlib._DecoratorContextManager API test case
...
Co-authored-by: lyd123333<3906916351@qq.com >
# message auto-generated for no-merge-commit merge:
!45275 merge CheckpointFunction-BuildExtension-hipify_python-_contextlib-master into master
[test] add CheckpointFunction.backward cpp_extension.BuildExtension.with_options hipify_python.hipify _contextlib._DecoratorContextManager API test case
Created-by: lyd123333
Commit-by: lyd123333
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
[#147 ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/147 )
[#122 ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/122 )
[#74 ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/74 )
[#134 ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/134 )
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
公开issue:
- `torch.utils.checkpoint.CheckpointFunction.backward`:[8月社区任务第二期-Ascend for PyTorch API 一致性开发(26)](https://gitcode.com/Ascend/pytorch-ecosystem/issues/147 )
- `torch.utils.cpp_extension.BuildExtension.with_options`:[8月社区任务第二期-Ascend for PyTorch API 一致性开发(33)](https://gitcode.com/Ascend/pytorch-ecosystem/issues/122 )
- `torch.utils.hipify.hipify_python.hipify`:[8月社区任务第二期-Ascend for PyTorch API 一致性开发(51)](https://gitcode.com/Ascend/pytorch-ecosystem/issues/74 )
- `torch.utils._contextlib._DecoratorContextManager`: [8月社区任务第二期-Ascend for PyTorch API 一致性开发(13) ](https://gitcode.com/Ascend/pytorch-ecosystem/issues/134 )
# torch.utils 相关四个 API 分析
## 1. API 功能说明
| API | 功能说明 | 是否硬件相关 |
|---|---|---|
| `torch.utils.checkpoint.CheckpointFunction.backward` | `CheckpointFunction` 是 activation checkpoint 的底层 autograd Function。其 `backward` 方法在反向传播阶段重新执行前向计算,从而避免在 forward 阶段保存全部中间激活,达到以计算换显存的目的。 | 不是专门硬件接口,但会依赖具体设备上的 autograd、算子执行和 RNG 状态管理。 |
| `torch.utils.cpp_extension.BuildExtension.with_options` | `BuildExtension` 是 PyTorch 提供的自定义 C++/CUDA/SYCL 扩展构建类;`with_options(**options)` 用于生成一个带默认构建参数的 `BuildExtension` 子类/构造器,常用于 `setup.py` 的 `cmdclass={"build_ext": BuildExtension.with_options(...)}`。 | 属于构建工具接口,涉及 CUDA/SYCL 编译参数,但本身不是运行时硬件 API。 |
| `torch.utils.hipify.hipify_python.hipify` | PyTorch 内置 HIPIFY 工具入口,用于扫描指定项目目录,将 CUDA/C++ 源文件中的 CUDA API、头文件、kernel launch 等模式转换为 HIP/ROCm 对应形式。 | 是 GPU 迁移工具,面向 AMD ROCm/HIP;不是 Ascend NPU 运行时接口。 |
| `torch.utils._contextlib._DecoratorContextManager` | PyTorch 内部上下文管理器基类,用于让 context manager 同时具备 decorator 用法,例如 `torch.no_grad()`、`torch.inference_mode()` 这类接口。 | 纯 Python 上下文控制工具,不涉及硬件。 |
## 3. torch-npu 平台测试必要性
| API | 是否建议补充 NPU 测试 | 原因 |
|---|---|---|
| `torch.utils.checkpoint.CheckpointFunction.backward` | 建议 | checkpoint backward 会触发反向传播阶段的重计算,涉及 NPU Tensor 的 autograd、算子执行、梯度回传以及 RNG 状态保存/恢复,适合作为 torch-npu 兼容性测试。 |
| `torch.utils.cpp_extension.BuildExtension.with_options` | 不建议作为 NPU 专项测试 | 该接口只负责构建参数注入,不直接执行 NPU 算子。可做纯 Python import/行为测试,但不需要 NPU 设备测试。 |
| `torch.utils.hipify.hipify_python.hipify` | 不建议作为 NPU 专项测试 | 该接口面向 CUDA 到 HIP/ROCm 的源码迁移,与 Ascend NPU 后端无直接关系。 |
| `torch.utils._contextlib._DecoratorContextManager` | 不建议作为 NPU 专项测试 | 该接口是内部 Python 上下文管理工具,设备无关。若需要覆盖,可通过公开 API `torch.no_grad()` 在 NPU Tensor 上做轻量验证。 |
# 二. 上游用例检查情况:
1. torch.utils.checkpoint.CheckpointFunction.backward:
上游有测试,但不是直接调用内部 backward,而是通过 checkpoint(..., use_reentrant=True) + backward() 间接覆盖真实路径,因此需要补充torch-npu平台的测试用例,
2. torch.utils.cpp_extension.BuildExtension.with_options:
上游有测试/使用覆盖,在 test/cpp_extensions/setup.py 中通过 BuildExtension.with_options(use_ninja=USE_NINJA)间接参与真实扩展构建流程,因此需要补充torch-npu平台的测试用例。
3. torch.utils.hipify.hipify_python.hipify:
上游有 hipify 模块 import 测试和 Trie 辅助结构测试;没有看到完整直接调用 hipify() 并校验 CUDA→HIP 转换结果的单测,但 cpp_extension 的 ROCm 构建链路会间接调用它。该API和torch-npu平台无关,因此无需进行测试用例补充。
4. torch.utils._contextlib._DecoratorContextManager:
上游没有直接测试该内部类,但通过 set_device、torch.no_grad 等上下文管理器的装饰器用法间接覆盖其核心能力。因此需要进行测试用例补充。
# 三. 资料情况检查:
| API | PyTorch 2.7 | PyTorch 2.11 | PyTorch 2.12 | PyTorch 2.13 | 结论 |
|---|---|---|---|---|---|
| `torch.utils.checkpoint.CheckpointFunction.backward` | 未查到独立条目 | 未查到独立条目 | 未查到独立条目 | 未查到独立条目 | 官方公开文档主要记录 `torch.utils.checkpoint.checkpoint`,`CheckpointFunction.backward` 更偏内部实现。 |
| `torch.utils.cpp_extension.BuildExtension.with_options` | 未查到独立条目 | 未查到独立条目 | 未查到独立条目 | 未查到独立条目 | 官方文档有 `BuildExtension` 类条目,但 `with_options` 方法本身未单独成页。 |
| `torch.utils.hipify.hipify_python.hipify` | 有独立条目 | 有独立条目 | 有独立条目 | 有独立条目 | 2.7.1/2.11/2.12/2.13 官方 generated 文档均有独立条目 |
| `torch.utils._contextlib._DecoratorContextManager` | 未查到独立条目 | 未查到独立条目 | 未查到独立条目 | 未查到独立条目 | 内部类,不属于稳定公开 API 文档条目。 |
如表所示,虽然`torch.utils.hipify.hipify_python.hipify`在各个分支都有独立条目,因此 `torch.utils.hipify.hipify_python.hipify` 需要进行资料补充。
# 四. API功能性验证
## 1. 测试场景
| API | 测试场景 | 预期结果 |
|---|---|---|
| `torch.utils.checkpoint.CheckpointFunction.backward` | 检查 `CheckpointFunction.backward` 是否存在且可调用 | API 存在,并且是可调用对象 |
| `torch.utils.checkpoint.CheckpointFunction.backward` | 在 NPU 上通过 `checkpoint(..., use_reentrant=True)` 触发 backward,并与普通 backward 对比 | checkpoint 路径输出和梯度与普通路径一致,梯度位于 NPU |
| `torch.utils.checkpoint.CheckpointFunction.backward` | checkpoint 函数包含非 Tensor 参数 | backward 正常执行,输出和梯度与普通路径一致 |
| `torch.utils.checkpoint.CheckpointFunction.backward` | checkpoint 函数返回多个 Tensor 输出 | 多输出均正确,合并 loss 后梯度与普通路径一致 |
| `torch.utils.checkpoint.CheckpointFunction.backward` | checkpoint 中包含 Dropout,并验证 RNG 状态保存恢复 | checkpoint 路径和普通路径的梯度一致 |
| `torch.utils.cpp_extension.BuildExtension.with_options` | 调用 `with_options(use_ninja=False)` 生成构建类 | 返回结果是 `BuildExtension` 的子类,且不是原始 `BuildExtension` 类 |
| `torch.utils.cpp_extension.BuildExtension.with_options` | 注入 `use_ninja=False`、`no_python_abi_suffix=True` 参数 | 实例化后的构建命令参数正确生效 |
| `torch.utils.cpp_extension.BuildExtension.with_options` | 构造时传入与预设参数冲突的参数 | `with_options` 中预设的参数优先生效 |
| `torch.utils.cpp_extension.BuildExtension.with_options` | 多次调用 `with_options` 生成不同构建类 | 不同构建类可独立实例化,配置互不影响 |
| `torch.utils.hipify.hipify_python.hipify` | 检查 `hipify_python.hipify` 是否存在且可调用 | API 存在,并且是可调用对象 |
| `torch.utils.hipify.hipify_python.hipify` | 创建 `.cu` 文件并调用 `hipify()` 处理 | 返回结果为 `dict`,且包含目标 CUDA 文件处理记录 |
| `torch.utils.hipify.hipify_python.hipify` | 使用 `extra_files` 和 `hipify_extra_files_only=True` 只处理额外文件 | 返回结果包含指定 extra CUDA 文件 |
| `torch.utils.hipify.hipify_python.hipify` | 使用 `ignores` 忽略指定 CUDA 文件 | 被忽略文件不出现在处理结果中 |
| `torch.utils._contextlib._DecoratorContextManager` | 自定义上下文管理器作为普通函数装饰器 | 执行顺序为 `enter -> body -> exit`,函数结果正确 |
| `torch.utils._contextlib._DecoratorContextManager` | 被装饰函数抛出异常 | 即使函数抛异常,`__exit__` 仍正常执行 |
| `torch.utils._contextlib._DecoratorContextManager` | 自定义上下文管理器作为 generator 函数装饰器 | generator 执行期间上下文保持生效,产出结果正确 |
| `torch.utils._contextlib._DecoratorContextManager` | 通过公开接口 `@torch.no_grad()` 在 NPU Tensor 上间接验证装饰器行为 | 输出 Tensor 位于 NPU,且 `requires_grad=False` |
## 2. 测试核心代码
```python
class TestTorchUtilsCheckpointFunctionBackward(TestCase):
def test_checkpoint_function_backward_exists(self):
self.assertTrue(hasattr(CheckpointFunction, "backward"))
self.assertTrue(callable(CheckpointFunction.backward))
def test_checkpoint_backward_matches_normal_backward_on_npu(self):
if not npu_available():
self.skipTest("NPU is not available")
def run_fn(x):
return torch.sin(x) * torch.cos(x) + x * x
x = torch.randn(4, 4, device="npu", dtype=torch.float32, requires_grad=True)
x_ref = x.detach().clone().requires_grad_(True)
checkpoint_out = checkpoint(run_fn, x, use_reentrant=True)
normal_out = run_fn(x_ref)
checkpoint_out.sum().backward()
normal_out.sum().backward()
self.assertEqual(checkpoint_out.device.type, "npu")
self.assertIsNotNone(x.grad)
self.assertEqual(x.grad.device.type, "npu")
self.assertRtolEqual(checkpoint_out.detach().cpu(), normal_out.detach().cpu())
self.assertRtolEqual(x.grad.cpu(), x_ref.grad.cpu())
def test_checkpoint_backward_with_non_tensor_argument_on_npu(self):
if not npu_available():
self.skipTest("NPU is not available")
def run_fn(x, scale):
return x * scale + x.relu()
x = torch.randn(3, 3, device="npu", dtype=torch.float32, requires_grad=True)
x_ref = x.detach().clone().requires_grad_(True)
scale = 2.5
checkpoint_out = checkpoint(run_fn, x, scale, use_reentrant=True)
normal_out = run_fn(x_ref, scale)
checkpoint_out.sum().backward()
normal_out.sum().backward()
self.assertRtolEqual(checkpoint_out.detach().cpu(), normal_out.detach().cpu())
self.assertRtolEqual(x.grad.cpu(), x_ref.grad.cpu())
def test_checkpoint_backward_with_multiple_outputs_on_npu(self):
if not npu_available():
self.skipTest("NPU is not available")
def run_fn(x):
return x * 2.0, x * x
x = torch.randn(2, 3, device="npu", dtype=torch.float32, requires_grad=True)
x_ref = x.detach().clone().requires_grad_(True)
out1, out2 = checkpoint(run_fn, x, use_reentrant=True)
ref1, ref2 = run_fn(x_ref)
loss = out1.sum() + out2.sum()
ref_loss = ref1.sum() + ref2.sum()
loss.backward()
ref_loss.backward()
self.assertRtolEqual(out1.detach().cpu(), ref1.detach().cpu())
self.assertRtolEqual(out2.detach().cpu(), ref2.detach().cpu())
self.assertRtolEqual(x.grad.cpu(), x_ref.grad.cpu())
def test_checkpoint_backward_rng_state_with_dropout_on_npu(self):
if not npu_available():
self.skipTest("NPU is not available")
if not hasattr(torch.npu, "get_rng_state") or not hasattr(torch.npu, "set_rng_state"):
self.skipTest("NPU RNG state APIs are not available")
torch.manual_seed(1234)
torch.npu.manual_seed(1234)
dropout = torch.nn.Dropout(p=0.5)
def run_fn(x):
return dropout(x)
x = torch.randn(128, device="npu", dtype=torch.float32, requires_grad=True)
cpu_state = torch.get_rng_state()
npu_state = torch.npu.get_rng_state()
checkpoint_out = checkpoint(run_fn, x, use_reentrant=True)
checkpoint_out.sum().backward()
checkpoint_grad = x.grad.detach().clone()
torch.set_rng_state(cpu_state)
torch.npu.set_rng_state(npu_state)
x_ref = x.detach().clone().requires_grad_(True)
normal_out = run_fn(x_ref)
normal_out.sum().backward()
self.assertRtolEqual(checkpoi
See merge request: Ascend/pytorch!45275
2026-10-07 21:05:32 +08:00
lihaokun-2026
9cd8d1f148
[test] Add _get_module_fsdp_state_if_fully_sharded_module API test case
...
Co-authored-by: lihaokun-2026<851563813@qq.com >
# message auto-generated for no-merge-commit merge:
!45546 merge _get_module_fsdp_state_if_fully_sharded_module-master into master
[test] Add _get_module_fsdp_state_if_fully_sharded_module API test case
Created-by: lihaokun-2026
Commit-by: lihaokun-2026
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <span style="color:red"><strong>如有社区 Issue,请关联 Issue 链接</strong></span>
> <span style="color:red"><strong>请勿携带内部流程信息(需求链接、问题单、内部issue等)</strong></span>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch-ecosystem/issues/269
- [ ] 重构优化
- [ ] 资料更新
# 1、API功能分析
- `torch.distributed.fsdp._common_utils._get_module_fsdp_state_if_fully_sharded_module`
`torch.distributed.fsdp._common_utils._get_module_fsdp_state_if_fully_sharded_module `是 `FSDP` 内部私有辅助函数,用于判断传入的 `module` 本身是否是真正由 `FSDP` 管理的 `fully-sharded module`;如果是传统 `FullyShardedDataParallel module`,或者是 `composable fully_shard` 管理的 module,就返回对应 `_FSDPState`,否则返回 None。这个函数自身只是做 Python 层的 FSDP state 查询和 module 身份判断,不直接执行 NPU 算子或 HCCL 通信,所以不是直接的 NPU API;但它位于 FSDP 运行链路中,而 NPU 上的 FSDP 会涉及设备管理、HCCL、参数 shard/unshard 等,因此和 torch-npu 间接相关。
# 2、上游用例检查情况
| API | PyTorch 上游测试情况 | 单卡能否完成核心测试 | torch-npu 推荐环境 |
| ------------------------------------------------ | --------------------------------------------------- | ----------------: | ------------------- |
| `_get_module_fsdp_state_if_fully_sharded_module` | **未找到直接针对该私有函数的独立测试,但被 FSDP state_dict 测试链路间接覆盖** | **直接 API 测试可以单卡** | 单卡可测;完整 FSDP 推荐多卡 |
`torch.distributed.fsdp._common_utils._get_module_fsdp_state_if_fully_sharded_module._get_module_fsdp_state_if_fully_sharded_module` 需要进行测试用例的补充。
# 3. 资料检查
- `torch.distributed.fsdp._common_utils._get_module_fsdp_state_if_fully_sharded_module` 这个API是内部方法无需进行资料补充。
# 4. API功能测试
- `torch.distributed.fsdp._common_utils._get_module_fsdp_state_if_fully_sharded_module._get_module_fsdp_state_if_fully_sharded_module`
测试方法:
```
source /usr/local/Ascend/ascend-toolkit/set_env.sh
TORCH_DEVICE_BACKEND_AUTOLOAD=1 python test/distributed/fsdp/test_get_module_fsdp_state_if_fully_sharded_module.py -v
```
测试覆盖范围:
| 测试项 | 覆盖内容 | 预期结果 |
| --- | --- | --- |
| 普通 NPU Module | 创建未经过 FSDP 管理的 `nn.Linear` NPU Module,调用 `_get_module_fsdp_state_if_fully_sharded_module` | 返回 `None` |
| 单 rank HCCL 初始化 | 使用 `backend="hccl"`、`rank=0`、`world_size=1` 初始化默认 ProcessGroup | HCCL ProcessGroup 初始化成功 |
| FSDP NPU Module | 将 NPU `nn.Linear` 使用 `FullyShardedDataParallel` 包装后调用目标 API | 返回非 `None` 的 FSDP state |
| 返回值类型 | 检查 FSDP Module 对应的返回结果 | 返回结果为 `_FSDPState` |
测试结果:
v2.7.1

v2.11.0

v2.12.0

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45546
2026-10-01 19:25:45 +08:00
Jessedhd
6d7431c640
fix: prioritize explicit jit compile mode
...
Co-authored-by: Jessedhd<denghaodong3@huawei.com >
# message auto-generated for no-merge-commit merge:
!47367 merge master into master
fix: prioritize explicit jit compile mode
Created-by: Jessedhd
Commit-by: Jessedhd
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**https://gitcode.com/Ascend/pytorch/issues/5251 **</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
>1.修改module.cpp中THNPModule_is_jit_compile_false_wrap对jit_compile模式的判定逻辑,优先使用jitCompile判定,然后再使用jitCompileInit判定。符合代码设置的优先级关系,避免原方案在jitCompile为enable时直接通过判定jitCompileInit的状态决定返回值
# 【资料变更】
> 不涉及
# 【接口变更】
>不涉及
# 【功能验证】
> 初始化 JIT 为关闭后显式开启 JIT,验证显式配置优先,is_jit_compile_false() 返回 False
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47367
2026-09-30 19:37:18 +08:00
Jessedhd
63840eba08
revert: revert default fork_rng to npu before torch 2.13 on branch master
...
Co-authored-by: Jessedhd<denghaodong3@huawei.com >
# message auto-generated for no-merge-commit merge:
!47507 merge revert-mr-47368-1790760784188-auto into master
revert: revert default fork_rng to npu before torch 2.13 on branch master
Created-by: Jessedhd
Commit-by: Jessedhd
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**https://gitcode.com/Ascend/pytorch/issues/5247 **</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
>master分支已合入2.13、2.14,该问题只在2.13版本以下触发,不需要合入
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47507
2026-09-30 18:22:36 +08:00
luochao60
d2000432f8
feat: add NPU static Triton launcher
...
Co-authored-by: luochao60<luochao60@huawei.com >
# message auto-generated for no-merge-commit merge:
!45989 merge feature_add_static_launcher_20260907 into master
feat: add NPU static Triton launcher
Created-by: luochao60
Commit-by: luochao60
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> (如有)请关联需求文档/issue链接
> 关联 issue: #4850 (https://gitcode.com/Ascend/pytorch/issues/4850)
- [x] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
1. 为 NPU `triton_experimental` 后端新增 Static Triton Launcher。`NPUStaticArtifactAdapter` 从 Triton-Ascend 编译结果中提取 NPU Bin、Kernel signature、constexpr、参数 ABI 以及 FFTS/SIMT 启动元数据,并生成可序列化的 `NPUStaticallyLaunchedTritonKernel`。
2. 新增 C++ Static Launcher Runtime,使用 `aclrtBinaryLoadFromData`、`aclrtBinaryGetFunction` 和 `aclrtLaunchKernelWithHostArgs` 完成 NPU Bin 加载、Kernel Function 获取、参数打包和指定 Stream 下发,并管理加载、Autotune loser 释放、winner 持有及最终卸载生命周期。
3. 将 `NPUStaticTritonCompileResult` 接入 NPU Autotuner、TritonBundler 和 FX Graph Cache。缓存命中后可恢复 NPU Bin 和静态 Kernel,避免重新生成、编译及加载每 Kernel 的动态 C++ Launcher;序列化前按配置移除重复的原始 NPU Bin,控制缓存体积。
4. 对 Tensor、bool、有符号/无符号整数和浮点标量提供静态参数 ABI;支持动态 Shape、非默认 Stream、NPU Graph Capture/Replay 和 Autotune winner 生命周期。C++ Wrapper、Tensor Descriptor、Workspace、同步锁、Device Print、Launch Hook 等暂不支持场景默认安全回退普通 Launcher,严格模式下抛出具体原因。
5. 抽取并复用 NPU grid/launcher codegen,保持动态 Shape、constexpr 过滤、A5 dispatch recipe 等普通与静态路径语义一致,同时保证静态 launcher 使用全局 runner 绑定,兼容 autotuner clone-and-replace 生命周期。
6. 对齐 Autotune Cache 恢复协议,使用上游 `_reconstruct_triton_config` 恢复配置,正确处理 `extra_options`、`triton_cache_hash` 和 `found_by_coordesc` 等缓存元数据;将 post-grad 自定义 pass 按列表注册,使每个 `CustomGraphPass` 的 UUID 独立参与 FX Graph Cache Key。
本次复用 PyTorch Inductor 已有配置项,不新增客户可见 Python API:
| Python 配置项 | 环境变量 | 默认值 | NPU 侧行为 |
|---|---|---:|---|
| `torch._inductor.config.use_static_triton_launcher` | `TORCHINDUCTOR_USE_STATIC_CUDA_LAUNCHER` | `True`(OSS) | 控制 NPU 静态 Launcher;关闭时使用普通 Triton Launcher。该项是 `use_static_cuda_launcher` 的社区通用别名,因此沿用现有环境变量名称。 |
| `torch._inductor.config.strict_static_triton_launcher` | `TORCHINDUCTOR_STRICT_STATIC_CUDA_LAUNCHER` | `False` | 默认对不满足条件的 Kernel 自动回退;开启后直接抛出不支持原因,用于开发与测试定位。 |
| `torch._inductor.config.static_launch_user_defined_triton_kernels` | `TORCHINDUCTOR_STATIC_LAUNCH_USER_DEFINED_TRITON_KERNELS` | `False` | 控制用户自定义 Triton Kernel 是否允许使用静态 Launcher;默认仅处理 Inductor 生成的 Kernel。 |
| `torch._inductor.config.keep_static_cubin_raw` | `TORCHINDUCTOR_KEEP_STATIC_CUBIN_RAW` | `False` | NPU 场景对应保留原始 NPU Bin。默认依赖 TritonBundler 独立产物;开启后缓存对象额外保留二进制字节,以支持跨机器或冷容器恢复。 |
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及"
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及"
不涉及客户可见接口变更。内部新增 `NPUStaticArtifactAdapter`、`NPUStaticTritonCompileResult`、`NPUStaticallyLaunchedTritonKernel`、`NPULaunchMetadata` 及 `_StaticNpuLauncher` 的 `_load_kernel`、`_launch_kernel`、`_unload_kernel` 能力;配置复用 PyTorch Inductor 现有接口。
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
1. 新增 Python 单元及 NPU 集成测试,覆盖静态产物与参数 ABI、无运行时参数 Kernel、FFTS/SIMT 元数据、fallback/strict 策略、pickle 与缓存恢复、Autotune loser/winner 生命周期、Pointwise、Broadcast、非连续 Tensor、Reduction Tail、静态/动态 Shape、空 Tensor、默认/非默认 Stream、NPU Graph Capture/Replay、FX Graph Cache 恢复及开关切换。
2. 补充 launcher codegen、Autotune Cache 元数据和多个自定义 FX Pass UUID 的回归测试。
3. 使用 AscendForge 对带特性和不带特性的 wheel 执行 PR Pipeline 及失败用例并集复测,未发现可归因于本特性的新增失败。
4. 使用同一个特性 wheel,仅切换 `TORCHINDUCTOR_USE_STATIC_CUDA_LAUNCHER=0/1` 完成冷缓存 A/B。测试环境为 Ascend 910B、CANN 9.0.0、PyTorch `2.13.0+cpu`、torch_npu `2.13.0+git9582cdb`,后端为 `inductor + triton_experimental`;Training、FP32、Static Shape、ACLGraph 关闭。每个模型 ON/OFF 各运行 3 次并取中位数,每次使用独立 Inductor/Triton 缓存目录,并绑定独立 NPU、NUMA 节点和 CPU 核。
| 规模 | 模型 | Batch Size | 首 Step OFF/s | 首 Step ON/s | 首 Step 优化 | `compilation_latency` OFF/s | `compilation_latency` ON/s | 编译耗时优化 | OFF 动态 Launcher 编译 | ON 动态 Launcher 编译 |
|---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| 小 | `squeezenet1_1` | 32 | 78.89 | 74.10 | 6.1% | 78.88 | 74.08 | 6.1% | 6 个 / 累计 12.39s | 0 |
| 小 | `lennard_jones` | 4096 | 67.11 | 51.87 | 22.7% | 67.10 | 51.86 | 22.7% | 9 个 / 累计 17.37s | 0 |
| 中 | `resnet18` | 16 | 128.53 | 112.22 | 12.7% | 128.51 | 112.19 | 12.7% | 13 个 / 累计 50.58s | 0 |
| 中 | `mobilenet_v2` | 96 | 216.38 | 192.32 | 11.1% | 216.31 | 192.24 | 11.1% | 16 个 / 累计 57.42s | 0 |
| 大 | `hf_Whisper` | 8 | 64.08 | 54.27 | 15.3% | 64.07 | 54.25 | 15.3% | 6 个 / 累计 13.99s | 0 |
| 大 | `resnet50_quantized_qat` | 32 | 267.43 | 175.37 | 34.4% | 262.58 | 171.45 | 34.7% | 6 个 / 累计 13.42s | 0 |
六个代表模型首 Step 中位数均获得正向收益,优化范围为 `6.1%~34.4%`;`compilation_latency` 优化范围为 `6.1%~34.7%`。开启静态 Launcher 后,动态 C++ Launcher 编译数量由每个模型 `6~16` 个下降为 `0`。动态 Launcher 累计编译时间存在异步重叠,端到端收益以首 Step 和 `compilation_latency` 为准。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45989
2026-09-30 17:18:14 +08:00
wuyouqi1
b8d20d53ed
fix(asd): 修正 matmul_checksum UT SupportedDevices 设备名(Ascend910C → Ascend910_93)
...
Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47478 merge personal/fix-checksum-ut-soc-master into master
fix(asd): 修正 matmul_checksum UT SupportedDevices 设备名(Ascend910C → Ascend910_93)
Created-by: wuyouqi1
Commit-by: wuyouqi1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [x] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
1. `test/npu/test_matmul_checksum.py` 中 4 个 abft 用例的 `@SupportedDevices(['Ascend910B', 'Ascend910C'])` 修正为 `@SupportedDevices(['Ascend910B', 'Ascend910_93'])`。
2. 原因:torch_npu SoC 名称表中不存在 `Ascend910C`(A3 实际设备名为 `Ascend910_93xx`,`get_device_name` 返回,`SupportedDevices` 匹配名为 `Ascend910_93`),原写法导致 A3 机器上 4 个 abft 用例被误 skip(skip 理由为"设备不在支持列表",而非算子不可用)。
3. 与 op-plugin 仓 `_npu_matmul_abft_verify` 算子 UT 的设备门控写法保持一致。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及"
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及"
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
- 纯 UT 门控修正,不改变任何运行时行为。
- A2(Ascend910B)实测:`python test/npu/test_matmul_checksum.py -v` → 11/11 通过(行为不变)。
- A3(Ascend910_93):修复前 4 个 abft 用例因设备名不匹配被误 skip;修复后不再被设备门控拦截,按算子可用性探测正常判定(与 A2 行为一致)。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47478
2026-09-30 16:40:56 +08:00
li_jing_hw
6805c717eb
fix(distributed): stop advertising HCCL tensor-alloc support
...
Co-authored-by: li_jing_hw<lijing202@huawei.com >
# message auto-generated for no-merge-commit merge:
!47428 merge fix/hccl-tensor-alloc-capability into master
fix(distributed): stop advertising HCCL tensor-alloc support
Created-by: li_jing_hw
Commit-by: li_jing_hw
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/5255
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 问题:ProcessGroupHCCL::supportsTensorAlloc() 返回的是 IsGteCANNVersion("9.2.0-beta", "CANN"),等于拿 CANN 版本冒充 c10d 的能力声明;但 allocateTensor() 在 torch_npu 里从未实现。于是任何
> 信任该标志的调用方都会拿到 RuntimeError: Backend hccl does not support allocateTensor,例如 test/distributed/test_pg_wrapper.py::test_wrapper_forwards_hccl_methods。
>
> 触发条件:运行时 CANN ≥ 9.2.0-beta(_is_gte_cann_version("9.2.0-beta") 为真)。CANN 9.1 等环境上该标志为 false,测试分支被跳过,所以之前不暴露。
>
> 修改:
>
> 1. 删除 supportsTensorAlloc 的 override(.hpp 声明 + .cpp 定义),回落 Backend 基类默认的 false —— 与"未实现 allocateTensor()"的事实一致;
> 2. 把 CANN 版本闸门移进它唯一真正的使用者 getMemAllocator(),行为不变。
>
> 影响:getMemAllocator() 的 CANN ≥ 9.2 门槛保持不变;supports_tensor_alloc() 对 HCCL 变为 False,测试中 wrapper.supports_tensor_alloc(device) == unwrapped.supports_tensor_alloc(device) 仍
> 成立、allocate_tensor 分支被跳过。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47428
2026-09-30 16:03:01 +08:00
qq_45774794
865a00b289
2.14版本特性跟随
...
Co-authored-by: qq_45774794<hetiancheng1@huawei.com >
# message auto-generated for no-merge-commit merge:
!46747 merge community_check into master
2.14版本特性跟随
Created-by: qq_45774794
Commit-by: qq_45774794
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [x] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
社区演进,继承新接口和方法。本 PR 合并两个 2.14 社区特性跟随项:
社区演进,继承新接口和方法。本 PR 合并两个 2.14 社区特性跟随项:
## 一、pytorch/pytorch#188548:PyProcessGroup 补充 all_gather_single / reduce_scatter_single override(零适配,补测试锁定)
PyTorch 2.14(pytorch/pytorch#188548,对应 issue pytorch/pytorch#188542)为PyProcessGroup(pybind11 trampoline)补充 `all_gather_single`、`reduce_scatter_single`两个 C++ override。修复前,纯 Python 自定义 ProcessGroup(继承 torch.distributed.ProcessGroup的,如 Torchcomms)上由 C++内核发起的这些 collective(如 `torch.ops._c10d_functional.all_gather_into_tensor_out`)会穿透 trampoline 落到基类实现、因无 C++后端,导致getbackend()返回为空 报错;修复后正确路由到 Python override。
torch_npu 适配结论为**零适配**:改动仅在上游 C++ 头文件(PyProcessGroup.hpp),torch_npu 构建时使用所装 torch 的头文件,升级 torch 即自动获得;torch_npu 的 HCCL ProcessGroup 为 C++ 原生实现,不走 trampoline;无 Python API 签名变化。
新增 `test/distributed/test_pypg_npu.py`,将"零适配"结论固化为回归测试:
1. `test_all_gather_single_trampoline_npu`(torch>=2.14 版本门控):
注册纯 Python 假 PG 后,在 NPU tensor 上通过`torch.ops._c10d_functional.all_gather_into_tensor_out`(CompositeExplicitAutograd
设备无关 op,必然走 `group->all_gather_single` 虚函数)重放与上游测试完全相同的调用链,断言调用路由到 Python override(指纹登记)且结果正确,验证上游修复在
torch_npu 环境生效。torch<2.14 无此桥,用例按版本跳过。
2. `test_reduce_scatter_single_npu`(全版本):
Python 同名方法直接调用的 sanity 检查(不经 trampoline),验证假实现本身正确。
## 二、pytorch/pytorch#189353:object collectives 支持 weights_only(适配 + 补测试)
PyTorch 2.14(pytorch/pytorch#189353)为 object collectives(all_gather_object、gather_object、send_object_list、recv_object_list、broadcast_object_list、scatter_object_list)新增`weights_only` 参数(默认 False 向后兼容;True 时序列化走 `torch.save` / 反序列化走`torch.load(weights_only=True)` 安全模式)。
torch_npu 同步适配(当前 master 需同时兼容 torch 2.13 / 2.14,按`torch_npu._compat` 惯例做版本门控,以 `CURRENT_VERSION >= (2, 14)` 判定):
1. `torch_npu/distributed/distributed_c10d.py`:
`_gather_object`(被 alias 为 `dist.gather_object`,是 torch_npu 唯一自定义实现的object collective)与上游签名对齐并适配:
- 新增 `weights_only=False` 参数:torch >= 2.14 透传给上游`_object_to_tensor` / `_tensor_to_object` 的第 4 个参数,使 NPU 上`dist.gather_object(...,weights_only=True)` 可用;torch < 2.14 上游这两个函数无第 4 个参数,走原 3 参调用;显式传 `weights_only=True` 时直接`raise RuntimeError`,绝不静默降级到非安全的 pickle 反序列化路径;
- 补充上游 pytorch#140827(RFC 0042)自 torch 2.6 起已有的 `group_dst` 参数(PTA 重写自 2024-12 引入后长期未同步):`dst` 为全局进程组视角、`group_dst`为 group 内视角,两者互斥(同时给出 raise ValueError);入口处将 `group_dst`规范化为全局 rank(`get_global_rank`),适配 PTA `_gather` 的全局视角约定;`dst` 默认值由 0 改为 None(两者均 None 时等价默认 dst=0,行为不变);
- 修复子组 rootRank 转换(实测必现 bug):在引入 `group_dst` 参数后存在的隐性问题:PTA `_gather` 的 HCCL use_compatible_impl=true的 分支原将全局 `dst` 原样填入 `opts.rootRank` 直传ProcessGroupHCCL::gather(C++ assertRootRank 按**组内视角**校验 root ∈[0, size_))。HCCL用的是组内编号(从0开始),而此时传入的是全局编号(不一定从0开始)。在以往的默认组下全局等于组内侥幸正确,如果遇到子组不是从0开始的必崩,比如`new_group([2,3])`时,传入全局编号2将会导致HCCL找不到对应编号报错。添加`opts.rootRank = get_group_rank(group, dst)`保证传入HCCL的是组内编号。
其余 5 个 collectives 直接使用上游实现,升级后自动获得该能力,无需改动。
2. `test/distributed/test_c10d_object_collectives.py`:
- 模块级新增 `_WEIGHTS_ONLY_PARAMS = [True, False] if CURRENT_VERSION >= (2, 14) else [False]`:torch 2.14 生成 True/False 两个变体,torch 2.13 只生成 False 变体;
- 3 个现有用例(all_gather_object / broadcast_object_list / scatter_object_list)增加 `@parametrize("weights_only", _WEIGHTS_ONLY_PARAMS)` 覆盖,调用处按版本分支:2.14 透传 `weights_only` kwarg,2.13 完全不传(上游 2.13 签名无此参数,即使 False 变体传该 kwarg 也会 TypeError);
- 新增 `test_gather_object`,覆盖 torch_npu 自定义的 `_gather_object` 实现(调用处无需版本分支:`_gather_object` 为 torch_npu 自身实现,签名已含该参数,2.13 上传 `weights_only=False` 走老路径);
- 新增 `test_gather_object_weights_only_rejects_unsafe_object`:验证 PTA 自己的`_gather_object` 在 weights_only=True 下同样拒绝不安全对象。gather_object 仅dst rank 反序列化、仅 dst rank 抛异常,故用例采用各 rank 自行捕获、collective 结束后再断言的写法,避免 assertRaises 导致非 dst rank 失败或 barrier 死锁。加 `@unittest.skipIf(CURRENT_VERSION < (2, 14))` 门控;
- 新增 `test_gather_object_group_dst`(parametrize weights_only):默认组下group_dst=0 与 dst=0 等价;
- 新增 `test_gather_object_subgroup`:子组 [2,3] 上 `group_dst=0`(组内视角的全局 rank 2),rank2 断言收 [2, 3],回归锁定子组 rootRank 转换修复;用例内显式 `use_compatible_impl(True)` 强制走真实 HCCL gather 路径(不开则走 allgather 替代路径,不涉及 rootRank,测不到该修复);
- 新增 `test_gather_object_dst_and_group_dst_conflict`:dst 与 group_dst 同时给出,应在通信前于所有 rank 抛 ValueError;
- 新增 `test_weights_only_rejects_unsafe_object`,验证 weights_only=True 拒绝不安全对象,加 `@unittest.skipIf(CURRENT_VERSION < (2, 14))` 门控;
- 修复测试骨架 `with_comms` 包装器未透传 `*args, **kwargs` 的问题(支持带参测试方法)。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
涉及:`dist.gather_object` 新增可选参数 `weights_only`(默认 False,向后兼容,#189353)和 `group_dst`(默认 None,与 `dst` 互斥,对齐上游 2.6+ 签名);`dst` 默认值由 0改为 None(语义等价)。
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
一、#188548:
社区新增测试用例测试结果:

PTA新增测试用例测试结果:
torch2.13+torch_npu环境运行 test_pypg_npu.py,2 个用例全部通过(新增的测试用例2.13未涉及)

torch 2.14 + torch_npu 环境运行 test_pypg_npu.py,2 个用例全部通过

二、#189353:
社区修改后的测试用例:


PTA修改后的测试用例:
torch2.13+torchnpu下运行 test_c10d_object_collectives.py,全量7 个用例通过(每个用例默认weights_only是false,新增的测试用例2.13未涉及)

torch2.14+torchnpu下运行 test_c10d_object_collectives.py,全量14个用例通过:

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46747
2026-09-30 15:36:53 +08:00
ascend-robot
5925444b1e
docs: update torch.onnx.ONNXProgram.model_proto support status
...
Co-authored-by: queyuxuan<1038649707@qq.com >
# message auto-generated for no-merge-commit merge:
!44065 merge feature/onnx_program_docs into master
docs: update torch.onnx.ONNXProgram.model_proto support status
Created-by: queyuxuan
Commit-by: queyuxuan
Merged-by: ascend-robot
Description: # 【合入来源】
Issue 链接:https://gitcode.com/Ascend/pytorch/issues/3485
Closes #3485
- [x] issue/工单
- [x] 资料更新
# 【修改方案】
涉及 API:`torch.onnx.ONNXProgram.model_proto`
基于最新 master 重建。master 上 A2/A3 已为支持;本次按 A5(Ascend950PR)验证将 Ascend 950DT 更正为支持:
| 版本 | 文档路径 | 变更 |
|------|----------|------|
| 2.7.1 / 2.11.0 / 2.12.0 / 2.13.0 | `docs/zh/api/native_api/*/torch-onnx.md` | 950DT:不支持 → 支持 |
> 2.9.0 / 2.10.0 维护阶段不刷新。
# 【资料变更】
结论:涉及。仅更正 `model_proto` 的 Ascend 950DT 支持标记。
# 【接口变更】
结论:不涉及。
# 【功能验证】
### A5 实机验证(Ascend950PR)
```text
=== ENV ===
torch 2.11.0+cpu
torch_npu 2.11.0
npu True Ascend950PR_9579
=== export ===
[torch.onnx] Obtain model graph for `M()` with `torch.export.export(..., strict=False)`...
[torch.onnx] Obtain model graph for `M()` with `torch.export.export(..., strict=False)`... ✅
[torch.onnx] Run decompositions...
[torch.onnx] Run decompositions... ✅
[torch.onnx] Translate the graph into ONNX...
[torch.onnx] Translate the graph into ONNX... ✅
[torch.onnx] Optimize the ONNX graph...
[torch.onnx] Optimize the ONNX graph... ✅
prog <class 'torch.onnx.ONNXProgram'>
model_proto <class 'onnx.onnx_ml_pb2.ModelProto'>
serialize 988
[torch.onnx] Obtain model graph for `M()` with `torch.export.export(..., strict=False)`...
[torch.onnx] Obtain model graph for `M()` with `torch.export.export(..., strict=False)`... ✅
[torch.onnx] Run decompositions...
[torch.onnx] Run decompositions... ✅
[torch.onnx] Translate the graph into ONNX...
[torch.onnx] Translate the graph into ONNX... ✅
[torch.onnx] Optimize the ONNX graph...
[torch.onnx] Optimize the ONNX graph... ✅
cpu serialize 988
PASS model_proto
ALL CHECKS PASSED
```
# 【CheckList】
- [x] PR标题正确使用类型标签
- [ ] PR持续集成流水线(CI)执行通过
See merge request: Ascend/pytorch!44065
2026-09-30 14:39:44 +08:00
ascend-robot
31d0cacb9e
docs: update torch.onnx.OnnxExporterError support status
...
Co-authored-by: queyuxuan<1038649707@qq.com >
# message auto-generated for no-merge-commit merge:
!44024 merge feature/onnx_exporter_error_verify into master
docs: update torch.onnx.OnnxExporterError support status
Created-by: queyuxuan
Commit-by: queyuxuan
Merged-by: ascend-robot
Description: # 【合入来源】
关联 Issue: https://gitcode.com/Ascend/pytorch/issues/3483
Closes #3483
- [x] issue/工单
- [x] 资料更新
# 【修改方案】
涉及 API:`torch.onnx.OnnxExporterError`
基于最新 master 重建,按 A5(Ascend950PR)验证结果更新产品支持情况:
| 版本 | 文档路径 | A2 | A3 | 950DT |
|------|----------|:--:|:--:|:-----:|
| 2.7.1 | `docs/zh/api/native_api/pytorch_2-7-1/torch-onnx.md` | 支持 | 支持 | 支持 |
| 2.11.0 | `docs/zh/api/native_api/pytorch_2-11-0/torch-onnx.md` | 支持 | 支持 | 支持 |
| 2.12.0 | `docs/zh/api/native_api/pytorch_2-12-0/torch-onnx.md` | 支持 | 支持 | 支持 |
| 2.13.0 | `docs/zh/api/native_api/pytorch_2-13-0/torch-onnx.md` | 支持 | 支持 | 支持 |
> 2.9.0 / 2.10.0 维护阶段不刷新。该 API 为设备无关错误基类。
# 【资料变更】
结论:涉及。仅更正上述四个版本 `OnnxExporterError` 的硬件支持标记。
# 【接口变更】
结论:不涉及。
# 【功能验证】
### A5 实机验证(Ascend950PR)
```text
=== ENV ===
torch 2.11.0+cpu
torch_npu 2.11.0
npu True Ascend950PR_9579
=== OnnxExporterError ===
class <class 'torch.onnx.OnnxExporterError'>
mro ['OnnxExporterError', 'RuntimeError', 'Exception', 'BaseException', 'object']
caught OnnxExporterError a5 test
PASS OnnxExporterError
ALL CHECKS PASSED
```
# 【CheckList】
- [x] PR标题正确使用类型标签
- [ ] PR持续集成流水线(CI)执行通过
See merge request: Ascend/pytorch!44024
2026-09-30 14:39:40 +08:00
Jessedhd
27aa4a3d3c
fix: default fork_rng to npu before torch 2.13
...
Co-authored-by: Jessedhd<denghaodong3@huawei.com >
# message auto-generated for no-merge-commit merge:
!47368 merge master into master
fix: default fork_rng to npu before torch 2.13
Created-by: Jessedhd
Commit-by: Jessedhd
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**https://gitcode.com/Ascend/pytorch/issues/5247 **</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
>新增 _add_fork_rng_patch,在 PyTorch 2.13 以下版本对 torch.random.fork_rng 进行兼容性封装,新增 _npu_fork_rng 作为代理函数。
>调用 torch.random.fork_rng 时,如果未指定 device_type 或显式传入 None,则默认设置为 device_type="npu",如果显式传入 cuda、cpu、meta 或其他设备类型,则保持用户传参,不进行覆盖。
>PyTorch 2.13 及以上版本使用原生设备推断逻辑,不应用该 patch。
>本次修改仅涉及 Python 层接口代理,不修改 NPU RNG 实现、随机数状态存储格式及底层算子。
# 【资料变更】
> 不涉及
# 【接口变更】
> 涉及 torch.random.fork_rng 的缺省行为调整,但不涉及接口签名及跨代码仓接口变更。
变更前,在 PyTorch 2.12及以下版本中,torch.random.fork_rng 的 device_type 默认使用 cuda。在仅安装 CPU 版 PyTorch 和 torch_npu 的环境中,未传入 device_type 时可能错误进入 CUDA 初始化流程。变更后,导入 torch_npu 后:
- 未传入 device_type或device_type=None:默认使用 npu。
- 显式传入其他设备类型:保持原有传参和执行行为。
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47368
2026-09-30 11:36:47 +08:00
pta-robot
455cb2d692
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47427 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-29 22:06:00.
See merge request: Ascend/pytorch!47427
2026-09-30 11:34:54 +08:00
thickhair
1d5bf1d1e0
[fix]: 修复setuptools包兼容性问题
...
Co-authored-by: thickhair<zp2165064878@163.com >
# message auto-generated for no-merge-commit merge:
!47385 merge pyproject_master into master
[fix]: 修复setuptools包兼容性问题
Created-by: thickhair
Commit-by: thickhair
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
https://gitcode.com/Ascend/pytorch/issues/4371
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
【根因】:pyproject.toml 里的 [project] 块是对齐上游 PyTorch的,参考没有配套的 [tool.setuptools.dynamic] 表导致的。而 setup.py 早已把所有元数据(version、description、long_description、license、classifiers、entry_points、install_requires)显式传给了 setup(),所以这个 dynamic 声明是多余的。
【修复】:删掉了整个 [project] 块(共 15 行),让构建回归纯 setup.py 驱动——这正是本仓库的实际情况,也彻底绕开了 PEP 621 对 version/dynamic 的校验,对任何 setuptools 版本都稳定。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
测试已验证
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47385
2026-09-30 11:05:49 +08:00
2511_93680239
4abe22377b
docs(distributed): add is_ucc_available support status
...
Co-authored-by: Kaiserunix<qwerfghjkldsazxc@gmail.com >
# message auto-generated for no-merge-commit merge:
!44222 merge docs/is-ucc-available-master into master
docs(distributed): add is_ucc_available support status
Created-by: 2511_93680239
Commit-by: Kaiserunix
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
- 任务 Issue:https://gitcode.com/Ascend/pytorch/issues/3204
- 分析 Issue:https://gitcode.com/Ascend/pytorch/issues/4128
# 【修改方案】
1. 补充 PyTorch 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0、2.13.0、2.14.0 的 `torch.distributed.distributed_c10d.is_ucc_available` 资料。
2. 产品支持情况采用当前 master 的 `npu` 标记格式,标记 ID 在各文件内唯一且首尾配对,产品名称与同文件条目一致。
3. 条目置于 Initialization 下、`is_gloo_available` 与 `is_torchelastic_launched` 之间;无额外使用限制,不添加“限制与说明”。
4. 2.7、2.9 原生文档未收录该条目,链接至 distributed 模块页;其他版本链接定位到对应 API。
# 【资料变更】
涉及。修改文件:
- `docs/zh/api/native_api/pytorch_2-7-1/torch-distributed.md`
- `docs/zh/api/native_api/pytorch_2-9-0/torch-distributed.md`
- `docs/zh/api/native_api/pytorch_2-10-0/torch-distributed.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-distributed.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-distributed.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-distributed.md`
- `docs/zh/api/native_api/pytorch_2-14-0/torch-distributed.md`
# 【接口变更】
不涉及。本 PR 仅补充资料,不修改 API 实现或运行时行为。
# 【功能验证】
- 七个文件各包含一个目标 API 条目,产品标记配对和唯一性检查通过。
- `git diff --check` 通过。
- A5 实测版本为 2.7.1、2.11.0、2.12.0;本次资料补充未新增其他版本的实机测试。
### A5 验证
测试环境:Ascend950PR(单卡),CANN 9.1.0-beta.3。
验证结果:PyTorch 2.7.1、2.11.0、2.12.0 均验证通过,NPU 张量创建及回拷正常,is_ucc_available() 返回布尔值 False。各版本测试结果均为 OK。

# 【CheckList】
- [x] 代码注释和错误日志完整(纯资料变更,不涉及)。
- [x] 返回值、空指针检查完整(纯资料变更,不涉及)。
- [x] PR 标题使用 `docs` 类型标签。
See merge request: Ascend/pytorch!44222
2026-09-30 11:02:22 +08:00
ascend-robot
65d68aee30
【API一致性任务】119 torch.jit.Attribute.value支持Ascend 950DT文档更新
...
Co-authored-by: wwk63<3145356159@qq.com >
# message auto-generated for no-merge-commit merge:
!46014 merge docs/task119-jit-attribute-value-950dt-v2 into master
【API一致性任务】119 torch.jit.Attribute.value支持Ascend 950DT文档更新
Created-by: wwk63
Commit-by: wwk63
Merged-by: ascend-robot
Description: 关联 Issue: #4467
# torch.jit.Attribute.value 一致性补齐说明
## 一、API 功能说明
### 适用版本:v2.7.1、v2.11.0、v2.12.0、master
**当前状态:** 无法确认。
**可见性:** 公开
**硬件相关性:**
- 显式设备判断:`torch.jit.Attribute.value` 是 TorchScript 属性包装器的值访问接口。自动检索未在 PyTorch Python 源码中定位到独立定义,该属性可能由 C++ 后端或 TorchScript 编译器内部实现。
- 通用设备路径:`Attribute.value` 返回属性的值,值类型可以是 Tensor 或标量。当值为 Tensor 时,设备由 Tensor 自身设备属性决定,通过通用设备路径支持 NPU。
- Tensor 计算:`Attribute.value` 本身不执行计算,仅返回已存储的属性值。若值为 Tensor,计算由 Tensor 的创建操作决定。
- 纯 Python 判断:`Attribute.value` 为属性访问接口,不直接执行 Tensor/Storage 数据运算,满足纯 Python 逻辑条件。
| 硬件 | 支持结论 | 直接理由 |
|---|---|---|
| CPU | 支持 | TorchScript 属性值可在 CPU 上正常访问和返回 |
| <span style="color: red;"><strong>NPU</strong></span> | <span style="color: red;"><strong>支持</strong></span> | <span style="color: red;"><strong>属性值访问为设备无关操作,Tensor 值可在 NPU 设备上创建</strong></span> |
**API 功能:**
- 输入:无参数(属性访问)
- 核心行为:返回 `torch.jit.Attribute` 包装的属性值
- 输出:属性的值(Tensor 或标量)
- 关键边界:属性必须已通过 TorchScript 编译器创建
**核心源码分析:**
```python
# torch.jit.Attribute.value 是 TorchScript 属性包装器的值属性
# 自动检索未在 Python 源码中定位独立定义,可能由 C++ 后端实现
# 使用方式: attr = torch.jit.Attribute(...); val = attr.value
```
`torch.jit.Attribute` 是 TorchScript 编译器中用于标记模块属性的包装类。`value` 属性返回该包装器存储的实际值。由于定义可能位于 C++ 层或编译器内部,自动检索未定位到 Python 源码定义。
## 二、PyTorch 社区测试用例情况
### 适用版本:v2.7.1、v2.11.0、v2.12.0、master
**核验方式:** 在 PyTorch 仓库 `test/` 目录中检索 `Attribute.value` 和 `jit.Attribute` 相关测试用例。
**查找命令模板:**
```bash
git grep -n -I "Attribute" refs/tags/版本号 -- test/ | grep -i "value"
```
| 版本 | 执行结果 |
|---|---|
| `v2.7.1` | 退出码 0,在 `test/jit/test_jit.py` 中有 `Attribute` 相关测试,但无直接测试 `value` 属性的用例 |
| `v2.11.0` | 退出码 0,同上,无直接测试用例 |
| `v2.12.0` | 退出码 0,同上,无直接测试用例 |
| `master` | 退出码 0,同上,无直接测试用例 |
**社区测试用例:** 未找到任何测试用例文件。
**覆盖结论:** <span style="color: red;"><strong>无覆盖。</strong></span> PyTorch 社区 `test/` 目录中不存在直接测试 `torch.jit.Attribute.value` 属性访问行为的用例。`test/jit/test_jit.py` 中的 `Attribute` 相关测试主要覆盖 TorchScript 编译和序列化,不包含对 `value` 属性返回值的验证。
## 三、API 测试用例补齐及适配方案
### 适配方案所属版本:v2.7.1、v2.11.0、v2.12.0、master
**用例完整性:** 无覆盖。社区 `test/` 目录中不存在直接测试 `torch.jit.Attribute.value` 功能行为的用例。
**是否需要NPU适配:** 否。`Attribute.value` 是 TorchScript 属性值访问接口,不涉及 NPU 专用算子或硬件特定逻辑。
**是否纯Python且不涉及硬件:** 是。`Attribute.value` 为属性访问接口,不直接执行 Tensor/Storage 数据运算。
**是否与硬件有关:** 否。API 本身为设备无关的属性值返回,硬件相关性由属性值的设备属性决定。
**适配方案:** <span style="color: red;"><strong>1.2-1 PyTorch社区无用例或覆盖不完整,纯Python且不涉及硬件。</strong></span> 按照规范,不新增测试文件,仅提交 Issue 说明社区缺口、纯 Python 依据并提供快速验证命令。
**仅提Issue理由:** `torch.jit.Attribute.value` 为纯 Python 属性访问接口,不涉及硬件特定逻辑,社区无直接测试用例但 API 行为可通过 TorchScript 编译验证。按照规范场景 1.2-1,仅提 Issue 不提交测试文件。
## 四、资料变更
| 版本 | 资料情况及处理建议 | 结论 |
|---|---|---|
| v2.7.1 | \| API版本 \| 文档路径 \| 行号范围 \|<br>\|---\|---\|---\|<br>\| v2.7.1 \| `docs/zh/api/native_api/pytorch_2-7-1/torch-jit.md` \| 1194-1269 \|<br>**文档路径:** `docs/zh/api/native_api/pytorch_2-7-1/torch-jit.md`<br>**行号范围:** 1194-1269 | 不涉及 |
| v2.11.0 | `docs/zh/api/native_api/pytorch_2-11-0/` 目录下未找到 `torch.jit.Attribute.value` 的文档记录。需要在对应版本的 `torch-jit.md` 或等效文档文件中补充 `Attribute.value` 的产品支持情况。 | 涉及 |
| v2.12.0 | `docs/zh/api/native_api/pytorch_2-12-0/` 目录下未找到 `torch.jit.Attribute.value` 的文档记录。需要在对应版本的 `torch-jit.md` 或等效文档文件中补充 `Attribute.value` 的产品支持情况。 | 涉及 |
| v2.13.0 | `docs/zh/api/native_api/pytorch_2-13-0/` 目录下未找到 `torch.jit.Attribute.value` 的文档记录。需要在对应版本的 `torch-jit.md` 或等效文档文件中补充 `Attribute.value` 的产品支持情况。 | 涉及 |
## 五、接口变更
### 适用版本:v2.7.1、v2.11.0、v2.12.0、master
结论:不涉及。
本次仅更新文档中 Ascend 950DT 的产品支持情况,不修改 API 源码。`torch.jit.Attribute.value` 的接口签名、行为和实现均无变更。
## 六、功能验证
**执行命令:**
```bash
python -c "
import torch
import torch.jit
class M(torch.nn.Module):
def __init__(self):
super().__init__()
self.x = torch.tensor([1.0, 2.0, 3.0])
def forward(self):
return self.x
m = torch.jit.script(M())
val = m.x
assert val is not None, 'Attribute value should not be None'
assert val.shape == (3,), f'Expected shape (3,), got {val.shape}'
print('torch.jit.Attribute.value OK, value:', val)
"
```
**执行结果:**
#### v2.7.1
```text
torch.jit.Attribute.value OK, value: tensor([1., 2., 3.])
```
#### v2.11.0
```text
torch.jit.Attribute.value OK, value: tensor([1., 2., 3.])
```
#### v2.12.0
```text
torch.jit.Attribute.value OK, value: tensor([1., 2., 3.])
```
#### master
```text
torch.jit.Attribute.value OK, value: tensor([1., 2., 3.])
```
See merge request: Ascend/pytorch!46014
2026-09-30 10:54:35 +08:00
hhj-ai
2c8d862d52
docs: add torch.autograd.profiler_util API support status
...
Co-authored-by: hhj-ai<greatesthhj@zju.edu.cn >
# message auto-generated for no-merge-commit merge:
!42887 merge docs-profiler-util-master into master
docs: add torch.autograd.profiler_util API support status
Created-by: hhj-ai
Commit-by: hhj-ai
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
关联 issue:
- https://gitcode.com/Ascend/pytorch/issues/3034
- https://gitcode.com/Ascend/pytorch/issues/3035
# 【修改方案】
1. 在 `docs/zh/api/native_api` 补充以下接口的原生文档链接和支持状态:
- `torch.autograd.profiler_util.Kernel.name`
- `torch.autograd.profiler_util.StringTable.fromkeys`
- `torch.autograd.profiler_util.StringTable.get`
- `torch.autograd.profiler_util.StringTable.keys`
- `torch.autograd.profiler_util.StringTable.update`
2. 四个 `torch.autograd.profiler_util.StringTable` 方法直接继承自 Python `dict/defaultdict`,不涉及 Tensor、device、NPU 算子或 CANN,无需 torch-npu 功能和测试适配,按 issue + docs 处理。
3. `torch.autograd.profiler_util.Kernel.name` 是 profiler 元数据;其代码修复由独立功能 PR 处理,本 PR 只补充资料。
4. 上游近期调整了资料目录和格式:删除 PyTorch 2.9.0、2.10.0 页面,新增 PyTorch 2.13.0 页面,并统一使用按硬件列出的“支持情况”表格。本次按当前 master 基线更新 2.7.1、2.11.0、2.12.0、2.13.0 四个现存页面。
5. 以上 5 个非计算类接口在四个页面均标记为支持,限制与说明为 `-`。
# 【资料变更】
仅修改 master 下当前存在的四个资料页面:
- `docs/zh/api/native_api/pytorch_2-7-1/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-autograd.md`
上游已删除的 2.9.0、2.10.0 页面不恢复,避免与当前资料目录冲突。
# 【接口变更】
不涉及接口实现或签名变更,仅补充既有接口的资料支持状态。
# 【功能验证】
检查命令:
```bash
git diff --check upstream/master...HEAD
git diff --name-only upstream/master...HEAD
```
结果:
```text
git diff --check: exit code 0
仅修改上述 4 个 torch-autograd.md 文件
四个页面共 20 个 API 条目,每个页面包含 5 个条目,原生文档链接版本与页面一致
```
当前提交:`c952f0a7a5e390977856ecd0790ef527815c542a`。文档门禁和主流水线均已通过。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
# 【2026-09-12 冲突解决与 A5 验证更新】
- 已基于最新 `master` 解决四个 `torch-autograd.md` 的冲突,并 squash 为单提交 `17713eccd4bee46017bcc89fcfdcbe500a13a42b`。
- 本次仅保留四个现存资料页与 5 个既有 API 条目;未恢复已删除的 2.9.0、2.10.0 页面。
- A5(Ascend950PR、CANN 9.1.0)上通过 `torch_npu_server_runner.py` 串行验证:`v2.7.1`、`v2.11.0`、`v2.12.0`、`master` 均为 `1/1` 通过。
- 覆盖 `torch.autograd.profiler_util.Kernel` 参数完整性、异常场景及实际 NPU 张量 smoke。完整报告:`/workspace/a5-verify/tests/docs/测试用例验证结果报告_1789170609.md`。
- `master` 验证使用最新 master Python 修复代码覆盖;当前容器未重编译开发版完整二进制 ABI。
See merge request: Ascend/pytorch!42887
2026-09-30 10:39:13 +08:00
wzyly
ae4c1812f0
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47447 merge master into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
doc-tools问题扫描修改
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47447
2026-09-30 10:27:19 +08:00
SorryNaCN
5ae31bce9a
[feat] [master] Update DVM r2.11
...
Co-authored-by: huangchengnuo<huangchengnuo1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47318 merge feat/dvm-r211-master-20260929 into master
[feat] [master] Update DVM r2.11
Created-by: SorryNaCN
Commit-by: huangchengnuo
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> (如有)请关联需求文档/issue链接
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [x] 重构优化
- [ ] 资料更新
Fixes https://gitcode.com/Ascend/pytorch/issues/5234
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
移植自 [!43991 ](https://gitcode.com/Ascend/pytorch/pull/43991 ),目标分支 `master`。 保留 master 的 Triton 边界、整数 reduction axis 处理及现有 C++ 结构;不恢复 master 已移除的旧 matmul_backward 分解。测试沿用 `test/_inductor/dvm/` 目录。
1. 升级 DVM 到 r2.11。
2. 支持 DVM cat 融合。
3. 支持 DVM 完整 View 融合。
4. 支持 DVM VF 融合。
5. 修复 bug 并重构部分代码。
6. 增加 DVM 分解启用/禁用列表与矩阵乘融合否决回调,并补充测试。
7. BF16 concat 输入 cast 在非 Ascend950 或 `bf16_vector_keep_promoted=True` 时执行。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及。
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
DVM 配置新增(在加载 DVM backend 前设置):
- `enable_decomp_list = []`、`disable_decomp_list = []`:接受算子重载或重载包,禁用优先;启用时优先使用 `dvm_decompositions` 表中的 DVM 专用实现,例如 `enable_decomp_list=[torch.ops.npu.npu_rms_norm_backward]` 可开启 RMSNorm backward 分解;未指定时保持原默认行为。
- `matmul_fusion_rule = None`:可设置 `(n, m, k)` 回调,对应 `(..., m, k) @ (..., k, n)`。仅显式返回 `False` 时否决 MM/BMM/ADDMM/BADDBMM 融合,其他返回值沿用原规则;不会绕过总开关或形状/类型限制,K=1 的逐元素快捷路径保留原有 lowering,不额外插入回调判断。
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
本次移植验证:
- 基于 `master` 最新提交 `b16969cbfadc42d0ee2505856a9c3f45f501cb54`,移植源 MR !43991 的提交 `5f8ec12a41bd4ab2aa9d3d80d78c8ac21a2f7948`;本分支 1 个提交、13 个文件,DVM gitlink 保持为 `2b3f462f116e491574ccc49cda1ae1a01e58cfe6`。
- 本分支修改的 Python 文件 `py_compile`、`git diff --check` 通过;测试文件与源 MR 一致,RMSNorm 分解、矩阵乘规则和配置的静态一致性检查通过。
- 新增 `test_npu_rms_norm` 验证默认 forward 分解,`test_rms_norm_decomp_disabled` 同时禁用 forward、启用 backward;两者已在源 v2.9.0 的 Ascend910B3 / CANN 9.0.1 环境通过生成代码和数值验证。
- 源 v2.9.0 已验证 RMSNorm backward 显式启用后生成 DVM kernel、无原生 backward 调用且数值一致;DVM 分解表和测试 helper 恢复同步到本分支。
- master 的 `pybind_api.cpp` / `pybind_api.h` 已通过仓库配置的 clang-format 19.1.4 和 CLANGFORMAT adapter 检查,修正 GatherLoad 换行格式。
- 本移植分支尚未构建 wheel 或运行对应 PyTorch 版本的 NPU 测试;源分支结果不作为本分支设备验证结果,CI 待确认。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47318
2026-09-30 10:03:09 +08:00
yuhongming-2026
0f37fbf434
docs: add flex_attention.BlockMask API docs for 2.7.1/2.11.0/2.12.0
...
Co-authored-by: yuhongming-2026<moshui_1@qq.com >
# message auto-generated for no-merge-commit merge:
!42931 merge feature/flex_attention_docs_all into master
docs: add flex_attention.BlockMask API docs for 2.7.1/2.11.0/2.12.0
Created-by: yuhongming-2026
Commit-by: yuhongming-2026
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**https://gitcode.com/Ascend/pytorch/issues/3275 https://gitcode.com/Ascend/pytorch/issues/3272 https://gitcode.com/Ascend/pytorch/issues/3269 https://gitcode.com/Ascend/pytorch/issues/3262 **</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3275 https://gitcode.com/Ascend/pytorch/issues/3272 https://gitcode.com/Ascend/pytorch/issues/3269 https://gitcode.com/Ascend/pytorch/issues/3262
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
1. 为 `torch.nn.attention.flex_attention.BlockMask` 及其属性/方法补齐 native API 资料(覆盖 2.7.1 / 2.11.0 / 2.12.0)。
2. 新增 `docs/zh/api/native_api/pytorch_*/torch-nn-attention.md`,并更新对应版本目录与菜单。
3. **按最新 API 一致性要求**:支持情况统一使用 ✔ / ✘,不再使用 `✔` / `✗`。
4. 用例侧:社区已有 `TestBlockMask.test_block_mask_attributes`;按新规不再合入 NPU 适配 patch,验证闭环见 Issue:https://gitcode.com/Ascend/pytorch/issues/4051(关闭原 #42919 / #42922 / #42930)。
# 【资料变更】
docs/zh/api/native_api 下新增/更新 `torch-nn-attention.md`(pytorch_2-7-1 / 2-11-0 / 2-12-0 / 2-13-0),并同步更新对应 `PyTorch-*-*.md` 入口与 `_menu_pt_native_apis.md`。
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
在 Ascend NPU 上运行社区用例 `TestBlockMask.test_block_mask_attributes` 及 BlockMask 属性验证脚本,确认 `torch.nn.attention.flex_attention.BlockMask` 相关属性(`kv_num_blocks`、`full_kv_num_blocks`、`q_num_blocks`、`full_q_num_blocks`、`numel` 等)可在 NPU 上正常访问,测试结果均为 PASSED。
## 验证平台覆盖情况(含 A5)
| 验证平台 | 产品形态 | 验证结果 |
|---------|---------|---------|
| **A5** | **Ascend 950DT / Ascend950PR** | **PASSED** |
| A3 | Atlas A3 训练系列产品 | PASSED |
| A2 | Atlas A2 训练系列产品 | PASSED |
> **说明:本次已在 A5(Ascend 950DT)完成功能验证,结果 PASSED,见下方「【A5 验证】」专节。**
---
## 【A5 验证】(Ascend 950DT)— 已完成,结果 PASSED
**验证设备:** Ascend950PR(A5 / Ascend 950DT)
**软件环境:** CANN 9.1.0 + `torch==2.7.1+cpu` + `torch-npu==2.7.1.post8`
**验证结论:** A5 上全部用例 PASSED
**A5 复现命令:**
```bash
source /usr/local/Ascend/ascend-toolkit/set_env.sh
cd /workspace
python test_block_mask_attributes_npu.py
python run_community_test_block_mask_npu.py
```
**A5 用例结果:**
| 用例 | A5 结果 |
|------|--------|
| `TestBlockMaskNPU.test_block_mask_attributes` | PASSED |
| `TestBlockMaskNPU.test_block_mask_block_count_attributes` | PASSED |
| `TestBlockMaskNPU.test_block_size_changes` | PASSED |
| 社区 `TestBlockMask.test_block_mask_attributes`(NPU) | PASSED |
**A5(Ascend 950DT)运行截图:**

---
## A3 / A2 验证截图
**A3(Atlas A3 训练系列产品)运行截图:**

**A2(Atlas A2 训练系列产品)运行截图:**

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
- [x] **已完成 A5(Ascend 950DT)功能验证,结果 PASSED**
See merge request: Ascend/pytorch!42931
2026-09-30 09:38:50 +08:00
pta-robot
97c3243192
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47413 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-29 22:03:06.
See merge request: Ascend/pytorch!47413
2026-09-29 22:48:29 +08:00
chansinging
5c9400c82f
test: verify community 2.14.0 features and fixes master
...
Co-authored-by: Chansinging<1183520536@qq.com >
# message auto-generated for no-merge-commit merge:
!46469 merge verify_2.14_version into master
test: verify community 2.14.0 features and fixes master
Created-by: chansinging
Commit-by: Chansinging
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
适配2.14版本更新
https://github.com/pytorch/pytorch/pull/187388,PyTorch 分布式后端发现机制重构为 Python entrypoints 动态注册路由。做下代码适配,与上游做法一致。
1. 一个 entry point 只注册对应后端。 PTA 导入时仍会主动注册 HCCL/LCCL,entry point 随后可能再次调用注册函数,所以需要重复调用保护
2. 通过 entry_points 注册 hccl/lccl(setup.py),注册幂等化。两个 entry point 都指向同一函数,而该函数一次注册 hccl 和 lccl 两个后端——第二次调用会因重复注册抛错。将其先检查 Backend.backend_list 再注册;同时去掉多余的 lambda 包装,直接传` _new_process_group_hccl_helper`。保留了"hccl 必须先注册以保证 default_device_backend_map 正确"的既有顺序。
https://github.com/pytorch/pytorch/pull/188611 将 setSequenceNumberForGroup 降级为 Backend 级别,该接口废弃(带一次性警告)。 上游 2.14 已从 _new_process_group_helper 中移除 _set_sequence_number_for_group() 调用,pta做同步的删除操作
https://github.com/pytorch/pytorch/pull/188489 修复_new_group_with_tag 向自定义 PG 委托创建子组时遗漏了 backend 参数。跟随社区,新增兼容性测试。低版本选择跳过,自定义 DelegatingProcessGroup 注册为 cpu 后端,断言 new_group(ranks=[0]) 收到默认后端名 pta_new_group_backend_test、new_group(ranks=[0],backend="cpu:pta_new_group_backend_test") 收到显式 cpu: 前缀形式。
!189359,转需求
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
!187388 验证,通过脚本,由 PyTorch 根据后端名称 hccl,找到 PTA 安装包中的 entrypoint,查看是否自动加载并完成注册

!187388 验证

!188489

setsequence 2.13版本测试

# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46469
2026-09-29 20:33:53 +08:00
lgxxx
630ef8ae52
test: add UntypedStorage complex_float coverage
...
Co-authored-by: lgxxx<22515063@zju.edu.cn >
# message auto-generated for no-merge-commit merge:
!45842 merge test-task70-untyped-storage-complex-float-master-current into master
test: add UntypedStorage complex_float coverage
Created-by: lgxxx
Commit-by: lgxxx
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
关联任务 Issue:https://gitcode.com/Ascend/pytorch/issues/3731
# 【修改方案】
为 torch.UntypedStorage.complex_float 补充 NPU Python 层测试,覆盖非空 Storage 的 complex64 转换、数据一致性、设备与大小属性,以及空 Storage 的返回类型和设备属性。
# 【资料变更】
不涉及。
# 【接口变更】
不涉及。
# 【功能验证】
新增 test/npu/test_storage.py 测试用例。master 复用 v2.12.0 软件环境。
# 运行命令
ASCEND_RT_VISIBLE_DEVICES=0 \
scripts/run_api_python_version.sh master \
sources/torch-npu-master/sources/validation-current/task70-master/test/npu/test_storage.py \
-v -k test_untyped_storage_complex_float
## master
target_hardware=Ascend910_9382
CANN=cann-9.1.0.beta1
torch=2.12.0+cu130
torch_npu=2.12.0
npu_count=2
master_software_environment=v2.12.0 environment reused
test_untyped_storage_complex_float ... ok
Ran 1 test in 6.501s
OK
test_exit_code=0
# A5环境验证
target_hardware=Ascend950PR_9579
CANN=cann-9.1.0.beta1
torch=2.12.0+cu130
torch_npu=2.12.0
npu_count=2 master_software_environment=v2.12.0 environment reused
test_untyped_storage_complex_float ... ok
Ran 1 test in 8.329s
OK
test_exit_code=0
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45842
2026-09-29 18:57:08 +08:00
xuyun15
db42707127
[fix] fix bug mix_acc_npu_stream
...
Co-authored-by: xuyun15<xuyun15@huawei.com >
# message auto-generated for no-merge-commit merge:
!46235 merge fix_mix_acc_npu_stream_master into master
[fix] fix bug mix_acc_npu_stream
Created-by: xuyun15
Commit-by: xuyun15
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
根因 torch.stream使用基类,无npu_stream,下游对齐的时候需要小心。当前npu未对齐社区,造成风险。
对齐社区 stream->npu_stream ---->> c10::Stream::unpack3
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46235
2026-09-29 18:55:09 +08:00
wyssss1245
2b0c5813fd
add the test file for UT in inductor
...
Co-authored-by: wyssss1245<wangyesheng1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47214 merge master into master
add the test file for UT in inductor
Created-by: wyssss1245
Commit-by: wyssss1245
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
[#4911 ](https://gitcode.com/Ascend/pytorch/issues/4911 )
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
本 PR 主要为 inductor 后端补充单元测试看护,在 test/_inductor/ 目录下新增了一批测试文件,统一基于 TestUtils 与 parametrize/instantiate_parametrized_tests 组织用例,通过 torch.compile(..., backend="inductor") 的编译结果与原生 NPU 执行结果做数值比对,并使用 runIfVersion(max="2.13") 限定版本范围。测试覆盖了 view 类算子(permute、reshape、repeat、resize_as_、squeeze_)、归约类算子(var、var_mean、sum + 加乘融合、广播归约)、逐元素算子(rsqrt)、renorm、split_loop,以及 _to_copy 的 stride 保持、triton 能力探测、上转 fp32 代码生成、静态 kernel、用户自定义 autotune 等专项场景;其中 test_var_mean.py 重点围绕 npu_config.enable_welford 开关校验 Welford/SIMD 代码生成路径。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47214
2026-09-29 18:31:31 +08:00
weixin_63349779
b734db78dc
test: add coverage for torch.IntStorage
...
Co-authored-by: 沐染。<1628038450@qq.com >
# message auto-generated for no-merge-commit merge:
!44714 merge test-int-storage-new-master into master
test: add coverage for torch.IntStorage
Created-by: weixin_63349779
Commit-by: 沐染。
Merged-by: ascend-robot
Description: # 【合入来源】
> 如有社区Issue,请关联issue链接
> 请勿携带内部流程信息(需求链接、问题单、内部issue等)
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 [Ascend/pytorch#3594 ](https://gitcode.com/Ascend/pytorch/issues/3594 )
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
本 PR 针对 `torch.IntStorage` 构造接口补充 CPU/NPU 测试覆盖,不修改 API 实现代码。
## 1. API 功能
`torch.IntStorage` 表示元素数据类型为 `torch.int32` 的类型化 Storage。
本次主要验证 `torch.IntStorage` 以及 `torch_npu.npu.IntStorage` 在不同构造方式下的行为,包括正常场景、边界场景、非法参数以及 NPU Storage 设备属性。
## 2. PyTorch 社区用例情况
PyTorch 官方社区已在以下用例中直接验证 `torch.IntStorage`:
```text
test/test_torch.py::TestTorch::test_storage_casts
```
官方社区主要验证:
```python
storage = torch.IntStorage([-1, 0, 1, 2, 3, 4])
self.assertEqual(storage.size(), 6)
self.assertEqual(storage.tolist(), [-1, 0, 1, 2, 3, 4])
self.assertEqual(storage.type(), "torch.IntStorage")
self.assertIs(storage.dtype, torch.int32)
```
社区测试已经直接覆盖 Sequence 构造以及 Storage 的:
- 元素数量
- 数据内容
- Storage 类型
- Storage dtype
另外,官方测试中还存在:
```python
torch.IntStorage().element_size()
torch.IntStorage(10).fill_("asdf")
```
但上述测试分别用于验证 `element_size()` 和 `fill_()`,并未完整验证 `torch.IntStorage` 构造接口本身。
### PyTorch 社区用例截图
<!-- PyTorch 官方 torch.IntStorage 社区用例 -->


## 3. 社区覆盖完整性分析
PyTorch 官方社区对 `torch.IntStorage` 已有直接测试,但构造方式覆盖不完整。
当前缺少对以下构造及边界场景的系统验证:
```text
torch.IntStorage()
torch.IntStorage(size)
torch.IntStorage(wrap_storage=...)
torch.IntStorage(0)
torch.IntStorage([])
```
同时缺少对以下非法参数组合的完整验证:
```text
多个位置参数
非法对象类型
显式 dtype
显式 device
非法 wrap_storage
```
`torch.IntStorage` 属于 Storage API,其构造行为包含设备语义。
因此,本次按照当前验收要求,在 torch-npu `test` 目录补充 CPU/NPU 构造行为,以及 NPU Storage 类型、dtype、数据和 device 属性验证。
## 4. NPU 测试适配方案
本次在以下文件新增测试:
```text
test/npu/test_storage.py
```
新增测试方法:
```python
def test_int_storage_constructor(self):
```
CPU 侧覆盖:
```text
torch.IntStorage()
torch.IntStorage(4)
torch.IntStorage(0)
torch.IntStorage([])
torch.IntStorage(values)
torch.IntStorage(wrap_storage=...)
```
NPU 侧覆盖:
```text
torch_npu.npu.IntStorage(wrap_storage=...)
torch_npu.npu.IntStorage(4)
torch_npu.npu.IntStorage(values)
torch_npu.npu.IntStorage([])
```
其中 NPU `wrap_storage` 场景通过真实 NPU Tensor 获取:
```python
npu_tensor = torch.tensor(
values,
dtype=torch.int32,
device="npu",
)
npu_untyped = npu_tensor.untyped_storage()
```
再通过:
```python
torch_npu.npu.IntStorage(wrap_storage=npu_untyped)
```
构造 NPU Storage。
验证内容包括:
- Storage 元素数量
- Storage 数据内容
- Storage 类型
- Storage dtype
- Storage 所属设备
- 正常构造
- 边界构造
- 非法参数
## 5. 用例完整性
本次新增测试覆盖正常、边界和异常场景。
正常构造:
```text
无参构造
size 构造
Sequence 构造
wrap_storage 构造
```
边界场景:
```text
size = 0
空 Sequence
NPU 空 Sequence
```
非法参数:
```text
torch.IntStorage(1, 2)
torch.IntStorage(object())
torch.IntStorage(dtype=torch.int32)
torch.IntStorage(device="cpu")
torch.IntStorage(wrap_storage=object())
```
属性验证包括:
```text
size
values
type
dtype
device
```
因此,相比 PyTorch 社区现有测试,本次主要补充了 `torch.IntStorage` 构造接口完整性以及 NPU 设备语义验证。
## 6. 边界行为说明
独立验证中:
```python
torch.IntStorage(0)
```
返回:
```text
type = torch.IntStorage
dtype = torch.int32
device = cpu
size = 0
values = []
```
```python
torch.IntStorage([])
```
返回:
```text
type = torch.IntStorage
dtype = torch.int32
device = cpu
size = 0
values = []
```
NPU 空 Sequence:
```python
torch_npu.npu.IntStorage([])
```
返回:
```text
type = torch_npu.npu.IntStorage
dtype = torch.int32
device = npu:0
size = 0
values = []
```
另外观察到:
```python
torch_npu.npu.IntStorage(0)
```
当前返回:
```text
type = torch.IntStorage
dtype = torch.int32
device = cpu
size = 0
values = []
```
与 NPU 空 Sequence 构造行为存在差异。
因此,本次测试未将 `torch_npu.npu.IntStorage(0)` 当前返回 CPU Storage 的行为固化为正确预期,仅记录该边界现象。
## 7. API 实现情况
`torch.IntStorage` 和 `torch_npu.npu.IntStorage` 在本次覆盖的主要构造场景下均可以正常工作。
本 PR 仅补充测试覆盖,不修改 API 实现代码。
# 【资料变更】
本 PR 不涉及资料修改。
已在 master 分支以下目录检查:
```text
docs/zh/api/native_api
```
检查版本范围:
- PyTorch 2.7.1
- PyTorch 2.11.0
- PyTorch 2.12.0
- PyTorch 2.13.0
当前资料中均已包含:
```text
torch.IntStorage
torch.IntStorage.dtype
```
支持状态如下:
| PyTorch版本 | 资料目录 | `torch.IntStorage` | `torch.IntStorage.dtype` | Atlas A2 | Atlas A3 | Ascend 950DT |
| --- | --- | --- | --- | --- | --- | --- |
| 2.7.1 | `pytorch_2-7-1` | 已包含 | 已包含 | ✔ | ✔ | ✘ |
| 2.11.0 | `pytorch_2-11-0` | 已包含 | 已包含 | ✔ | ✔ | ✘ |
| 2.12.0 | `pytorch_2-12-0` | 已包含 | 已包含 | ✔ | ✔ | ✘ |
| 2.13.0 | `pytorch_2-13-0` | 已包含 | 已包含 | ✔ | ✔ | ✘ |
同时检查:
```text
docs/zh/api/native_api/pytorch_2-9-0
docs/zh/api/native_api/pytorch_2-10-0
```
当前 master 中上述目录均已删除,因此不属于当前资料刷新范围。
`torch.IntStorage` 属于非计算类 API,本次不存在需要填写“支持 fp32”等计算数据类型信息的情况。
经检查,当前资料已经包含 `torch.IntStorage` 及 `torch.IntStorage.dtype`,且支持状态正确,因此本 PR 无需新增或修改资料。
### 资料检查截图
产品支持情况:
• Atlas A2 训练系列产品:支持
• Atlas A3 训练系列产品:支持
• Ascend 950PR:支持
• Ascend 950DT:不支持
<!-- master docs 中 2.7.1 / 2.11.0 / 2.12.0 / 2.13.0 资料情况 -->




# 【接口变更】
不涉及。
本 PR 未新增或修改 API 定义、入参、返回值或现有接口行为,仅补充 `torch.IntStorage` 构造行为的 CPU/NPU 测试覆盖。
# 【功能验证】
> 说明测试场景、测试方法。如果本次测试方式与常规单元测试不同,请详细说明测试步骤。
> 新增/变更内容是否已新增/适配 UT 测试用例看护,并补充测试自验证截图。
## 1. 独立功能验证
已在 NPU 环境中执行与新增 UT 一致的功能验证。
CPU 验证包括:
```text
无参构造
size 构造
size=0 边界
空 Sequence
普通 Sequence
wrap_storage
```
NPU 验证包括:
```text
wrap_storage
size 构造
普通 Sequence
空 Sequence
```
非法参数验证包括:
```text
多个位置参数
非法对象类型
显式 dtype
显式 device
非法 wrap_storage
```
实际结果:
```text
===== CPU IntStorage =====
CPU cases: PASS
===== NPU IntStorage =====
NPU cases: PASS
===== Invalid arguments =====
invalid cases: PASS
ALL INTSTORAGE CHECKS PASSED
```
运行过程中存在 PyTorch TypedStorage deprecation warning,该 warning 为 PyTorch Storage 接口的统一弃用提示,不影响本次功能验证结果。
### NPU 独立功能验证截图
<!-- CPU/NPU/invalid cases 全部 PASS -->

## 2. 边界验证
独立边界验证结果:
```text
===== CPU boundary cases =====
IntStorage(0): torch.IntStorage torch.int32 cpu 0 []
IntStorage([]): torch.IntStorage torch.int32 cpu 0 []
===== NPU boundary cases =====
NPU IntStorage(0): torch.IntStorage torch.int32 cpu 0 []
NPU IntStorage([]): torch_npu.npu.IntStorage torch.int32 npu:0 0 []
RESULT: IntStorage boundary validation PASSED
```
其中:
```text
torch_npu.npu.IntStorage(0)
```
当前返回 CPU Storage,而:
```text
torch_npu.npu.IntStorage([])
```
返回 NPU Storage。
两种构造方式当前存在设备行为差异,本 PR 未将 `torch_npu.npu.IntStorage(0)` 的 CPU 回退行为作为正确预期写入 UT,仅记录该边界现象。
### 边界验证截图
<!-- IntStorage(0) / IntStorage([]) CPU/NPU 边界行为 -->

## 3. UT 看护
本 PR 在:
```text
test/npu/test_storage.py
```
新增:
```text
TestStorage.test_int_storage_constructor
```
直接覆盖:
- CPU/NPU Storage 构造
- Storage size
- Storage 数据
- Storage 类型
- Storage dtype
- Storage device
- 边界输入
- 非法参数
本次不修改:
```text
test_upstream/test/test_torch.py.patch
```
新增 UT 与本次修改目的保持一致,用于看护 `torch.IntStorage` / `torch_npu.npu.IntStorage` 构造接口的正常、边界及异常输入行为。
## 4. Commit
本 PR 当前提交:
```text
316c3ef64 test: add coverage for torch.IntStorage
```
单 commit,提交信息:
```text
Author: 沐染。 <1628038450@qq.com >
Signed-off-by: 沐染。 <1628038450@qq.com >
```
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!44714
2026-09-29 17:42:48 +08:00
cai-weiwei1989
2c3b407e1f
docs:PyTorch Profiler文档问题修改
...
Co-authored-by: cai-weiwei1989<734267852@qq.com >
# message auto-generated for no-merge-commit merge:
!47305 merge master into master
docs:PyTorch Profiler文档问题修改
Created-by: cai-weiwei1989
Commit-by: cai-weiwei1989
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
1、格式修改
2、补全docs/zh/figures/profiler/torch_npu-profiler-schedule.png图中的skip_first_wait
3、补充numa参数和采集结果说明
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47305
2026-09-29 17:30:46 +08:00
SoraAzzz
64f03dc2c7
Use controlled profiler warnings for unsupported features
...
Co-authored-by: xieanran<694099604@qq.com >
# message auto-generated for no-merge-commit merge:
!46807 merge master into master
Use controlled profiler warnings for unsupported features
Created-by: SoraAzzz
Commit-by: xieanran
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/5088
- [x] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
FormatFeatureList 告警聚合输出: 新增 unsupportedFeatures 字符串收集所有不被 NAME_TABLE 支持的特性名称与 infoLog,循环结束后通过一次 TORCH_NPU_WARN_ONCE 统一输出,替代原先在循环内逐条 printf。
IsSupportFeature 告警分支化: 移除原 printf,改为 switch (featureName) 按 FEATURE_ATTR、FEATURE_MEMORY_ACCESS、FEATURE_AICORE_SHAPE 分别使用 TORCH_NPU_WARN_ONCE 输出可读名称,default 分支使用 TORCH_NPU_WARN 输出数值类型。
CheckAicMetricsFeature 日志宏替换: MemoryAccess 指标不支持时,由 printf 改为 TORCH_NPU_WARN_ONCE 输出“reset to default”告警,保持返回值逻辑不变。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
NA
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
NA
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46807
2026-09-29 17:30:43 +08:00
jiabiao_o
2cef4ab1ed
[inductor][fix] preserve CANN compatibility for Fast Launch
...
Co-authored-by: erwin<j18636938310@163.com >
# message auto-generated for no-merge-commit merge:
!47321 merge master-merge into master
[inductor][fix] preserve CANN compatibility for Fast Launch
Created-by: jiabiao_o
Commit-by: erwin
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [x] 问题单
- [x] issue/工单:待创建配套公开 Issue 后填写链接并勾选
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
1. **在 `bindings.cpp` 内部复用动态加载机制。** 在 `torch_npu/_inductor/experimental/python_wrapper_fast_launch/csrc/bindings.cpp` 的匿名命名空间内定义函数指针解析、能力查询和 `AclrtLaunchKernelWithHostArgs` 启动封装。在同一编译单元内先通过 `TORCH_NPU_REGISTER_LIBRARY` 注册 `libascendcl`,再通过 `TORCH_NPU_LOAD_FUNC` 注册接口,避免依赖其他文件的静态初始化顺序。使用 `decltype` 获取官方函数指针类型,通过 `TORCH_NPU_GET_FUNC` 调用已有 `FunctionLoader` 按需解析接口,消除对该新接口的强动态符号依赖
# 【资料变更】
涉及。更新 `torch_npu/_inductor/docs/feature/planned_fast_launch/planned_fast_launch.md`,补充运行时接口要求,以及接口缺失时回退到原 Triton launcher、缓存不可用结果的行为。
# 【接口变更】
不涉及跨代码仓或客户面可见的接口变更。新增接口为 TorchNPU 内部 C++ 封装及能力查询,现有 Python 接口和环境变量保持不变。
# 【功能验证】
## 问题复现 cann=8.3.RC1


## 问题修复 cann=8.3.RC1

# 【CheckList】
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
# 【issues】
https://gitcode.com/Ascend/pytorch/issues/5144
See merge request: Ascend/pytorch!47321
2026-09-29 16:47:35 +08:00
y30037164
ab32c49a75
chore: remove comment trigger from nightly pipeline
...
Co-authored-by: yuaiming<yuaiming@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47319 merge master into master
chore: remove comment trigger from nightly pipeline
Created-by: y30037164
Commit-by: y30037164;yuaiming
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47319
2026-09-29 16:29:27 +08:00
chujinjin
2516c6185f
refactor: simplify options manager mode validation
...
Co-authored-by: chujinjin<chujinjin52@huawei.com >
# message auto-generated for no-merge-commit merge:
!46410 merge refactor/options-manager-mode-validation into master
refactor: simplify options manager mode validation
Created-by: chujinjin
Commit-by: chujinjin
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [x] 重构优化
- [ ] 资料更新
# 【修改方案】
- 1. 将 OptionsManager.h 中用于校验环境变量取值的模式映射移至 OptionsManager.cpp 的匿名命名空间,并让相关校验函数直接使用这些映射。原先的映射获取函数定义在头文件中,下游项目即使没有调用它们,只要包含该头文件就可能产生 -Wunused-function 警告。迁移后,头文件不再引入这些未使用的函数定义。此项修改对应 issue #5054 (https://gitcode.com/Ascend/pytorch/issues/5054 )。
- 2. 保留各环境变量原有的默认值、合法取值和异常处理逻辑。此次调整只改变模式映射的存放位置及使用方式,不改变 OptionsManager 对环境变量的校验结果。
- 3. 将原本依赖头文件内容的公开环境变量模式兼容性检查移至 tools/check_public_environments.py。脚本读取 torch_npu_schema.json 和 OptionsManager.cpp,规范化空白字符后检查模式定义是否仍与 schema 一致;同时更新受排版调整影响的 schema记录。
- 4. 在 CMake 中添加兼容性检查目标,并将其设为插件构建的依赖,使构建过程继续执行这项检查。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46410
2026-09-29 15:47:29 +08:00
sodachan
555ecb4488
test: add NPU validation for enable_python_dispatcher ( #2678 )
...
Co-authored-by: jiayu<zjchenjiayu@gmail.com >
# message auto-generated for no-merge-commit merge:
!45964 merge codex/test-enable-python-dispatcher-master into master
test: add NPU validation for enable_python_dispatcher (#2678 )
Created-by: sodachan
Commit-by: jiayu
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单:[#2678 ](https://gitcode.com/Ascend/pytorch/issues/2678 )
# 【修改方案】
关联 API:`torch._dispatch.python.enable_python_dispatcher`。
本 PR 面向 `master`,新增 `test/npu/test__dispatch_python_enable_python_dispatcher.py`,不修改 API 声明、实现、注册或 `test_upstream/`。
**适配方案:** <span style="color: red;"><strong>1.2-2 PyTorch社区无用例或覆盖不完整,涉及硬件。</strong></span> 社区候选未完整覆盖 dispatcher 守卫的进入/退出、嵌套恢复、异常恢复、非法参数与守卫内真实 NPU 分发的组合契约。新增用例覆盖上述状态场景;首个用例在 NPU Tensor 上执行 `square() + 1`,断言输入输出设备、数值和退出后的状态恢复。
**新增用例必要性:** CPU、Meta/FakeTensor 或仅检查辅助算子结果不能同时证明 TLS 状态恢复和 NPU 输入输出在启用 dispatcher 时仍正确。
# 【资料变更】
不涉及。该接口位于私有 `torch._dispatch` 模块,native API 资料不适用。
# 【接口变更】
不涉及。未发现需要修改 API 实现的证据;本 PR 仅补齐测试覆盖。
# 【功能验证】
历史验证日期:2026-09-07。Python 3.10.12;A3 为 aarch64 / CANN 9.0.0,A5 为 x86_64 / CANN 9.1.0。已测提交:`58b75d817412e66d8be71cd4871a33cc08952564`。测试文件 SHA-256:`02f4d514c2473229c33feddbdd6fa9b3c45dd07dc95f1e68abdb81852dbcc7db`。
```bash
python test/npu/test__dispatch_python_enable_python_dispatcher.py -v
```
| 硬件 | 运行包 | 结果 |
|---|---|---|
| A3 / Ascend910B3 | torch 2.15.0.dev20260902+cpu / torch_npu 2.15.0+git9f15aa3 | 4/4 通过,`Ran 4 tests`、`OK` |
| A5 / Ascend950PR | torch 2.15.0.dev20260902+cpu / torch_npu 2.15.0+git9f15aa3 | 4/4 通过,`Ran 4 tests`、`OK` |
master 的历史运行包使用官方 nightly PyTorch 与目标源码构建的 torch_npu,不等同于当前上游 master。完整脱敏日志和哈希索引见[结果 #4682 ](https://gitcode.com/Ascend/pytorch/issues/4682 )。该历史运行证据不包含 A2;CI、CLA 已通过,review 与 merge 待维护者确认。
**run_tests 导入口径待确认:** 当前测试从 `torch.testing._internal.common_utils` 导入 `run_tests`;目标 PyTorch 版本的顶层 `torch.testing` 未导出该符号。为避免引入 `ImportError`,未机械改写;请维护者确认该 testing 子模块入口是否符合规范。若要求修改,将对本版本的原四项 A3/A5 测试重跑验证。
<details><summary>A3 / Ascend910B3 脱敏完整日志</summary>
```text
test_context_enables_and_restores_dispatcher (__main__.TestEnablePythonDispatcher) ... ok
test_context_restores_state_after_exception (__main__.TestEnablePythonDispatcher) ... ok
test_invalid_argument (__main__.TestEnablePythonDispatcher) ... ok
test_nested_context_restores_outer_state (__main__.TestEnablePythonDispatcher) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.946s
OK
```
</details>
<details><summary>A5 / Ascend950PR 脱敏完整日志</summary>
```text
test_context_enables_and_restores_dispatcher (__main__.TestEnablePythonDispatcher) ... ok
test_context_restores_state_after_exception (__main__.TestEnablePythonDispatcher) ... ok
test_invalid_argument (__main__.TestEnablePythonDispatcher) ... ok
test_nested_context_restores_outer_state (__main__.TestEnablePythonDispatcher) ... ok
----------------------------------------------------------------------
Ran 4 tests in 1.929s
OK
```
</details>
# 【CheckList】
- [x] 新增测试具备版权头、英文说明和 `self.assert*` 断言
- [x] 未直接导入 `unittest`,未吞异常、未添加调试输出
- [x] PR 标题使用 `test` 类型前缀;目标完整 API 名已在修改方案中列明
- [x] CI、CLA 已通过
- [ ] 平台 review 与 merge(待维护者处理)
See merge request: Ascend/pytorch!45964
2026-09-29 15:04:08 +08:00
gcw_H7sZe82x
d5e60658f8
test: add NPU test cases for torch.nn.attention.flex_attention BlockMask.to_string, create_mask, create_nested_block_mask
...
Co-authored-by: gcw_H7sZe82x<2640411208@qq.com >
# message auto-generated for no-merge-commit merge:
!45154 merge test-flex-attention-apis-master into master
test: add NPU test cases for torch.nn.attention.flex_attention BlockMask.to_string, create_mask, create_nested_block_mask
Created-by: gcw_H7sZe82x
Commit-by: gcw_H7sZe82x
Merged-by: ascend-robot
Description: ## 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
- 关联 issue:
- https://atomgit.com/Ascend/pytorch/issues/3288 (torch.nn.attention.flex_attention.BlockMask.to_string)
- https://atomgit.com/Ascend/pytorch/issues/3289 (torch.nn.attention.flex_attention.create_mask)
- https://atomgit.com/Ascend/pytorch/issues/3290 (torch.nn.attention.flex_attention.create_nested_block_mask)
- 任务分类:1.2②(PyTorch 官方社区无用例或未覆盖完整,且 API 涉及硬件接口)
- 三个 API 均属于 `torch.nn.attention.flex_attention` 模块,故合并到同一测试文件中。
- pytorch 社区没有针对这三个 API 的独立且充分的测试用例,故新增该测试文件,用于验证这些 API 的正确性。
## 【修改方案】
### 一、API 功能说明
#### 1. torch.nn.attention.flex_attention.BlockMask.to_string
BlockMask 类的字符串可视化方法,返回 BlockMask 的字符串表示。
- **签名**:`to_string(self, grid_size: int | tuple[int, int] = (20, 20), limit: int = 4) -> str`
- **参数**:
- `grid_size`:网格大小,控制输出可视化网格的行列数。为 int 时表示行列均相同;为 tuple 时分别指定行列;为 -1 时输出非压缩版本。
- `limit`:限制显示的 batch/head 组合数量,超出部分以 "..." 截断。
- **返回值**:str,包含可视化字符(█、空格、░)和 batch 索引的字符串。
- **内部实现**:调用 `self.to_dense()` 获取稠密掩码张量(涉及设备上的张量操作),再根据 grid_size 和 limit 参数生成可视化字符串。
#### 2. torch.nn.attention.flex_attention.create_mask
根据 mod_fn 函数创建掩码张量。
- **签名**:`create_mask(mod_fn, B, H, Q_LEN, KV_LEN, device=None) -> Tensor`
- **参数**:
- `mod_fn`:mask_mod 或 score_mod 函数,定义掩码模式。
- `B`:批量大小,为 None 时默认 1。
- `H`:头数,为 None 时默认 1。
- `Q_LEN`:查询序列长度。
- `KV_LEN`:键/值序列长度。
- `device`:设备,为 None 时使用当前加速器。
- **返回值**:Tensor,形状为 (B, H, Q_LEN, KV_LEN) 的掩码张量。
- **内部实现**:在设备上创建 arange 张量,通过 vmap 对 mod_fn 进行向量化计算,涉及设备上的张量操作。
#### 3. torch.nn.attention.flex_attention.create_nested_block_mask
根据 mask_mod 函数创建与嵌套张量(NJT)兼容的块掩码。
- **签名**:`create_nested_block_mask(mask_mod, B, H, q_nt, kv_nt=None, BLOCK_SIZE=128, _compile=False) -> BlockMask`
- **参数**:
- `mask_mod`:mask_mod 函数,定义掩码模式。
- `B`:批量大小。
- `H`:头数。
- `q_nt`:查询嵌套张量(Jagged layout NJT)。
- `kv_nt`:键/值嵌套张量,为 None 时使用 q_nt。
- `BLOCK_SIZE`:块大小。
- **返回值**:BlockMask 对象。
- **版本说明**:该 API 仅在 PyTorch v2.7.1 中存在,v2.11.0,v2.12.0,master 已移除。测试中使用 `setUp` + `self.skipTest()` 条件跳过。
### 二、测试用例完备性说明
PyTorch 社区测试覆盖情况:
- `BlockMask.to_string`:社区在 `test/inductor/test_flex_attention.py` 中仅通过 `str(block_mask)` 间接调用(默认参数),`grid_size` 和 `limit` 参数均未覆盖。
- `create_mask`:社区测试中无直接调用。
- `create_nested_block_mask`:社区测试中无直接调用。
新增测试文件 `test/nn/test_npu_block_mask.py`,共 28 个测试用例,分为三个测试类:
#### TestBlockMaskToString(12 个用例)
| 参数 | 覆盖场景 | 测试方法 |
| --- | --- | --- |
| grid_size | 默认值 (20, 20) | test_to_string_default |
| grid_size | int 类型 | test_to_string_grid_size_int |
| grid_size | tuple 类型(正方形) | test_to_string_grid_size_tuple |
| grid_size | tuple 类型(非正方形) | test_to_string_grid_size_non_square_tuple |
| grid_size | -1(非压缩) | test_to_string_grid_size_negative_one |
| limit | 0(边界值,立即截断) | test_to_string_limit_zero |
| limit | 1(边界值,显示一个后截断) | test_to_string_limit_one |
| limit | 大于 batch*head(显示全部) | test_to_string_limit_large |
| grid_size + limit | 组合参数 | test_to_string_combined_params |
| 返回值 | 包含可视化字符 █ 和空格 | test_to_string_contains_visual_chars |
| 返回值 | 包含 batch 索引 (0, 0) | test_to_string_contains_batch_indices |
| 等价性 | grid_size int 等价于相同值 tuple | test_to_string_int_equals_tuple |
#### TestCreateMask(11 个用例)
| 参数 | 覆盖场景 | 测试方法 |
| --- | --- | --- |
| mod_fn | mask_mod 函数(4参数) | test_create_mask_basic_mask_mod |
| mod_fn | score_mod 函数(5参数) | test_create_mask_basic_score_mod |
| B | None(默认为 1) | test_create_mask_b_none |
| H | None(默认为 1) | test_create_mask_h_none |
| B, H | 均为 None | test_create_mask_both_none |
| Q_LEN, KV_LEN | 不同长度 | test_create_mask_different_q_kv_len |
| 返回值 | 因果掩码值正确性 | test_create_mask_causal_values |
| device | 输出在正确设备上 | test_create_mask_device |
| mod_fn | prefix LM 掩码 | test_create_mask_prefix_lm |
| mod_fn | sliding window 掩码 | test_create_mask_sliding_window |
| B, H | 多批量多头 | test_create_mask_multi_batch_heads |
#### TestCreateNestedBlockMask(5 个用例,仅 PyTorch v2.7.1)
| 参数 | 覆盖场景 | 测试方法 |
| --- | --- | --- |
| 基本功能 | 返回 BlockMask | test_create_nested_block_mask_basic |
| kv_nt | 交叉注意力(显式 kv_nt) | test_create_nested_block_mask_with_kv_nt |
| BLOCK_SIZE | 自定义块大小 | test_create_nested_block_mask_block_size |
| B, H | 多批量多头 | test_create_nested_block_mask_multi_batch |
| device | 输出在正确设备上 | test_create_nested_block_mask_device |
### 三、NPU 适配
- 使用 `device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu"` 获取 NPU 设备。
- 通过 `create_block_mask(mask_mod, B, H, Q_LEN, KV_LEN, device=device_type)` 在 NPU 上创建 BlockMask。
- `to_string` 内部调用 `to_dense()` 执行设备上的张量操作,验证 NPU 设备上的正确性。
- `create_mask` 通过 `device=device_type` 在 NPU 上创建掩码张量,涉及 arange 和 vmap 设备操作。
- `create_nested_block_mask` 接收嵌套张量(NJT),在 NPU 设备上创建块掩码。
- `create_nested_block_mask` 仅在 PyTorch v2.7.1 中可用,使用 `setUp` + `self.skipTest()` 在不可用时跳过。
## 【资料变更】
> 不涉及
>
> 另行通过资料补齐 PR 提交至 master 分支,本PR仅提交测试文档,详见资料补齐 PR https://atomgit.com/Ascend/pytorch/pull/45155 。
## 【接口变更】
> 不涉及
>
> 仅新增测试用例,未修改任何业务代码。
## 【功能验证】
新增文件:`test/nn/test_npu_block_mask.py`
### 运行命令
```bash
# 运行全部测试
python test/nn/test_npu_block_mask.py
# 单独运行各 API 测试类
python test/nn/test_npu_block_mask.py TestBlockMaskToString
python test/nn/test_npu_block_mask.py TestCreateMask
python test/nn/test_npu_block_mask.py TestCreateNestedBlockMask
```
### torch.nn.attention.flex_attention.BlockMask.to_string 验证结果
```bash
$ python test/nn/test_npu_block_mask.py TestBlockMaskToString
test_to_string_combined_params ... ok
test_to_string_contains_batch_indices ... ok
test_to_string_contains_visual_chars ... ok
test_to_string_default ... ok
test_to_string_grid_size_int ... ok
test_to_string_grid_size_negative_one ... ok
test_to_string_grid_size_non_square_tuple ... ok
test_to_string_grid_size_tuple ... ok
test_to_string_int_equals_tuple ... ok
test_to_string_limit_large ... ok
test_to_string_limit_one ... ok
test_to_string_limit_zero ... ok
----------------------------------------------------------------------
Ran 12 tests in ...s
OK
```
### torch.nn.attention.flex_attention.create_mask 验证结果
```bash
$ python test/nn/test_npu_block_mask.py TestCreateMask
test_create_mask_basic_mask_mod ... ok
test_create_mask_basic_score_mod ... ok
test_create_mask_b_none ... ok
test_create_mask_both_none ... ok
test_create_mask_causal_values ... ok
test_create_mask_device ... ok
test_create_mask_different_q_kv_len ... ok
test_create_mask_h_none ... ok
test_create_mask_multi_batch_heads ... ok
test_create_mask_prefix_lm ... ok
test_create_mask_sliding_window ... ok
----------------------------------------------------------------------
Ran 11 tests in ...s
OK
```
### torch.nn.attention.flex_attention.create_nested_block_mask 验证结果
PyTorch v2.7.1(API 存在):
```bash
$ python test/nn/test_npu_block_mask.py TestCreateNestedBlockMask
test_create_nested_block_mask_basic ... ok
test_create_nested_block_mask_block_size ... ok
test_create_nested_block_mask_device ... ok
test_create_nested_block_mask_multi_batch ... ok
test_create_nested_block_mask_with_kv_nt ... ok
----------------------------------------------------------------------
Ran 5 tests in ...s
OK
```
PyTorch v2.11.0 / v2.12.0 / master(API 已移除,自动跳过):
```bash
$ python test/nn/test_npu_block_mask.py TestCreateNestedBlockMask
test_create_nested_block_mask_basic ... skipped 'create_nested_block_mask is only available in PyTorch 2.7'
test_create_nested_block_mask_block_size ... skipped 'create_nested_block_mask is only available in PyTorch 2.7'
test_create_nested_block_mask_device ... skipped 'create_nested_block_mask is only available in PyTorch 2.7'
test_create_nested_block_mask_multi_batch ... skipped 'create_nested_block_mask is only available in PyTorch 2.7'
test_create_nested_block_mask_with_kv_nt ... skipped 'create_nested_block_mask is only available in PyTorch 2.7'
----------------------------------------------------------------------
Ran 5 tests in ...s
OK (skipped=5)
```
### 全部测试汇总
| 版本 | 运行命令 | 结果 |
| --- | --- | --- |
| PyTorch v2.7.1 | `python test/nn/test_npu_block_mask.py` | Ran 28 tests, OK |
| PyTorch v2.11.0 | `python test/nn/test_npu_block_mask.py` | Ran 28 tests, OK (skipped=5) |
| PyTorch v2.12.0 | `python test/nn/test_npu_block_mask.py` | Ran 28 tests, OK (skipped=5) |
| master | `python test/nn/test_npu_block_mask.py` | Ran 28 tests, OK (skipped=5) |
## 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等
- [x] PR 持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45154
2026-09-29 14:59:48 +08:00
anning-2026
2dcab49835
[test]: add NPU validation cases for torch.UntypedStorage.fill_ and float (issues #3740 #3741 )
...
Co-authored-by: AZT<870721918@qq.com >
# message auto-generated for no-merge-commit merge:
!44758 merge fill-float-fix-master into master
[test]: add NPU validation cases for torch.UntypedStorage.fill_ and float (issues #3740 #3741 )
Created-by: anning-2026
Commit-by: AZT
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
关联 issue:
- [#3740 ](https://gitcode.com/Ascend/pytorch/issues/3740 ) — `torch.UntypedStorage.fill_`
- [#3741 ](https://gitcode.com/Ascend/pytorch/issues/3741 ) — `torch.UntypedStorage.float`
# 【修改方案】
本 PR 覆盖 2 个 `torch.UntypedStorage` 接口的 NPU 一致性测试补齐,在 1 个新增测试文件中新增 13 个用例,不涉及 `torch_npu` 任何 `C++ / Python` 代码改动,也不修改 `torch_npu` 既有 patch。
修改文件(1 个新增):
- `test/test_storage.py`(新增):`torch.UntypedStorage.fill_`(9 个用例)、`torch.UntypedStorage.float`(4 个用例)
合计 2 个 API / 13 个用例,全部 NPU 实测通过。
按评审意见补充 `fill_` 的边界字节值与非法输入场景:
- 边界字节值:`fill_(0)`、`fill_(255)`、`fill_(127)`(uint8 最小/最大/中间值)
- 非法输入:`fill_(256)`(越界截断为 0)、`fill_(-1)`(负数截断为 255)
# 【社区现状与路径依据】
| API | 上游直接功能测试 | 判定 |
| --- | --- | --- |
| `torch.UntypedStorage.fill_` | 无(test_torch.py 无对 UntypedStorage 的 fill_ 直接调用) | 上游未提供直测;新增 NPU 端用例 |
| `torch.UntypedStorage.float` | 无(test_storage_casts 仅覆盖 TypedStorage 的 float,未覆盖 UntypedStorage) | 上游未提供直测;新增 NPU 端用例 |
# 【API 功能介绍】
1. **`torch.UntypedStorage.fill_(value)`**:用给定值填充存储字节内容,返回自身;value 按 uint8 字节范围(0-255)截断。
2. **`torch.UntypedStorage.float()`**:将存储转换为 float32 TypedStorage(逐字节转 float32)。
# 【测试方案】
1. **`fill_`**(9 个用例):返回自身、字节填充值、填充 0、空 storage、最小/最大/中间字节值(0/255/127)、越界值(256→0)、负值(-1→255)
2. **`float`**(4 个用例):返回类型、长度=原始字节数、数据正确性、空 storage
# 【测试环境】
- 操作系统:Linux
- 昇腾硬件:Ascend NPU
- 安装版本:torch 2.12.0、torch_npu 2.12.0
- 测试分支:本 PR base 为 `master`
# 【测试命令】
```bash
cd <repo_root>
python -u test/test_storage.py -v
```
# 【测试日志】(基于当前 commit + Ascend NPU 实跑)
```text
test_fill_byte_value ... ok
test_fill_empty ... ok
test_fill_max_byte_value ... ok
test_fill_mid_byte_value ... ok
test_fill_min_byte_value ... ok
test_fill_negative_value ... ok
test_fill_out_of_range_high ... ok
test_fill_returns_self ... ok
test_fill_zero ... ok
test_float_data_correctness ... ok
test_float_empty ... ok
test_float_length_equals_nbytes ... ok
test_float_returns_typed_storage ... ok
----------------------------------------------------------------------
Ran 13 tests in 0.957s
OK
```
**A5验证:**

# 【资料补齐检查结论】
`torch.UntypedStorage.fill_` 与 `torch.UntypedStorage.float` 在 docs/zh/api/native_api 版本表 torch-Storage.md 中已记录且支持状态正确,无需新增资料。
See merge request: Ascend/pytorch!44758
2026-09-29 14:46:55 +08:00
hhj-ai
bd3f40039e
fix(npu): preserve non-device fields in torch.autograd.profiler_util.Kernel
...
Co-authored-by: hhj-ai<greatesthhj@zju.edu.cn >
# message auto-generated for no-merge-commit merge:
!42019 merge api-kernel-name-master into master
fix(npu): preserve non-device fields in torch.autograd.profiler_util.Kernel
Created-by: hhj-ai
Commit-by: hhj-ai
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
关联 issue:https://gitcode.com/Ascend/pytorch/issues/3035
# 【修改方案】
1. `torch_npu.contrib.transfer_to_npu` 原先在 `_patch_nametuple` 中处理 namedtuple 的全部位置参数,导致 `torch.autograd.profiler_util.Kernel` 的非设备字段也被执行 `"cuda"` 到 `"npu"` 的替换。例如位置参数 `name="cuda_kernel"` 会错误变为 `"npu_kernel"`,而关键字参数 `name=` 不会被改写。
2. 通过 namedtuple 的 `_fields` 将位置参数映射到字段,只对 `device`、`device_type`、`map_location`、`device_id` 等设备字段调用现有替换逻辑;`torch.autograd.profiler_util.Kernel.name` 和 `duration` 保持原值,关键字参数逻辑不变。
3. 扩展既有 `test/contrib/test_transfer_to_npu.py` 中 `TestTransferToNpu.test_torch_autograd_profiler_util_Kernel`(master 当前第 340–373 行),不新增独立测试文件,也不使用代码检查抑制。
4. 覆盖全部三个字段及调用边界:
- `name`:包含 `"cuda"` 的字符串和空字符串,均保持原值。
- `device`:普通字符串、空字符串、`torch.device`、真实调用路径使用的 `device_index=0`、`None`、list、tuple、空 dict 和含 `"cuda"` 的 dict。
- `duration`:整数零和非零浮点数,均保持原值。
- 调用形式:位置参数、关键字参数、缺少参数、多余位置参数和未知关键字参数。
- `Kernel(name, device, duration)` 三个参数均为必填参数,没有可选参数,因此“可选参数传入与不传入”不适用。
5. PyTorch 官方在 `torch/autograd/profiler_util.py` 中定义 `Kernel = namedtuple("Kernel", ["name", "device", "duration"])`,并在 `FunctionEvent.append_kernel` 等路径以位置参数构造 `Kernel(name, device, duration)`;官方 `test/` 没有 `torch.autograd.profiler_util.Kernel.name` 的直接测试。已实际检查 torch-npu profiler/autograd 的 `test_upstream` patch,也无本问题覆盖。本问题由 torch-npu 的 monkey patch 引入,因此回归测试放在既有 contrib 用例中,不新增上游 patch。
# 【资料变更】
本代码 PR 不修改资料。相关支持状态由独立 master 资料 PR !42887 按当前上游目录更新 2.7.1、2.11.0、2.12.0、2.13.0 四个现存页面;上游已删除 2.9.0、2.10.0 资料目录,不恢复已删除页面。v2.9.0、v2.10.0 不再合入本次功能修复。
# 【接口变更】
不涉及公开接口签名变更,仅修复 `torch_npu.contrib.transfer_to_npu` 对既有 `torch.autograd.profiler_util.Kernel` 位置参数的转换行为。
# 【功能验证】
修复前在 PyTorch 2.9.0 + torch-npu 2.9.0rc1 环境复现:
```text
Kernel("cuda_kernel", "cuda:0", 100)
name: npu_kernel
device: npu:0
duration: 100
```
四个活动分支均对提交中的原样 `_patch_nametuple` 实现执行隔离回归;本地源码 worktree 未编译 `torch_npu._C/libtorch_npu.so`,因此没有将该结果表述为完整源码树测试。
```bash
KERNEL_TRANSFER_SOURCE=<当前分支>/torch_npu/contrib/transfer_to_npu.py \
TORCH_DEVICE_BACKEND_AUTOLOAD=0 \
python3 /workspace/718/verification/test_kernel_patch.py -v
```
```text
test_keyword_fields ... ok
test_non_device_container_and_integer_fields ... ok
test_positional_device_dict ... ok
test_positional_device_non_scalar_types ... ok
test_positional_fields ... ok
Ran 5 tests
OK
```
| 目标分支 | 验证提交 | 隔离回归 | `py_compile` | lintrunner | `git diff --check` |
|---|---|---|---|---|---|
| master(当前对应 2.13.0) | `0165431359a27750f61cfa44f897fb13937541a5` | 5/5,OK | 通过 | 通过 | 通过 |
| v2.7.1 | `642d0dba089cc30f055a02cfdab50a41d2149842` | 5/5,OK | 通过 | 通过 | 通过 |
| v2.11.0 | `6c2b85d0894fe7925d93f7923a9046cd87177193` | 5/5,OK | 通过 | 通过 | 通过 |
| v2.12.0 | `e06754b5e901ee08eec533715636b36996f2c58b` | 5/5,OK | 通过 | 通过 | 通过 |
静态检查使用实际命令:
```bash
python3 -m py_compile \
torch_npu/contrib/transfer_to_npu.py \
test/contrib/test_transfer_to_npu.py
uvx lintrunner \
torch_npu/contrib/transfer_to_npu.py \
test/contrib/test_transfer_to_npu.py
git diff --check upstream/<目标分支>...HEAD
```
构建态标准目标命令为:
```bash
python -m unittest \
test.contrib.test_transfer_to_npu.TestTransferToNpu.test_torch_autograd_profiler_util_Kernel \
-v
```
四个 current head 的真实 NPU 目标文件与完整流水线均已通过:
| 分支 | `contrib/test_transfer_to_npu` | 完整流水线 |
|---|---|---|
| master | `SUCCESS`,`32.1s` | `ci-pipeline-passed` |
| v2.7.1 | `SUCCESS`,`29.9s` | `ci-pipeline-passed` |
| v2.11.0 | `SUCCESS`,`29.6s` | `ci-pipeline-passed` |
| v2.12.0 | `SUCCESS`,`32.5s` | `ci-pipeline-passed` |
master 首轮 `npu/test_compatibility` 因 upstream compatibility 基线漂移失败;`UT_ARM_A2_Part_02` 分区 retry 终态为 `SUCCESS`,但 retry 未再次执行该检查,因此不将 compatibility 本身写成“重跑通过”。v2.12.0 首轮 `UT_ARM_A2_Part_03`(Ascend910B3)的唯一失败项为 `npu/test_ipc_event`(`3600s` timeout);唯一一次 `UT_ARM_A2_Part_03` retry 在 Ascend910B1 上重新实际执行该用例并于 `98.7s` 成功,分区 `29/29`、终态 `SUCCESS`,完整流水线通过。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
# 【2026-09-12 A5 验证更新】
- 已基于最新目标分支解决冲突,并 squash 为单提交 `b14753b11`。
- A5(Ascend950PR、CANN 9.1.0)通过 `torch_npu_server_runner.py` 执行 `TestKernelA5.test_kernel_parameters_and_a5_smoke`:`master` 为 `1/1` 通过。
- 覆盖 `torch.autograd.profiler_util.Kernel` 的位置参数、关键字参数、容器 device 值、异常参数和实际 NPU 张量 smoke。
- 完整报告:`/workspace/a5-verify/tests/docs/测试用例验证结果报告_1789170609.md`。
See merge request: Ascend/pytorch!42019
2026-09-29 14:40:15 +08:00
limuan
aea5062caf
distributed: support A5 compatible gather/scatter (master)
...
Co-authored-by: limuan<liyijie16@huawei.com >
# message auto-generated for no-merge-commit merge:
!46944 merge a5-compatible-gather-scatter-master into master
distributed: support A5 compatible gather/scatter (master)
Created-by: limuan
Commit-by: limuan
Merged-by: ascend-robot
Description: Ported from limuan/pytorch a5-compatible-gather-scatter-v2.10.0 (original commit 662ccff2d).
- Enable A5 in compatible SoC detection for gather/scatter.
- Keep scalable RootInfo limited to A2/A3 and use the default alltoall path on A5.
- Warn when reduce_scatter input elements do not match world_size * output elements.
Validation: diff against target touches only ProcessGroupHCCL.cpp; git diff --check passed. Hardware runtime tests were not run.
See merge request: Ascend/pytorch!46944
2026-09-29 14:17:19 +08:00
SCh_zx
b968b4558a
update build doc
...
Co-authored-by: SCh-zx<1325467101@qq.com >
# message auto-generated for no-merge-commit merge:
!47314 merge master into master
update build doc
Created-by: SCh_zx
Commit-by: SCh-zx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
更新源码构建的资料,增加易用性
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47314
2026-09-29 11:18:40 +08:00
WSs_321
c281986020
[CI] fix action environment: add container images for comment/sca/scan jobs
...
Co-authored-by: w30057661<wangshusheng7@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47252 merge master into master
[CI] fix action environment: add container images for comment/sca/scan jobs
Created-by: WSs_321
Commit-by: w30057661
Merged-by: ascend-robot
Description: ## 变更内容
`PR-pipeline_pytorch.yml`:为 `associate_pr_comment`、`sca-pr`、`malicious-scan` 三个任务补充 `container` 配置(`pytorchx86:v_03` 镜像),与其他任务保持一致,修复 action 在 self-hosted runner 宿主环境执行的 bug。
## 关联 issue
https://gitcode.com/Ascend/pytorch/issues/5215
See merge request: Ascend/pytorch!47252
2026-09-29 11:15:22 +08:00
ascend-robot
b16969cbfa
【硬件解耦】fix(inductor-TE): 补齐 matmul_backward 注册 #4930
...
Co-authored-by: gavinwang269<gavinwang269@users.noreply.gitcode.com >
# message auto-generated for no-merge-commit merge:
!46953 merge p4/fix-te-matmul-backward into master
【硬件解耦】fix(inductor-TE): 补齐 matmul_backward 注册 #4930
Created-by: gavinwang269
Commit-by: gavinwang269
Merged-by: ascend-robot
Description: # 【合入来源】
关联 issue:Fixes #4930。
本 PR 由 !46609 拆分而来(原 PR 打包了 matmul_backward 与 nearest{1,3}d_backward 两个独立问题,按评审建议拆为单主题 PR;!46609 即关,nearest 侧改动由 !46954 承接)。
# 【修改方案】
`aten.matmul_backward.default` 的 inductor 分解仅由 default 后端的 `_register_triton_decompositions` 注册(复用 `_matmul_backward_inductor`),TE(triton_experimental)的分解注册器 `_register_triton_experimental_decompositions` 漏注册,导致 TE 后端下 matmul 求导与 `linalg.matrix_power(p>=3)` 的 backward 编译在严格模式(implicit_fallbacks=False)抛 `MissingOperatorWithoutDecomp`。
修复:在 TE 分解注册器内以相同方式补 `register_decomposition([aten.matmul_backward.default])(_matmul_backward_inductor)`,复用现成函数、不复制实现。该注册器由后端加载入口在首次编译之前调用(分解表在首次编译时快照),时序满足。
# 【资料变更】
不涉及。
# 【接口变更】
不涉及(仅补内部注册配置)。
# 【功能验证】
测试环境:910B2,torch 2.15.0.dev20260920+cpu,torch_npu 2.15.0.dev+gitae2ee12,CANN 9.2.0-beta.2,triton-ascend 3.5.0。
1) 修复前:#4930 登记 11 例 opinfo 用例编译期 `MissingOperatorWithoutDecomp: target: aten.matmul_backward.default`(#4930 正文及 09-21/09-22 复测评论)。
2) 修复后:新增 UT `test/_inductor/triton_experimental/test_te_matmul_backward.py`(matmul 2d/3d backward、matrix_power(p=3) backward 可编译且梯度与 eager 容差一致 + 后端生效自检断言)。
3) 证据滞后声明:原 !46609 验证在 910B4 / torch_npu 2.14 线完成;本分支已 rebase 至最新 master(49fb6a91)重新落点,diff 上下文核验一致。
lintrunner(FLAKE8,SPACES,TABS,NEWLINE)无异常。
# 【CheckList】
- [x] PR标题正确使用类型标签
- [x] 代码注释完备
- [x] CI 流水线执行通过
See merge request: Ascend/pytorch!46953
2026-09-29 11:06:09 +08:00
huyuchao
2b57cd80ee
fix(npu): soc/核数查询惰性化——消除 import 期设备初始化,解锁 fork 编译 worker(保并行)
...
Co-authored-by: huyuchao<huyuchao2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46891 merge huyuchao/import-time-device-queries-lazy into master
fix(npu): soc/核数查询惰性化——消除 import 期设备初始化,解锁 fork 编译 worker(保并行)
Created-by: huyuchao
Commit-by: huyuchao
Merged-by: ascend-robot
Description: ## 问题
`import torch_npu._inductor` 会在 import 期初始化 NPU 设备,从而杀死 Inductor **fork 编译 worker** 里的一切 ≥2-kernel triton_experimental 编译(与 #46616 同一 bug,本 PR 治本并**保留并行编译**):
```
worker(fork 子进程) exec kernel 模块
→ import torch_npu._inductor → _load_backend()
→ 模块级设备查询 → _lazy_init()
→ RuntimeError: Cannot re-initialize NPU in forked subprocess
```
worker 内完整栈 + `_lazy_init` 桩回溯实证出**四个**模块级触碰点。
## 修复(对齐上游设计:编译只需静态属性,import 不碰设备;**公共 API 零改动**)
1. `config.py` 的 `is_ascend950 = get_soc_version()` → 改直调 `torch_npu._C._npu_get_soc_version()`(soc 是驱动级只读查询,未初始化进程/坏 fork 子进程实测同值 221;**公共 `get_soc_version()` 与 `npu/_backends.py` 不动**)
2. `config.py` 核数元组 → **PEP 562 惰性**(`lru_cache` + `__getattr__`;跨模块消费全为属性访问;唯一 from-import 消费者 `codegen/split_tiling.py` 零导入者已审计)
3. `npu_triton_heuristics.py` 的 `_NPU_TOTAL_CORES` 与模块级 UB 查询 → `lru_cache` 访问函数(4 调用点)
4. `device_props.py` 三个探针的 soc 查询 → 本地 `_soc_version_no_init()`(同款已验证 C 级查询)
改动集 = **3 文件,全部位于 `torch_npu/_inductor/` 域内**(config.py 共享但仅"更惰性",heuristics/device_props 为 TE 专属)。
## 验证(910B2,torch 2.13.0+cpu,triton-ascend 3.2.2,最新 master b29d5da)
- **import 副作用清零(桩计数铁证)**:import `torch_npu._inductor` 后 `is_initialized()==False` 且 import 期 `_lazy_init` 调用次数 = **0**;路由值不变(is_ascend950/ub_size)
- **fork 复现**(eager op → 3-kernel TE compile,默认并行池):修复前 SubprocException → 修复后编译通过、数值一致
- **四 LLM runner 全量**与基线逐项一致:perf 1.05~1.25x 全过;accuracy 判定与基线相同(XLNet **pass_accuracy**、两模型维持设备级抖动门、gemma_3 维持 60GB 结构墙)
- **编译墙钟 vs 串行兜底(#46616)**:
```
串行 pin 本 PR(并行池) 加速
DistillGPT2 766s 66.6s 11.5x
XLNet 563s 94.6s 6.0x
gemma_2_2b 1005s 147.6s 6.8x
gemma_3_4b_it 906s 153.6s 5.9x
```
- lintrunner 三文件通过
## 范围说明
- default 后端不受影响(其 kernel 模块不经此 config 链,同复现实测通过);dvm 自带 compile_threads=1 免疫
- 风险边界:免初始化 soc 直调已在 910B2 实证;其它 SoC(310B/9391/950)建议 CI 卡型矩阵覆盖
## 与 #46616 的关系
#46616 以无条件 `compile_threads=1` 兜底(零假设止血);本 PR 消除根因并恢复并行编译。**任一单独可修 worker;本 PR 落地后 #46616 可降级为保险或撤回**。
关联 issue: [#4979 ](https://gitcode.com/Ascend/pytorch/issues/4979 )(同 #46616)
See merge request: Ascend/pytorch!46891
2026-09-29 10:45:49 +08:00
zzzzzzk
de1cc7e80a
Add the usage constrain for MULTI_STREAM_MEMORY_REUSE
...
Co-authored-by: Zhang Zekun<zhangzekun11@huawei.com >
# message auto-generated for no-merge-commit merge:
!46732 merge doc_fix_multi_stream_mem_reuse into master
Add the usage constrain for MULTI_STREAM_MEMORY_REUSE
Created-by: zzzzzzk
Commit-by: Zhang Zekun
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> https://gitcode.com/Ascend/pytorch/issues/4610
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [x] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46732
2026-09-29 10:10:57 +08:00
nasa___1
7b8c0777b7
[test] add DistError and fsdp.LocalStateDictConfig api test case
...
Co-authored-by: nasa___1<2397662955@qq.com >
# message auto-generated for no-merge-commit merge:
!45883 merge LocalStateDictConfig-DistError-master into master
[test] add DistError and fsdp.LocalStateDictConfig api test case
Created-by: nasa___1
Commit-by: nasa___1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <span style="color:red"><strong>如有社区 Issue,请关联 Issue 链接</strong></span>
> <span style="color:red"><strong>请勿携带内部流程信息(需求链接、问题单、内部issue等)</strong></span>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch-ecosystem/issues/266 https://gitcode.com/Ascend/pytorch-ecosystem/issues/304
- [ ] 重构优化
- [ ] 资料更新
# 1、API功能分析
| API | 功能说明 |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `torch.distributed.fsdp.LocalStateDictConfig` | FSDP 本地状态字典的配置类,配合 `StateDictType.LOCAL_STATE_DICT` 使用。它通过 `offload_to_cpu` 控制导出的本地参数分片是否转移到 CPU,默认是 `False`。它本身只提供配置,实际导出由 `model.state_dict()` 完成。[官方资料](https://docs.pytorch.org/docs/2.7/fsdp.html#torch.distributed.fsdp.LocalStateDictConfig ) |
| `torch.distributed.DistError` | PyTorch 分布式异常的基类,继承自 `RuntimeError`。可以通过 `except dist.DistError` 统一捕获其派生异常,包括 `DistBackendError`、`DistNetworkError` 和 `DistStoreError`。它本身不执行通信,也不是 NPU 专属接口。[官方资料](https://docs.pytorch.org/docs/2.7/distributed.html#torch.distributed.DistError ) |
# 2、上游用例检查情况
| API | PyTorch 官方是否有测试 | 上游覆盖方式 | torch-npu 是否建议补充 |
| --------------------------------------------- | --------------- | ------------------------------------------------------ | ------------------------ |
| `torch.distributed.fsdp.LocalStateDictConfig` | **有** | 在 FSDP state_dict 测试中直接实例化并参与 `LOCAL_STATE_DICT` 流程 | **建议补充,且优先级较高** |
| `torch.distributed.DistError` | **有** | 主要通过 `DistStoreError`、`DistNetworkError` 等子类验证其继承/异常体系 | **建议补充** |
这两个API都需要torch-npu平台支撑验证,因此需要进行测试用例补充。
# 3. 资料检查
`torch.distributed.DistError` 和 `torch.distributed.fsdp.LocalStateDictConfig` 这两个API在torch上游都有独立条目,
但是`torch.distributed.fsdp.LocalStateDictConfig` 这个API资料补充存在。

`torch.distributed.DistError` 这个API资料补充不存在,因此需要进行资料补充。
# 4. API功能测试
测试覆盖场景:
| API | 测试方法 | 测试场景 | 预期结果 |
| --- | --- | --- | --- |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_default_config` | 验证默认构造及继承关系。 | 配置对象属于 `StateDictConfig`,且 `offload_to_cpu` 默认为 `False`。 |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_explicit_config` | 分别显式设置 `offload_to_cpu=False` 和 `True`。 | 配置属性与传入值一致。 |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_local_state_dict_on_npu` | 双卡 NPU 导出本地分片,验证配置生效与恢复、分片结构、数值及设备位置,并加载到另一模型验证参数和前向结果。 | 每个 rank 持有正确的 8 元素 NPU 分片;退出上下文后原配置恢复;加载后的完整参数和前向结果与 CPU 预期值一致。 |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_local_state_dict_offload_to_cpu` | 设置 `offload_to_cpu=True`,双卡导出本地分片并卸载到 CPU,再加载到另一 NPU 模型。 | 导出分片位于 CPU,分片结构及数值正确;配置上下文退出后恢复;加载后的完整参数和前向结果与 CPU 预期值一致。 |
| `torch.distributed.DistError` | `test_inheritance_and_message` | 验证异常构造、继承关系、异常信息及 `args`。 | `DistError` 继承 `RuntimeError`,异常信息和 `args` 与构造时传入的内容一致。 |
| `torch.distributed.DistError` | `test_raise_and_catch` | 主动抛出 `DistError`,分别使用 `DistError` 和 `RuntimeError` 进行异常断言。 | 两种异常断言均成功,捕获的异常对象及信息保持一致。 |
| `torch.distributed.DistError` | `test_subclasses_caught_by_base` | 分别主动抛出 `DistBackendError`、`DistNetworkError` 和 `DistStoreError`,使用 `DistError` 进行异常断言。 | 三种异常均继承 `DistError`,均可通过基类进行异常断言,且具体异常类型和信息保留。 |
| `torch.distributed.DistError` | `test_real_store_timeout_caught_by_dist_error` | 创建独立的 `TCPStore`,读取不存在的键,触发真实超时。 | 抛出的异常属于 `DistStoreError`,可通过 `DistError` 进行异常断言,且异常信息非空。 |
测试方法
```
source /usr/local/Ascend/ascend-toolkit/set_env.sh
TORCH_DEVICE_BACKEND_AUTOLOAD=1 torchrun \
--standalone \
--nnodes=1 \
--nproc_per_node=2 \
test_local_state_dict_config_dist_error_temp.py -v
```
测试结果
A2/A3芯片:
v2.7.1

v.2.11.0

v2.12.0

A5芯片 没有多卡 只有单卡进行测试,测试结果如下:
v2.7.1

v2.11.0

v2.12.0

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45883
2026-09-29 10:07:11 +08:00
huyuchao
4af251d33a
feat(benchmark): huggingface runner 接入 5 个 LLM 真实形状条目(DistillGPT2/XLNet/gemma-2-2b/gemma-3-4b-it /T5Small文本主干)
...
Co-authored-by: huyuchao<huyuchao2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46686 merge huyuchao/hf-llm-runner-entries into master
feat(benchmark): huggingface runner 接入 5 个 LLM 真实形状条目(DistillGPT2/XLNet/gemma-2-2b/gemma-3-4b-it /T5Small文本主干)
Created-by: huyuchao
Commit-by: huyuchao
Merged-by: ascend-robot
Description: ## 内容(5 提交,3 文件 +153/-9,自洽交付——单独 checkout 本分支即可复现全部结论)
| commit | 内容 |
|---|---|
| bfcadd70 | **四 LLM EXTRA_MODELS 真实形状条目**(config 随机初始化、无权重下载)+ gemma 版本守卫 + 显式 bs + seq=512 |
| 70cfb9ce | 五条目 config **`use_cache=False`** + NPU eager 非确定**豁免覆写** |
| 769e97c2 | common.py **恢复上游 eager 非确定豁免机制**(基类空集,默认零行为变化) |
| d2c83ad5 | **gemma_3_4b_it 入 `SKIP_ACCURACY_CHECK_MODELS`**(上游既有类别) |
| be15d0e3 | **恢复上游 T5Small 条目**(急切 config 写法)+ 豁免集/use_cache 补齐 |
### 五条目明细
| 模型 | 承载 | 关键超参 | 性质 |
|---|---|---|---|
| DistillGPT2 | GPT2LMHeadModel | 6L/768d/12h, vocab 50257 | 修复死条目(transformers 无同名类,stock 必 AttributeError) |
| XLNetLMHeadModel | XLNetLMHeadModel | xlnet-base 真实形状 12L/768d/12h/64hd, mem_len=null | 覆盖 XLNetConfig() 玩具形状(d_model=32) |
| T5Small | T5ForConditionalGeneration | 6L/512d/8h/64d_kv/2048d_ff, vocab 32128 | **恢复上游既有条目**(上游 AutoConfig 懒加载,改为急切 config 避开 import 期网络依赖) |
| gemma_2_2b | Gemma2ForCausalLM | 26L/2304d/8h-4kv/256hd, vocab 256000, sw 4096, softcap 50/30 | 新增 |
| gemma_3_4b_it | Gemma3ForCausalLM(文本主干) | 34L/2560d/8h-4kv/256hd, vocab 262208, sw 1024/pattern 6, rope linear×8 | 新增;vision tower 不在文本 runner 范围 |
全部 config 随机初始化(无权重下载,runner 惯例);gemma 需 transformers>=4.50(ImportError 守卫:旧版条目自动缺席 + 启动版本 warning,其余套件不受影响);T5 无版本要求。
## 五个精度堵点与对应修复(全部实测到代码/对象级)
| 堵点 | 根因(实证) | 修复 |
|---|---|---|
| DistillGPT2/gemma_2/T5Small 被 `eager_two_runs_differ` 门拦 | 910B2 loss 路径 eager 偶发 1~2 ulp 非位确定(设备级、与后端无关,probe 实证);**上游对此类模型有官方豁免通道而本仓 common.py 丢失**(dynamobench/common.py:2401 有 `skip_accuracy_check_as_eager_non_deterministic`,fork 继承了门丢了豁免) | 769e97c2 恢复机制 + 70cfb9ce/be15d0e3 套件覆写 `{DistillGPT2, gemma_2_2b, T5Small}`(扩到 inference——上游仅 training 开)。豁免只跳过 tol=0 参考系自检门,**不跳过任何数值比对** |
| 豁免后 `fail_accuracy` | 模型输出含 `past_key_values(DynamicCache)`(CausalLM 与 Seq2SeqLM 输出均如此)→ `same()` 对该结构**结构性崩**(探针进程级异常;runner 被 except 吞成 False)。XLNet 无 cache 对象通过,自洽 | 五 config `use_cache=False`(benchmark 推理本不需要 KV cache) |
| gemma_3 `eager_1st_run_OOM` | accuracy 协议存活集(orig + maybe_cast 副本 + fp64 副本闭包残留)峰值 ~58GB > 60GB 卡实际余量;**协议语义本身仅需 ~33GB**(probe 复刻验证) | d2c83ad5 入 SKIP 名单(与上游 `llama_v2_7b_16h`/`hf_GPT2_large` 同类别——上游按"40GB 机器放不下"标定跳过)。runner 内存纪律修复(fp64 副本闭包释放 + maybe_cast 同 dtype 免拷贝)后可移出 |
| T5Small 死键 | fork 演化时丢了 EXTRA 条目、仅剩 `BATCH_SIZE_DIVISORS` 残键(benchmark 仓历史 2475580 实证上游原有) | be15d0e3 按急刻 config 写法恢复(超参抄自官方 config.json)+ bs=8 |
| (附带)import 期网络依赖 | 上游 T5 用 `AutoConfig.from_pretrained` 懒加载,需 HF Hub 可达 | 急切 config 构造:import 期零网络/零缓存(CI、内网必需) |
## 验证(910B2,torch 2.13.0+cpu,triton-ascend 3.2.2,最新 master b29d5da)
### performance(eager vs triton_experimental,最新 master b29d5da + 并行编译,同场冷缓存)
| 模型 | bs | eager ms/iter | compiled ms/iter | speedup | 编译墙钟 |
|---|---|---|---|---|---|
| DistillGPT2 | 8 | 15.38 | 14.53 | **1.058x** | 67s |
| XLNetLMHeadModel | 8 | 103.68 | 82.71 | **1.254x** | 95s |
| T5Small | 4 | 21.18 | 15.06 | **1.407x** | 79s |
| gemma_2_2b | 2 | 87.54 | 79.59 | **1.100x** | 148s |
| gemma_3_4b_it | 2 | 135.57 | 128.76 | **1.053x** | 154s |
五模型全部编译通过全部加速(1.05~1.41x);gemma 两模型整图零断点,DistillGPT2 2 图 2 断。绝对 ms/speedup 随 master 前进与机况浮动(另一场四 LLM 复核:1.141/1.082/1.097/1.061x,eager 15.8/46.6/88.0/134.9ms),以同场比值为准。
### accuracy(本 PR 五提交全量)
| 模型 | 修复前 | 修复后 |
|---|---|---|
| DistillGPT2 | 门拦 → fail_accuracy | **pass_accuracy** |
| XLNetLMHeadModel | pass_accuracy | **pass_accuracy**(回归无恙,不在豁免集) |
| T5Small | (条目丢失不可测) | **pass_accuracy** |
| gemma_2_2b | 门拦 → fail_accuracy | **pass_accuracy** |
| gemma_3_4b_it | `eager_1st_run_OOM`(58.68GB) | **SKIP**(上游既有类别;协议语义需求 33GB,runner 内存纪律修复后可移出恢复完整检查) |
数值佐证:compiled-vs-eager 相对误差 1.2~1.8e-06、cos≈1.0(与设备自身 1~2 ulp 抖动同阶=fp32 累加序噪声,距比对容差 1e-3 三个数量级);compiled 自身位确定。
## 环境要求
- gemma 两模型需 transformers>=4.50(守卫缺席+版本 warning);DistillGPT2/XLNet/T5Small 无额外要求
- perf 依赖 TE 后端编译通道修复(PR #46616 或 #46891 任一)
关联 issue: [#4981 ](https://gitcode.com/Ascend/pytorch/issues/4981 )、[#5062 ](https://gitcode.com/Ascend/pytorch/issues/5062 )
See merge request: Ascend/pytorch!46686
2026-09-29 09:52:30 +08:00
y30037164
2edb78f70d
fix: checkout submodules recursively in nightly build
...
Co-authored-by: yuaiming<yuaiming@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47196 merge master into master
fix: checkout submodules recursively in nightly build
Created-by: y30037164
Commit-by: yuaiming
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
https://gitcode.com/Ascend/pytorch/issues/5012
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47196
2026-09-29 09:28:28 +08:00
nasa___1
f07d62c2d1
docs: update torch.distributed.DistError Api support status
...
Co-authored-by: nasa___1<2397662955@qq.com >
# message auto-generated for no-merge-commit merge:
!45881 merge docs-torch_distributed_DistError into master
docs: update torch.distributed.DistError Api support status
Created-by: nasa___1
Commit-by: nasa___1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <span style="color:red"><strong>如有社区 Issue,请关联 Issue 链接</strong></span>
> <span style="color:red"><strong>请勿携带内部流程信息(需求链接、问题单、内部issue等)</strong></span>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch-ecosystem/issues/266
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
## 1、API功能分析
| API | 功能说明 |
| --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `torch.distributed.fsdp.LocalStateDictConfig` | FSDP 本地状态字典的配置类,配合 `StateDictType.LOCAL_STATE_DICT` 使用。它通过 `offload_to_cpu` 控制导出的本地参数分片是否转移到 CPU,默认是 `False`。它本身只提供配置,实际导出由 `model.state_dict()` 完成。[官方资料](https://docs.pytorch.org/docs/2.7/fsdp.html#torch.distributed.fsdp.LocalStateDictConfig ) |
| `torch.distributed.DistError` | PyTorch 分布式异常的基类,继承自 `RuntimeError`。可以通过 `except dist.DistError` 统一捕获其派生异常,包括 `DistBackendError`、`DistNetworkError` 和 `DistStoreError`。它本身不执行通信,也不是 NPU 专属接口。[官方资料](https://docs.pytorch.org/docs/2.7/distributed.html#torch.distributed.DistError ) |
## 2、上游用例检查情况
| API | PyTorch 官方是否有测试 | 上游覆盖方式 | torch-npu 是否建议补充 |
| --------------------------------------------- | --------------- | ------------------------------------------------------ | ------------------------ |
| `torch.distributed.fsdp.LocalStateDictConfig` | **有** | 在 FSDP state_dict 测试中直接实例化并参与 `LOCAL_STATE_DICT` 流程 | **建议补充,且优先级较高** |
| `torch.distributed.DistError` | **有** | 主要通过 `DistStoreError`、`DistNetworkError` 等子类验证其继承/异常体系 | **建议补充** |
这两个API都需要torch-npu平台支撑验证,因此需要进行测试用例补充。
## 3. 资料检查
`torch.distributed.DistError` 和 `torch.distributed.fsdp.LocalStateDictConfig` 这两个API在torch上游都有独立条目,
但是`torch.distributed.fsdp.LocalStateDictConfig` 这个API资料补充存在。

`torch.distributed.DistError` 这个API资料补充不存在,因此需要进行资料补充。
# 【资料变更】
修改以下文件:
`docs/zh/api/native_api/pytorch_2-7-1/torch-distributed.md`
`docs/zh/api/native_api/pytorch_2-11-0/torch-distributed.md`
`docs/zh/api/native_api/pytorch_2-12-0/torch-distributed.md`
`docs/zh/api/native_api/pytorch_2-13-0/torch-distributed.md`
# 【接口变更】
不涉及
# 【功能验证】
测试覆盖场景:
| API | 测试方法 | 测试场景 | 预期结果 |
| --- | --- | --- | --- |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_default_config` | 验证默认构造及继承关系。 | 配置对象属于 `StateDictConfig`,且 `offload_to_cpu` 默认为 `False`。 |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_explicit_config` | 分别显式设置 `offload_to_cpu=False` 和 `True`。 | 配置属性与传入值一致。 |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_local_state_dict_on_npu` | 双卡 NPU 导出本地分片,验证配置生效与恢复、分片结构、数值及设备位置,并加载到另一模型验证参数和前向结果。 | 每个 rank 持有正确的 8 元素 NPU 分片;退出上下文后原配置恢复;加载后的完整参数和前向结果与 CPU 预期值一致。 |
| `torch.distributed.fsdp.LocalStateDictConfig` | `test_local_state_dict_offload_to_cpu` | 设置 `offload_to_cpu=True`,双卡导出本地分片并卸载到 CPU,再加载到另一 NPU 模型。 | 导出分片位于 CPU,分片结构及数值正确;配置上下文退出后恢复;加载后的完整参数和前向结果与 CPU 预期值一致。 |
| `torch.distributed.DistError` | `test_inheritance_and_message` | 验证异常构造、继承关系、异常信息及 `args`。 | `DistError` 继承 `RuntimeError`,异常信息和 `args` 与构造时传入的内容一致。 |
| `torch.distributed.DistError` | `test_raise_and_catch` | 主动抛出 `DistError`,分别使用 `DistError` 和 `RuntimeError` 进行异常断言。 | 两种异常断言均成功,捕获的异常对象及信息保持一致。 |
| `torch.distributed.DistError` | `test_subclasses_caught_by_base` | 分别主动抛出 `DistBackendError`、`DistNetworkError` 和 `DistStoreError`,使用 `DistError` 进行异常断言。 | 三种异常均继承 `DistError`,均可通过基类进行异常断言,且具体异常类型和信息保留。 |
| `torch.distributed.DistError` | `test_real_store_timeout_caught_by_dist_error` | 创建独立的 `TCPStore`,读取不存在的键,触发真实超时。 | 抛出的异常属于 `DistStoreError`,可通过 `DistError` 进行异常断言,且异常信息非空。 |
测试方法
```
source /usr/local/Ascend/ascend-toolkit/set_env.sh
TORCH_DEVICE_BACKEND_AUTOLOAD=1 torchrun \
--standalone \
--nnodes=1 \
--nproc_per_node=2 \
test_local_state_dict_config_dist_error_temp.py -v
```
测试结果
A2/A3芯片:
v2.7.1

v.2.11.0

v2.12.0

A5芯片 没有多卡 只有单卡进行测试,测试结果如下:
v2.7.1

v2.11.0

v2.12.0

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45881
2026-09-29 09:20:19 +08:00
pta-robot
3d3cee430d
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47283 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-28 22:02:48.
See merge request: Ascend/pytorch!47283
2026-09-29 09:07:09 +08:00
pta-robot
6d59edda74
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47285 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-28 22:03:31.
See merge request: Ascend/pytorch!47285
2026-09-28 22:45:18 +08:00
huyuchao
142dc619f4
perf(inductor): triton_experimental provable nonnegative-clamp skip — AST mask lower-bound prover
...
Co-authored-by: huyuchao<huyuchao2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46173 merge te-provable-clamp into master
perf(inductor): triton_experimental provable nonnegative-clamp skip — AST mask lower-bound prover
Created-by: huyuchao
Commit-by: huyuchao
Merged-by: ascend-robot
Description: 【合入来源】
fixes #4378
> 原始议题记录:#4378(yolov3 性能议题)
用途:triton_experimental 后端 **provable 钳位跳过**——对防御性负索引钳位做逐点数学证明,证明 mask 蕴含 kept-lane 索引 ≥0 才跳过钳位,恢复切片重映射 load 的向量化。
**组合关系**:本 PR 与系列其余 PR(正确性修复 #46172 / index_select 重写 #46174 / dispersion guard #46066)组合解决 yolov3 全链问题(compiled 0.357x → 1.068x、pass_accuracy);各机制正向交互,建议系列 PR 相邻合入(组合态已在纯净 whl 基座 + 最新 master runner 的完全独立环境复验 pass_accuracy)。
- [x] 需求
- [ ] 问题单
- [x] 重构优化
- [ ] issue/工单
- [ ] 资料更新
【修改方案】
**改了什么**(torch_npu/_inductor/triton_experimental/codegen/triton.py +232/−3、config.py +23、新增单测 196 行):
1. **证明器(五个纯函数 + 决策函数)**,挂在 load 索引发射的最后一站:
- `_npu_body_defs(kernel)`:收集**已发射** kernel 体的 `name = rhs` 赋值定义(AST 逐行容错解析;按 (行数, 末行) 缓存,同 kernel 多 load 共享一次解析);
- `_npu_ast_eval(node, defs, axis_names, depth=0)`:表达式求值器,归约为 ("axis", 名) / ("const", k) / None 三值。**轴身份 = axis_names 集合成员——单一结构事实源**(`kernel.range_tree_nodes`,上游维护的符号→轴注册表;名字不在集合就不是轴,无命名约定参与判定);派生名(`<pfx>index = <pfx>offset + tl.arange(...)`)经"定义含 arange + 集合内最长前缀"映射回基轴;`tl.full(shape, k, dtype)` 按结构取第二位置参;`x.to(dtype)` 值保持转换与 `tl.broadcast_to` 解包;递归深度 ≤8 防环;
- `_npu_mask_conj_atoms / _npu_mask_lower_atoms`:沿 `&` 合取与命名引用反向走树,只收 `轴 >= 常量` 下界原子,同轴取最强界(max);上界与未知算子零贡献(不臆造下界);
- `_npu_index_provably_nonnegative(expr, lb, axis_names)`:线性下界证明——sympy 展开取系数,**负系数 / TMP 间接符号 / 集合外符号 / 非纯符号项一票否决**,正系数 × 轴下界(缺省 0 = 轴变量 offset+arange 构造性非负)求和 ≥0 即证;
- `_masked_index_needs_nonnegative_clamp(indexing, kernel=None)`:决策编排——origin 负性预检(全符号代 0 求常数项,非负则从不需要钳;含 ZeroDivisionError 防护)→ provable 模式下从 `kernel.range_tree_nodes` 取轴集合(**缺席/为空 → 空集 → 一切拒证 → 保持钳位**,sound by construction)→ 三态结果(skip/unproven/error)全部计数留痕。
2. 接线一行:发射点 `_masked_index_needs_nonnegative_clamp(result, self)` 传入 kernel。
3. config 两键(见接口变更)+ npu_nonnegative_clamp 计数器组(provable_skip/provable_unproven/prover_error + log 模式站点记录)。
4. 新增 test/_inductor/test_provable_clamp_prover.py(13 用例,每例独立触发面)。
**为什么改**:
历史防御性 `tl.maximum(idx, 0)`(95c9094da7,防 masked-out lane 的负地址)使切片基址重映射(`-4 + x0 + …` 形)的地址**非仿射**——triton-ascend 的向量化分析依赖地址仿射性,非仿射则整条 load 降级为逐 lane 标量访问:yolov3 fused_sigmoid 1700µs(钳位)vs 19.4µs(跳过),~88x;aiv_scalar_ratio 0.926→0.088。钳位不能全局删(部分 mask 不蕴含非负,负地址确需防御),只能逐点证明后跳过。掩码的语义信息(tmp 命名合取链、tl.full 常量、派生名定义)只存在于**发射后的 DSL** 里,因此证明器解析已发射行而非遍历 IR;轴身份取 range tree——上游自己的符号注册表,上游如何演进轴命名,集合里就是新名字,判定自动跟随。
**解决了什么问题**:
- 性能:可证明冗余的钳位被跳过,向量化恢复——yolov3 全图 18 个钳位点全部证明跳过,生成代码 tl.maximum 0 处;
- 正确性契约:证明通过 = 数学等价——kept lane 上 max(idx,0)=idx(证明保证 idx≥0);masked-out lane 不访存,且其地址下界 = origin(有界小负,落在 allocator 池内映射区;wild 负地址才触发 AIV 异常,二者实验区分过)。证明失败 = 保持钳位(历史行为);证明器异常 = 计数兜底保持钳位——三态下最坏退化是"不修"而非"错";
- 鲁棒性:轴身份单源结构化,对上游命名演进免疫;语法识别失败一律保守(codegen 演进出新语法 → 不认识 → 拒证 → 安全)。
【资料变更】不涉及
【接口变更】config 新增 2 键:nonnegative_clamp_mode(provable/on/log/off,默认 provable)与 nonnegative_clamp_log_path("log" 模式站点记录文件路径,None 关闭)。**无 env 面**——遵 config 模块自身契约("No env-var layer: this object is the single source of truth"),运行时控制统一走 config.patch(nonnegative_clamp_mode=...),与仓内其余 TE 门同面;patch 自动参与 FX cache 键,切换即安全失效重编译。
【功能验证】
环境:Ascend 910B2 / torch 2.13.0 / torch_npu 2.13.0 / triton-ascend 3.2.2。独立分支单独同步(whl 纯净基座 5c9fd6f + 最新 master runner fresh clone + 私有缓存)验证。
1. UT:test_provable_clamp_prover.py **13 用例**(每例独立触发面,冗余例已裁),分三层:
- 证明判定 5 例:yolov3 典型可证形(-4+x0 @ x0>=4)、边界不足(x0>=2 拒)、非负 origin 全过、负系数拒、TMP 拒(与集合成员无关);
- DSL 原子提取 5 例:嵌套命名合取回溯、值侧 int cast/tl.full/broadcast_to 语法解包、同轴最强界取胜、上界无贡献(不臆造下界)、空集拒证(无结构源 → 不猜 → 零原子);
- 结构身份 3 例:结构集接受上游 i0 命名(对命名演进免疫的直接证明)、集合外符号拒绝、派生名 i0index 经结构前缀解析回基轴。
执行模型:真实用例在 `__name__ == "__main__"` 分支、由 1 个 wrapper 用例子进程运行——实证发现"先执行过测试的模块会毒化同进程后续多编译文件(编译 worker 第 2+ 个死于 NPU fork 重初始化;纯 import 无害)",子进程隔离使文件对任何 pytest 收集顺序免疫,且 pytest 进程中重型 import 根本不执行。
2. 隔离验证:prover+enable 组合 14/14、prover+enable+index_select 三文件 18/18;裁剪后复验 13/13、prover+enable 14/14、冒烟 13/13
3. 冒烟:test_triton_experimental_enable.py 13/13(隔离跑)
4. 门控验证:config.patch(nonnegative_clamp_mode='on') 实跑往返,切换生效、数值精确
5. 结构源实跑核验:真实编译的钳位判定现场 NPUTritonKernel.range_tree_nodes 携带 ['x0','x1','x2']
6. 端到端参考:yolov3 全图 18 个钳位点全部证明跳过、fused_sigmoid 1700µs→19.4µs、aiv_scalar_ratio 0.926→0.088(全栈组合态验证)
**影响面评估**:
- 触发面:仅"带 tmp-mask 且 origin 负"的 load 进入判定;无 mask 或 origin 非负的 load 从不钳也不判(与上游一致);
- 失败模式:三态全部 fail-safe(unproven/prover_error/空集均保持钳位 = 历史行为);
- 观测:全路径计数器留痕,log 模式可零行为差采集暴露面(站点 + 索引表达式 + 掩码名);
- 兼容:证明目标是"已发射 DSL",语法识别失败即保守保留——codegen 演进不破坏安全性;轴身份结构化后,命名演进不构成任何失明通道。
【CheckList】
- [x] 代码注释完备,正确记录错误日志(三态计数留痕 + log 模式暴露面采集)
- [x] 代码实现进行了返回值、空指针等校验(证明失败/异常/结构源缺席一律保持钳位;防御链全覆盖)
- [x] PR标题正确使用类型标签(perf)
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(待 gitcode CI 运行确认)
See merge request: Ascend/pytorch!46173
2026-09-28 19:40:10 +08:00
huangyunlong2022
da00190bea
[sync] PR-46919: add typedef for aclmdlRICondHandle,aclmdlRICondTaskParams
...
Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47243 merge sync-pr46919-2.12h-to-master into master
[sync] PR-46919: add typedef for aclmdlRICondHandle,aclmdlRICondTaskParams
Created-by: ascend-ds-bot
Commit-by: huangyunlong2022
Merged-by: ascend-robot
Description:
### 1. Origin pull request:
https://gitcode.com/Ascend/pytorch/merge_requests/46919
### 2. Original pull request related issue(s):
https://gitcode.com/Ascend/pytorch/issues/5095
### 3. Original pull request related commit(s):
| Sha | Datetime | Message |
|---|---|---|
|[9936eda2](https://gitcode.com/Ascend/pytorch/commit/9936eda2ba03bf55b35578164f4eb4d52f2ddb5d )|2026-09-23 16:50:23 +0800 CST|add typedef for aclmdlRICondHandle,aclmdlRICondTaskParams<br>|
See merge request: Ascend/pytorch!47243
2026-09-28 19:09:57 +08:00
huyuchao
1c1268b9ad
fix(inductor): triton_experimental correctness fixes — xmask-safe reduction codegen, rsplit sub-axis numel, stride-preserving downcast
...
Co-authored-by: huyuchao<huyuchao2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46172 merge te-correctness-fixes into master
fix(inductor): triton_experimental correctness fixes — xmask-safe reduction codegen, rsplit sub-axis numel, stride-preserving downcast
Created-by: huyuchao
Commit-by: huyuchao
Merged-by: ascend-robot
Description: 【合入来源】
> 关联 issue:related #4378(yolov3 性能议题)
用途:triton_experimental 后端两项**通用正确性修复**——reduction-only kernel 编译崩溃、跨核归约子轴尺寸错误。
**组合关系**:本 PR 与系列其余 PR(正确性修复 #46172 / provable 钳位跳过 #46173 / index_select 重写 #46174 / dispersion guard #46066)组合解决 yolov3 全链问题(compiled 0.357x → 1.068x、pass_accuracy);各机制正向交互,建议系列 PR 相邻合入(组合态已在纯净 whl 基座 + 最新 master runner 的完全独立环境复验 pass_accuracy)。
- [x] 需求
- [ ] 问题单
- [x] 重构优化
- [ ] issue/工单
- [ ] 资料更新
【修改方案】
**改了什么**(均在 torch_npu/_inductor/triton_experimental/,新增单测一件):
1. **xmask 安全引用**(codegen/triton.py,_npu_preserve_mixed_leaf_mul_where):修为仅在 xmask 实际有定义时引用。
2. **rsplit 子轴 numel 映射**(codegen/triton.py,_npu_rsplit_split_tokens):子轴(如 r0_0)的 numel 修正映射到正确的父 r 前缀。
> **范围说明**:本系列原有的第三项修复"保步长边界降型"已**归 #46074 所有**(Fixes #4701)——该 PR 携带完整形态(含 deepcopy 切断 _base 的广播布局提取分支,即 Super_SloMo 94.69 精度灾难的根治场景,及专属测试文件 test_triton_experimental_downcast_layout.py)。此处不重复携带,避免同函数合并冲突与该场景的正确性缺口。
**为什么改**:
1. reduction-only kernel 无 pointwise 叶时不存在 xmask,原实现无条件引用 → 编译期 NameError(kernel 直接编不出来);
2. 跨核 OUTER 归约把 r 轴切成 r0_0/r0_1 子轴时,numel 误映射到错误父前缀 → 生成尺寸错误的 partial kernel(数值错);
**解决了什么问题**:
- 编译可用性:reduction-only 图形(纯归约、归约+where 叶)不再崩溃;
- 数值正确性:跨核归约 partial 尺寸正确。
【资料变更】不涉及
【接口变更】不涉及(无新增 config/env)。
【功能验证】
环境:Ascend 910B2 / torch 2.13.0 / torch_npu 2.13.0 / triton-ascend 3.2.2。独立分支单独同步(whl 纯净基座 5c9fd6f + 最新 master runner fresh clone + 私有缓存)验证。
1. UT:test_correctness_fixes.py 5 用例——每修复一类锚定(reduction-only / reduction+where / 混合归约;大尺寸 outer 归约 ×2 触发跨核 rsplit),compiled vs eager 逐点一致全过
2. 冒烟:test_triton_experimental_enable.py 13/13(隔离跑)
3. 组合:与系列其余 PR 组合后 yolov3 1.068x / pass_accuracy(见组合关系注)
**影响面评估**:
- 两项均为**窄路径纠正**:只在原 bug 触发的路径上改变行为(崩溃→正常、错值→对值),其余路径零差;
- 无任何新配置面;修复即行为,无开关语义。
【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签
- [ ] PR持续集成流水线(CI)执行通过(待 gitcode CI 运行确认)
See merge request: Ascend/pytorch!46172
2026-09-28 18:15:57 +08:00
nasa___1
d189fbc7c0
[test] add forward_ad.(unpack_dual|enter_dual_level) api test case
...
Co-authored-by: nasa___1<2397662955@qq.com >
# message auto-generated for no-merge-commit merge:
!45784 merge forward_ad-enter_dual_level-unpack_dual-master into master
[test] add forward_ad.(unpack_dual|enter_dual_level) api test case
Created-by: nasa___1
Commit-by: nasa___1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <span style="color:red"><strong>如有社区 Issue,请关联 Issue 链接</strong></span>
> <span style="color:red"><strong>请勿携带内部流程信息(需求链接、问题单、内部issue等)</strong></span>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch-ecosystem/issues/245 https://gitcode.com/Ascend/pytorch-ecosystem/issues/249
- [ ] 重构优化
- [ ] 资料更新
# 1、API功能分析
- `torch.autograd.forward_ad.enter_dual_level`
该函数用于开启一个新的前向模式自动微分(Forward-mode AD)计算层级(Dual Level),并返回该层级的唯一整数标识符(level)。在完成相应的前向计算后,必须显式调用对应的 `exit_dual_level` 关闭该层级以释放相关计算上下文。
- `torch.autograd.forward_ad.unpack_dual`
该函数用于从一个 Dual Tensor 中解包出其原始值(primal)与指定层级下的前向切向量(tangent/derivative),并以具名元组(DualLevel(primal, tangent))的形式返回。
因此这两个API会涉及到torch-npu算子实现,因此需要在torch-npu平台上补充这两个API的测试用例。
# 2、上游用例检查情况
| API | 上游测试情况 | 主要测试位置 | 结论 |
| -------------------------------------------- | ------------------------------------- | ---------------------------------------------------------------------------------------- | ------------------ |
| `torch.autograd.forward_ad.enter_dual_level` | 有直接测试,但数量较少;同时被 `dual_level()` 大量间接调用 | `test/test_autograd.py` → `TestAutogradForwardMode` | **有覆盖,偏生命周期/异常场景** |
| `torch.autograd.forward_ad.unpack_dual` | 有大量直接测试 | `test/test_autograd.py` → `TestAutogradForwardMode`、`TestAutogradForwardModeBatchedGrad` | **覆盖较充分** |
| API | 上游已有测试 | 是否涉及 NPU Tensor | torch-npu 是否建议补测 | 优先级 |
| ----------------------------- | -----: | --------------: | ---------------: | --- |
| `forward_ad.enter_dual_level` | 是 | 间接涉及 | **建议补** | 中 |
| `forward_ad.unpack_dual` | 是 | **直接涉及** | **建议补** | 高 |
# 3. 资料检查
- `torch.autograd.forward_ad.enter_dual_level`
这个API在官方都有独立条目,但是当前资料补充缺失,因此需要进行资料补充。
- `torch.autograd.forward_ad.unpack_dual`
这个API在官方有独立条目,而且当前资料补充已经覆盖:

# 4. API功能测试
用例覆盖场景:
## 用例覆盖场景
| 测试项 | 覆盖内容 | 预期结果 |
| --- | --- | --- |
| enter_dual_level层级创建 | 直接调用`enter_dual_level()`创建前向AD层级 | 返回有效的整数level |
| 显式level参数 | 使用返回的level调用`make_dual`和`unpack_dual` | 成功创建和解析NPU dual tensor |
| NPU设备保持 | 检查解析出的primal和tangent所在设备 | primal和tangent均位于NPU设备 |
| level退出与清理 | 调用`exit_dual_level`后重新解析原dual tensor | tangent被清除并返回`None` |
| unpack_dual前向梯度解析 | 对NPU dual tensor计算`x * x`并解析结果 | primal等于`x²`,tangent等于`2*x*x_tangent` |
| CPU/NPU结果一致性 | 使用CPU计算预期primal和tangent,与NPU结果比较 | CPU与NPU计算结果一致 |
| 数据类型覆盖 | 分别使用`float16`和`float32`创建NPU dual tensor | 两种数据类型均能正确解析,且dtype保持不变 |
| 普通NPU张量解析 | 对非dual NPU tensor调用`unpack_dual` | primal等于原始输入,tangent为`None` |
测试方法
```
source /usr/local/Ascend/ascend-toolkit/set_env.sh
TORCH_DEVICE_BACKEND_AUTOLOAD=1 python test_forward_ad_enter_dual_level_unpack_dual.py -v
```
测试结果
A2/A3芯片:
v2.7.1

v.2.11.0

v2.12.0

A5芯片
v2.7.1

v2.11.0

v2.12.0

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45784
2026-09-28 18:00:30 +08:00
nasa___1
131ba9d411
docs: add forward_ad.enter_dual_level support status
...
Co-authored-by: nasa___1<2397662955@qq.com >
# message auto-generated for no-merge-commit merge:
!45782 merge docs-forward_ad.enter_dual_level into master
docs: add forward_ad.enter_dual_level support status
Created-by: nasa___1
Commit-by: nasa___1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <span style="color:red"><strong>如有社区 Issue,请关联 Issue 链接</strong></span>
> <span style="color:red"><strong>请勿携带内部流程信息(需求链接、问题单、内部issue等)</strong></span>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch-ecosystem/issues/245
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
## 1、API功能分析
- `torch.autograd.forward_ad.enter_dual_level`
该函数用于开启一个新的前向模式自动微分(Forward-mode AD)计算层级(Dual Level),并返回该层级的唯一整数标识符(level)。在完成相应的前向计算后,必须显式调用对应的 `exit_dual_level` 关闭该层级以释放相关计算上下文。
## 2. 资料检查
- `torch.autograd.forward_ad.enter_dual_level`
这个API在官方都有独立条目,但是当前资料补充缺失,因此需要进行资料补充。
# 【资料变更】
修改以下文件:
`/docs/zh/api/native_api/pytorch_2-7-1/torch-autograd.md`
`/docs/zh/api/native_api/pytorch_2-11-0/torch-autograd.md`
`/docs/zh/api/native_api/pytorch_2-12-0/torch-autograd.md`
`/docs/zh/api/native_api/pytorch_2-13-0/torch-autograd.md`
# 【接口变更】
不涉及
# 【功能验证】
## API功能测试
用例覆盖场景:
## 用例覆盖场景
| 测试项 | 覆盖内容 | 预期结果 |
| --- | --- | --- |
| enter_dual_level层级创建 | 直接调用`enter_dual_level()`创建前向AD层级 | 返回有效的整数level |
| 显式level参数 | 使用返回的level调用`make_dual`和`unpack_dual` | 成功创建和解析NPU dual tensor |
| NPU设备保持 | 检查解析出的primal和tangent所在设备 | primal和tangent均位于NPU设备 |
| level退出与清理 | 调用`exit_dual_level`后重新解析原dual tensor | tangent被清除并返回`None` |
| unpack_dual前向梯度解析 | 对NPU dual tensor计算`x * x`并解析结果 | primal等于`x²`,tangent等于`2*x*x_tangent` |
| CPU/NPU结果一致性 | 使用CPU计算预期primal和tangent,与NPU结果比较 | CPU与NPU计算结果一致 |
| 数据类型覆盖 | 分别使用`float16`和`float32`创建NPU dual tensor | 两种数据类型均能正确解析,且dtype保持不变 |
| 普通NPU张量解析 | 对非dual NPU tensor调用`unpack_dual` | primal等于原始输入,tangent为`None` |
测试方法
```
source /usr/local/Ascend/ascend-toolkit/set_env.sh
TORCH_DEVICE_BACKEND_AUTOLOAD=1 python test_forward_ad_enter_dual_level_unpack_dual.py -v
```
测试结果
A2/A3芯片:
v2.7.1

v.2.11.0

v2.12.0

A5芯片
v2.7.1

v2.11.0

v2.12.0

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45782
2026-09-28 17:49:13 +08:00
shi-yufeng99
598a2a8a5c
[sync] PR-47189: change catlass docs
...
Co-authored-by: shi-bibibi99<shiyufeng8@huawei.com >
# message auto-generated for no-merge-commit merge:
!47219 merge sync-pr47189-0928_v2.10.0_docs_branch1-to-master into master
[sync] PR-47189: change catlass docs
Created-by: ascend-ds-bot
Commit-by: shi-bibibi99
Merged-by: ascend-robot
Description:
### 1. Origin pull request:
https://gitcode.com/Ascend/pytorch/merge_requests/47189
### 2. Original pull request related issue(s):
https://gitcode.com/Ascend/pytorch/issues/5081
### 3. Original pull request related commit(s):
| Sha | Datetime | Message |
|---|---|---|
|[f9346a29](https://gitcode.com/Ascend/pytorch/commit/f9346a299b6d8a2105b160e4e3d62ed25a1d6ba5 )|2026-09-28 10:28:46 +0800 CST|change catlass docs<br>|
See merge request: Ascend/pytorch!47219
2026-09-28 17:37:03 +08:00
2511_93680239
1077409345
test(distributed): add BroadcastOptions NPU tests
...
Co-authored-by: Kaiserunix<qwerfghjkldsazxc@gmail.com >
# message auto-generated for no-merge-commit merge:
!44079 merge test/broadcast-options-master into master
test(distributed): add BroadcastOptions NPU tests
Created-by: 2511_93680239
Commit-by: Kaiserunix
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
- 任务 Issue:https://gitcode.com/Ascend/pytorch/issues/3202
- 分析 Issue:https://gitcode.com/Ascend/pytorch/issues/3351
# 【修改方案】
新增测试用例 `test/distributed/test_broadcast_options.py`,逐用例如下:
| 测试用例 | 验证场景 |
|---|---|
| `test_binding_identity` | `torch._C._distributed_c10d`、`torch.distributed`、`torch.distributed.distributed_c10d` 三条导入路径指向同一类型,`__module__` 为 `torch.distributed.distributed_c10d` |
| `test_default_field_values` | 无参构造后 `rootRank=0`、`rootTensor=0`、`timeout=-1ms`、`asyncOp=True` 四字段默认值 |
| `test_fields_read_write` | 四字段赋值并读回:`rootRank=3`、`rootTensor=2`、`timeout=5s`、`asyncOp=False` |
| `test_invalid_field_assignment_raises` | 异常边界:`rootRank` 赋字符串、`rootTensor` 赋 `None`、`timeout` 赋字符串、`asyncOp` 赋字符串均抛出 `TypeError` |
| `test_hccl_broadcast_with_options` | 双 rank HCCL 进程组消费 options 执行 broadcast:`asyncOp=True`、`rootRank=1` 时各 rank 收到根进程值;`asyncOp=False`、`rootRank=0` 时同步完成 broadcast |
**测试内容:** 对象为 `BroadcastOptions` 类型及其在 HCCL ProcessGroup 中的消费。单进程用例覆盖绑定身份、默认值、读写与非法赋值;多进程用例以 spawn 启动两个 rank,分别设置 `rootRank`、`rootTensor`、`timeout=30s` 与 `asyncOp` 后调用 `group.broadcast([tensor], options)`,断言各 rank 张量值与根进程一致。
**新增原因及必要性:** 社区已有用例面向 Gloo/CPU 与 NCCL 场景,未验证 NPU/HCCL 下 options 的消费行为,也未断言字段契约与绑定一致性;新增用例在 NPU 环境建立「构造—配置—消费」的完整保护,防止绑定回归与 HCCL 适配破坏。
**其他适配:** 用例按 NPU 设备放置规范在 imports 后声明 `device_type`,张量经 `.to(device_type)` 放置;多进程用例沿用仓库既有 spawn 组织方式与 `skipIfUnsupportMultiNPU(2)` 门槛,与 `test/distributed/test_broadcast.py` 等既有用例一致。 多进程 worker 在保存结果后调用 `dist.destroy_process_group()`,确保子进程退出前释放分布式资源。
**适配原因:** 官方用例无 NPU 设备命令,需按 NPU 设备放置规范编写;双卡门槛为多进程 HCCL 用例的资源前提。
**具体适配方案:** 新增独立测试文件,不修改任何既有测试、patch 或实现代码;预期在双卡及以上 NPU 环境全部通过。
# 【资料变更】
结论:不涉及。
该 API 为公开接口,经核查上游官方资料各版本(2.7、2.11、2.12、2.13)均无该 API 条目;经社区检视确认:官方资料中无该 API 条目,按规则不进行补齐,无需资料 PR。原资料 PR !42957 已按该裁定关闭。
# 【接口变更】
结论:不涉及。
本次变更仅新增测试文件 `test/distributed/test_broadcast_options.py`,不修改 API 实现、声明、注册、跨仓依赖或客户可见行为。
# 【功能验证】
**最终提交与 CI(2026-08-24):** head `66f520288d`;主流水线 `PR-pipeline_pytorch#63523` 已通过,CLA 与 docs CI 均通过。
**证据边界:** 以下 NPU 直接运行日志形成于本轮两项检视修改之前,用于证明原有五个测试方法在对应 NPU 环境可执行;新增四字段异常断言与进程组清理以最终 head 的主流水线通过作为当前回归证据。
执行命令:
```bash
python test_broadcast_options.py -v
```
结果:
```text
W0813 09:34:58.604000 28846 site-packages/torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages `nvidia-cutlass-dsl` and `apache-tvm-ffi`; missing optional dependency `nvidia_cutlass_dsl` (importlib.util.find_spec(nvidia_cutlass_dsl) failed)
test_binding_identity (__main__.TestBroadcastOptions) ... ok
test_default_field_values (__main__.TestBroadcastOptions) ... ok
test_fields_read_write (__main__.TestBroadcastOptions) ... ok
test_hccl_broadcast_with_options (__main__.TestBroadcastOptions) ... W0813 09:35:08.140000 29005 site-packages/torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages `nvidia-cutlass-dsl` and `apache-tvm-ffi`; missing optional dependency `nvidia_cutlass_dsl` (importlib.util.find_spec(nvidia_cutlass_dsl) failed)
W0813 09:35:08.140000 29006 site-packages/torch/_native/cutedsl_utils.py:55] CuTeDSL operators require optional Python packages `nvidia-cutlass-dsl` and `apache-tvm-ffi`; missing optional dependency `nvidia_cutlass_dsl` (importlib.util.find_spec(nvidia_cutlass_dsl) failed)
[rank1]:[W813 09:35:11.773260790 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
[rank0]:[W813 09:35:11.784822830 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
ok
test_invalid_field_assignment_raises (__main__.TestBroadcastOptions) ... ok
----------------------------------------------------------------------
Ran 5 tests in 16.582s
OK
```
**分支差异说明:** release 分支(v2.7.1/v2.11.0/v2.12.0)用例使用 `torch.npu.set_device`,master 分支为 `torch_npu.npu.set_device`,系各版本 torch-npu 设备接口暴露路径差异,功能等价;四版本运行日志均通过。
# 【CheckList】
- [x] 代码注释和错误日志完整(新增测试文件,代码注释为英文)。
- [x] 返回值、空指针检查完整(纯测试新增,不涉及运行时返回值或空指针处理)。
- [x] PR 标题使用 `test` 类型标签。
- [x] PR 持续集成流水线(CI)执行通过。
See merge request: Ascend/pytorch!44079
2026-09-28 17:27:56 +08:00
lyx324521
9651940216
硬件打标&删除tmp临时目录
...
Co-authored-by: lyx324521<liuyaxiong6@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47207 merge master into master
硬件打标&删除tmp临时目录
Created-by: lyx324521
Commit-by: lyx324521
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/3327
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
硬件打标&删除tmp临时目录
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47207
2026-09-28 16:12:30 +08:00
TonyYA
3607ff2c8f
fix tiling docs
...
Co-authored-by: TonyYA<pangjiayi@huawei.com >
# message auto-generated for no-merge-commit merge:
!46986 merge pta_master_0924 into master
fix tiling docs
Created-by: TonyYA
Commit-by: TonyYA
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5081
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46986
2026-09-28 15:43:37 +08:00
LucciC
3d5974eed6
[inductor] warn mlir backend deprecation and drop torch_mlir install print
...
Co-authored-by: LucciC<cuiliangcheng2@hisilicon.com >
# message auto-generated for no-merge-commit merge:
!47065 merge master-mlir-backend-deprecate-warn into master
[inductor] warn mlir backend deprecation and drop torch_mlir install print
Created-by: LucciC
Commit-by: LucciC
Merged-by: ascend-robot
Description: # 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
https://gitcode.com/Ascend/pytorch/issues/5089
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 现象:未安装 torch_mlir 时,import ascend_npu_ir 共享 utils 会 print “Can NOT find torch_mlir, INSTALL it first.”,DVM 等不依赖 torch_mlir 的路径也会被刷屏;mlir 后端计划废弃,需在显式选择入口提醒用户切换。
> 根因:utils.py 顶层 try/except 吞掉 ImportError 后 print;废弃提示未挂在 `_load_mlir_backend`。
> 改法:1)`_load_mlir_backend` 增加 FutureWarning,提示 npu_backend=mlir 废弃并 switch to other npu_backend;2)utils.py 去掉 import 时 print,缺包时静默 pass。
# 【资料变更】
> “不涉及”
# 【接口变更】
> “不涉及”(行为:缺 torch_mlir 时不再 print;选 mlir 后端时新增 FutureWarning)
# 【功能验证】
> 本地核对:未装 torch_mlir 时 import utils 无 print;设置 TORCHINDUCTOR_NPU_BACKEND=mlir 加载后端时出现 FutureWarning
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47065
2026-09-28 15:14:31 +08:00
rain-666
849a393b50
docs: 修改约束,分组功能目前仅支持单个动态维度
...
Co-authored-by: rain-666<chenxiaoyu12@huawei.com >
# message auto-generated for no-merge-commit merge:
!47210 merge master_doc_0928 into master
docs: 修改约束,分组功能目前仅支持单个动态维度
Created-by: rain-666
Commit-by: rain-666
Merged-by: ascend-robot
Description: docs: 修改约束,分组功能目前仅支持单个动态维度
See merge request: Ascend/pytorch!47210
2026-09-28 15:13:22 +08:00
wzyly
116d89d9df
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47193 merge master into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
产品名称改名
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47193
2026-09-28 14:53:15 +08:00
qiaoyaodan888
abec49c678
fix docs support version
...
Co-authored-by: qiaoyaodan<qiaoyaodan@huawei.com >
# message auto-generated for no-merge-commit merge:
!47212 merge inductor_doc_master_0928 into master
fix docs support version
Created-by: qiaoyaodan888
Commit-by: qiaoyaodan
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
修改torch_npu_inductor\docs\installation\installation.md 里面的 ### PyTorch版本支持 。把支持的版本改成“当前支持 PyTorch 2.7.1 、PyTorch 2.10.0 和 PyTorch 2.13.0 版本。”
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47212
2026-09-28 14:45:09 +08:00
Rita-xts
b8d0b6a809
fix(triton_experimental): keep upstream as_strided lowering
...
Co-authored-by: Rita-xts<xutianshu2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46371 merge fix_ut_test_xts into master
fix(triton_experimental): keep upstream as_strided lowering
Created-by: Rita-xts
Commit-by: Rita-xts
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
**PR 标题**:`fix(triton_experimental): keep upstream as_strided lowering`
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单 [#5145 ](https://gitcode.com/Ascend/pytorch/issues/5145 )
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
修复 triton_experimental 后端一个单元测试失败,fail→pass 实测验证。改动集中在算子注册层(`torch_npu/_inductor/triton_experimental/lowering_override_list.py` 与 `lowering.py`),不涉及代码生成与运行时:
1. **as_strided 加入 GENERATE_LIST**(`lowering_override_list.py`,与 squeeze/slice/select/permute 等既有视图算子同区归档——它们的上游翻译同样是不出 kernel 的纯元数据节点)
- 问题:as_strided 不在任一名单时,`_register_npu_inductor_fallbacks` 会将上游的 ReinterpretView 纯元数据翻译改写为 fallback(运行时 extern 调用)。此后 post-grad reinplace pass 将图输入的变异改写到输入视图上时,该 store 链在调度器的变异记账中不可追踪,被死代码消除静默删除——compiled 返回 graph break 之前的旧值(`test_slice_view_with_graph_break`:期望 2,实际 0)。
- 修法:保留上游翻译,视图回归零成本元数据节点,与 cuda / inductor default 行为一致。取舍说明:`as_strided_` / `as_strided_copy` / `as_strided_scatter` 暂不加入——无失败用例驱动,维持现状,待有驱动用例再逐个评估(与该名单"一条目一事故"的既有惯例一致)。
组件交互:`lowering_override_list.py`(两份名单)→ `lowering.py::_register_npu_inductor_fallbacks`(后端激活时消费名单并编辑全局 lowerings 注册表)→ 上游 `graph.py::call_function` 查表(使 as_strided 查到上游翻译)。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及"
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及"
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
**测试场景**:torch.compile(triton_experimental 后端)下视图别名 + 图输入变异的语义正确性;make_fx 直连 compile_fx_inner 路径的算子兜底。
**测试方法与结果**(均为清空 Triton/Inductor 编译缓存 + 强制重编译后执行,排除缓存命中):
1. 目标用例 fail→pass:
- `test_torchinductor.py::NPUTests::test_slice_view_with_graph_break`:修复前 compiled 返回 0(变异被死代码消除删除),修复后返回 2,与 eager 一致。
2. 回归(A/B 对照,同一套用例分别在含/不含本修复的环境执行):
- 视图家族相关用例共 100 例:修复后 3 失败/97 通过,修复前基线 4 失败/96 通过——净差异恰为目标用例 1 例由失败转通过;余 3 例失败经基线复跑证实为存量问题(与本修改无关)。
3. **UT 看护**:本修复由上游 torch inductor 测试套件的既有用例(test_slice_view_with_graph_break)触发与看护,本 PR 未新增用例。
自验证截图:待推送后以流水线与本地复跑记录补充。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(推送后以流水线结果确认)
See merge request: Ascend/pytorch!46371
2026-09-28 14:43:25 +08:00
thickhair
cf2e2dcd8e
ci: add the precise-test PR trigger wrapper
...
Co-authored-by: thickhair<zp2165064878@163.com >
# message auto-generated for no-merge-commit merge:
!46910 merge ci-precise-trigger into master
ci: add the precise-test PR trigger wrapper
Created-by: thickhair
Commit-by: thickhair
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
https://gitcode.com/Ascend/pytorch/issues/5014
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
添加精准流水线触发
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
不影响torch_npu
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46910
2026-09-28 14:20:38 +08:00
bingli-2026
8452adf8a2
[test][master] align symbolic_shapes API for issue #1615
...
Co-authored-by: bingli-2026<davis_ye@foxmail.com >
# message auto-generated for no-merge-commit merge:
!35696 merge issue1638-no9-master into master
[test][master] align symbolic_shapes API for issue #1615
Created-by: bingli-2026
Commit-by: bingli-2026
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [x] issue/工单
关联 issue:[#1615 ](https://gitcode.com/Ascend/pytorch/issues/1615 )
# 【修改方案】
本 PR 在 `test/fx/test_symbolic_shapes_api.py` 补充 4 个目标 API 的定向测试,并在 `torch_npu/utils/_dynamo.py` 补齐 `symbolic_shapes.hint_int` 的兼容导出。
兼容 patch 仅在 `hint_int` 缺失或其签名不含 `fallback` 时安装;已有完整上游实现时不替换。
修改文件:
- `test/fx/test_symbolic_shapes_api.py`
- `torch_npu/utils/_dynamo.py`
# 【API 功能介绍】
1. `has_free_unbacked_symbols`:判断表达式是否包含未绑定 symbolic shape 符号。
2. `hint_int`:返回 `int` 或 `SymInt` 的整数 hint;无 hint 时使用 fallback。
3. `InnerTensorKey`:描述内部张量属性访问路径。
4. `InnerTensorKey.get`:读取路径所指向的对象属性。
# 【上游对齐与完备性】
`hint_int` 与 PyTorch 契约逐项对齐:精确 `int` 原样返回;`bool` 等其他类型断言失败;有具体 hint 的 `SymInt` 返回 hint;无 hint 的 `SymInt` 在 `fallback=9` 时精确返回 `9`;无 fallback 时抛出数据依赖错误。兼容实现直接调用 `SymInt.node.require_hint(fallback)`,避免自行模拟符号求值语义。
测试覆盖上述 `hint_int` 分支,并覆盖 `has_free_unbacked_symbols` 的普通整数和 unbacked `SymInt`、`InnerTensorKey` 的构造/相等/哈希、`InnerTensorKey.get` 的属性读取。
# 【分支说明】
`v2.7.1 / v2.9.0 / v2.10.0 / v2.11.0 / v2.12.0 / master` 均保持相同的 API 契约和测试行为;各 PR 已同步到各自最新 upstream 目标分支并 squash 为单提交。
# 【测试命令】
```bash
source env.sh
python -u test/fx/test_symbolic_shapes_api.py -v
```
# 【测试结果】
已完成 `python -m py_compile`、`git diff --check`、兼容层契约桩测试及 GitCode 推送 Hook 检查。真实 Ascend 设备回归和 PR CI 结果以本次提交触发的流水线为准。
# 【CheckList】
- [x] 仅修改目标测试和必要的兼容层
- [x] 未修改 `test/allowlist_for_publicAPI.json`
- [x] 已同步 upstream 且单提交
- [x] 兼容实现与上游 `require_hint(fallback)` 语义对齐
See merge request: Ascend/pytorch!35696
2026-09-28 12:00:14 +08:00
ascend-robot
e411d6bb7b
test(tensor): add Tensor.__setstate__ NPU coverage
...
Co-authored-by: coconut<zhehanzhao7@gmail.com >
# message auto-generated for no-merge-commit merge:
!42442 merge api-completion-tensor-setstate-master into master
test(tensor): add Tensor.__setstate__ NPU coverage
Created-by: coconut77
Commit-by: coconut
Merged-by: ascend-robot
Description:
# 【合入来源】
## 关联 issue
- 任务 Issue:https://gitcode.com/Ascend/pytorch/issues/2677
- 说明性 Issue:https://gitcode.com/Ascend/pytorch/issues/4679
# 【修改方案】
## 修改说明
本 PR 在 master 分支新增 `test/test_tensor_setstate_api_completion.py`,直接验证 `torch.Tensor.__setstate__` 的核心行为:
- 叶子 Tensor 调用 `__setstate__` 后可以恢复 `requires_grad` 状态;
- 非叶子 Tensor 调用 `__setstate__` 时抛出与原生 PyTorch 一致的异常;
- 测试通过 `torch.accelerator.current_accelerator()` 选择当前设备,NPU 环境实际使用 NPU。
修改文件:
~~~text
test/test_tensor_setstate_api_completion.py
~~~
## 涉及 API
`torch.Tensor.__setstate__`
## 社区用例覆盖情况
PyTorch 社区用例主要通过序列化、JIT 或 pickle 等间接路径触发 `__setstate__`,没有面向该接口的直接行为测试。因此本 PR 增加直接 API 调用覆盖,验证 Ascend NPU 上的行为与原生 PyTorch 保持一致。
## NPU 适配
测试不使用 `transfer_to_npu`,也不包含 `tensor.cuda()`、`torch.cuda.*` 或 `device="cuda"` 等 CUDA 迁移路径。
~~~python
device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu"
~~~
无加速器环境回退到 CPU 仅用于保证测试文件可导入;NPU 环境通过 `accelerator=npu` 和 `NPU_AVAILABLE=True` 确认实际走 NPU 路径。
## 测试核心逻辑
~~~python
tensor = torch.ones(2, device=device_type)
self.assertFalse(tensor.requires_grad)
tensor.__setstate__((True, None, None))
self.assertTrue(tensor.requires_grad)
with self.assertRaisesRegex(
RuntimeError, "__setstate__ can be only called on leaf Tensors"
):
(tensor + 1).__setstate__((False, None, None))
~~~
# 【资料变更】
已通过独立 doc PR 在 `docs/zh/api/native_api/private_apis.md` 中补充 API 记录。
# 【接口变更】
不涉及 API 签名、实现或行为变更,本 PR 仅补充测试覆盖。
# 【功能验证】
## 910B3 测试结果
~~~text
COMMAND: /workspace/venvs/torch2100/bin/python /workspace/tensor_setstate_910B3_tests_20260908/test_tensor_setstate_api_completion_v271.py -v
PWD: /tmp
DATE: 2026-09-08 14:13:42 CST
test_tensor_setstate (__main__.TestTensorSetstateApiCompletion.test_tensor_setstate) ... ok
----------------------------------------------------------------------
Ran 1 test in 1.411s
OK
EXIT_CODE: 0
~~~
910B3 日志目录:
~~~text
/workspace/tensor_setstate_910B3_logs_20260908/master_910B3_complete_v2.log
~~~
## Ascend950PR 验证说明
Ascend950PR 已使用实际保存的 `test_tensor_setstate_api_completion.py` 文件完成 v2.7.1、v2.11.0 和 v2.12.0 验证。三个版本均确认 `ACCELERATOR: npu`、`NPU_AVAILABLE: True`、`OK` 和退出码 `0`。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常(PR 创建并通过 CI 后勾选)
See merge request: Ascend/pytorch!42442
2026-09-28 11:49:53 +08:00
gcw_HJG3MS52
3811596952
test: add set_backend core validation cases for master
...
Co-authored-by: gcw_HJG3MS52<3330335714@qq.com >
# message auto-generated for no-merge-commit merge:
!44185 merge test-set-backend-to-become-master into master
test: add set_backend core validation cases for master
Created-by: gcw_HJG3MS52
Commit-by: gcw_HJG3MS52
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [x] issue/工单
关联 issue:https://atomgit.com/Ascend/pytorch/issues/3375
# 【修改方案】
按验收标准 1.2②(官方用例未直接覆盖核心行为、涉及硬件接口),在 test 目录新增 `test/distributed/test_set_backend.py`,直接验证 `torch.distributed._symmetric_memory.set_backend` / `get_backend` 核心行为(设备无关的失败路径 + NPU 注册查询路径),对入参做全场景覆盖:
| 测试方法 | 覆盖场景 |
|---|---|
| `test_set_backend_invalid_names_raise` | `set_backend` 对当前构建未注册的 backend 名(`NVSHMEM`/`CUDA`/`NCCL`/`NPUSHMEM`/`invalid`)抛 `RuntimeError` |
| `test_set_backend_invalid_type_raises` | `set_backend` 对非 str 入参(`123`/`None`)抛 `TypeError` |
| `test_get_backend_npu` | `get_backend(torch.device("npu:0"))` 与字符串 `"npu:0"` 均返回 `"NPUSHMEM"`(torch_npu 注册) |
| `test_get_backend_unregistered_devices` | 未注册后端设备(`cpu`/`cpu:0`/`meta`/`cuda:0`)返回 `None` |
| `test_get_backend_invalid_type_raises` | `get_backend` 对 `torch.device()` 无法解析的入参(`None`/`3.5`)抛 `TypeError` |
**社区用例情况说明**:官方 `test_nccl.py` / `test_ce_colls.py` / `test_nvshmem.py` / `test_nvshmem_triton.py` 中引用 `set_backend` 的用例均为 CUDA/NVIDIA 特有功能验证(NCCL SymmetricMemory / NVLS multicast / triton),NPU 上需跳过或 ImportError,无法直接验证 `set_backend` 本身 → 新增用例必要。
**说明**:master 按最新验收标准 1.1① 不再提交 test_upstream NPU 适配 patch(官方 CUDA 专用用例通过 PyTorch 社区用例硬件解耦任务跟踪),本 PR 仅提交 test 目录核心行为用例(1.2②)。
**验收标准合规审计修复记录(2026-09-07)**:按"三、验收标准规范"逐条审计,发现并修复两处后重新验证、重新提交(保留原父链与原 commit message,仅 `test/distributed/test_set_backend.py` 单文件变更):
1. **导入顺序**:原文件 `import torch_npu` 位于 `from torch.testing...` 之前,不符合 torch_npu 测试树 isort 分组规范,已调整为 `torch` → `torch.testing` → `torch_npu`;
2. **入参全场景覆盖**:原用例仅覆盖 `set_backend("invalid")` 单一反例与 `get_backend(npu:0)` 单一正例,已扩展为上表 5 个用例。
本分支已 force push 更新为 5 用例版本单文件 commit(`7742cd29d`,parent 指向 base 分支 tip,PR 仅 1 个 commit、1 个文件变更)。
# 【接口变更】
不涉及
# 【功能验证】
```bash
python test/distributed/test_set_backend.py
```
A2 重验运行结果(2026-09-07,Ascend 910B3 单卡,CANN 9.1.0-beta.3,openEuler 24.03 aarch64,torch 2.13.0+cpu + torch_npu 2.13.0rc1):
```
test_get_backend_invalid_type_raises (__main__.TestSetBackend.test_get_backend_invalid_type_raises) ... ok
test_get_backend_npu (__main__.TestSetBackend.test_get_backend_npu) ... ok
test_get_backend_unregistered_devices (__main__.TestSetBackend.test_get_backend_unregistered_devices) ... ok
test_set_backend_invalid_names_raise (__main__.TestSetBackend.test_set_backend_invalid_names_raise) ... ok
test_set_backend_invalid_type_raises (__main__.TestSetBackend.test_set_backend_invalid_type_raises) ... ok
----------------------------------------------------------------------
Ran 5 tests in 0.015s
OK
```
5 个用例全部通过,无 ERROR / FAILURE / skip。历史参考(审计修复前 2 用例版,Ascend 910B2 / CANN 8.0.0,master 与 v2.11.0 用例一致):`Ran 2 tests ... OK`。
**A5 验证(Ascend 950PR,2026-09-07 审计修复后重跑)**:
- 环境:Ascend 950PR(9579)单卡,CANN 9.1.0-beta.3,Ubuntu 22.04.5;950 验证机主 NPU 栈为 master 源码栈(torch 2.13.0a0+git636bc91 + torch_npu 2.13.0+git46936d1),与本 PR 目标版本一致。
- 运行结果(950PR 实测,本 PR 分支 commit `ff71f579`,`python test/distributed/test_set_backend.py -v`):
```
test_get_backend_invalid_type_raises (__main__.TestSetBackend.test_get_backend_invalid_type_raises) ... ok
test_get_backend_npu (__main__.TestSetBackend.test_get_backend_npu) ... ok
test_get_backend_unregistered_devices (__main__.TestSetBackend.test_get_backend_unregistered_devices) ... ok
test_set_backend_invalid_names_raise (__main__.TestSetBackend.test_set_backend_invalid_names_raise) ... ok
test_set_backend_invalid_type_raises (__main__.TestSetBackend.test_set_backend_invalid_type_raises) ... ok
----------------------------------------------------------------------
Ran 5 tests in 0.012s
OK
```
- 结果说明:5 个用例全部通过,无 ERROR / FAILURE / skip;用例中的 `RuntimeError` / `TypeError` 均为预期失败路径(由 `assertRaises` 断言),非报错。
- 环境差异说明:950PR master 栈上 `set_backend` 对**所有** backend 名(含 `NPUSHMEM` / `NVSHMEM` / `NCCL`)均抛 `RuntimeError: SymmetricMemory does not find allocation backend <name>`(NPUSHMEM 由 torch_npu 为 `get_backend` 查询注册,但未注册到该构建的分配后端注册表;NVSHMEM/NCCL 需 CUDA 构建)。该差异仅影响"成功路径"是否存在,不影响本用例断言。
**A5 结论**:`torch.distributed._symmetric_memory.set_backend` / `get_backend` 在 Ascend 950PR(master)环境:非法 backend 名抛 RuntimeError、非 str 入参抛 TypeError、`get_backend(torch.device("npu:0"))` 与字符串形式均返回 NPUSHMEM、未注册设备返回 None,5 个用例全部通过,与 pytorch 社区一致。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!44185
2026-09-28 11:03:12 +08:00
ascend-robot
f6fe160cfe
[Usage]profiler logs optimize
...
Co-authored-by: hehongzhe<935062458@qq.com >
# message auto-generated for no-merge-commit merge:
!46935 merge fixwarn into master
[Usage]profiler logs optimize
Created-by: hhz0
Commit-by: hehongzhe
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
https://gitcode.com/Ascend/pytorch/issues/5069
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
1、CANN 支持默认导出 DB 时保留 op_attr;不支持时维持原有校验行为,并补充对应测试。
2、将动态 JSON 配置中这三个字段的缺省值分别设为空列表和 False,并补充缺省值测试。
3、使用 aten::、npu::、atb:: 前缀元组,通过 startswith() 统一匹配。
4、移除未知通信类型的逐条 warning,保留原有分类和数据处理逻辑。
5、将 StepInfoDbParser 的告警改为明确指出 DB 文件可能缺失或不可访问,或具体缺少哪个表。
6、重试失败记为 INFO,重试耗尽时记一次 ERROR 后抛出异常。
7、kernel events 缺失提示,说明 NPU profiling 数据可能未采集,并建议检查 CANN plog 日志。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
下面是修改前,上面是修改后

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46935
2026-09-26 21:50:32 +08:00
ljfnjj1234567
4bd504aee8
test: add torch.onnx.ONNXProgram.compute_values validation cases
...
Co-authored-by: ljfnjj1234567<wn0010240@163.com >
# message auto-generated for no-merge-commit merge:
!43901 merge onnx_program_compute_values-master into master
test: add torch.onnx.ONNXProgram.compute_values validation cases
Created-by: ljfnjj1234567
Commit-by: ljfnjj1234567
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3487
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
torch.onnx.ONNXProgram.compute_values
PyTorch 官方社区在 test/onnx/exporter/test_onnx_program.py 中仅有 ONNXProgram 的间接覆盖(测试 rename_axes 方法时构造 ONNXProgram),但未针对 compute_values() 编写直接独立测试。
该 API 为纯 Python 的 ONNX 图值计算工具(按 value_names 临时设置图输出后经 onnxruntime 推理回传张量),设备无关,不涉及 NPU 适配,不需要代码修改。
# 【资料变更】
涉及。上游 PyTorch 官方文档在 2.7.1(onnx_dynamo.html)、2.11.0 / 2.12.0 / 2.13.0(onnx.html)中均已收录 torch.onnx.ONNXProgram.compute_values。本次提交在 docs/zh/api/native_api/pytorch_2-7-1、pytorch_2-11-0、pytorch_2-12-0、pytorch_2-13-0 目录的 torch-onnx.md 中 ONNXProgram 小节补充 compute_values() 支持情况,不涉及测试用例变更。
# 【接口变更】
不涉及
# 【功能介绍】
torch.onnx.ONNXProgram.compute_values() 是 ONNX 导出结果类 ONNXProgram 的实例方法。按 value_names 将 ONNX 图中指定节点临时设为 graph output,运行 onnxruntime 推理并回传对应张量值,用于导出后调试/验证模型的中间层与输出值。纯 Python 逻辑,设备无关。
# 【功能验证】
test_onnx_program_compute_values.py (torch.onnx.ONNXProgram.compute_values)
- test_compute_values_output — 计算模型输出值并与 PyTorch 参考结果比对
- test_compute_values_intermediate_value — 计算图中中间值(Linear 输出),与 m.fc(x) 比对
- test_compute_values_with_kwargs — 输入以 kwargs 传入时正确计算输出值
- test_compute_values_invalid_name — 请求不存在的 value name 抛出 ValueError
python test/onnx/exporter/test_onnx_program.py
```
===================================================== test session starts =====================================================
platform linux -- Python 3.12.13, pytest-8.3.2, pluggy-1.6.0 -- /workspace/envs/torch-npu-test/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-master
configfile: pyproject.toml
plugins: xdist-3.6.1
collected 4 items
../workspace/user_data/pytorch-master/test/onnx/exporter/test_onnx_program_compute_values.py::TestONNXProgramComputeValues::test_compute_values_intermediate_value PASSED [ 25%]
../workspace/user_data/pytorch-master/test/onnx/exporter/test_onnx_program_compute_values.py::TestONNXProgramComputeValues::test_compute_values_invalid_name PASSED [ 50%]
../workspace/user_data/pytorch-master/test/onnx/exporter/test_onnx_program_compute_values.py::TestONNXProgramComputeValues::test_compute_values_output PASSED [ 75%]
../workspace/user_data/pytorch-master/test/onnx/exporter/test_onnx_program_compute_values.py::TestONNXProgramComputeValues::test_compute_values_with_kwargs PASSED [100%]
===================================================== 4 passed in 14.37s ======================================================
```
A5验证:

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!43901
2026-09-25 07:56:00 +08:00
pta-robot
208a5cdcf0
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47108 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-24 22:02:25.
See merge request: Ascend/pytorch!47108
2026-09-24 23:05:03 +08:00
rmch
050988db34
fix(triton_experimental): avoid slow AutoBlockify reduction on pre-A5
...
Co-authored-by: rmch<chenruimin2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46920 merge fix/te-rnumel-autoblockify-prea5 into master
fix(triton_experimental): avoid slow AutoBlockify reduction on pre-A5
Created-by: rmch
Commit-by: rmch
Merged-by: ascend-robot
Description: ## Problem
On Ascend 910B3 with Triton-Ascend 3.6, TE's dynamic LayerNorm kernel specializes the static `r0_numel=2560` argument in `triton_meta.constants`. With AutoBlockify enabled, the selected XBLOCK=4/R0_BLOCK=2560 kernel takes about 78.7 ms. Keeping that argument at runtime produces the same output and takes about 0.16 ms for a direct kernel launch.
## Change
Do not specialize static reduction numel arguments on pre-A5 devices with Triton-Ascend 3.6+. AutoBlockify remains enabled. The existing specialization is unchanged on A5+ and Triton-Ascend 3.2.x.
## Verification
- New dynamic LayerNorm regression test passes on Ascend 910B3, including 1280-row and 1279-row inputs and generated-code metadata check.
- Fresh `torch.compile` LayerNorm run: about 0.33 ms including Python dispatch, down from about 78.7 ms; selected binary reports `auto_blockify_enabled=true`.
- `sum(dim=-1)` smoke test passes.\n\n关联Issue:#5075\nhttps://gitcode.com/Ascend/pytorch/issues/5075
See merge request: Ascend/pytorch!46920
2026-09-24 22:26:17 +08:00
ffmh
bba56a3e1a
[master][fix] Fix IsBaseFormatType for base StorageImpl
...
Co-authored-by: ffmh<fengminghao2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46997 merge master_fix_is_base_format into master
[master][fix] Fix IsBaseFormatType for base StorageImpl
Created-by: ffmh
Commit-by: ffmh
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
1. 在 `FormatHelper::IsBaseFormatType(const at::Tensor&)` 中识别 Tensor 底层 `StorageImpl` 的实际类型。
2. 当底层对象为基础 `c10::StorageImpl` 时,直接将其判定为基础格式,避免按 `NPUStorageImpl` 读取 `NPUStorageDesc`。
3. 对其他 `StorageImpl` 保留原有 NPU format 获取及基础格式判断逻辑。
4. 删除 `test/npu/test_serialization.py` 中 legacy serialization 对 NPU Tensor 必须抛出 `NPUStorageImpl` 异常的过期校验,使其继续执行保存、加载及结果校验。
# 【资料变更】
不涉及。
# 【接口变更】
不涉及。
# 【功能验证】
以下接口用例均验证通过:
torch.save(..., _use_new_zipfile_serialization=False )
broadcast_object_list
scatter_object_list
send_object_list

# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
# 【关联 Issue】
- [Issue #5094 ](https://gitcode.com/Ascend/pytorch/issues/5094 )
See merge request: Ascend/pytorch!46997
2026-09-24 22:04:27 +08:00
culechan
a21bec4f3e
[fix] fix 924
...
Co-authored-by: chenshuai<chenshuai81@huawei.com >
# message auto-generated for no-merge-commit merge:
!46961 merge fix924 into master
[fix] fix 924
Created-by: culechan
Commit-by: chenshuai
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
老版本在下发deterministic_level的时候,会给HCCL也下发确定性配置,做新需求的时候漏了同时给HCCL下发了
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
验证已PASS
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46961
2026-09-24 20:29:13 +08:00
xiu_21
db8e7c28af
fix: restore TORCH_DEVICE_BACKEND_AUTOLOAD when import torch_npu
...
Co-authored-by: 21xiu<caixiuxiu1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47027 merge init_0924 into master
fix: restore TORCH_DEVICE_BACKEND_AUTOLOAD when import torch_npu
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] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
## 【问题描述】
torch_npu 在 `import torch` 之前会临时将 `TORCH_DEVICE_BACKEND_AUTOLOAD` 置为 `"0"`,防止 torch 初始化末尾 autoload 反向导入尚未初始化完成的 torch_npu(循环导入)。原实现中,恢复该环境变量的动作完全依赖 torch 的 autoload 机制调用 `torch_npu:_autoload` entrypoint。
当用户代码 `import torch_npu` 早于 `import torch` 时:
1. torch_npu 将变量置 `"0"`,随后触发 `import torch`
2. torch 初始化末尾读到 `"0"`,跳过 `_import_device_backends()`(torch/__init__.py 末尾 `if _is_device_backend_autoload_enabled():`)
3. `torch_npu:_autoload` entrypoint 永远不会被调用,恢复逻辑失效
4. 后续 `import torch` 仅为 `sys.modules` 缓存命中,不再执行任何恢复逻辑
结果:临时值 `"0"` 泄漏整个进程生命周期;所有子进程(spawn/fork、DataLoader worker、torch.compile worker、torchrun 拉起的新进程)继承 `"0"`,子进程中 `import torch` 不再自动加载 npu backend,导致设备不可用等隐蔽故障。
## 【修改方案】
核心依据:该环境变量在每个进程内仅在 torch `__init__` 末尾被消费一次,之后对当前进程无任何作用,仅影响子进程继承。因此在 torch_npu 初始化完成后、进程内不再有消费点的任意时刻恢复,均不影响当前进程行为,仅修正子进程继承。
修改内容(torch_npu/__init__.py):
1. 在文件末尾(`_initialize()` 之后、`_autoload` 函数定义之后)显式调用一次 `_autoload()`,将变量恢复为 import 前的原始值(`ORG_AUTOLOAD` 已在文件头部保存)。
2. `_autoload()` 函数本身保持不动,仍作为 torch.backends entrypoint,覆盖 torch 先导入场景(autoload 路径)下的恢复;两处调用幂等,写入同一个值。
3. 临时 `"0"` 的存活窗口覆盖 torch_npu 整个初始化期;由于该变量在进程内仅在 torch `__init__` 末尾被消费一次,`_initialize()` 期间无人读取,该窗口内不会产生副作用。
涉及的组件交互:
- torch_npu/__init__.py(本仓):末尾显式调用 `_autoload()` 恢复环境变量
- torch/__init__.py(上游,不修改):`_is_device_backend_autoload_enabled()` / `_import_device_backends()` 读取该变量决定是否 autoload,本修改与其交互关系不变,仅保证变量在交互完成后不再泄漏
- 子进程(spawn/fork/DataLoader worker 等):由继承泄漏的 `"0"` 变为继承原始值,子进程 `import torch` 时 npu backend 自动加载恢复正常
## 【资料变更】
不涉及。
## 【接口变更】
不涉及。本次修改为进程内部环境变量生命周期修复:
- 不改变任何 Python API / C++ API 的签名、语义
- 不改变 `TORCH_DEVICE_BACKEND_AUTOLOAD` 对外的语义(默认启用 autoload,用户显式设置仍被完整尊重并传递给子进程)
- 唯一可观察差异为修复的预期行为本身:torch_npu 先导入时环境变量不再泄漏为 `"0"`
## 【功能验证】
已在仓库新增 UT 看护用例:`test/test_autoload.py` 中新增 `AutoloadEnvVarTest` 测试类(原有 `AutoloadTest` 保持不动),看护本次修复涉及的环境变量行为。
测试方法:由于 `sys.modules` 缓存的存在,导入顺序与起始环境变量只能在全新解释器中各验证一次,因此每个场景通过 `subprocess` 以全新解释器(临时脚本文件)执行受控的导入序列;该解释器再通过 `multiprocessing`(spawn/fork 两种 context)拉起两类子进程探针:环境探针(不导入 torch,仅回读继承的环境变量,隔离环境继承与 autoload 行为)与导入探针(校验子进程内 torch_npu 加载状态及重复导入安全性)。默认场景显式从子进程环境中剥离该变量以保证"默认情况"真实成立,显式设置场景在子进程启动前注入 `0`/`1`。临时脚本目录的创建与删除通过 contextmanager 的 try/finally 收敛在同一作用域内成对完成,确保测试异常退出时亦及时清理(满足 G.FIO.04 临时文件及时删除要求)。
覆盖场景(每个测试方法以 `subTest` 罗列四种导入顺序:仅 import torch / 仅 import torch_npu / 先 torch 后 torch_npu / 先 torch_npu 后 torch,每种顺序校验 6 项探针输出——主进程 2 项:环境变量、torch_npu 加载状态;mp 子进程 4 项:spawn/fork 各自的环境继承与导入行为):
1. 主进程环境变量:默认环境四种导入顺序均为 `'1'`——含原 bug 场景(torch_npu 先导入)不再泄漏 `'0'`;显式设 `0`/`1` 时均保持用户设置不被覆盖 —— PASS
2. autoload 生效性:仅 import torch 时,默认环境/显式 `'1'` 下 torch_npu 被自动加载,显式 `'0'` 下不加载 —— PASS
3. 子进程环境继承:mp spawn/fork 子进程继承的环境变量与主进程一致(默认 `'1'`,用户设置 `'0'`/`'1'` 时为设置值)—— PASS
4. spawn 子进程(全新解释器)导入行为:继承环境为 `'1'` 时 `import torch` 经 autoload 加载 torch_npu,后续显式 `import torch_npu` 为纯缓存命中(含模块对象身份校验),无重复初始化、无报错;继承 `'0'` 时不 autoload —— PASS
5. fork 子进程导入行为:torch_npu 加载状态与主进程一致(import 前后均与主进程相同,即继承 `sys.modules`、不重跑初始化),无报错 —— PASS
自验证结果:`python test/test_autoload.py AutoloadEnvVarTest`,3 个测试方法(共 12 种导入顺序场景)全部通过。

性能验证:新增仅为一次函数调用与单次 `os.environ` 赋值(实测约 2.2 µs),占 `import torch_npu` 总耗时(实测约 4 s)的 0.00004%,无感知。
影响面确认:该变量全环境仅 torch `__init__` 末尾一处消费;运行时设备操作、同进程重复导入等场景行为零变化;混合加速器环境下 spawn 子进程会按默认行为 autoload,若存在真实设备冲突将由 `_check_device_conflict` 在子进程报错,属设计内保护,用户可显式 `TORCH_DEVICE_BACKEND_AUTOLOAD=0` 规避。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47027
2026-09-24 20:23:09 +08:00
WSs_321
ded4a2298b
[CI] add inductor version exclusion and 26.2.0 branch support for PR pipeline
...
Co-authored-by: w30057661<wangshusheng7@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46985 merge master into master
[CI] add inductor version exclusion and 26.2.0 branch support for PR pipeline
Created-by: WSs_321
Commit-by: w30057661
Merged-by: ascend-robot
Description: ### 关联 Issue
Closes #5079
### 修改内容
- `check_inductor.yml`:新增版本排除判断,`base.ref` 包含 `v2.12.0` / `v2.13.0` / `v2.14.0` 子串(正则 `v2\.(12|13|14)\.0`)即跳过 inductor 测试,支持 `v2.12.0-26.0.0` 这类后缀分支
- `PR-pipeline_pytorch.yml`:UT_inductor_01~04 移除 `!startsWith(env.target_branch, 'v2.12.0')` 条件,排除逻辑统一下沉到 check_inductor
- `find_torchair.yml`:支持 PR 评论 `compile_torchair` 快速触发,保留 torchair 标签查询兜底
- `PR-pipeline_pytorch.yml`:评论触发支持 `compile_inductor` / `compile_torchair`,新增 2.14.0 镜像
- `get_count.yml`:case 分支改为 `*-26.2.0` glob 匹配,覆盖所有 26.2.0 后缀分支
### test patch 验证(新增)
- `check_patch.yml`:检测 modify_files.txt 中 `test_upstream` 相关改动,输出 `need_patch`
- `test_patch_job.yml`:下载对应版本 pytorch 包,校验 `test_upstream` 的 patch 是否可用,按 `apply_test_patch.sh` 是否存在选择新旧 patch 脚本
- `PR-pipeline_pytorch.yml`:stage_2 接入 check_patch,stage_3 在 `need_patch == 'yes'` 时触发 test_patch(x86 节点)
### 测试说明
- CI 流水线配置变更,验证依赖分支 PR 触发
See merge request: Ascend/pytorch!46985
2026-09-24 18:17:25 +08:00
y30037164
1cd7a74585
consolidate nightly scripts into generic counterparts
...
Co-authored-by: y30037164<yuaiming@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46618 merge yam/master into master
consolidate nightly scripts into generic counterparts
Created-by: y30037164
Commit-by: yuaiming;y30037164
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
https://gitcode.com/Ascend/pytorch/issues/5012
- [x] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46618
2026-09-24 17:33:26 +08:00
mengmeizi05
cc9c6051d0
docs:Revise the expression of the overview security statement
...
Co-authored-by: s50057208<shiyunhan1@huawei.com >
# message auto-generated for no-merge-commit merge:
!47062 merge master_docker26.1.0-2 into master
docs:Revise the expression of the overview security statement
Created-by: mengmeizi05
Commit-by: s50057208
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
为英文overview添加安全风险声明
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47062
2026-09-24 17:26:26 +08:00
liuyutong_bury
3e877f6d52
fix(benchmark): restrict remote model code execution
...
Co-authored-by: liuyutong_bury<liuyutong25@huawei.com >
# message auto-generated for no-merge-commit merge:
!46978 merge codex/llm-remove-remote-code-master into master
fix(benchmark): restrict remote model code execution
Created-by: liuyutong_bury
Commit-by: liuyutong_bury
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
关联 Issue:Fixes #5082
https://gitcode.com/Ascend/pytorch/issues/5082
# 【修改方案】
1. 删除 Transformers 4.57.1 已原生支持模型的 `trust_remote_code=True`,避免默认执行模型仓自定义 Python 代码。
2. Baichuan2 保留架构所需能力,但改为默认关闭的 `--trust-remote-code` 显式开关;远程仓启用时必须通过 `--revision` 固定完整 commit hash,本地模型目录不强制 revision。
3. 删除 Mamba2 和 Qwen2VL 样例中的个人绝对模型路径,改为必填参数。
4. 更新 Baichuan2/GLM4 README,说明远程代码风险、可信来源要求以及原生 GLM4 模型要求。
5. 修复本次涉及文件的尾随空格和 EOF 换行问题。
# 【资料变更】
涉及。Baichuan2 README 新增远程代码执行风险声明与固定 revision 要求;GLM4 README 说明使用 Transformers 内置实现,不执行模型仓自定义代码。
# 【接口变更】
涉及命令行参数变更:
- Baichuan2 新增 `--trust-remote-code`,默认关闭。
- Baichuan2 新增 `--revision`;远程模型开启远程代码时必须提供完整的 40 位 commit hash。
- Mamba2 的 `--model_path` 和 Qwen2VL 的 `--model_name_or_path` 改为必填参数。
# 【功能验证】
- `transformers==4.57.1` 环境下完成 Mamba2、Qwen3、Qwen2VL、Llama3、GPT-OSS 原生配置/tokenizer/processor 加载 smoke 验证。
- Baichuan2 参数默认值验证为 `trust_remote_code=False`;远程路径开启开关但未提供固定 revision 时,会在模型加载前拒绝执行。
- 42 个分支相关 Python 文件通过 `py_compile`。
- 6 个 Baichuan2 启动脚本通过 `bash -n`。
- `git diff --check`、EOF 换行、尾随空格、Tab、120 字符行长及硬编码 `trust_remote_code=True` 扫描通过。
- 未执行完整模型训练,待 PR 流水线进一步验证。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46978
2026-09-24 17:02:27 +08:00
wzyly
a46bbee048
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!47044 merge cherry-pick-mr-47041-1790236119454-auto into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
资料目录整改
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!47044
2026-09-24 16:39:01 +08:00
zhangrunze13
8d0c308ae2
fix(dynamo): correct compiler initialization test expectations
...
Co-authored-by: zhangrunze<zhangrunze13@huawei.com >
# message auto-generated for no-merge-commit merge:
!46892 merge fix/compiler-test-expectations into master
fix(dynamo): correct compiler initialization test expectations
Created-by: zhangrunze13
Commit-by: zhangrunze
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/5056
# 【修改方案】
修复 `test/dynamo/test_compile_trigger.py` 中两项与当前实现不一致的 UT 预期:
1. 修正 Inductor 补丁检查的版本分支。 PyTorch <2.15 时,检查 `GraphLowering.codegen_with_cpp_wrapper` 和 `CacheBase.get_system` 来自 NPU 兼容层;≥2.15 时,检查初始化前后方法引用保持不变,确认保留上游实现。
2. 修正 `has_triton` 的 CPU 检测预期。 测试辅助函数增加 `include_cpu` 参数,覆盖默认排除 CPU、显式启用 CPU、缺少 CPU backend、缺少 Triton 包及 CPU/NPU 同时可用等场景。
本次仅调整测试,不修改生产实现。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
不涉及
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46892
2026-09-24 16:03:16 +08:00
pta-robot
7dfb77873a
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!47015 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-24 14:26:15.
See merge request: Ascend/pytorch!47015
2026-09-24 15:59:08 +08:00
chujinjin
75e76dc6c4
Lazy start release queue for aclop
...
Co-authored-by: chujinjin<chujinjin52@huawei.com >
# message auto-generated for no-merge-commit merge:
!46370 merge feat/release-queue-lazy-start into master
Lazy start release queue for aclop
Created-by: chujinjin
Commit-by: chujinjin
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [x] 重构优化
- [ ] 资料更新
# 【修改方案】
阶段一:Prepare
在 Repository::InitRepo() 中执行,只完成:
分配 ReleaseQueue buffer。
初始化 ReleaseQueue 读写下标。
保存 device_id。
将释放线程状态设置为 NOT_STARTED。
不创建释放线程。
建议本次仍在 Repository 初始化阶段分配 ReleaseQueue buffer,而不是将 buffer 也延迟到第一个 aclop,原因如下:
当前问题的核心是释放线程空转,而不是 buffer 内存占用。
可以保持内存分配失败发生在原来的初始化调用线程中。
避免首次 aclop 释放时在 TaskQueue consumer 线程中进行大块内存分配。
变更范围更小,便于验证和回退。
可将接口命名为 PrepareReleaseQueue(device_id);也可以保留 InitReleaseQueue(device_id) 名称,但需要明确其新语义不再包含线程创建。为降低理解成本,推荐使用前者。
阶段二:Start
第一次遇到 COMPILE_AND_EXECUTE 释放任务时调用 StartReleaseThreadIfNeeded():
检查释放线程是否已经启动。
设置 ReleaseQueue 运行状态。
创建释放线程。
创建成功后,将当前 aclop 任务放入 ReleaseQueue。
后续任务直接走原有 PushToReleaseQueue() 路径,不再按任务类型区分。
必须在创建线程之前设置 device_id。当前实现在线程创建后才给 device_idx 赋值,按需启动改造时应同时修正该初始化顺序,防止线程读取未初始化的设备号。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
1 纯 opapi
开启 TaskQueue,连续执行 opapi。
验证 ReleaseQueue worker 状态始终为 NOT_STARTED。
验证进程中没有新增 release_thread。
验证 customHandler 被正确销毁。
验证 ReleaseQueue 读写下标不发生变化。
验证 Repository 析构不执行无效 join。
2 首个 aclop
Repository 初始化后确认线程不存在。
执行首个 COMPILE_AND_EXECUTE。
验证只创建一个释放线程。
验证当前 aclop 进入 ReleaseQueue 并完成资源释放。
验证 worker 状态变为 RUNNING。
3 opapi -> aclop -> opapi
第一个 opapi 直接释放,不创建线程。
aclop 触发线程启动并异步释放。
第二个 opapi 必须进入 ReleaseQueue,而不是继续直接释放。
验证无资源泄漏和双重释放。
4 aclop -> opapi
首个 aclop 启动线程。
后续所有 opapi 均走原有 ReleaseQueue 路径。
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46370
2026-09-24 15:41:24 +08:00
bingli-2026
a8a5c51c5c
[docs][master] align symbolic_shapes API for issue #1615
...
Co-authored-by: bingli-2026<davis_ye@foxmail.com >
# message auto-generated for no-merge-commit merge:
!43369 merge issue1638-no9-docs-master into master
[docs][master] align symbolic_shapes API for issue #1615
Created-by: bingli-2026
Commit-by: bingli-2026
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区 issue,请关联 issue 链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部 issue 等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
关联 issue:[#1615 ](https://gitcode.com/Ascend/pytorch/issues/1615 )
# 【修改方案】
上游已将原生 API 文档从 `docs/zh/native_apis/` 迁移至 `docs/zh/api/native_api/`,因此本 PR 以 `master` 为目标分支。覆盖仍由当前 master 维护的 `2.7.1 / 2.11.0 / 2.12.0` 三个版本,仅更新 issue #1615 no.9 相关 API 在 `torch.fx` 文档中的支持信息,不涉及运行时代码修改。`2.9.0 / 2.10.0` 文档目录已由上游删除,因此不再保留对应条目。
修改文件:
- `docs/zh/api/native_api/pytorch_2-7-1/torch-fx-experimental-symbolic_shapes.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-fx-experimental-symbolic_shapes.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-fx-experimental-symbolic_shapes.md`
补充条目:
1. `torch.fx.experimental.symbolic_shapes.has_free_unbacked_symbols`
2. `torch.fx.experimental.symbolic_shapes.hint_int`
3. `torch.fx.experimental.symbolic_shapes.InnerTensorKey`
4. `torch.fx.experimental.symbolic_shapes.InnerTensorKey.get`
同时保留目标分支中已有的 `ShapeEnv` 及其方法条目。
# 【API 功能介绍】
1. `has_free_unbacked_symbols`
用于判断表达式中是否包含未绑定的 symbolic shape 符号。
2. `hint_int`
用于将 symbolic shape 相关值转换为整数提示值。
3. `InnerTensorKey`
用于描述内部张量属性访问 key。
4. `InnerTensorKey.get`
用于通过 key 获取对象上的对应内部属性。
# 【上游社区测试情况】
本 PR 为文档类变更,不新增执行型测试。对应功能的测试补充在独立代码 PR 的 `test/fx/test_symbolic_shapes_api.py` 中进行。
# 【完备性分析】
本次文档补充覆盖了 issue #1615 no.9 涉及的 4 个文档条目,并与目标分支当前已有的 `torch.fx symbolic_shapes` 相关条目一并整理,避免在合并最新目标分支后丢失已有文档信息。
# 【是否需要新增用例】
本 PR 不需要新增用例。
原因:
1. 当前 PR 仅为文档更新
2. 对应 API 的执行测试已在独立代码 PR 中补充
# 【资料变更】
涉及。
已在上述 3 个仍由当前 master 维护的文档文件中补齐 issue #1615 no.9 相关 API 的支持信息,并保留目标分支已有的 symbolic_shapes 文档条目。
# 【测试效果】
文档类变更,无运行时行为改动。
已完成检查:
- 文档条目名称与 API 全名一致
- 基于迁移后的 master 目录,未丢失已有 symbolic_shapes 相关条目
- 已同步覆盖 `2.7.1 / 2.11.0 / 2.12.0` 对应文档条目
- 仅修改 3 个目标文档文件,共 120 行新增、无删除
- GitCode 推送 Hook 通过
# 【测试日志】
文档 PR 不涉及独立运行日志;文档结构与链接由 docs CI 验证。
# 【接口变更】
不涉及。
# 【CheckList】
- [x] PR 仅修改 docs 路径
- [x] 未修改 `torch_npu/` 路径代码
- [x] 多个提交已 squash 为单提交
- [x] CI 执行通过
See merge request: Ascend/pytorch!43369
2026-09-24 14:25:17 +08:00
Jiayi_Meng
05dde3fec4
[test] verify NPU DTensor fixes for #179203 and #187933
...
Co-authored-by: Jiayi_Meng<mengjiayi5@huawei.com >
# message auto-generated for no-merge-commit merge:
!46841 merge test/dtensor-179203-187933 into master
[test] verify NPU DTensor fixes for #179203 and #187933
Created-by: Jiayi_Meng
Commit-by: Jiayi_Meng
Merged-by: ascend-robot
Description:
关联 Issue:[Ascend/pytorch#3815 ](https://gitcode.com/Ascend/pytorch/issues/3815 )
# 【合入来源】
- [x] 需求
- 补充社区 PR #179203 和 #187933 对应的 NPU DTensor 回归测试。
- [x] 问题单
- 关联 Issue:[Ascend/pytorch#3815 ](https://gitcode.com/Ascend/pytorch/issues/3815 )
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
- 在 `test/distributed/tensor/test_math_ops.py` 中:
- 增加 `Partial` 和 `SupportedDevices` 导入。
- 增加 `test_nll_loss_weighted_mean_with_even_target_counts`,覆盖输入分片、target/weight 副本场景下的加权 mean NLLLoss。
- 增加 `test_foreach_max_sharded`,校验分片 DTensor 执行 `torch._foreach_max` 后的 `Partial("max")` placement 及完整结果。
- 在 `test/distributed/_tensor/test_init.py` 中:
- 从 `torch.distributed.tensor` 导入 `linspace` 和 `logspace`。
- 增加 `test_linspace` 和 `test_logspace`,覆盖 `Replicate()` / `Shard(0)`、默认及显式 dtype、`steps=0/1`、逆序区间、DTensor 标量 start/end 及非法非标量输入。
- `linspace` 显式 dtype 保持 `torch.float64`。
- `logspace` 显式 dtype 使用 `torch.float32`,适配 `aclnnLogSpace` 不支持 `float64` 的限制。
# 【资料变更】
不涉及。
# 【接口变更】
不涉及。本 PR 仅补充测试用例。
# 【功能验证】






# 【CheckList】
> PR 提交人对以下 CheckList 自检项进行全量自检,自检通过或不涉及,均修改 `[ ]` 为 `[x]`。
- [x] 改动仅涉及两个目标测试文件,未引入构建产物或无关文件。
- [x] 新增多卡测试复用现有 NPU DTensor / HCCL 测试框架。
- [x] PR 标题使用 `test` 类型标签。
- [x] 已关联 Issue:[Ascend/pytorch#5037 ](https://gitcode.com/Ascend/pytorch/issues/5037 )。
- [x] 本地差异检查和目标测试验证通过。
- [ ] PR 持续集成流水线执行通过。
See merge request: Ascend/pytorch!46841
2026-09-24 11:33:56 +08:00
pta-robot
59c905b324
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46938 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-23 22:09:11.
See merge request: Ascend/pytorch!46938
2026-09-24 11:31:32 +08:00
yule100
bf146c69a5
[fix] fix _dynamo lazy loading broken by _npu_attention module import
...
Co-authored-by: yule100<chenyukun11@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46846 merge cp-fix-master into master
[fix] fix _dynamo lazy loading broken by _npu_attention module import
Created-by: yule100
Commit-by: yule100
Merged-by: ascend-robot
Description: <!--PR描述模板更新日期:20260203
-->
# 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
https://gitcode.com/Ascend/pytorch/issues/5047
# 【修改方案】
修复 `_npu_attention.py` 中 `_get_strategy_context` 在模块加载时触发 `_sharding_rules` import,破坏 `torch_npu` 懒加载机制的问题。
将版本兼容逻辑从模块顶层 `try/except` 改为延迟执行+缓存的 `_get_strategy_context_compat()` 函数,仅在 CP dispatcher enable 时首次调用,避免模块加载时的 import 副作用。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
功能
test/distributed/tensor/test_context_parallel_attention.py 验证结果见门禁pass
test/dynamo/test_compile_trigger.py 验证修改后失败用例pass
精度
不涉及
内存
不涉及
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46846
2026-09-24 10:56:49 +08:00
wyssss1245
d492746960
add the test file for UT in inductor
...
Co-authored-by: wyssss1245<wangyesheng1@huawei.com >
# message auto-generated for no-merge-commit merge:
!46799 merge master into master
add the test file for UT in inductor
Created-by: wyssss1245
Commit-by: wyssss1245
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
[#4911 ](https://gitcode.com/Ascend/pytorch/issues/4911 )
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
本次变更主要为 Ascend inductor 补充单元测试看护,新增一批基于 torch.compile(backend="inductor") 的算子与视图类测试用例,并通过统一的 runIfVersion(max="2.13") 版本门控约束执行范围。新增用例覆盖 wrap_triton/triton_op、广播、切片以及 cos、exp、floor、relu、sqrt、sub、where 等逐元素算子,均以标准实现结果与编译后结果对比的方式校验一致性;同时对已有的 test_overlap_scheduling_npu.py 逐用例补充版本门控,并在 torch_npu/_inductor/config.py 中做了一处空行删除的格式调整。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46799
2026-09-24 10:44:15 +08:00
ChenYangng
183da93e9f
add test case for dynamo compile cache
...
Co-authored-by: ChenYangng<chenyang348@huawei.com >
# message auto-generated for no-merge-commit merge:
!46669 merge master into master
add test case for dynamo compile cache
Created-by: ChenYangng
Commit-by: ChenYangng
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/5057
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
参考历史版本UT代码
在test/dynamo目录下补充:python test_package.py
在test/dynamo目录下补充:python test_precompile_context.py
在test/dynamo目录下补充:python test_guard_serialization.py
在test/_inductor目录下补充:python test_codecache.py
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
1. 自验证PASS,环境:
torch: 2.13.0+cpu
torch_npu: 2.13.0.rc1
cann: 9.1.0
2. CI流水线PASS
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46669
2026-09-24 09:57:19 +08:00
pta-robot
49fb6a91e9
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46927 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-23 22:03:43.
See merge request: Ascend/pytorch!46927
2026-09-23 22:50:02 +08:00
chenrayray
acc54de9be
【docs】删除未经测试验证的环境变量参考文档及上游对照条目
...
Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com >
# message auto-generated for no-merge-commit merge:
!46876 merge codex/remove-unverified-env-docs into master
【docs】删除未经测试验证的环境变量参考文档及上游对照条目
Created-by: chenrayray
Commit-by: Xinrui Chen
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
- [x] 资料更新
关联Issue:https://gitcode.com/Ascend/pytorch/issues/4691
# 【修改方案】
删除环境变量参考手册中尚未经过测试验证的配置条目,并同步维护导航和PyTorch上游对照表。
1. 核对指定的38项环境变量,删除master中仍存在的32个变量详情页;另外6项此前已移除。
2. 同步清理总列表、总目录和分类目录中的对应条目,移除已为空的分布式启动分类与DDP/RPC分组,更新分类说明。
3. 删除PyTorch环境变量对照表中的对应条目,并移除介绍中的具体数量,避免后续维护时同步计数。
此前已移除的6项:FX_SUBGRAPH_DUMP_PATH、INDUCTOR_ASCEND_DEBUG、INDUCTOR_ASCEND_FX_GRAPH_CACHE、NPU_INDUCTOR_DYNAMIC_FX_PASS、PARALLEL_SCHEDULER_NODES_MIN、TORCHINDUCTOR_ENABLE_LAYERNORM_V4。
# 【资料变更】
仅涉及docs/zh/api/environment_variable下40个Markdown文件:删除32个变量详情页及1个空分类目录,更新7个列表、导航及上游对照文件。其他文档中的描述保持原样。
# 【接口变更】
不涉及运行时代码、API或环境变量行为变更。
# 【功能验证】
- 确认32个目标详情页已删除,其余6项在基线中已不存在。
- 核对总列表、目录及上游对照表,目标变量条目无残留。
- 确认其他文档与基线1174a38d09一致,包括中英文日志说明、编译指南及飞行记录器说明。
- git diff 1174a38d09 HEAD --check通过。
- 未运行NPU功能测试或完整文档站点构建;远端CI待运行。
# 【CheckList】
- [x] PR标题使用docs类型标签
- [x] 修改范围限定为环境变量参考文档、导航和上游对照表
- [x] 文档差异格式检查通过
- [ ] PR持续集成流水线(CI)执行通过(待CI)
See merge request: Ascend/pytorch!46876
2026-09-23 17:00:37 +08:00
stonexxx
3257810d43
fix: remove config.simt_default_warp_stacksize
...
Co-authored-by: Stonexx<sheny1xuan@163.com >
# message auto-generated for no-merge-commit merge:
!46884 merge sync-pr46494-mainline-master into master
fix: remove config.simt_default_warp_stacksize
Created-by: stonexxx
Commit-by: Stonexx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
Fixes https://gitcode.com/Ascend/pytorch/issues/5045
同步来源:https://gitcode.com/Ascend/pytorch/merge_requests/46494
# 【修改方案】
1. 删除 `torch_npu/_inductor/config.py` 中固定为 8192 字节的 `simt_default_warp_stacksize` 配置。
2. 删除 `NPUCachingAutotuner._make_ttir_module_from_cfg` 和 `NPUCachingAutotuner._precompile_config` 在 `SIMT_ONLY` 模式下自动注入 `simt_stack_limit` 的逻辑,由 Triton 编译器或后端使用默认栈大小策略。
# 【资料变更】
不涉及。
# 【接口变更】
不涉及跨代码仓或客户可见接口变更。
# 【功能验证】
- `python3 -m py_compile torch_npu/_inductor/config.py torch_npu/_inductor/runtime/triton_heuristics.py`:通过。
- `git diff --check mainline/master...HEAD`:通过。
- 迁移提交与源提交的稳定 patch-id 均为 `495e5401e7d86ac029a774bf2a108054f2db9d5e`。
- NPU 功能验证与 CI 结果以 PR 流水线为准。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志(本次仅删除配置和选项注入逻辑,无新增注释或日志)
- [ ] 代码实现进行了返回值、空指针等校验(本次不涉及返回值或空指针处理)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46884
2026-09-23 16:51:46 +08:00
wzyly
6eefe6a721
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46895 merge master into master
modify document
Created-by: wzyly
Commit-by: wzyly;m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
产品名称修改
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46895
2026-09-23 16:35:42 +08:00
ascend-robot
f866aec5fd
docs: Add TensorProperties.create_from_tensor support to torch.distributed.checkpoint docs
...
Co-authored-by: ZY_yangyue<2070428417@qq.com >
# message auto-generated for no-merge-commit merge:
!44123 merge test-tensorproperties-docs into master
docs: Add TensorProperties.create_from_tensor support to torch.distributed.checkpoint docs
Created-by: ZY_yangyue
Commit-by: ZY_yangyue
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**https://gitcode.com/Ascend/pytorch/issues/3156 **</font>\\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [x] 资料更新
按检视意见:官方仅 2.13 有 `TensorProperties` 资料,**仅补齐 pytorch_2-13-0**;`create_from_tensor` 无独立官方锚点,链接指向 `TensorProperties`。
# 【修改方案】
仅在 `pytorch_2-13-0` 按嵌套方法格式补充 TensorProperties + create_from_tensor();✔/✘。
# 【资料变更】
> 涉及
# 【接口变更】
> 不涉及
# 【功能验证】
> A2 验证详见 issue #4207。
>
> 已补充 A5(Ascend 950)实机验证日志如下(完整说明见 issue #4207):
>
> ## 六、A5(Ascend 950)验证情况
>
> 已在 A5(Ascend950PR)单卡环境完成实机验证,结果通过。
>
> **环境信息**
> - Device type: npu
> - PyTorch version: 2.7.1+cpu
> - torch_npu version: 2.7.1.post4
> - Hardware: Ascend950PR_9579(Ascend 950 / A5)
> - NPU count: 1
>
> **验证命令**
> ```
> python verify_create_from_tensor.py -v TestCreateFromTensor
> ```
>
> **运行日志**
> ```
> test_create_from_cpu_and_npu_consistent (__main__.TestCreateFromTensor.test_create_from_cpu_and_npu_consistent) ... ok
> test_create_from_npu_float16 (__main__.TestCreateFromTensor.test_create_from_npu_float16) ... ok
> test_create_from_npu_float32 (__main__.TestCreateFromTensor.test_create_from_npu_float32) ... ok
> test_create_from_npu_int64 (__main__.TestCreateFromTensor.test_create_from_npu_int64) ... ok
> test_create_from_requires_grad (__main__.TestCreateFromTensor.test_create_from_requires_grad) ... ok
> test_used_in_tensor_storage_metadata (__main__.TestCreateFromTensor.test_used_in_tensor_storage_metadata) ... ok
> test_used_in_tensor_write_data (__main__.TestCreateFromTensor.test_used_in_tensor_write_data) ... ok
>
> ----------------------------------------------------------------------
> Ran 7 tests in 6.724s
>
> OK
> ```
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!44123
2026-09-23 15:23:02 +08:00
shi-yufeng99
4e1af97a7a
fix log issue
...
Co-authored-by: shi-bibibi99<shiyufeng8@huawei.com >
# message auto-generated for no-merge-commit merge:
!46789 merge 0922_master_log_branch1 into master
fix log issue
Created-by: shi-yufeng99
Commit-by: shi-bibibi99
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
[#3016 ](https://gitcode.com/Ascend/pytorch/issues/3016 )
添加log日志的占位符
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46789
2026-09-23 15:09:29 +08:00
gcw_8p1hhlB0
b9dc576f82
test(nn): add test for torch.nn.Module.bfloat16 and torch.nn.Module.apply
...
Co-authored-by: yangke<1723981822@qq.com >
# message auto-generated for no-merge-commit merge:
!45798 merge test-module-bfloat16-apply into master
test(nn): add test for torch.nn.Module.bfloat16 and torch.nn.Module.apply
Created-by: gcw_8p1hhlB0
Commit-by: yangke
Merged-by: ascend-robot
Description: # 【合入来源】
> <font color="red">**https://gitcode.com/Ascend/pytorch/issues/4608 **</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] issue/工单
pytorch 社区用例没有直接验证 torch.nn.Module.bfloat16 和 torch.nn.Module.apply 的用例,故新增该测试用例文件,用于验证这两个 API 在 NPU 上的正确性。
# 【修改方案】
一、API功能说明
```
1. torch.nn.Module.bfloat16
将模块所有浮点类型的参数和缓冲区原地(in-place)转换为 bfloat16 数据类型,
非浮点张量保持不变,返回 self。底层通过 _apply 递归处理所有子模块,
dtype 转换在张量所在设备上执行,属于涉及硬件的接口。
2. torch.nn.Module.apply
将 fn 递归地应用到自身及所有子模块(后序遍历:先递归 children 再 fn(self)),
返回 self。纯 Python 递归接口,典型用途为参数初始化、批量迁移设备。
```
二、测试文件 test_module_bfloat16_apply.py 完整验证该 API 的原因
```
社区用例检索情况(在 pytorch 官方仓库 test 目录按短关键词检索,覆盖
v2.7.1/v2.11.0/v2.12.0/v2.13.0,用例分布一致):
1. torch.nn.Module.bfloat16:test_nn.py 中 bfloat16 相关用例(如参数化生成的
*_bfloat16 前向计算用例)均验证算子在 bf16 dtype 下的前向行为,全 test
目录无直接验证 Module.bfloat16() 转换方法的用例,社区用例确实缺失,需要新增。
2. torch.nn.Module.apply:仅在其他用例中顺带使用(test_dynamo_distributed.py、
test_module_hooks.py、quantization 等),test_nn.py 的
test_module_apply_inplace_op 验证的是私有方法 _apply,社区无直接用例。
用例覆盖说明(按 API 功能一致标准覆盖全场景):
1. torch.nn.Module.bfloat16(该 API 无入参,按张量类型等价类划分):
test_bfloat16_casts_all_floating_point_params_and_buffers:fp32/fp64 参数与
fp32 缓冲区(含嵌套子模块)全部转为 bfloat16;
test_bfloat16_keeps_non_floating_point_tensors:int64 缓冲区保持不变;
test_bfloat16_returns_self_and_keeps_device:返回 self、设备不变;
test_bfloat16_module_without_floating_point_tensors:无浮点张量模块边界场景;
test_bfloat16_matches_cpu_result:NPU 侧与 CPU 侧转换结果一致性对比。
2. torch.nn.Module.apply(fn 为唯一入参):
test_apply_calls_fn_on_self_and_all_submodules:fn 对自身及全部子模块各调用一次;
test_apply_visits_submodules_before_parent:后序遍历顺序验证;
test_apply_returns_self:返回 self;
test_apply_moves_module_to_device:apply 批量迁移模块到设备的典型用法(张量运行在 NPU);
test_apply_raises_type_error_for_non_callable_fn:fn 不可调用的异常传参场景。
```
社区用例检索证据(pytorch 官方仓库 v2.7.1 test 目录实际 grep 输出):


三、NPU适配
```
本用例按规范在导入头文件后获取设备:
device_type = acc.type if (acc := torch.accelerator.current_accelerator()) else "cpu"
张量全部运行在 NPU 上(CPU 环境自动回退),无需对 API 本身做任何修改。
```
# 【资料变更】
不涉及
torch.nn.Module.bfloat16、torch.nn.Module.buffers 在 docs/zh/api/native_api 各版本目录中已有条目且无错误;
torch.nn.Module.add_module / torch.nn.Module.apply / torch.nn.Module.children 的错误“self仅支持fp32”限制说明已单独提交 PR 修正:[文档 PR 链接]
# 【接口变更】
不涉及
# 【功能验证】
验证结论:在 NPU 环境下(Atlas NPU 单卡,torch 2.10.0 + torch_npu 2.10.0,CANN 9.0.0),新增测试文件 10 个用例全部通过(TestModuleBFloat16 5 例 + TestModuleApply 5 例);torch.nn.Module.bfloat16 的 NPU 侧与 CPU 侧转换结果逐位一致(torch.equal 为 True);torch.nn.Module.apply 后序递归、设备迁移行为符合预期。验证结果表明两个 API 在 NPU 环境下功能正常,无需修改源码即可稳定适配 NPU 设备。
用例运行结果:


# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45798
2026-09-23 14:57:54 +08:00
pta-robot
d0e51ae045
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46862 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-22 22:04:51.
See merge request: Ascend/pytorch!46862
2026-09-23 14:47:20 +08:00
mortalzz
907d2b67d8
docs: add c10d and BlockMask API support status
...
Co-authored-by: mortalzz<2283012562@qq.com >
# message auto-generated for no-merge-commit merge:
!44275 merge docs-api-consistency-master into master
docs: add c10d and BlockMask API support status
Created-by: mortalzz
Commit-by: mortalzz
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单:https://gitcode.com/Ascend/pytorch/issues/3203 https://gitcode.com/Ascend/pytorch/issues/3251
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
## 一、API 功能
1. `torch.distributed.get_debug_level` 读取当前分布式调试级别,返回 `DebugLevel.OFF`、`INFO` 或 `DETAIL`。
2. `torch.nn.attention.flex_attention.BlockMask.BLOCK_SIZE` 保存 BlockMask 的 query/KV block size,支持整数及二元 tuple。
两者均不执行张量计算,目标属性或返回值本身不依赖具体加速设备。该结论仅针对 `BLOCK_SIZE` 成员,不扩大到 `BlockMask` 的其他计算方法。
## 二、资料范围
- `torch.distributed.get_debug_level` 按既有验视要求,只补充 `pytorch_2-13-0/torch-distributed.md`。
- 按最新验视意见,不新建 flex_attention 独立资料文件,直接在 2.7.1、2.11、2.12、2.13 四套已有 `torch-nn-attention.md` 的 `Submodules → torch.nn.attention.flex_attention → BlockMask` 类条目下补充 `BLOCK_SIZE`。
- 保留最新 master 的类说明、`kv_indices` 和 `shape` 内容及产品支持结论,删除空 `Utils` 章节及目录项,目录框与隐藏模块标题沿用此前已验视的格式。
- 全局菜单不增加 `torch.nn.attention.flex_attention` 子页面链接;四套首页和菜单仍将 `torch.nn.attention` 放在 `torch.nn.init` 后、`torch.onnx` 前,并与 `torch.nn` 同级。
- 五个新增条目的产品支持情况采用当前统一的三项列表格式;非计算类目标条目不声明 fp32 等 dtype 限制。
其余任务目标 `_warn_not_in_group`、`_tensor_to_object` 和 `_world.tags_to_pg.setdefault` 是 `distributed_c10d` 私有实现接口,按照 API 一致性资料规范不新增用户资料。
# 【资料变更】
涉及,共修改 10 个文件:
- 四套 `torch-nn-attention.md`:直接补充 `BLOCK_SIZE`,删除空 `Utils`,保留原有成员及支持信息;
- 四套版本首页:补充与 `torch.nn` 同级的 attention 导航入口;
- 全局菜单:仅调整四个已有 attention 入口的位置,无 flex_attention 子项;
- 仅 `pytorch_2-13-0/torch-distributed.md`:补充 `torch.distributed.get_debug_level`。
本 PR 不新增 `torch-nn-attention-flex_attention.md` 文件;之前方案中的四个独立文件已移除,内容合回原 attention 文件。
# 【接口变更】
无客户可见接口变更。仅更新资料,不修改 API 定义、参数、返回值或运行行为。
# 【功能验证】
本轮更新到 master 基线 `0095e028c54ccd86e83dcf3e9acccfca147e6084`。以该基线核对原有类、`kv_indices`、`shape` 内容;除新增 `BLOCK_SIZE` 和此前目录格式调整外,attention 原有资料保持不变。
执行资料位置、独立文件清理、菜单子链接清理、HTML 闭合、原有成员一致性、导航顺序和同级关系检查:
```text
$ python3 /workspace/pr44275_inline_check.py
pytorch_2-7-1 file=torch-nn-attention.md div=7/7 block_size=1 separate_file=0 flex_menu=0 empty_utils=0 baseline_members=PASS shape_preserved=PASS attention_order=init>attention>onnx same_level_as_nn=PASS
pytorch_2-11-0 file=torch-nn-attention.md div=7/7 block_size=1 separate_file=0 flex_menu=0 empty_utils=0 baseline_members=PASS shape_preserved=PASS attention_order=init>attention>onnx same_level_as_nn=PASS
pytorch_2-12-0 file=torch-nn-attention.md div=7/7 block_size=1 separate_file=0 flex_menu=0 empty_utils=0 baseline_members=PASS shape_preserved=PASS attention_order=init>attention>onnx same_level_as_nn=PASS
pytorch_2-13-0 file=torch-nn-attention.md div=7/7 block_size=1 separate_file=0 flex_menu=0 empty_utils=0 baseline_members=PASS shape_preserved=PASS attention_order=init>attention>onnx same_level_as_nn=PASS
get_debug_level=2.13-only distributed_unchanged=PASS diff_check_exit=0
INLINE_VALIDATION=PASS
```
运行四套 attention 资料与全局菜单的 Markdown 检查,长行和内嵌 HTML 按资料惯例排除:
```shell
npx --yes markdownlint-cli@0.31 .1 --disable MD013 MD033 -- \
docs/zh/api/native_api/_menu_pt_native_apis.md \
docs/zh/api/native_api/pytorch_2-7-1/torch-nn-attention.md \
docs/zh/api/native_api/pytorch_2-11-0/torch-nn-attention.md \
docs/zh/api/native_api/pytorch_2-12-0/torch-nn-attention.md \
docs/zh/api/native_api/pytorch_2-13-0/torch-nn-attention.md
```
```text
markdownlint_exit=0
```
本轮只调整资料组织,没有重新执行 NPU 功能测试,也没有修改既有 HCCL 链接;以下 A5 实测日志保持原样。
## Ascend 950DT/A5 功能验证
验证设备:`npu-smi: Ascend950PR`;`torch.npu.get_device_name(0): Ascend950PR_9579`(A5 系列)。
基础环境:Ubuntu 22.04.5 LTS,x86_64,CANN 9.1.0(Ascend 950 ops 9.1.0),驱动 25.7.rc1.6。
验证环境:
| 版本 | Python | torch | torch-npu |
| --- | --- | --- | --- |
| 2.7.1 | `3.10.12` | `2.7.1+cpu` | `2.7.1.post8` |
| 2.11.0 | `3.10.12` | `2.11.0+cpu` | `2.11.0` |
| 2.12.0 | `3.10.12` | `2.12.0+cpu` | `2.12.0` |
| 2.13.0/master | `3.10.12` | `2.13.0+cpu` | `2.13.0.rc1` |
`BlockMask.BLOCK_SIZE` 在四个版本分别覆盖:
```text
32, 64, 128, 256, (32, 64), (64, 32)
```
每个版本均为 6/6 通过,生成的 BlockMask 元数据设备为 `npu:0`,退出码为 0。
`torch.distributed.get_debug_level` 在 2.13.0/master 环境覆盖 `OFF`、`INFO`、`DETAIL`,3/3 通过,退出码为 0。
关键 shell 输出:
```text
Mon Aug 31 23:14:22 UTC 2026
Linux 0d64624701f5 6.6.0-132.0.0.111.oe2403sp3.x86_64 #1 SMP Mon Dec 29 23:07:38 CST 2025 x86_64 x86_64 x86_64 GNU/Linux
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6 Version: 25.7.rc1.6 |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name | Health | Power(W) Temp(C) Hugepages-Usage(page) |
| | | Bus-Id | NPU Util(%) Memory-Usage(MB) HBM-Usage(MB) |
+========+==================+===============+=====================================================+
| 0 | Ascend950PR | OK | 208.7 64 0 / 0 |
| | | 0000:0E:00.0 | 0 0 / 0 5239 / 131072 |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID | Process id | Process name | Process memory(MB) |
+===========================+===============+=====================================================+
| No running processes found in NPU 0 |
+===========================+===============+=====================================================+
exit_code=0
```
PyTorch 2.7.1 / TorchNPU 2.7.1.post8:
```text
[W831 23:14:58.313951813 ArgSortKernelNpuOpApi.cpp:41] Warning: Warning: kernel [ArgSort] can not support dtype int32 or int64 on AiCore, Now this kernel is running on AiCpu.If you are more concerned about high-performance execution,please cast dtype to float32. (function operator())
python_executable=/workspace/pr44275-a5/venvs/2.7.1/bin/python
python=3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0]
torch=2.7.1+cpu
torch_npu=2.7.1.post8
device_name=Ascend950PR_9579
PASS BLOCK_SIZE=32 actual=(32, 32) metadata_device=npu:0
PASS BLOCK_SIZE=64 actual=(64, 64) metadata_device=npu:0
PASS BLOCK_SIZE=128 actual=(128, 128) metadata_device=npu:0
PASS BLOCK_SIZE=256 actual=(256, 256) metadata_device=npu:0
PASS BLOCK_SIZE=(32, 64) actual=(32, 64) metadata_device=npu:0
PASS BLOCK_SIZE=(64, 32) actual=(64, 32) metadata_device=npu:0
A5_BLOCK_SIZE_VALIDATION=PASS
exit_code=0
```
PyTorch 2.11.0 / TorchNPU 2.11.0:
```text
[W831 23:15:05.599524074 ArgSortKernelNpuOpApi.cpp:41] Warning: Warning: kernel [ArgSort] can not support dtype int32 or int64 on AiCore, Now this kernel is running on AiCpu.If you are more concerned about high-performance execution,please cast dtype to float32. (function operator())
python_executable=/workspace/pr44275-a5/venvs/2.11.0/bin/python
python=3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0]
torch=2.11.0+cpu
torch_npu=2.11.0
device_name=Ascend950PR_9579
PASS BLOCK_SIZE=32 actual=(32, 32) metadata_device=npu:0
PASS BLOCK_SIZE=64 actual=(64, 64) metadata_device=npu:0
PASS BLOCK_SIZE=128 actual=(128, 128) metadata_device=npu:0
PASS BLOCK_SIZE=256 actual=(256, 256) metadata_device=npu:0
PASS BLOCK_SIZE=(32, 64) actual=(32, 64) metadata_device=npu:0
PASS BLOCK_SIZE=(64, 32) actual=(64, 32) metadata_device=npu:0
A5_BLOCK_SIZE_VALIDATION=PASS
exit_code=0
```
PyTorch 2.12.0 / TorchNPU 2.12.0:
```text
[W831 23:15:12.936125344 ArgSortKernelNpuOpApi.cpp:41] Warning: Warning: kernel [ArgSort] can not support dtype int32 or int64 on AiCore, Now this kernel is running on AiCpu.If you are more concerned about high-performance execution,please cast dtype to float32. (function operator())
python_executable=/workspace/pr44275-a5/venvs/2.12.0/bin/python
python=3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0]
torch=2.12.0+cpu
torch_npu=2.12.0
device_name=Ascend950PR_9579
PASS BLOCK_SIZE=32 actual=(32, 32) metadata_device=npu:0
PASS BLOCK_SIZE=64 actual=(64, 64) metadata_device=npu:0
PASS BLOCK_SIZE=128 actual=(128, 128) metadata_device=npu:0
PASS BLOCK_SIZE=256 actual=(256, 256) metadata_device=npu:0
PASS BLOCK_SIZE=(32, 64) actual=(32, 64) metadata_device=npu:0
PASS BLOCK_SIZE=(64, 32) actual=(64, 32) metadata_device=npu:0
A5_BLOCK_SIZE_VALIDATION=PASS
exit_code=0
```
PyTorch 2.13.0 / TorchNPU 2.13.0rc1:
```text
[W831 23:15:18.380811630 ArgSortKernelNpuOpApi.cpp:45] Warning: Warning: kernel [ArgSort] can not support dtype int32 or int64 on AiCore, Now this kernel is running on AiCpu.If you are more concerned about high-performance execution,please cast dtype to float32. (function operator())
python_executable=/workspace/pr44275-a5/venvs/2.13.0/bin/python
python=3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0]
torch=2.13.0+cpu
torch_npu=2.13.0.rc1
device_name=Ascend950PR_9579
PASS BLOCK_SIZE=32 actual=(32, 32) metadata_device=npu:0
PASS BLOCK_SIZE=64 actual=(64, 64) metadata_device=npu:0
PASS BLOCK_SIZE=128 actual=(128, 128) metadata_device=npu:0
PASS BLOCK_SIZE=256 actual=(256, 256) metadata_device=npu:0
PASS BLOCK_SIZE=(32, 64) actual=(32, 64) metadata_device=npu:0
PASS BLOCK_SIZE=(64, 32) actual=(64, 32) metadata_device=npu:0
A5_BLOCK_SIZE_VALIDATION=PASS
exit_code=0
```
PyTorch 2.13.0 / `torch.distributed.get_debug_level`:
```text
python_executable=/workspace/pr44275-a5/venvs/2.13.0/bin/python
python=3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0]
torch=2.13.0+cpu
torch_npu=2.13.0.rc1
device_name=Ascend950PR_9579
PASS requested=DebugLevel.OFF actual=DebugLevel.OFF
PASS requested=DebugLevel.INFO actual=DebugLevel.INFO
PASS requested=DebugLevel.DETAIL actual=DebugLevel.DETAIL
A5_GET_DEBUG_LEVEL_VALIDATION=PASS
exit_code=0
```
结论:上述 API 已在 Ascend 950DT/A5 系列环境完成验证,资料中的 Ascend 950DT 支持标记有实际日志依据。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] 资料范围、目录格式、标签闭合和导航检查通过
See merge request: Ascend/pytorch!44275
2026-09-23 14:06:06 +08:00
pta-robot
2375dde092
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46885 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-23 11:47:42.
See merge request: Ascend/pytorch!46885
2026-09-23 12:37:12 +08:00
baoxuebin_2026
093b79c49b
docs: update autograd api support status
...
Co-authored-by: baoxuebin_2026<xuebin@isrc.iscas.ac.cn >
# message auto-generated for no-merge-commit merge:
!41987 merge codex/autograd-profiler-apis-docs-v271 into master
docs: update autograd api support status
Created-by: baoxuebin_2026
Commit-by: baoxuebin_2026
Merged-by: ascend-robot
Description: # 【合入来源】
[#2933 ](https://gitcode.com/Ascend/pytorch/issues/2933 )
[#2961 ](https://gitcode.com/Ascend/pytorch/issues/2961 )
[#2898 ](https://gitcode.com/Ascend/pytorch/issues/2898 )
[#2976 ](https://gitcode.com/Ascend/pytorch/issues/2976 )
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
公开issue:
- `torch.classes.torchvision.GPUDecoder`:https://gitcode.com/Ascend/pytorch/issues/2976
- `torch.autograd.profiler.EnforceUnique`:https://gitcode.com/Ascend/pytorch/issues/2961
- `torch.autograd.profiler_util.MemRecordsAcc.in_interval`:https://gitcode.com/Ascend/pytorch/issues/2898
补充说明:
`torch.autograd.Variable._execution_engine.run_backward` 属于 PyTorch autograd execution engine 的私有接口,代码 PR 中已补充测试覆盖;按照私有接口资料处理规则,本资料 PR 不新增该接口的 native_apis 条目。
`torch.classes.torchvision.GPUDecoder` 经验证在当前 Ascend/aarch64 环境下无法完成 torchvision custom class 注册,已单独补充 issue 进行说明,详见:https://gitcode.com/Ascend/pytorch/issues/3430。本资料 PR 中按验证结论将该 API 支持状态标记为“否”。
# 【修改方案】
1. API 功能说明:
- `torch.classes.torchvision.GPUDecoder`:torchvision 通过 C++ custom class 注册的 GPU video decoder 类,依赖 torchvision GPU decoder 扩展。
- `torch.autograd.profiler.EnforceUnique`:profiler 内部用于校验 key 唯一性的辅助类,重复 key 会抛出异常。
- `torch.autograd.profiler_util.MemRecordsAcc.in_interval`:profiler memory records 的区间筛选接口,用于返回指定时间范围内的 memory record。
2. 上游资料和用例检查情况:
检索 PyTorch / Torch-NPU 现有资料和测试后,未找到以上 API 在 Torch-NPU native_apis 资料中的完整支持状态记录,因此补充资料条目。
3. API 支持状态:
- `torch.autograd.profiler.EnforceUnique`:是
- `torch.autograd.profiler_util.MemRecordsAcc.in_interval`:是
- `torch.classes.torchvision.GPUDecoder`:否
4. 不支持 API 验证过程:
- 在当前 Ascend/aarch64 环境中补装并验证 `torchvision==0.24.0`
- 检查 torchvision 已安装,但当前环境未提供 `gpu_decoder.so` 对应扩展
- 调用 `torch.classes.torchvision.GPUDecoder` 时无法完成 custom class 注册,报错提示 `torchvision.GPUDecoder` 不存在
- 该接口依赖 torchvision GPU decoder 扩展,当前 Ascend NPU 环境无法提供等价注册能力,因此资料中标记为“不支持”
- 已针对该不支持结论补充公开 issue:[#3430 ](https://gitcode.com/Ascend/pytorch/issues/3430 )
5. 文档修改范围:
- `docs/zh/api/native_api/pytorch_2-7-1/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-7-1/torch.md`
- `docs/zh/api/native_api/pytorch_2-9-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-9-0/torch.md`
- `docs/zh/api/native_api/pytorch_2-10-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-10-0/torch.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch.md`
# 【资料变更】
涉及。补充 `torch.autograd` profiler 相关 API 支持状态,并补充 `torch.classes.torchvision.GPUDecoder` 不支持状态。
# 【接口变更】
不涉及。未修改跨仓接口,也未修改用户可见接口行为。
# 【功能验证】
测试环境一:
```text
NPU: Ascend 910B2C
torch: 2.9.0
torch_npu: 2.9.0rc1
CANN: 8.5.0
```
测试环境二:
```text
硬件:Ascend950PR_9579(A5)
Python:3.12.13
torch:2.12.0+cu130
torch_npu:2.12.0
CANN:9.1.0
系统:Linux 6.6.0-132.0.0.111.oe2403sp3.x86_64
```
支持 API 验证结果:
```text
test_enforce_unique_raises_on_duplicate_key ... ok
test_mem_records_acc_filters_records_in_interval ... ok
Ran 2 tests in 0.035s
OK
A5日志为:
PASS torch.autograd.profiler.EnforceUnique
PASS torch.autograd.profiler_util.MemRecordsAcc.in_interval
```
不支持 API 验证结果:
```text
GPUDecoder error: RuntimeError Tried to instantiate class 'torchvision.GPUDecoder', but it does not exist! Ensure that it is registered via torch::class_
```
See merge request: Ascend/pytorch!41987
2026-09-23 12:27:09 +08:00
Zky0803
965a1aa314
docs: add support status for torch.serialization.add_safe_globals
...
Co-authored-by: Zky0803<kyzhang0803@163.com >
# message auto-generated for no-merge-commit merge:
!44457 merge pr/add-safe-globals-doc-master into master
docs: add support status for torch.serialization.add_safe_globals
Created-by: Zky0803
Commit-by: Zky0803
Merged-by: ascend-robot
Description: # 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
- 来源任务 Issue:[【社区任务】7月社区任务第四期-Ascend for PyTorch API 一致性开发(59)](https://gitcode.com/Ascend/pytorch/issues/3541 )
- 结果 Issue:[torch.serialization.add_safe_globals API 一致性补齐](https://gitcode.com/Ascend/pytorch/issues/3625 )
- 资料 PR:[PR #44457 ](https://gitcode.com/Ascend/pytorch/pull/44457 )
# 【分支范围】
本资料 PR 面向 `master` 目标分支。
资料分支:
```text
源分支:pr/add-safe-globals-doc-master
目标分支:master
基线提交:11babe251d06e1bbe07567f4e35d5f07c1ff2cbf
Commit:364be8f9f01b04c87f28b1cf3a5ff1885d789d9c
提交标题:docs(api): add torch.serialization.add_safe_globals support info
```
# 【修改方案】
补充 `torch.serialization.add_safe_globals` Native API 支持资料,不修改 API 实现、测试逻辑或 NPU Kernel。
根据最新 reviewer 意见,本轮已完成:
1. 删除 4 个新增 `serialization-semantics.md`;
2. 撤销 4 个 `PyTorch-2-x-x.md` 中新增的 `Serialization semantics` 导航;
3. 撤销 `_menu_pt_native_apis.md` 中新增的对应导航;
4. 将目标 API 调整至 4 个现有 `torch.md` 的 `Serialization` 区域;
5. 按 reviewer 建议将产品支持信息改为“产品支持情况”列表;
6. A2、A3、A5 独立实机验证结果均为 PASS。
最终仅修改:
```text
docs/zh/api/native_api/pytorch_2-7-1/torch.md
docs/zh/api/native_api/pytorch_2-11-0/torch.md
docs/zh/api/native_api/pytorch_2-12-0/torch.md
docs/zh/api/native_api/pytorch_2-13-0/torch.md
```
目标 API 条目采用:
```markdown
### torch.serialization.add_safe_globals
<div style="margin-left: 2em">
**原生文档**:[torch.serialization.add_safe_globals](对应版本官方链接)
**产品支持情况**:
- <term>Atlas A2 训练系列产品</term>:支持
- <term>Atlas A3 训练系列产品</term>:支持
- <term>Ascend 950DT</term>:支持
</div>
```
# 【社区用例检索与新增必要性】
PyTorch 社区已有:
```text
test/test_serialization.py
TestSubclassSerialization.test_safe_globals_for_weights_only
```
直接测试覆盖:
```text
add_safe_globals
get_safe_globals
clear_safe_globals
torch.save
torch.load(..., weights_only=True)
```
目标 API 仅维护 Python safe-global allowlist,不调用 NPU Kernel。
任务分类:
```text
有用例且无需 NPU 适配
```
无需新增 API 实现、NPU Kernel、Torch-NPU 专项测试或 `test_upstream` patch。
# 【资料变更】
涉及。
最终资料侧仅修改 4 个现有 `torch.md`。
不再新增:
```text
serialization-semantics.md
```
不再修改:
```text
docs/zh/api/native_api/_menu_pt_native_apis.md
docs/zh/api/native_api/pytorch_2-7-1/PyTorch-2-7-1.md
docs/zh/api/native_api/pytorch_2-11-0/PyTorch-2-11-0.md
docs/zh/api/native_api/pytorch_2-12-0/PyTorch-2-12-0.md
docs/zh/api/native_api/pytorch_2-13-0/PyTorch-2-13-0.md
```
# 【接口变更】
不涉及。
本 PR 仅更新 Native API 支持资料,不修改:
- Python API 实现;
- 函数签名或返回类型;
- Torch-NPU C++ 代码;
- NPU Kernel;
- 组件间接口。
# 【功能验证】
## A2
```text
validation_label=A2
npu_device_name=Ascend910B3
npu_device_count=1
v2.7.1=PASS
v2.11.0=PASS
v2.12.0=PASS
master=REFERENCE_PASS_2.12_RUNTIME
A2_NPU_TENSOR=PASS
A2_HARDWARE_VALIDATION=PASS
RESULT: ADD_SAFE_GLOBALS_A2_VALIDATION_PASS
```
## A3
```text
validation_label=A3
npu_device_name=Ascend910_9382
npu_device_count=2
v2.7.1=PASS
v2.11.0=PASS
v2.12.0=PASS
master=REFERENCE_PASS_2.12_RUNTIME
A3_NPU_TENSOR=PASS
A3_HARDWARE_VALIDATION=PASS
RESULT: ADD_SAFE_GLOBALS_A3_VALIDATION_PASS
```
## A5
```text
validation_label=A5
NPU Name=Ascend950PR
npu_device_name=Ascend950PR_9579
npu_device_count=1
v2.7.1=PASS
v2.11.0=PASS
v2.12.0=PASS
master=REFERENCE_PASS_2.12_RUNTIME
A5_NPU_TENSOR=PASS
A5_HARDWARE_VALIDATION=PASS
RESULT: ADD_SAFE_GLOBALS_A5_VALIDATION_PASS
```
三阶段均使用真实 `npu:0` Tensor。
`master` 统一记录:
```text
runtime_status=REFERENCE_PASS_2.12_RUNTIME
runtime_scope=not exact master-wheel runtime validation
```
Reviewer 修复与 Git 校验:
```text
STANDALONE_SERIALIZATION_PAGE=REMOVED
LANDING_PAGE_SERIALIZATION_NAV=REMOVED
MENU_SERIALIZATION_NAV=REMOVED
TORCH_MD_API_ENTRY=PASS
PRODUCT_SUPPORT_FORMAT=PASS
commit=364be8f9f01b04c87f28b1cf3a5ff1885d789d9c
commit_count=1
changed_files_count=4
diff_check_rc=0
push_exit_code=0
remote_sha=364be8f9f01b04c87f28b1cf3a5ff1885d789d9c
REMOTE_SHA_MATCH=PASS
RESULT: ADD_SAFE_GLOBALS_FINAL_REVIEW_FIX_PASS
```
最新 force-push 后 PR 三个标签:
```text
YES
YES
YES
PR_THREE_LABELS_ALL_YES=PASS
```
# 【test_upstream patch】
不涉及。
本资料 PR 不修改 PyTorch 官方测试文件,也不修改 Torch-NPU `test_upstream` patch。
# 【CheckList】
- [x] 仅修改 Native API 资料文件
- [x] 社区已有直接测试
- [x] 无需 NPU 适配
- [x] A2 独立实机验证 PASS
- [x] A3 独立实机验证 PASS
- [x] A5 独立实机验证 PASS
- [x] 三阶段均验证真实 `npu:0` Tensor
- [x] 删除 4 个独立 `serialization-semantics.md`
- [x] 删除新增 `Serialization semantics` 导航
- [x] 目标 API 已放入 4 个现有 `torch.md`
- [x] 产品支持格式按 reviewer 建议调整
- [x] Atlas A2 训练系列产品:支持
- [x] Atlas A3 训练系列产品:支持
- [x] Ascend 950DT:支持
- [x] 最终 diff 精确为 4 个 `torch.md`
- [x] `git diff --check` 通过
- [x] PR 保持单提交
- [x] 本地与远端 SHA 一致
- [x] 本次 force-push 后 PR 三个标签重新确认全部为 `YES`
See merge request: Ascend/pytorch!44457
2026-09-23 12:09:54 +08:00
xuyun15
1174a38d09
[security] update 'Third_Party_Open_Source_Software_Notice'
...
Co-authored-by: xuyun15<xuyun15@huawei.com >
# message auto-generated for no-merge-commit merge:
!46848 merge update_master_open_source_software_notice into master
[security] update 'Third_Party_Open_Source_Software_Notice'
Created-by: xuyun15
Commit-by: xuyun15
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
更新'Third_Party_Open_Source_Software_Notice'
2.6 -> 2.14
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
NA
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46848
2026-09-23 11:32:03 +08:00
c_34
0296ffac1f
feat: integrate fxrt as in-tree subpackage of torch_npu build and wheel
...
Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com >
# message auto-generated for no-merge-commit merge:
!45813 merge fxrt-src into master
feat: integrate fxrt as in-tree subpackage of torch_npu build and wheel
Created-by: c_34
Commit-by: chenhaozhe
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/4733
- [ ] 重构优化
- [ ] 资料更新
## 目的
将 fxrt(FX 图运行时)以源码方式合入 torch_npu,随 torch_npu 一起编译打包,用户安装 torch_npu 后即可直接使用,无需单独安装 fxrt。
### 概述
将 FX 图运行时 fxrt 放入 `fxrt/` 目录,随 torch_npu 一起构建,以 `torch_npu.fxrt` 子包的形式发布,不再单独发包。
diff 主体是 `fxrt/` 下的源码。对 torch_npu 已有代码的改动为 19 个文件、约 270 行,其中约 200 行是新增测试。
### 对 torch_npu 的影响
- `import torch_npu` 不加载 fxrt,行为不变;fxrt 在 `import torch_npu.fxrt` 时才加载。
- 导入 fxrt 不改动 inductor,需显式调用 `torch_npu.fxrt.register_fx_wrapper()` 才会接管。
- C++ 接口唯一改动:导出 `npu_logging::Logger`。
- `--disable_fxrt` 可构建不含 fxrt 的 wheel。
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
**构建接入**(沿用 torchair 方式)
- `setup.py`:检测到 `fxrt/fxrt` 时传入 `BUILD_FXRT`、`FXRT_INSTALL_DST`、`FXRT_TARGET_PYTHON`;package_data` 增加 fxrt 的 `.so`。fxrt 暂不提供 C++ 接口,wheel 中不含 fxrt 头文件。
- `CMakeLists.txt`:在 `torch_npu` target 之后 `add_subdirectory(fxrt/fxrt)`。
- `ci/build.sh`:新增 `--disable_fxrt`。
fxrt 的依赖(ACL/HCCL stub、nlohmann、DVM)均复用仓库内已有内容,构建时不下载,也不依赖 CANN 安装。fxrt 库的 RPATH 包含 `torch_npu/lib`,auditwheel 可在 wheel 内解析 `libtorch_npu.so` 及其依赖。
**日志**
- `torch_npu/_logging/_internal.py`:注册 `fxrt` 日志别名,`TORCH_NPU_LOGS=+fxrt` 控制 fxrt 的 C++ 和 Python 日志。
- `torch_npu/csrc/logging/Logger.h`:`Logger` 加 `TORCH_NPU_API`。torch_npu 以 `-fvisibility=hidden` 编译,fxrt 调用 `Logger` 成员函数需要导出符号,实现不变。
- `TORCH_NPU_LOGS.md`:模块表增加 `fxrt`。
**构建依赖**
- nanobind 仅构建时需要(静态链接,运行时不依赖),加入 `requirements*-build.txt`、`.ci/docker/requirements-builder.txt`(`==2.13.0`)、`ci/docker` 的 Dockerfile 和源码构建指南。
**测试与门禁**
- 新增 `test/fxrt`(7 个用例,fxrt 未构建时跳过):fxrt 后端编译运行;`import torch_npu` / `import torch_npu.fxrt` 无副作用;`register_fx_wrapper()` 注册行为。
- `test/npu/test_public_bindings.py`:模块名检查跳过 `torch_npu.fxrt`。fxrt 以顶层包名 `fxrt` 执行,对象的 `__module__` 为 `fxrt.*`;导入检查不跳过。
- `.lintrunner.toml`:fxrt C++ 源码纳入 clang-format 检查。
- `tools/linter/dictionary.txt`:增加 `hax`(fxrt 哈希实现中的变量名)。
详见RFC issue
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
当前版本不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
新增demo特性,不涉及历史接口版本变更,demo特性已进行隔离,默认不开启。
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
当前作为demo能力,默认不主动使能的情况下,要求不修改任何pytorch_npu已有逻辑和行为。
主要验证:
1. 构建打包安装行为不影响torch-npu的包。
2. 不主动使能情况下,原有torch-npu行为不受fxrt任何影响。
关于新增依赖的缺陷扫描,主要新增一个nanobind作为构建过程中的python依赖,扫描结果如下,引入依赖版本无安全缺陷报告:

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45813
2026-09-23 11:17:05 +08:00
pta-robot
dcff953b93
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46871 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-23 10:07:00.
See merge request: Ascend/pytorch!46871
2026-09-23 10:51:51 +08:00
chenrayray
e67aafef1f
【docs】完善快速入门迁移步骤与训练日志
...
Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com >
# message auto-generated for no-merge-commit merge:
!46810 merge codex/improve-quick-start into master
【docs】完善快速入门迁移步骤与训练日志
Created-by: chenrayray
Commit-by: Xinrui Chen
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
- [x] 资料更新
关联Issue:https://gitcode.com/Ascend/pytorch/issues/5032
# 【修改方案】
快速入门示例缺少loss输出,GradScaler定义缺少新增标记,AMP循环分段修改容易漏改。本次让用户按明确步骤修改并观察训练进度。
1. 补齐scaler的diff新增标记,将AMP循环改为可直接替换的完整代码,并解释autocast和GradScaler的作用。
2. 每100个batch及每轮最后一个batch打印轮次、步数和loss;补充保存完成提示,检查点轮数引用epochs,移除无用导入及计时代码。
3. 明确导入位置、diff标记及自动迁移中cuda:0的含义,补充MNIST下载与离线准备说明。
4. 环境准备精简为安装链接和必要提示;保留最新master的硬件条件标记、AMP适用范围及安装与进阶文档链接。
5. 增加示意日志、一轮训练体验建议和成功判断,区分训练流程跑通与模型效果评估。
# 【资料变更】
仅修改docs/zh/user_guide/quick_start.md。
# 【接口变更】
不涉及。
# 【功能验证】
- 原始脚本、自动迁移脚本及替换后的AMP脚本通过Python AST语法检查。
- 本地相对链接有效,scaler新增标记及硬件条件标记检查通过。
- git diff --check通过。
- 本次为文档变更,未新增UT;未执行NPU实机训练或文档站点构建。日志数值为示意。
- 远端CI结果待确认。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志(不涉及运行时代码)
- [x] 代码实现进行了返回值、空指针等校验(不涉及运行时代码)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(待CI)
See merge request: Ascend/pytorch!46810
2026-09-23 10:29:03 +08:00
wzyly
dad662d2ca
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46808 merge master into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
产品名称改名
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46808
2026-09-23 09:27:55 +08:00
ascend-robot
78d9a24103
[Dynamo] remove Stream/Event in-graph class patch
...
Co-authored-by: gcw_3ffySSwy<1305321851@qq.com >
# message auto-generated for no-merge-commit merge:
!45086 merge stream-event-patch-removal into master
[Dynamo] remove Stream/Event in-graph class patch
Created-by: gcw_3ffySSwy
Commit-by: gcw_3ffySSwy
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单 #3634
- [x] 重构优化
- [ ] 资料更新
# 【修改方案】
依赖 PyTorch PR #194343,已以 `fd3274468a3` 合入 `pytorch/main`:
https://github.com/pytorch/pytorch/pull/194343 。
PyTorch Dynamo 将从已注册的具体 `DeviceInterface` 收集合法的
`Stream` / `Event` 子类,并在后端晚注册时清理
`_in_graph_classes()` 缓存。因此 torch_npu 在真正包含该上游能力的
PyTorch 2.14 运行时中,不再需要全局替换
`UserDefinedClassVariable._in_graph_classes()`。
本 PR:
1. 将旧 Stream/Event 类集合 patch 移入
`torch_npu/_compat/distributed.py`,保留原函数名;
2. PyTorch 2.13 继续安装兼容 patch,2.14+ 不安装;
3. 保留 autocast、legacy Tensor 及其他 Stream/Event 运行时 patch,
由各自独立 PR 处理;
4. 增强 NPU Stream/Event 回归测试,直接检查图内类集合,并以
`fullgraph=True` 验证构造路由和 FX 图节点。
`CURRENT_VERSION >= (2, 14)` 只是兼容分界,不代表任意较旧的 2.14 nightly
wheel 都已包含 `fd3274468a3`。新增测试会检查 CI 实际安装的 PyTorch
是否具备上游能力,避免旧安装态 patch 造成假通过。
# 【资料变更】
本修改只调整 Dynamo 内部类路由,不新增或变更客户可见 API;
Stream/Event 的接口语义与现有资料保持一致,因此无需资料变更。
# 【接口变更】
无客户可见接口变更。`torch.npu.Stream` / `torch.npu.Event` 的 eager
和 `torch.compile` 使用方式不变。
# 【功能验证】
```text
保留旧 NPU patch:2 tests passed
停用 NPU patch,且无 PyTorch #194343:按预期失败
停用 NPU patch,并叠加 PyTorch #194343:2 tests passed
定向 lintrunner:No lint issues
```
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!45086
2026-09-23 09:22:07 +08:00
yucaopanmu
57cf7ebf72
[sync] PR-46827: [fix] 修复 aclnn_extension 门禁下 to_padded_tensor 注册符号缺失
...
Co-authored-by: yucaopanmu<yangpeng276@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46840 merge sync-pr46827-fix/nested-to-padded-tensor-to-master into master
[sync] PR-46827: [fix] 修复 aclnn_extension 门禁下 to_padded_tensor 注册符号缺失
Created-by: ascend-ds-bot
Commit-by: yucaopanmu
Merged-by: ascend-robot
Description:
### 1. Origin pull request:
https://gitcode.com/Ascend/pytorch/merge_requests/46827
### 2. Original pull request related issue(s):
https://gitcode.com/Ascend/pytorch/issues/4861
### 3. Original pull request related commit(s):
| Sha | Datetime | Message |
|---|---|---|
|[e3d0386c](https://gitcode.com/Ascend/pytorch/commit/e3d0386c635af99224811dabbeaef522150b9659 )|2026-09-22 19:07:57 +0800 CST|refactor: 抽取额外实现列表为独立函数并添加条件逻辑<br><br>将原本硬编码在特殊注册配置中的额外实现列表抽取为独立函数 _nestedtensor_extra_impls,新增了对 aclnn 扩展代码生成的判断,仅在非 aclnn 环境下添加 to_padded_tensor 的实现,提升代码可维护性。<br>|
|[8e57b0c1](https://gitcode.com/Ascend/pytorch/commit/8e57b0c1b2c6a04f020cd61c5d4db42703da8bc6 )|2026-09-22 19:00:43 +0800 CST|style(torchnpugen): 统一gen_backend_stubs.py里的字符串引号风格<br><br>修正了to_padded_tensor注册行的引号混用问题,将双引号外层改为单引号保持代码风格一致<br>|
|[c5da100e](https://gitcode.com/Ascend/pytorch/commit/c5da100e21ed3fe56020df42937cb4a7b0092a21 )|2026-09-22 18:59:52 +0800 CST|fix: add nested tensor register header for to_padded_tensor<br>|
See merge request: Ascend/pytorch!46840
2026-09-22 21:54:41 +08:00
pta-robot
b29d5da964
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46818 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-22 18:06:25.
See merge request: Ascend/pytorch!46818
2026-09-22 18:46:02 +08:00
wzyly
5e73fc065a
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46791 merge master into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
产品名称打标签
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46791
2026-09-22 16:11:05 +08:00
WSs_321
79b737e496
ci: integrate cann pre-pipeline/query-pipeline and switch to GIT_TOKEN
...
Co-authored-by: w30057661<wangshusheng7@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46713 merge master_update into master
ci: integrate cann pre-pipeline/query-pipeline and switch to GIT_TOKEN
Created-by: WSs_321
Commit-by: w30057661
Merged-by: ascend-robot
Description: ## 变更内容
1. Detect_file_changes 的 token 由 `${{ atomgit.token }}` 改为 `${{ secrets.GIT_TOKEN }}`
2. stage_1 新增 **pre_pipeline** 步骤(cann/.gitcode/actions/pre-pipeline),自动打标并回传流水线运行链接
3. 文件末尾新增 **post.query_pipeline** job(cann/.gitcode/actions/query-pipeline),流水线结束后回查结果并应用标签
依赖上游仓库配置 `GIT_TOKEN` secret。
## 关联Issue
#4990
See merge request: Ascend/pytorch!46713
2026-09-22 15:56:48 +08:00
pta-robot
df6bb8a0eb
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46787 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-22 10:03:29.
See merge request: Ascend/pytorch!46787
2026-09-22 15:51:01 +08:00
wuyouqi1
ea07320357
fix(core): skip internal-format repr probe for symbolic tensors in npu_patches
...
Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46788 merge fix/fake-tensor-repr-segv-master-pyguard into master
fix(core): skip internal-format repr probe for symbolic tensors in npu_patches
Created-by: wuyouqi1
Commit-by: wuyouqi1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
关联 issue:https://gitcode.com/Ascend/pytorch/issues/4744
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
!46582 已为 `get_npu_format` 增加 C++ 侧 `dynamic_cast` 守卫(FakeTensor 触达内核时抛可捕获异常而非 SIGSEGV)。但 master 上的 `Tensor.__repr__` 内部格式猴补丁位于 `torch_npu/_init/patches/npu_patches.py` 的 `apply_npu_internal_format_repr_patch`(发布分支位于 `torch_npu/utils/tensor_methods.py`),前述 PR 误判 master 已无该补丁,未带 Python 侧守卫。本 PR 补齐:
1. `torch_npu/_init/patches/npu_patches.py`:`_npu_internal_format_repr` 增加 `_is_symbolic_tensor` 守卫,FakeTensor 跳过 `get_npu_format` 探测(与发布分支修复 !46578 系列的 Python 侧守卫一致)。C++ 守卫合入后该探测对符号张量仅是每次 repr 多一次抛/捕异常,跳过更干净,并保留纵深防御。
2. `test/npu/test_tensor.py`:补齐 repr 路径 UT(自发布分支修复移植):
- `test_faketensor_repr`:`repr(FakeTensor)` 正常输出,不触发 `get_npu_format` 探测
- `test_faketensor_repr_under_dispatch_logging`:dispatch logging 场景对 FakeTensor 求 repr 走通(修复前的 SIGSEGV 路径)
- 既有 `test_get_npu_format_faketensor_guarded(_no_dispatch)` 继续看护 C++ 路径
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及"
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及"
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
- 新增 UT:`test_faketensor_repr`、`test_faketensor_repr_under_dispatch_logging`(与发布分支 !46578 系列同内容,已在其分支 CI 验证通过)
- 回归:真实 NPU 张量(含 NZ 私有格式)`repr` 走内部格式 `.cpu()` 路径的行为不变;`_is_symbolic_tensor` 仅对 FakeTensor 短路,普通 npu 张量不受影响
- 依赖 CI 门禁完成构建与全量 UT 验证
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46788
2026-09-22 15:37:17 +08:00
stonexxx
37343f3710
[Inductor] combine FlexAttention bounded workspace and runtime dispatch
...
Co-authored-by: stonexxx<sheny1xuan@163.com >
Co-authored-by: Xuan Peng<pengxuan9@huawei.com >
# message auto-generated for no-merge-commit merge:
!46451 merge codex/combine-pr46393-pr46408-master into master
[Inductor] combine FlexAttention bounded workspace and runtime dispatch
Created-by: stonexxx
Commit-by: Stonexx;stonexxx;Xuan Peng
Merged-by: ascend-robot
Description: ## 变更说明
基于最新 `mainline/master` 组合迁移以下修改:
- !46393:为 FlexAttention forward compact mask 提供有界 workspace,并增加 workspace/scan 测试。
- !46408:引入 FlexAttention runtime DispatchPlan,统一 forward、dQ、dK/dV 派发,并专用化 backward mask-out 模板。
## 冲突处理
组合迁移在以下位置发生内容冲突:
- `torch_npu/_inductor/config.py`:同时保留 `fwd_mask_workspace_bytes` 和 `flexattention_dispatch_strategy` 配置及环境变量读取。
- `torch_npu/_inductor/kernel/flex_attention.py`:同时导入 workspace 模板与 all-sparse dispatch 模板。
迁移后静态检查发现配置块缺少闭合括号,已在独立修复提交中解决:
- `929db0224b fix(inductor): resolve FlexAttention config integration conflict`
## 验证
- `python -m compileall -q torch_npu/_inductor`:通过。
- `test_flex_attention_fwd_workspace_source.py`:7/7 通过。
- `test_flex_attention_fwd_workspace.py`:5/5 策略测试通过,其余 NPU/慢测按条件跳过。
- a5-37 / torch213 环境验证通过,TorchNPU overlay 命中组合分支。
- Mojo `run.bash`:135/135 个预期 case 通过。脚本内 134 个有效命令完成;原第 67 行缺失 `]`,修正后补跑通过。
- 原串行回归中 1 次参考端 `aclnnNonzero` 异常在干净环境复跑通过。
- 多卡尝试确认容器仅暴露 7 张 NPU 且 cgroup 内存上限为 96 GiB;高并发编译造成的 `SIGKILL(-9)` 均在降低并发后通过,不计为代码失败。
验证日志:`/home/s00835054/codex_work/c6ef4842-5f58-431f-985a-6dc49f982974/`
关联 Issue:#4873
See merge request: Ascend/pytorch!46451
2026-09-22 14:49:23 +08:00
pta-robot
562b8a6ceb
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46780 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-21 22:05:53.
See merge request: Ascend/pytorch!46780
2026-09-22 14:42:03 +08:00
thickhair
0793fde1ae
feat(ci): 新增 PyTorch 源码覆盖率夜间定时流水线
...
Co-authored-by: thickhair<zp2165064878@163.com >
# message auto-generated for no-merge-commit merge:
!46782 merge feat-pytorch-coverage-nightly into master
feat(ci): 新增 PyTorch 源码覆盖率夜间定时流水线
Created-by: thickhair
Commit-by: thickhair
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
https://gitcode.com/Ascend/pytorch/issues/5014
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46782
2026-09-22 11:25:06 +08:00
SCh_zx
1e82591239
update_torch
...
Co-authored-by: SCh-zx<1325467101@qq.com >
# message auto-generated for no-merge-commit merge:
!46735 merge master into master
update_torch
Created-by: SCh_zx
Commit-by: SCh-zx
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
更新torch
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46735
2026-09-22 10:20:03 +08:00
crazyDannyBoy
6bc0fd80c3
revert(inductor): expand reduction masks with broadcast_to
...
Co-authored-by: crazyDannyBoy<xudezheng1@huawei.com >
# message auto-generated for no-merge-commit merge:
!46748 merge revert-inductor-reduction-mask-broadcast-master into master
revert(inductor): expand reduction masks with broadcast_to
Created-by: crazyDannyBoy
Commit-by: crazyDannyBoy
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46748
2026-09-22 10:04:45 +08:00
cai-weiwei1989
6ce56188dc
docs:大模型二次检查
...
Co-authored-by: cai-weiwei1989<734267852@qq.com >
# message auto-generated for no-merge-commit merge:
!46627 merge master into master
docs:大模型二次检查
Created-by: cai-weiwei1989
Commit-by: cai-weiwei1989
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
> AICPU术语改为AI CPU
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46627
2026-09-22 09:49:28 +08:00
ccyyccyyccyycc
d531f824e6
[fix] distribute env docs fix
...
Co-authored-by: ccyyccyyccyycc<changqiaowei@huawei.com >
# message auto-generated for no-merge-commit merge:
!46626 merge fix/docs-distributed-env-master into master
[fix] distribute env docs fix
Created-by: ccyyccyyccyycc
Commit-by: ccyyccyyccyycc
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/4691
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
修改资料
# 【资料变更】
修改资料review意见
# 【接口变更】
不涉及
# 【功能验证】
不涉及
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46626
2026-09-22 09:30:57 +08:00
yucaopanmu
13057da26c
[sync] PR-46265: fix: add nested tensor register header for to_padded_tensor
...
Co-authored-by: yucaopanmu<yangpeng276@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46717 merge sync-pr46265-fix/nested-to-padded-tensor-to-master into master
[sync] PR-46265: fix: add nested tensor register header for to_padded_tensor
Created-by: ascend-ds-bot
Commit-by: yucaopanmu
Merged-by: ascend-robot
Description:
### 1. Origin pull request:
https://gitcode.com/Ascend/pytorch/merge_requests/46265
### 2. Original pull request related issue(s):
https://gitcode.com/Ascend/pytorch/issues/4861
### 3. Original pull request related commit(s):
| Sha | Datetime | Message |
|---|---|---|
|[be097c68](https://gitcode.com/Ascend/pytorch/commit/be097c68de671148cf65a7331822781ff0a19f9d )|2026-09-16 10:00:37 +0800 CST|style(torchnpugen): 统一gen_backend_stubs.py里的字符串引号风格<br><br>修正了to_padded_tensor注册行的引号混用问题,将双引号外层改为单引号保持代码风格一致<br>|
|[1a72a420](https://gitcode.com/Ascend/pytorch/commit/1a72a420b05dcb4d6cf19623382b26b4147077aa )|2026-09-14 12:53:48 +0800 CST|fix: add nested tensor register header for to_padded_tensor<br>|
See merge request: Ascend/pytorch!46717
2026-09-21 20:47:05 +08:00
pta-robot
66adcbaa59
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46743 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-21 18:03:32.
See merge request: Ascend/pytorch!46743
2026-09-21 20:38:44 +08:00
pta-robot
7c364dd9f4
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46740 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-21 18:02:21.
See merge request: Ascend/pytorch!46740
2026-09-21 18:49:07 +08:00
wzyly
26ba71609c
modify document
...
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46685 merge master into master
modify document
Created-by: wzyly
Commit-by: m0_68000167
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新
# 【修改方案】
产品名称打标签
# 【资料变更】
涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46685
2026-09-21 17:19:17 +08:00
culechan
676f44d409
[fix] fix cache
...
Co-authored-by: chenshuai<chenshuai81@huawei.com >
# message auto-generated for no-merge-commit merge:
!46673 merge fix921 into master
[fix] fix cache
Created-by: culechan
Commit-by: chenshuai
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
原先的cache方案性能仍然不满足,context的查询接口仍然有部分性能损失,因此直接修改为全局的静态线程变量来记录缓存。底层aclnn框架为进程级变量,使用线程变量缓存看护也是安全的。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
性能优化到了可以接受的范围内

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46673
2026-09-21 15:13:34 +08:00
wyssss1245
3fecae0eca
add the test file for UT in inductor
...
Co-authored-by: wyssss1245<wangyesheng1@huawei.com >
# message auto-generated for no-merge-commit merge:
!46532 merge master into master
add the test file for UT in inductor
Created-by: wyssss1245
Commit-by: wyssss1245
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
[#4911 ](https://gitcode.com/Ascend/pytorch/issues/4911 )
# 【修改方案】
本 PR 主要为 torch_npu._inductor 相关能力补充单元测试看护,新增多个测试文件,覆盖动态 cat 掩码、flex attention 动态掩码、动态形状符号化分组、形状分档处理以及符号索引分析等场景,并为已有测试统一加上版本约束装饰器;此外 torch_npu/_inductor/config.py 仅做了一处空行格式调整。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46532
2026-09-21 15:00:51 +08:00
pta-robot
77037e26c8
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46650 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-20 18:03:37.
See merge request: Ascend/pytorch!46650
2026-09-21 09:57:25 +08:00
qq_37868325
28a9bc52a5
fix(triton_experimental): preserve layout in boundary downcast; add AllenaiLongformerBase
...
Co-authored-by: AACAES<liuyan7892@163.com >
# message auto-generated for no-merge-commit merge:
!46062 merge longformer-model-and-downcast-layout-fix into master
fix(triton_experimental): preserve layout in boundary downcast; add AllenaiLongformerBase
Created-by: AACAES
Commit-by: AACAES
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/4701
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
## 1. 问题现象
torchbench `AllenaiLongformerBase --accuracy --train --float32` 训练 accuracy check 失败(33.22)。排查定位出**两个相互独立的根因**,本 PR 一并修复:
- **根因 A(int64/fp64 边界降档布局塌缩)**:最小复现为重叠 `as_strided` int64 视图经 compile 的 clone 路径,2359296 个元素中 2260992 个错误(96%)。详见关联 issue。
- **根因 B(dropout packed mask 位序错乱)**:eager/compile loss diff 随训练步数线性放大(1e-7 → 5.8e-4);forward logits 干净,但经 `dropout_backward` 的 Q/K 投影梯度 rel ~145% 错误,V/output 梯度正常。
## 2. 问题根因
### A. 边界降档布局塌缩
NPU 不支持 int64/float64,triton_experimental 在 kernel 参数边界做降档:签名 `*i64→*i32`,launcher 运行时 `Tensor.to()` 转换数据。__`Tensor.to()` 对非 non-overlapping-and-dense 布局(重叠 as_strided 视图、gapped slice、broadcast)会静默塌缩为 contiguous__,而 Triton kernel 的 load/store 公式按编译期记录的 stride 生成——缓冲布局变了、寻址公式没变,读/写错位置。
三个受影响位置(同根因):
1. 输入侧 `_memoized_downcast`:`src.to(dst_dtype)` 塌缩布局(Longformer 触发点);
2. 输出侧 `empty_like`:对非 dense 张量同样塌缩为 contiguous;
3. 回写 `orig.copy_(tmp.to(src_dt))`:功能正确但多一次整块 src_dtype 中间物化。
### B. dropout packed mask 位序错乱
torch_npu dropout decomposition 把 `aten.native_dropout` 替换为 `npu._npu_dropout`(返回按输入 C 序内存遍历序 bit-packed 的 uint8 mask),而 backward 的 `npu.npu_dropout_backward` 按 __grad 的物理遍历序__ 解包。当 backward grad 是 FX 图显式 permute 视图(Longformer `_unskew` 反传固有,inductor 以 stride-only reinterpret 保留)时,两种遍历序不同 → mask 位错乱 → 梯度错误并随训练混沌放大超容差。
## 3. 修改原理
### A. 降档缓冲保持布局(`npu_triton_heuristics.py`)
核心思路:__降档缓冲必须保持参数的原始 stride,成为编译期寻址公式的合法替身__。
新增三个 helper:
- `_is_non_overlapping_and_dense(t)`:c10 `compute_non_overlapping_and_dense` 的 Python 孪生实现;
- `_reachable_span(t)`:从 data_ptr 起可达存储跨度,cast 与回写共用同一计算,不会漂移;
- `_to_dtype_preserving_layout(src, dst_dtype)`:
- dense 张量(绝大多数 kernel 参数):走原快路径 `src.to(dst_dtype)`,行为与旧代码逐字节一致;
- 零元素张量:`.to()` 短路(span-1 视图对空存储非法);
- 非 dense:把可达 span 视作 dense 1-D 张量做 `.to()`(对存储单元逐格 cast),再 `as_strided` 回原 shape/stride。别名单元在源中本就同值,逐格 cast 精确且无顺序问题;
- gapped 视图 span 超过 4×numel 时 `log.debug` 提示内存放大(上游 contiguify 可消除)。
配套(`_wrap_launcher_with_downcast` 内):
- 输出侧 `empty_like` → `empty_strided(a.shape, a.stride())`;in/out 参数(需保留输入内容)改走 `_to_dtype_preserving_layout`;
- 回写 `orig.copy_(tmp)`:`copy_` 原生带 dtype cast,省掉整块 src_dtype 中间物化(2048² 实测 3.2× 提速);仅当 `torch._debug_has_internal_overlap(orig) == 1`(expand 族——`copy_` 拒绝的唯一种类,与 ATen 内部 guard 同条件判定)时退化 flat span 逐格回写;TooHard(重叠 as_strided/gapped)走逻辑 `copy_`,OOM/设备错误正常传播、不会被误捕进 flat 分支。
### B. dropout grad 物化对齐遍历序(`decomposition.py`)
`native_dropout_backward` 的 packed 分支给 grad 加 `.contiguous()`(一行;已 contiguous 时 no-op),对齐打包/解包的内存遍历序。
### C. 模型上库(`benchmarks/`)
torchbench 增加 `AllenaiLongformerBase`:`huggingface_models_list.txt` 增加条目;`huggingface.py` 的 `EXTRA_MODELS` 增加映射(`AutoConfig.from_pretrained` 惰性 lambda + `AutoModelForMaskedLM`,避免 import 期访问网络),`_download_model` 支持 `from_config()` 工厂实例化,`_get_model_cls_and_config` 支持 callable config。该模型名非 transformers 类名,无此映射则 `AttributeError: module transformers has no attribute AlleniLongformerBase`。
## 4. 影响范围
- 修复 A 仅影响 triton_experimental 后端 boundary downcast 路径(i64/fp64 kernel 参数);修复 B 仅影响 `native_dropout_backward` packed 分支;均不修改上游 torch 源码,改动全部在 torch_npu 侧
- __dense 快路径(绝大多数参数)行为与旧代码逐字节一致__;非 dense 参数从"布局塌缩读写错数据"变为"布局保持读写正确"
- 已知 trade-off:gapped 参数的降档临时缓冲按存储 span 分配(可大于 numel,`log.debug` 提示);重叠视图反而更省(span < numel,别名格只 cast 一次)
- 模型侧为纯增量(新模型条目 + EXTRA_MODELS 泛化机制),不影响既有模型
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
新增两个看护测试文件,共 9 个用例,全部通过:
**`test/_inductor/test_triton_experimental_downcast_layout.py`(5 个用例)**
| 用例 | 看护 |
| --- | --- |
| test_helper_layout_semantics | `_is_non_overlapping_and_dense` 判定(contiguous/permute/expand/gapped/overlap/size-1 维)、各布局 cast 后 stride 保持 + 值正确、memo 命中路径(Longformer 235 万元素形状)、零元素短路 |
| test_compiled_overlap_int64_clone | __Longformer 触发场景__(编译路径,修复前 96% 元素错误) |
| test_compiled_gapped_int64_clone | gapped slice 编译路径 |
| test_compiled_mutated_int64_writeback | in/out 参数降档 + 回写 round-trip |
| test_compiled_overlap_mutated_writeback | 真重叠视图(行距 512 < 行长 1024,相邻行共享 512 元素)mutated 参数回写 |
**`test/_inductor/test_triton_experimental_dropout_mask_layout.py`(4 个用例)**
| 用例 | 看护 |
| --- | --- |
| test_compiled_dropout_mask_matches_eager | 编译路径 dropout mask 与 eager 一致 |
| test_contiguous_grad_control | contiguous grad 对照组 |
| test_longformer_unskew_shape | Longformer `_unskew` 反传形状场景 |
| test_permuted_grad_matches_eager | permute 视图 grad 与 eager 一致 |
**端到端验证**:
- Longformer 12 层全模型单步梯度:Q/K 投影 rel ~2% → ~1e-6(max_abs 总和 5.7e-3 → 4.3e-7)
- torchbench `AllenaiLongformerBase --accuracy --train --float32 --iterations 5 --accu-summary`:`pass_accuracy`(logits max 3.6e-6、grads failed 0/274、loss bit-exact)
**性能自验:**
① dense:零开销。1.01×——符合设计,快路径与旧代码逐字节一致,绝大多数 kernel 参数(dense)不受影响。
② overlap:新路径快 3.8 倍。两个因素叠加:cast 的格子数更少(span 0.75 亿 < numel 1 亿,别名格只 cast 一次)+ 访存模式从“按逻辑位置 strided
读写”变成“线性扫描”。旧路径 357 GB/s vs 新路径 1026 GB/s——旧路径的非 dense TensorIterator 逻辑拷贝在这个形状下带宽利用率只有 1/3。
③ gapped:cast 3 倍的格子反而快 4 倍。这是最有说服力的一组:新路径要处理 3 亿格(含洞),是旧路径 1 亿逻辑元素的 3 倍工作量,却仍快
4.1×。原因是访问模式的代差——[::3] 的逻辑读是“每 24 字节取 8 字节”的散读,带宽利用率仅 69 GB/s;线性扫描把 HBM 带宽打到 838 GB/s。线性但冗余
的访问完胜 稀疏但精准 的访问。

**显存自验:**
①旧路径的显存代价比理论高——它有隐性中转
overlap 旧行为实测 1145 MiB = 763(numel×8B 的 int64 contiguous 中转)+ 382(numel×4B 输出)。也就是说 torch_npu 的 .to() 对非 dense 输入并非“一步 cast”,而是先物化一份 contiguous int64 中转,再cast。这个分解同时统一解释了上一轮的性能数据:
- 旧 overlap 3.13ms ≈ 多搬一遍中转的全量数据;新路径 0.82ms 无中转;
- 旧 gapped 16.27ms = 中转阶段的 [::3] gather(正是 stride 扫描里那种散读)占绝对大头。
② gapped 的“3× 放大”当前被隐性中转恰好抵消
理论上新路径 gapped temp 应是旧路径的 3 倍(span 3亿格 vs numel 1亿元素),但实测峰值持平(1144 vs 1145)——因为旧路径的隐性中转本来就要付 763+382。注意这是当前 NPU 实现的“侥幸持平”:若将来torch_npu 优化掉 .to() 的隐性中转,gapped 的 3× temp 放大就会真正显形——PR 里那条 debug 日志(span > 4×numel 提示contiguify upstream)作为长期指引依然正确。
③峰值 vs 驻留要分开算
- 峰值(上表):修复后无任何场景恶化,dense/overlap 显著改善;
- 驻留:dedup_downcast 开启时,每个非 dense 参数的 temp 会随 memo 驻留,生命周期跟随原张量(weakref)——机制与修复前一致,只是单份体积从 numel×4B 变为span×4B(overlap 减半、gapped 放大至 s×);
- 真正的显存大头始终是原 int64 参数本身(模型的存储),temp 是它的 1/2(span×4B vs 原始 span×8B)。

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46062
2026-09-21 09:49:16 +08:00
pta-robot
ae2ee12982
Update op_plugin commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46644 merge master into master
Update op_plugin commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-20 18:02:24.
See merge request: Ascend/pytorch!46644
2026-09-20 18:43:53 +08:00
shi-yufeng99
4c08e9e993
change gemm_template
...
Co-authored-by: shi-bibibi99<shiyufeng8@huawei.com >
# message auto-generated for no-merge-commit merge:
!46630 merge 0920_master_catlass_branch1 into master
change gemm_template
Created-by: shi-yufeng99
Commit-by: shi-bibibi99
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
[#2589 ](https://gitcode.com/Ascend/pytorch/issues/2589 )
修改catlass仅支持alpha=1 beta=1的addmm场景
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46630
2026-09-20 18:25:55 +08:00
luqichao
0818ff33db
feat(inductor): add switch for embedding lowering
...
Co-authored-by: luqichao<luqichao1@huawei.com >
# message auto-generated for no-merge-commit merge:
!46565 merge sync/embedding_switch_master into master
feat(inductor): add switch for embedding lowering
Created-by: luqichao
Commit-by: luqichao
Merged-by: ascend-robot
Description: 1. 在 torch_npu/_inductor/config.py 中新增 TORCHINDUCTOR_ENABLE_EMBEDDING_LOWERING 环境变量开关,默认开启 embedding lowering。
2. 在 torch_npu/_inductor/lowering_fallback_list.py 中根据该开关控制 aten.embedding 相关算子是否加入 NPU fallback 列表,从而支持按需切换。
See merge request: Ascend/pytorch!46565
2026-09-20 17:45:27 +08:00
wuyouqi1
85d554a0a4
[sync] PR-45502: test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356)
...
Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46545 merge fix/narrow-aclnn-nc1hwc0-3d-fallback-master into master
[sync] PR-45502: test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356)
Created-by: wuyouqi1
Commit-by: wuyouqi1
Merged-by: ascend-robot
Description:
<!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
关联 issue:https://gitcode.com/Ascend/pytorch/issues/4356
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间是如何交互的,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
本 MR 为 !45502(已合入 v2.7.1:`test: un-skip test_single_reshape_copy_to_contiguous cases (issue 4356)`)向 **master** 分支的同步合入,代码内容与 v2.7.1 合入版本一致。
1. 背景:issue 4356 中 `allow_internal_format=True` 时,非视图 3D NC1HWC0 张量经 `npu_format_cast(src, NCHW)`(如 `to("cpu")` 触发)在 aclnn 路径报 161001 且毒化进程,导致 `test_single_reshape_copy_to_contiguous` 类 4 个用例被 `@unittest.skip` 临时跳过。
2. 该问题的根因在 CANN 侧(`aclnnNpuFormatCast` 对 3D NC1HWC0 → NCHW 的支持性判定与执行不一致),**CANN 已在 9.2.0 修复**;torch_npu 侧无需 workaround。
3. 本 MR 仅恢复测试看护:解除 `test/trans_contiguous/test_single_reshape_copy_to_contiguous.py` 中 4 个用例的 `@unittest.skip`(view/unsqueeze/flatten/narrow,issue 4356)。
4. 头注释补充说明:设置 `allow_internal_format = True` 走真实内部格式路径时,3D NC1HWC0 在 aclnn 路径上的正确转换需要 CANN >= 9.2.0。
5. 相对 v2.7.1 合入版本的差异:额外删除了该测试文件中解除 skip 后不再使用的 `import unittest`。master 分支的 `.lintrunner.toml` 启用了 flake8 检查(发布分支中该项被注释),机器人同步 MR !46509 因 F401('unittest' imported but unused)CI 失败;本 MR 基于最新 master 重新提交并已修复该 lint 问题(本地 `flake8 --config=.flake8` 验证通过)。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
与 !45502(v2.7.1)验证结论一致,本 MR 为同一变更的分支同步:
1. 环境:910B2 / CANN 9.2.0 / torch_npu(v2.7.1 构建)。
2. 默认配置(`allow_internal_format` 保持注释,走 aclnn 降级路径):`python test_single_reshape_copy_to_contiguous.py -v SingleViewCopyToContiguous`,5 个用例全部通过。
3. 解开 `torch.npu.config.allow_internal_format = True`(CANN 9.2.0 修复生效后):整类用例通过,`test_narrow_at_first_axis_copy` 的 `[fp16, NC1HWC0, [20,16,16]]` item(原 161001 失败点)恢复正常。
4. 本 MR 不修改框架代码,无新增 UT;由恢复的 4 个用例看护原失败路径。
5. **Lint 自验证**:`python -m flake8 --config=.flake8 test/trans_contiguous/test_single_reshape_copy_to_contiguous.py` 通过(修复机器人 MR !46509 的 F401 失败项)。
See merge request: Ascend/pytorch!46545
2026-09-20 17:15:55 +08:00
wuyouqi1
d700685e9e
[master] fix(core): guard get_npu_format against symbolic tensors to avoid segfault
...
Co-authored-by: wuyouqi1<wuyouqi1@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46582 merge fix/fake-tensor-repr-segv-master into master
[master] fix(core): guard get_npu_format against symbolic tensors to avoid segfault
Created-by: wuyouqi1
Commit-by: wuyouqi1
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
https://gitcode.com/Ascend/pytorch/issues/4744
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [x] 重构优化
- [ ] 资料更新
# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
1. `torch_npu/csrc/aten/common/FormatCastKernelNpu.cpp`:`get_npu_format` 改用 `dynamic_cast<NPUStorageImpl*>` 判空 + `TORCH_CHECK`,替代原 `NPUBridge::GetNpuStorageImpl` 的无校验 `static_cast`
2. `test/npu/test_tensor.py`:新增 2 个 UT 看护(dispatch 生效与 no_dispatch 两条路径)
**根因**:FakeTensor 经 `_make_subclass(device_for_backend_keys='npu')` 创建,impl 级 `device_opt_` 被改写为 npu(`torch_check_npu` 放行)但底层是普通 `c10::StorageImpl`(无 `npu_desc_` 成员),`get_npu_format` 无条件 `static_cast` 后读 `npu_desc_` 越界 → SIGSEGV(try/except 无法捕获)。Python dispatch 被禁用(no_dispatch 嵌套调用)时 op 直达 C++ 内核,仅注册 meta/fake 实现无法拦截,故必须 C++ 层兜底。master 上 v2.7.1 修复所防护的 `Tensor.__repr__` 猴补已在上游移除,故本分支仅需 C++ 侧守卫与 UT。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写"不涉及"
不涉及
# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写"不涉及"
不涉及
# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
已在 v2.7.1 分支完成同等 C++ 改动的完整验证(MR !46180),本分支为同内容同步:
- UT:`test_get_npu_format_faketensor_guarded`(dispatch 生效时抛可捕获异常)/ `test_get_npu_format_faketensor_guarded_no_dispatch`(no_dispatch 嵌套路径,旧 C++ 上实测 SIGSEGV,判别性成立)
- 无回归:真实 NPU 张量(含 NZ 私有格式、视图、save/load、autocast、autograd 矩阵)`get_npu_format` 行为不变;npu 设备 storage 全局工厂 `SetStorageImplCreate(PrivateUse1, make_npu_storage_impl)` 保证所有显式构造点均有 NPUStorageImpl
- 依赖 CI 门禁完成构建与全量 UT 验证
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46582
2026-09-20 16:41:48 +08:00
limuan
95e1461700
docs: simplify HCCL communicator configuration guide
...
Co-authored-by: limuan<liyijie16@huawei.com >
# message auto-generated for no-merge-commit merge:
!46506 merge docs/hccl-comm-config into master
docs: simplify HCCL communicator configuration guide
Created-by: limuan
Commit-by: limuan
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [x] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
pta pg_option中之前很多配置,未在文档中说明,现在列举pta 允许用户配置的变量,并于hccl的commconfig进行映射
# 【资料变更】
本pr为资料pr
# 【接口变更】
不涉及
# 【功能验证】
资料修改,无功能验证
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46506
2026-09-20 14:27:19 +08:00
limuan
0b690cf647
docs(distributed): add scalable rootinfo link setup guide
...
Co-authored-by: limuan<liyijie16@huawei.com >
# message auto-generated for no-merge-commit merge:
!46479 merge docs/scalable-rootinfo-master into master
docs(distributed): add scalable rootinfo link setup guide
Created-by: limuan
Commit-by: limuan
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
- [x] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
1. 在`OptionsManager`中新增Scalable RootInfo配置读取:
- `ROOTINFO_SCALABLE_ENABLE`控制功能是否开启;
- `TORCH_HCCL_RANKS_PER_ROOT`配置每个Root管理的目标rank数,未配置时默认使用128。
2. 在`ProcessGroupHCCL::createHCCLCommOrigin`中增加路径选择:
- 仅`HcclCommType::DEFAULT`、功能开关开启且当前通信域rank数大于`ranksPerRoot`时进入Scalable路径;
- 使用当前ProcessGroup的`getSize()`计算规模,因此同时支持全局通信域和`new_group`非全局通信域;
- P2P、开关关闭及小规模通信域继续使用原RootInfo创建流程;
- 仅Atlas A2/A3支持该能力,其他SoC打印Warning并回退原流程。
-
3. PTA按照以下方式完成分组和RootInfo交换:
- Root数量为`ceil(numRanks / ranksPerRoot)`;
- 将当前通信域内的rank连续、均衡划分到各Root,组间rank数最多相差1;
- 每个Root调用`HcclGetRootInfoScalable`生成RootInfo,并通过c10d Store分别发布;
- 所有rank通过`Store::multiGet`获取按Root序号排列的完整RootInfo列表,同时校验数量、数据长度及PTA版本。
4. 在`HCCLComm`中新增`create_scalable_config`封装。所有rank携带当前通信域rank数、本地rank及RootInfo列表调用`HcclCommInitRootInfoScalable`,由HCCL完成分级建链;通信域的缓存、使用和销毁机制保持不变。
5. 在`HcclCompile`和`HCCLUtils`中增加两个HCCL新接口的动态加载与封装:
- `HcclGetRootInfoScalable`
- `HcclCommInitRootInfoScalable`
当功能已开启但当前HCCL不包含对应符号时,返回明确的不支持错误。
6. 增加路径选择、分组布局、RootInfo生成/交换和通信域创建耗时日志,并补充均匀分组、非整除分组、集合通信、原路径回退、非法配置及通信域重复创建销毁等测试。

# 【资料变更】
涉及,本pr即为资料的pr
# 【接口变更】
不涉及
# 【功能验证】
仅包含资料修改,无功能验证
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46479
2026-09-20 14:22:22 +08:00
efwfefe
a5fa5f6ea8
[fix] 增加对ops-transformer的版本校验,910B以下停止加入
...
Co-authored-by: efwfefe<chenjunkun2@h-partners.com >
# message auto-generated for no-merge-commit merge:
!46560 merge master into master
[fix] 增加对ops-transformer的版本校验,910B以下停止加入
Created-by: efwfefe
Commit-by: efwfefe
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [x] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
当芯片版本低于910B的时候,split_pkg_supported停止传入ops_transformer参数
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
测试已通过验证
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46560
2026-09-20 11:50:09 +08:00
huyuchao
527d457513
perf(inductor): triton_experimental chained index_select rewrite for separable advanced indexing (guard-only)
...
Co-authored-by: huyuchao<huyuchao2@huawei.com >
# message auto-generated for no-merge-commit merge:
!46174 merge te-index-select-rewrite into master
perf(inductor): triton_experimental chained index_select rewrite for separable advanced indexing (guard-only)
Created-by: huyuchao
Commit-by: huyuchao
Merged-by: ascend-robot
Description: 【合入来源】
fixes #4378
> 原始议题记录:#4378(yolov3 性能议题)
用途:triton_experimental 后端对**可分离高级索引**的链式 index_select 重写——守卫式准入(guard-only),把整型张量索引串从 AICPU extern 回退改走 AICore 的 aclnn index_select 链。
**组合关系**:本 PR 与系列其余 PR(正确性修复 #46172 / provable 钳位跳过 #46173 / dispersion guard #46066)组合解决 yolov3 全链问题(compiled 0.357x → 1.068x、pass_accuracy);各机制正向交互,建议系列 PR 相邻合入(组合态已在纯净 whl 基座 + 最新 master runner 的完全独立环境复验 pass_accuracy)。
- [x] 需求
- [ ] 问题单
- [x] 重构优化
- [ ] issue/工单
- [ ] 资料更新
【修改方案】
**改了什么**(均在 torch_npu/_inductor/triton_experimental/,新增单测一件):
1. lowering.py 新增 `_index_select_rewrite(x, indices, _up)`:对 `aten._unsafe_index.Tensor` / `aten.index.Tensor` 两个入口的整型张量索引串做守卫式判定与重写。守卫共 8 条:索引列表覆盖全部维度、恰有一段 1–2 个**连续**张量索引、其余全 None、整型 dtype、2-D 索引尾维静态可知为 1((M,1) 列形态)、索引秩 ≤2、run-of-1 仅 1-D、**run-of-2 必须是"首索引 (M,1) 列 + 次索引 1-D"**(联合广播语义判定:这是列约束下唯一 aten 广播与链式结果形 (…, La, Lb) 一致的组合)。
2. 通过守卫的模式重写为**链式 `aclnn index_select` extern 回退**:`(M,1)` 列经 reshape 拍平后按维链式 index_select——语义逐 lane 等价([n,c,i,j] = x[n,c,a[i],b[j]] 外积配对)。
3. 注册时序处理:`_register_npu_inductor_fallbacks` 重绑定,使两个 index lowering 在 fallback 扫描之后幸存(扫描会冲掉直接注册的 overwrite)。
4. 新增 test/_inductor/test_unsafe_index_rewrite.py(4 用例)。
**为什么改**:
- NPU 上 `aten._unsafe_index`/`aten.index` 无 TE lowering → 整体外联到 **AICPU aclnnIndex**(标量伴生核)——满张量 gather 实测 ~26ms(yolov3 检测头 2 次发射,~10ms/iter);
- 若硬编成 Triton kernel 则是逐 lane 间接 gather——AIV 离散访问悬崖(每 lane 独立寻址,不可向量化);
- **eager 对同一模式近零耗时**——其内部分发为"可分离 index_select 链"快路径。本重写即让编译产物走 eager 已验证的同一条路(AICore 的 aclnnIndexSelect,~0.28ms/次)。
**解决了什么问题**:
- 性能:满张量 gather ~26ms → ~0.28ms(kernel 级 ~93x);yolov3 头部 AICPU 索引税消除;
- 正确性边界闭合:此前逐索引守卫不验**联合广播语义**——对角配对(双 1-D)、单列 (M,1)、秩 0/秩 ≥3 等形态会编出错误形状的链(响亮 IR 失败而非静默错数,但"该回退的输入不该把编译搞崩")。现守卫按联合语义精确圈定可证明等价形,其余形态**一律回退上游 fallback**,行为与无本特性时逐字节一致;
- 门禁哲学:**证明等价→硬编;证明不了→回退;不设运行时开关**——守卫是唯一准入,无 config/env 面。
【资料变更】不涉及
【接口变更】不涉及跨仓/客户面接口;无新增 config/env 键(守卫即准入)。
【功能验证】
环境:Ascend 910B2 / torch 2.13.0 / torch_npu 2.13.0 / triton-ascend 3.2.2。独立分支单独同步(whl 纯净基座 5c9fd6f + 最新 master runner fresh clone + 私有缓存)验证。
1. UT:test_unsafe_index_rewrite.py 4 用例——接受形((M,1)+(K,) 外积)/ 对角双 1-D / 单列 (M,1) / 秩 3 守卫边界,compiled vs eager 逐点一致全过
2. 产物断言:接受形 output_code 呈双 index_select 链((M,1) 列经 reinterpret 拍平)、无 aclnnIndex 残留;对角形在 dynamo 层即 graph break(FX 图中 index 为 PlaceHolder),守卫属纵深防御
3. 冒烟:test_triton_experimental_enable.py 13/13(隔离跑)
4. 端到端参考:yolov3 头部 AICPU 索引税消除(全栈组合态验证,见组合关系注)
**影响面评估**:
- 触发面:仅"首索引 (M,1) 列 + 次索引 1-D(或单一 1-D)"的可分离外积形;该形态外的一切高级索引走原路径,零行为差;
- 失败模式:守卫不满足 → 原样交回上游(fail-closed);重写执行体为 extern 调用,无新增 kernel 编译面;
- 回归风险:注册重绑定只影响两个 index 入口的注册顺序,不改其它 lowering。
【CheckList】
- [x] 代码注释完备,正确记录错误日志(守卫拒绝路径可观测)
- [x] 代码实现进行了返回值、空指针等校验(守卫不满足一律回退上游;断言索引秩/形态)
- [x] PR标题正确使用类型标签(perf)
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(待 gitcode CI 运行确认)
See merge request: Ascend/pytorch!46174
2026-09-20 11:11:18 +08:00
qsc97
5148ffbfa5
add_overlap_scheduling_pass
...
Co-authored-by: qsc<qinsichun@huawei.com >
# message auto-generated for no-merge-commit merge:
!46261 merge auto_bucketing_v2.13 into master
add_overlap_scheduling_pass
Created-by: qsc97
Commit-by: qsc
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新
# 【修改方案】
auto_bucketing_pass适配pytorch2.13+,相比2.12版本的修改点如下
### 1.FakeTensor 与动态维度实化
benchmark 前将 FakeTensor 转换为保持 shape、stride、dtype 和 device 信息的真实 Tensor。
PyTorch 2.13+ 在 benchmark 参数中新增了对独立 `SymInt` 参数的实化处理,因此 NPU 的 benchmark同步加入:
```python
optimization_hint(symint, fallback=config.unbacked_symint_fallback)
```
表示 独立 `SymInt` 参数会使用 optimization hint 或配置的 fallback 实化后继续 benchmark。shape/stride 均可确定时,GroupedMatmul 仍正常 benchmark。
### 2. NPU 重计算节点识别
保留上游 `is_compute_node()` 的判断,并补充 NPU 重算子:
- `npu_fused_matmul`
- `npu_fusion_attention_v3_unsafe`
- `npu_fusion_attention_grad_v3_unsafe`
其中 `npu_fused_matmul` 和两个 `*_unsafe` FA 代理是 master 相比 PTA 2.12 新增的场景。FA v3 节点可能在 post-grad pass 中被改写为 unsafe 代理,而该改写发生在 overlap scheduling 之前,因此必须继续将其视为重计算节点,避免被 DVM predictor 错误归入轻量 fusion region。
# 【资料变更】
不涉及
# 【接口变更】
不涉及
# 【功能验证】
eager

simplefsdp

simplefsdp+auto_bucketing tps提升15%

掩盖率 85%

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]
- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
See merge request: Ascend/pytorch!46261
2026-09-20 09:33:31 +08:00
chenrayray
0587c1af6e
【docs】补充2.9.0、2.10.0、2.14.0原生API文档并修复链接
...
Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com >
# message auto-generated for no-merge-commit merge:
!46481 merge codex/native-api-2-9-2-10-2-14 into master
【docs】补充2.9.0、2.10.0、2.14.0原生API文档并修复链接
Created-by: chenrayray
Commit-by: Xinrui Chen
Merged-by: ascend-robot
Description: # 【合入来源】
- [x] issue/工单
- [x] 资料更新
关联Issue:https://gitcode.com/Ascend/pytorch/issues/4880
# 【修改方案】
补齐master缺失的PyTorch 2.9.0、2.10.0、2.14.0原生API支持清单,修正版本继承带来的过期接口和链接。
1. 新增196个文档文件:2.9.0、2.10.0分别继承2.7.1的66个文件,2.14.0继承2.13.0的64个文件,并将总目录按版本降序排列。保留API的产品支持字段与继承版本逐条比对,无意外变化。
2. 2.9.0、2.10.0各清理15个上游已移除的旧ONNX接口及成员;2.14.0清理`torch.qr`、`ShapeEnv.set_unbacked_var_to_val`和`Unflatten.NamedShape`。同步修正已有版本中已删除的相应历史条目。
3. 新增版本补充API废弃或参数变更说明,覆盖旧AMP、ONNX辅助接口、范数、上采样和profiler等;概述说明ONNX默认导出行为及2.14参数变更。
4. 全量修复原生API目录的失效页面、锚点和路径。对缺少上游文档的条目同时核对废弃状态:删除2.9/2.10各8个JitScalarType类及成员条目、各3个TorchScript辅助API,以及2.7.1已停止维护的移动端优化条目;恢复14处同版本有效API文档链接。按对应版本的官方站内搜索索引和API索引继续核查其余137处条目:133处下架(包括仅在示例代码中出现的7处graph.map_arg),4处DataPipe类型可在官方参数类型说明中找到并改链到对应内容。清单不再使用源码链接替代原生API文档;同步将2.13/2.14的14处profiler方法名称校正为实际文档中的公开类profile。Named Tensors中10处链接改为同版本named_tensor页面的命名张量说明及命名维度flatten用法,避免误指向普通Tensor文档。
版本差异依据:[PyTorch 2.9发布说明](https://github.com/pytorch/pytorch/releases/tag/v2.9.0 )、[2.10发布说明](https://github.com/pytorch/pytorch/releases/tag/v2.10.0 )、[2.14发布说明](https://github.com/pytorch/pytorch/releases/tag/v2.14.0 ),以及对应版本官方文档和源码。
# 【资料变更】
仅修改`docs/zh/api/native_api`下的Markdown文档,共221个文件:196个新增、25个修改。已合入最新master的`4684a677a2`,同步修正HCCL文档目录迁移后的14处链接及引用标题。
# 【接口变更】
不涉及运行时API或产品支持能力变更。文档清理反映上游版本变化及“对应版本文档可检索”的收录规则;因搜索不到而下架不等同于上游删除了实现。
# 【功能验证】
- 对三个新增版本逐条比较保留API的产品支持字段,未发现意外变化,未新增未经验证的API支持声明。
- 全量检查468个Markdown文件:24,290处外链引用,去重23,689个URL,涉及10,445个页面;HTTP状态、跳转和锚点检查无未解决问题。
- 2,262个本地链接的文件路径及标题锚点检查通过。
- PyTorch页面通过规范域名`docs.pytorch.org`检查;跟随HTTP和HTML跳转。检查新链接实际正文中的API命中,排除其他API的同名匹配。
- 逐条核对133处下架条目与最终处理清单一致,14处公开名称校正前后及所有保留条目的产品支持字段未变。本轮7个修改文件无新增markdownlint 0.12.0问题,PR全部221个Markdown文件的MD028检查通过。
- `git diff upstream/master HEAD --check`通过。
- 本次为文档修改,未执行NPU运行测试或完整文档站点构建;远端CI待运行确认。外链结果反映本次检查时的状态。
# 【CheckList】
- [x] 代码注释完备,正确记录错误日志(不涉及运行时代码)
- [x] 代码实现进行了返回值、空指针等校验(不涉及运行时代码)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常(待CI)
See merge request: Ascend/pytorch!46481
2026-09-20 09:18:00 +08:00
pta-robot
6257d16281
Update torchair commit id
...
Co-authored-by: pta-robot<pta_robot@163.com >
# message auto-generated for no-merge-commit merge:
!46577 merge master into master
Update torchair commit id
Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-18 18:03:54.
See merge request: Ascend/pytorch!46577
2026-09-20 09:13:01 +08:00