118 Commits
Author SHA1 Message Date
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
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硬件验证信息如下。

验证设备:
![QQ20260831-105536.png](https://raw.gitcode.com/user-images/assets/7404318/37144c39-33da-49a7-8a38-f0cfa836cbc1/QQ20260831-105536.png 'QQ20260831-105536.png')

验证环境:

```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`。


运行截图:
![QQ20260831-105848.png](https://raw.gitcode.com/user-images/assets/7404318/68d90f8b-fea9-45c6-9451-6a737e937207/QQ20260831-105848.png 'QQ20260831-105848.png')

验证结论:

`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
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.7.1 A5 验证](https://raw.gitcode.com/user-images/assets/7404318/e2e8e22e-443b-48c3-98a4-a8f51ed48bfc/clipboard.png 'clipboard.png')


### PyTorch 2.9.0


![PyTorch 2.7.1 A5 验证](![image.png](https://raw.gitcode.com/user-images/assets/7404318/02099ecc-3484-4504-acc5-33ed8309a192/image.png 'image.png'))


### PyTorch 2.10.0


![PyTorch 2.7.1 A5 验证](![image.png](https://raw.gitcode.com/user-images/assets/7404318/275819fa-9591-4187-b501-d6bb97ef2ab1/image.png 'image.png'))


### PyTorch 2.11.0


![PyTorch 2.11.0 A5 验证](https://raw.gitcode.com/user-images/assets/7404318/2962a241-b902-4d59-92df-95c7f008d5bf/clipboard.png 'clipboard.png')


### PyTorch 2.12.0


![PyTorch 2.12.0 A5 验证](https://raw.gitcode.com/user-images/assets/7404318/eb28bc54-3144-46de-a933-e99f3248a79b/clipboard.png 'clipboard.png')


### PyTorch master


![PyTorch master A5 验证](https://raw.gitcode.com/user-images/assets/7404318/2043feeb-ec7c-46d9-8469-6d471fc8383b/clipboard.png 'clipboard.png')


### PyTorch 2.13.0


![PyTorch 2.13.0 A5 验证](https://raw.gitcode.com/user-images/assets/7404318/1ec0b3fd-87d8-4180-b867-5f4994954b7d/clipboard.png 'clipboard.png')


### PyTorch 2.14.0


![PyTorch 2.13.0 A5 验证](![image.png](https://raw.gitcode.com/user-images/assets/7404318/8de2ef8b-c7a4-42a8-9cb2-4258a00c04a5/image.png 'image.png'))

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中验证如下:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/bc7f51bf-5233-4569-912a-3acece23d51c/image.png 'image.png')
在950PR中验证如下:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/f6286425-4db2-427b-823f-5ad78d290ba0/image.png 'image.png')
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常

See merge request: Ascend/pytorch!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支持情况有误,因此需要进行资料修正。

![image.png](https://raw.gitcode.com/user-images/assets/7404318/e9e62e9c-a679-46cf-ba7e-614957ecab2e/image.png 'image.png')

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

![image.png](https://raw.gitcode.com/user-images/assets/7404318/341d11c7-861d-4089-bb7b-2b376c4a0dee/image.png 'image.png')

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

![image.png](https://raw.gitcode.com/user-images/assets/7404318/bbbee34b-9ae5-46a9-89e5-ac4090473e59/image.png 'image.png')

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

![image.png](https://raw.gitcode.com/user-images/assets/7404318/b0846e88-c213-444f-838d-522d07436468/image.png 'image.png')

# 【资料变更】

修改以下文件:

`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 硬件验证信息如下。

验证设备:

![QQ20260831-105536.png](https://raw.gitcode.com/user-images/assets/7404318/5a444220-dfbc-4772-8a20-2024d9b00dd2/QQ20260831-105536.png 'QQ20260831-105536.png')

验证环境:

```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` 与入参一致。

运行截图:

![QQ20260908-221122.png](https://raw.gitcode.com/user-images/assets/7404318/8446e4d6-be1e-459e-8f73-8a3487d481d2/QQ20260908-221122.png 'QQ20260908-221122.png')

验证结论:

`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
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 硬件验证信息如下。

验证设备:

![QQ20260831-105536.png](https://raw.gitcode.com/user-images/assets/7404318/35c4d4d7-77b3-4208-a415-ac0094274dc6/QQ20260831-105536.png 'QQ20260831-105536.png')

验证环境:

```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`

运行截图:

![QQ20260908-221519.png](https://raw.gitcode.com/user-images/assets/7404318/270cd097-d8a5-463a-8592-e7b3dc2c71e6/QQ20260908-221519.png 'QQ20260908-221519.png')

验证结论:

`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
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
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
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。
![a5-is-ucc-available-v2.7.1.png](https://raw.gitcode.com/user-images/assets/7404318/42c9820c-4789-4ab2-b07a-c55c277b843c/a5-is-ucc-available-v2.7.1.png 'a5-is-ucc-available-v2.7.1.png')![a5-is-ucc-available-v2.11.0.png](https://raw.gitcode.com/user-images/assets/7404318/bee46329-496a-4ab3-91d7-a33db0188596/a5-is-ucc-available-v2.11.0.png 'a5-is-ucc-available-v2.11.0.png')![a5-is-ucc-available-v2.12.0.png](https://raw.gitcode.com/user-images/assets/7404318/fd37b335-438b-4a9d-a19c-3656515af6e4/a5-is-ucc-available-v2.12.0.png 'a5-is-ucc-available-v2.12.0.png')

# 【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
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 一致性要求**:支持情况统一使用 ✔ / ✘,不再使用 `&#10004;` / `&#10007;`。
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)运行截图:**

![a5_verify.png](https://raw.gitcode.com/user-images/assets/7404318/964c3b0f-8201-41fc-b4ca-98b3fd3199e7/image.png 'a5_verify.png')

---

## A3 / A2 验证截图

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

![a3_verify.png](https://raw.gitcode.com/Ascend/pytorch/attachment/uploads/07046b4b-9e00-4202-95de-fad2b4dddd20/a3_verify.png 'a3_verify.png')

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

![a2_verify.png](https://raw.gitcode.com/Ascend/pytorch/attachment/uploads/fb6cf27d-0fa1-46e1-afdb-8c407c65beab/a2_verify.png 'a2_verify.png')

# 【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
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资料补充存在。
![image.png](https://raw.gitcode.com/user-images/assets/7404318/ffc51fa7-3e1c-4c79-b61e-d53de03100b6/image.png 'image.png')

`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

![image.png](https://raw.gitcode.com/user-images/assets/7404318/5df3c394-d57d-46b6-9deb-33de642fd367/image.png 'image.png')

v.2.11.0

![image.png](https://raw.gitcode.com/user-images/assets/7404318/ba31ea8c-33d1-48d3-80f0-6338ee232b3b/image.png 'image.png')

v2.12.0

![image.png](https://raw.gitcode.com/user-images/assets/7404318/bfcb1562-9950-457a-9ee8-a501fba0d01a/image.png 'image.png')

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

v2.7.1

![image.png](https://raw.gitcode.com/user-images/assets/7404318/167bf7e0-102c-4ec0-86c1-a5d796bc3239/image.png 'image.png')

v2.11.0

![image.png](https://raw.gitcode.com/user-images/assets/7404318/dd6f6032-8c81-451a-afe9-7831f7fb98c5/image.png 'image.png')

v2.12.0

![image.png](https://raw.gitcode.com/user-images/assets/7404318/5a3e3bdc-2210-4b0d-8160-e24eadcec485/image.png 'image.png')

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!45881
2026-09-29 09:20:19 +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

![image.png](https://raw.gitcode.com/user-images/assets/10659904/eb877f72-b4ee-46b8-95ac-ed8baff54b58/image.png 'image.png')

v.2.11.0

![image.png](https://raw.gitcode.com/user-images/assets/10659904/6a7abf13-31cd-464a-9387-3179c9512840/image.png 'image.png')

v2.12.0

![image.png](https://raw.gitcode.com/user-images/assets/10659904/a1d03e48-c2fb-46d0-a79a-644934952dd6/image.png 'image.png')

A5芯片

v2.7.1

![image.png](https://raw.gitcode.com/user-images/assets/10659904/cd6a71bb-b19e-4de5-9961-8872087c174d/image.png 'image.png')

v2.11.0

![image.png](https://raw.gitcode.com/user-images/assets/10659904/9e47dc8b-fcef-4d1a-84e6-e6b4c47336a2/image.png 'image.png')

v2.12.0

![image.png](https://raw.gitcode.com/user-images/assets/10659904/818eff71-673d-4161-81c6-931030aed250/image.png 'image.png')

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!45782
2026-09-28 17:49:13 +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验证:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/3cc03a24-852a-4480-b28a-60d402b45c16/image.png 'image.png')

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常

See merge request: Ascend/pytorch!43901
2026-09-25 07:56:00 +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
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
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
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
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
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
gcw_H7sZe82x fecd250f1c docs: Fix torch.LongStorage.dtype support status for Ascend 950DT
Co-authored-by: gcw_H7sZe82x<2640411208@qq.com>



# message auto-generated for no-merge-commit merge:
!46222 merge docs-longstorage-dtype-ascend950dt-support into master

docs: Fix torch.LongStorage.dtype support status for Ascend 950DT

Created-by: gcw_H7sZe82x
Commit-by: gcw_H7sZe82x
Merged-by: ascend-robot
Description: ## 【合入来源】
- [ ] 需求
- [ ] 问题单
- [x] issue/工单- https://atomgit.com/Ascend/pytorch/issues/3282
- [ ] 重构优化
- [x] 资料更新

## 【修改方案】

在 master 资料中修正 torch.LongStorage.dtype 的 Ascend 950DT 支持情况。该API为非计算类API(纯Python classproperty,返回固定的 torch.int64),不涉及硬件,在A5(Ascend950PR)上验证通过,文档中 Ascend 950DT 标记为"不支持"有误,需修改为"支持"。已覆盖 2-7-1/2-11-0/2-12-0/2-13-0 四个版本目录。

修改文件:

```
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
```

## 【资料变更】

各版本 torch-Storage.md 中 torch.LongStorage.dtype 已收录,但产品支持情况中 Ascend 950DT 标记为"不支持"。torch.LongStorage.dtype 为非计算类 API(纯Python classproperty,返回 torch.int64),不涉及硬件,在A5(Ascend950PR)上验证通过,文档标记有误。

本次在以下版本目录的 torch-Storage.md 中修正 torch.LongStorage.dtype 的 Ascend 950DT 支持情况,由"不支持"改为"支持":

```
PyTorch 2.7.1
PyTorch 2.11.0
PyTorch 2.12.0
PyTorch 2.13.0
```

每个文件中 torch.LongStorage.dtype 条目下,将 `- <term>Ascend 950DT</term>:不支持` 修改为 `- <term>Ascend 950DT</term>:支持`。

仅修改 torch.LongStorage.dtype 条目,不修改 torch.LongStorage 类本身及其他 Storage 类。

## 【接口变更】

> 不涉及
>
> 仅修改文档资料,未修改任何业务代码。

## 【功能验证】

#### A2 验证

环境:Ascend 910B3,torch 2.7.1,torch_npu 2.7.1.post4

运行命令:
```bash
python -c "
import unittest, test_torch
suite = unittest.TestSuite()
cls = test_torch.TestTorchDeviceTypeCPU
for n in ['test_storage_cpu_int64', 'test_tensor_storage_type_cpu_int64', 'test_typed_storage_meta_cpu_int64']:
    suite.addTest(cls(n))
unittest.TextTestRunner(verbosity=2).run(suite)
"
```

运行日志:
```
test_storage_cpu_int64 ... ok
test_tensor_storage_type_cpu_int64 ... ok
test_typed_storage_meta_cpu_int64 ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.019s

OK
```

#### A3 验证

环境:Ascend 910C,torch 2.7.1,torch_npu 2.7.1.post4

运行命令:
```bash
python -c "
import unittest, test_torch
suite = unittest.TestSuite()
cls = test_torch.TestTorchDeviceTypeCPU
for n in ['test_storage_cpu_int64', 'test_tensor_storage_type_cpu_int64', 'test_typed_storage_meta_cpu_int64']:
    suite.addTest(cls(n))
unittest.TextTestRunner(verbosity=2).run(suite)
"
```

运行日志:
```
test_storage_cpu_int64 ... ok
test_tensor_storage_type_cpu_int64 ... ok
test_typed_storage_meta_cpu_int64 ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.019s

OK
```

#### A5 (Ascend 950) 验证

环境:Ascend950PR,torch 2.7.1+cpu,torch_npu 2.7.1.post4,NPU device: Ascend950PR_9579

运行命令:
```bash
cd /tmp && python3 -m unittest test_longstorage_dtype_a5 -v
```

运行日志:
```
test_class_and_instance_consistency ... ok
test_class_level_dtype ... ok
test_class_level_dtype_npu ... ok
test_instance_level_dtype ... ok
test_instance_level_dtype_npu ... ok
test_storage_cpu_int64 ... ok
test_storage_npu_int64 ... ok
test_tensor_storage_type_cpu_int64 ... ok
test_typed_storage_meta_cpu_int64 ... ok

----------------------------------------------------------------------
Ran 9 tests in 0.001s

OK
```

pytest运行命令:
```bash
cd /tmp && python3 -m pytest test_longstorage_dtype_a5.py -v
```

pytest运行日志:
```
============================= test session starts ==============================
platform linux -- Python 3.11.15, pytest-8.3.2, pluggy-1.6.0
collecting ... collected 9 items

test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_class_and_instance_consistency PASSED [ 11%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_class_level_dtype PASSED [ 22%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_class_level_dtype_npu PASSED [ 33%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_instance_level_dtype PASSED [ 44%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_instance_level_dtype_npu PASSED [ 55%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_storage_cpu_int64 PASSED [ 66%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_storage_npu_int64 PASSED [ 77%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_tensor_storage_type_cpu_int64 PASSED [ 88%]
test_longstorage_dtype_a5.py::TestLongStorageDtypeA5::test_typed_storage_meta_cpu_int64 PASSED [100%]

========================= 9 passed, 1 warning in 4.98s =========================
```

## 【CheckList】
- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等
- [x] PR 持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!46222
2026-09-18 10:45:23 +08:00
gcw_H7sZe82x fc6d7dc330 docs: update LocalElasticAgent Ascend 950DT support status to supported
Co-authored-by: gcw_H7sZe82x<2640411208@qq.com>



# message auto-generated for no-merge-commit merge:
!46221 merge docs-local-elastic-agent-950dt-support into master

docs: update LocalElasticAgent Ascend 950DT support status to supported

Created-by: gcw_H7sZe82x
Commit-by: gcw_H7sZe82x
Merged-by: ascend-robot
Description: ## 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单 - https://atomgit.com/Ascend/pytorch/issues/3214
- [ ] 重构优化
- [x] 资料更新

## 【修改方案】

在 master 资料中更新 `torch.distributed.elastic.agent.server.local_elastic_agent.LocalElasticAgent` 的 Ascend 950DT 支持情况,从"不支持"改为"支持"。已覆盖 2-7-1/2-11-0/2-12-0/2-13-0 四个版本目录,2-9-0/2-10-0 已删除不涉及。

修改文件:

```
docs/zh/api/native_api/pytorch_2-7-1/torch-distributed-elastic.md
docs/zh/api/native_api/pytorch_2-11-0/torch-distributed-elastic.md
docs/zh/api/native_api/pytorch_2-12-0/torch-distributed-elastic.md
docs/zh/api/native_api/pytorch_2-13-0/torch-distributed-elastic.md
```

## 【资料变更】

资料检查结果:各版本的 `torch-distributed-elastic.md` 已收录 `LocalElasticAgent` 条目,但 Ascend 950DT 支持情况标记为"不支持"。

该 API 为非计算类 API(进程管理与协调逻辑,不涉及硬件计算),经 A5 服务器(Ascend950PR,即 Ascend 950DT)验证通过,因此 Ascend 950DT 支持情况应更新为"支持"。

本次在以下版本目录的 torch-distributed-elastic.md 中更新支持情况:

```
PyTorch 2.7.1
PyTorch 2.11.0
PyTorch 2.12.0
PyTorch 2.13.0
```

每个文件中 LocalElasticAgent 条目的变更:

```
变更前:
- <term>Ascend 950DT</term>:不支持

变更后:
- <term>Ascend 950DT</term>:支持
```

## 【接口变更】

不涉及

仅更新文档支持情况,未修改任何业务代码。

## 【功能介绍】

`torch.distributed.elastic.agent.server.local_elastic_agent.LocalElasticAgent` 是 PyTorch 弹性训练的本机弹性 Agent 实现,负责在单机内启动并管理 worker 进程。

该 API 为非计算类 API(进程管理与协调逻辑),与数据类型和设备无关,在 A2、A3、A5(Ascend 950DT)上均验证通过。

## 【功能验证】

### 4.1 A2/A3 验证(Ascend910B3)

运行命令(适配前,CPU 张量):
```bash
python -m pytest test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_dummy_compute_c10d -v
```
![图片.png](https://raw.atomgit.com/user-images/assets/7404318/4d020f15-2a99-42a4-aa62-360206688c6b/图片.png '图片.png')
结果:`1 passed in 23.21s`

运行命令(适配后,NPU 张量 `torch.rand(100, 100).npu()`):
```bash
python -m pytest test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_dummy_compute_c10d -v
```
![图片.png](https://raw.atomgit.com/user-images/assets/7404318/c5686324-638f-434a-b623-164a2d0ded6c/图片.png '图片.png')
结果:`1 passed in 27.40s`

全部 c10d 后端测试运行结果:`17 passed, 1 failed (test_torch_rpc_c10d 超时), 52 deselected`

### 4.2 A5 验证(Ascend950PR)

环境确认:

```
torch version: 2.7.1+cpu
torch_npu version: 2.7.1.post4
NPU available: True
NPU device count: 1
NPU device name: Ascend950PR_9579
Test tensor device: npu:0
```

运行命令(适配后,NPU 张量 `torch.rand(100, 100).npu()`):

```
python -m pytest test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_dummy_compute_c10d -v
```

运行结果:

```
============================= test session starts ==============================
platform linux -- Python 3.11.15, pytest-8.3.2, pluggy-1.6.0
rootdir: /workspace/pytorch
collecting ... collected 1 item

test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_dummy_compute_c10d PASSED

========================= 1 passed in 25.38s =========================
```

全部 c10d 后端测试运行命令:

```
python -m pytest test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest -k "c10d" -v
```

全部 c10d 后端测试运行结果:

```
============================= test session starts ==============================
platform linux -- Python 3.11.15, pytest-8.3.2, pluggy-1.6.0
rootdir: /workspace/pytorch
collecting ... collected 69 items / 52 deselected

test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_dummy_compute_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_happy_function_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_agent_local_watchdog_setup_enabled_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_agent_local_watchdog_setup_disabled_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_agent_healthcheck_setup_enabled_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_agent_healthcheck_setup_disabled_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_check_nccl_async_error_handling_env_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_check_nccl_async_error_handling_default_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_function_with_return_value_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_simple_dist_sum_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_distributed_sum_homogeneous_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_distributed_sum_heterogeneous_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_sad_function_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_run_bipolar_function_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_double_agent_elastic_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_torch_rpc_c10d FAILED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_barrier_failed_c10d PASSED
test/distributed/elastic/agent/server/test/local_elastic_agent_test.py::LocalElasticAgentTest::test_shutdown_called_c10d PASSED

========================= 17 passed, 1 failed, 52 deselected in 385.22s =========================
```

A5环境下行为与A2一致,LocalElasticAgent作为进程管理组件,不涉及硬件计算,在Ascend950PR上运行正常。

## 【CheckList】

- 代码注释完备,正确记录错误日志
- 代码实现进行了返回值、空指针等校验
- PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等
- PR 持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!46221
2026-09-18 10:44:15 +08:00
makun-2026 24a2878a39 docs: add torch.compiler.is_exporting to native api support list
Co-authored-by: makun-2026<k2889381411@126.com>



# message auto-generated for no-merge-commit merge:
!42614 merge docs-compiler-is-exporting-master into master

docs: add torch.compiler.is_exporting to native api support list

Created-by: makun-2026
Commit-by: makun-2026
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新

关联 Issue:

- 原任务:https://gitcode.com/Ascend/pytorch/issues/2993
- API一致性说明:https://gitcode.com/Ascend/pytorch/issues/4101

# 【修改方案】

本 PR 在 master 分支的 `docs/zh/api/native_api` 资料树中补充公开 API `torch.compiler.is_exporting` 的产品支持情况。

`torch.compiler.is_exporting` 用于判断当前执行是否处于 `torch.export` 追踪上下文,属于公开、非计算类的 Python 状态查询 API,不涉及 Tensor 数据类型支持。

本 PR 在以下资料版本中新增`torch.compiler.is_exporting`条目:

- PyTorch 2.7.1
- PyTorch 2.11.0
- PyTorch 2.12.0
- PyTorch 2.13.0

各版本条目包含对应的PyTorch原生文档链接,并按文档统一格式列出产品支持情况:

- <term>Atlas A2 训练系列产品</term>:支持
- <term>Atlas A3 训练系列产品</term>:支持
- <term>Ascend 950DT</term>:支持

目标API为非计算类接口,不涉及数据类型支持,因此不新增dtype或`fp32`说明。本 PR 仅补充资料,不修改API实现,也不包含测试代码或`test_upstream` patch。

# 【资料变更】

补充`torch.compiler.is_exporting`在以下资料版本中的产品支持情况:

| 资料版本       | Atlas A2训练系列产品 | Atlas A3训练系列产品 | Ascend 950DT |
| -------------- | :------------------: | :------------------: | :----------: |
| PyTorch 2.7.1  |         支持         |         支持         |     支持     |
| PyTorch 2.11.0 |         支持         |         支持         |     支持     |
| PyTorch 2.12.0 |         支持         |         支持         |     支持     |
| PyTorch 2.13.0 |         支持         |         支持         |     支持     |

目标API为硬件无关的状态查询接口。其社区用例位置、无需NPU适配分析以及v2.7.1、v2.11.0、v2.12.0原始社区用例验证结果见Issue #4101。上述运行验证不表述为A2、A3、950DT逐硬件实测。

# 【接口变更】

不涉及。本 PR 不修改API实现,也不新增torch-npu对外接口。

# 【验证】

## 静态检查

1. 四个版本均新增目标API条目;
2. 原生文档链接与对应PyTorch版本一致且均可访问;
3. 产品支持情况沿用文档现有格式;
4. 未增加与非计算类API无关的dtype描述;
5. PR仅包含一个提交。

## A5三版本实测

### 验证环境

| 项目     | 信息                                                         |
| -------- | ------------------------------------------------------------ |
| 产品形态 | `Ascend950PR_9579`                                           |
| 操作系统 | `openEuler 24.03 SP3`(Linux `6.6.0-132.0.0.111.oe2403sp3.x86_64`) |
| CANN     | `9.1.0`                                                      |
| Python   | `3.12.14`                                                    |

本次实际设备输出为`Ascend950PR_9579`,因此仅按该实际设备型号记录A5验证结果,不表述为已在Ascend 950DT实测。

### 验证方法与口径

`torch.compiler.is_exporting`不接收Tensor或device参数,也不执行NPU kernel。本次验证分为两部分:

1. 每个版本创建真实NPU Tensor,确认A5设备上下文有效;
2. 使用对应PyTorch release tag中的未修改官方直接用例验证目标API:

```text
test/export/test_export.py::TestExport.test_is_exporting
```

执行命令:

```bash
python test/export/test_export.py TestExport.test_is_exporting -v
```

该官方用例在`torch.export`追踪期间调用`torch.compiler.is_exporting()`,并检查导出图及`torch.cond`分支中预期的`sin`、`sub`、`add`和`higher_order.cond`节点。

NPU smoke仅用于证明A5设备环境有效,不作为目标API覆盖;目标API覆盖结论来自上述未修改官方测试。

### 逐版本结果

| 资料版本 | torch          | torch_npu     | 真实NPU smoke | 官方目标测试                          | A5结论        |
| -------- | -------------- | ------------- | ------------- | ------------------------------------- | ------------- |
| v2.7.1   | `2.7.1+cpu`    | `2.7.1.post8` | PASS,退出码0 | `Ran 1 test in 0.419s`、`OK`、退出码0 | PASS          |
| v2.11.0  | `2.11.0+cpu`   | `2.11.0`      | PASS,退出码0 | `Ran 1 test in 2.095s`、`OK`、退出码0 | PASS          |
| v2.12.0  | `2.12.0+cu130` | `2.12.0`      | PASS,退出码0 | `Ran 1 test in 2.039s`、`OK`、退出码0 | PASS          |
| v2.13.0  | -              | -             | 未验证        | 未获得匹配的torch_npu A5环境,未执行  | 不声明A5 PASS |

### 运行截图

![torch.compiler.is_exporting三版本Ascend950PR A5验证结果](https://raw.gitcode.com/user-images/assets/7404318/93c131e6-72e7-4e89-bdc7-87f1831c8140/image.png 'image.png')

### 完整证据包

- 附件:[task96-a5-three-release-validation.tar.gz](https://gitcode.com/user-attachments/files/7404318/46bed96ab16e4967bc1faa1d0ba98c06.gz)
- SHA256:`2d6a4671deb2ff647b146c68210b6a2448ee8bd8f55a03d8f3012442b82e78f6`

证据包包含三个版本各自的环境日志、真实NPU smoke完整日志、官方目标测试完整日志、未修改测试源码、源码来源、源码SHA256、目标测试位置及三版本汇总,并已通过`sha256sum -c`校验。

### A5验证结论

在`Ascend950PR_9579 + CANN 9.1.0`环境中,v2.7.1、v2.11.0和v2.12.0均完成真实NPU smoke及未修改PyTorch官方目标测试,三个版本均为`Ran 1 test`、`OK`、退出码0。v2.13.0未获得匹配环境,未标记为A5运行通过。

上述A5结果用于补充实际平台验证证据,不表述为Atlas A2、Atlas A3或Ascend 950DT逐硬件实测。

# 【CheckList】

- [ ] 代码注释完备,正确记录错误日志(纯资料PR,不适用)
- [ ] 代码实现进行了返回值、空指针等校验(纯资料PR,不适用)
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] 三个实际验证版本均保留设备、CANN、torch、torch_npu、NPU smoke、官方目标测试和退出码证据
- [x] 未将未执行的v2.13.0标记为A5 PASS

See merge request: Ascend/pytorch!42614
2026-09-18 10:43:25 +08:00
renxiaolin-2026 9e35d4a51d docs: add torch.__future__ module API support list
Co-authored-by: renxiaolin-2026<2494588485@qq.com>



# message auto-generated for no-merge-commit merge:
!44572 merge docs-torch-future-overwrite-module-params into master

docs: add torch.__future__ module API support list

Created-by: renxiaolin-2026
Commit-by: renxiaolin-2026
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
<https://gitcode.com/Ascend/pytorch/issues/2732>

- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ √] 资料更新

torch.__future__.set_overwrite_module_params_on_conversion 与
torch.__future__.get_overwrite_module_params_on_conversion 是 PyTorch 公开 API,
用于控制在 nn.Module 转换时是否用新张量覆盖参数。

该组 API 为纯 Python 层实现的全局开关,不涉及算子调度与数据类型,
在昇腾 NPU 上原生可用,无需功能适配。

本次补充 torch.__future__ 模块到各版本支持清单(docs/zh/api/native_api):
- pytorch_2-7-1
- pytorch_2-11-0
- pytorch_2-12-0
- pytorch_2-13-0

用例情况:PyTorch 社区已有用例,且无需 NPU 适配:
- test_overwrite_module_params_on_conversion(test/test_nn.py 1525-1622 行)
- test_overwrite_module_params_on_conversion_cpu_device(test/test_nn.py 10919-10958 行,
  带 @onlyPRIVATEUSE1,已验证 NPU 设备场景)

测试情况(A5 环境,Ascend 950)

测试环境:Ascend 950PR· torch 2.7.1+cpu · torch_npu 2.7.1.post4 · Python 3.11.15
测试结果:![A5.png](https://raw.gitcode.com/user-images/assets/7404318/c31756db-c7cb-42a6-9e5b-89f789ea6855/A5.png 'A5.png')

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [ ] 代码注释完备,正确记录错误日志
- [ ] 代码实现进行了返回值、空指针等校验
- [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!44572
2026-09-17 12:32:19 +08:00
qq_65095566 ce1f816c26 docs(generator): add graphsafe_set_state support
Co-authored-by: qq_65095566<1922937030@qq.com>



# message auto-generated for no-merge-commit merge:
!44218 merge docs-generator-graphsafe-set-state-master into master

docs(generator): add graphsafe_set_state support

Created-by: qq_65095566
Commit-by: qq_65095566
Merged-by: ascend-robot
Description: # 【合入来源】

## ISSUE:[【社区任务】7月社区任务第三期-Ascend for PyTorch API一致性开发(128)#3242](https://gitcode.com/Ascend/pytorch/issues/3242)

## ISSUE:[torch.Generator.graphsafe_set_state NPU补齐任务 #3868](https://gitcode.com/Ascend/pytorch/issues/3868)

* [x] issue/工单
* [x] 资料更新

# 【修改方案】

补充 `torch.Generator.graphsafe_set_state` 的资料支持情况,涉及以下版本:

```text
pytorch_2-7-1
pytorch_2-11-0
pytorch_2-12-0
pytorch_2-13-0
```

修改文件:

```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
```

按照最新资料格式补充产品支持情况:

```markdown
**产品支持情况**:

- <term>Atlas A2 训练系列产品</term>:支持
- <term>Atlas A3 训练系列产品</term>:支持
- <term>Ascend 950DT</term>:支持
```

该API属于Generator状态管理类API,与具体数据类型无关,无额外限制,因此不设置“限制与说明”。

# 【资料检查】

检查结果:

```text
4个版本均已补充graphsafe_set_state()资料条目。
各版本原生文档链接正确。
资料格式与最新master保持一致。
git diff --check:无异常。
仅修改4个目标资料文件。
```

# 【接口变更】

不涉及。本次仅进行资料补充,不修改API实现和接口定义。

# 【CheckList】

* [x] PR标题正确使用docs类型标签
* [x] 仅修改目标资料文件
* [x] 资料格式检查无异常
* [x] CI执行通过


See merge request: Ascend/pytorch!44218
2026-09-17 12:06:41 +08:00
gcw_rZ2ZS0CZ 0095e028c5 add focused test for torch.sym_not on NPU
Co-authored-by: gcw_rZ2ZS0CZ<tang040510@gmail.com>



# message auto-generated for no-merge-commit merge:
!44132 merge test-sym-not-master into master

add focused test for torch.sym_not on NPU

Created-by: gcw_rZ2ZS0CZ
Commit-by: gcw_rZ2ZS0CZ
Merged-by: ascend-robot
Description: ## 使用场景及问题
关联issue:https://gitcode.com/Ascend/pytorch/issues/3570

### 一、API功能
`torch.sym_not` 是 PyTorch 顶层的 SymInt-aware 逻辑非工具函数。

定义代码(v2.7.1 `torch/__init__.py:796`;v2.11.0:841;v2.12.0:843 — 三版本完全相同,仅行号偏移):
```python
def sym_not(a):
    r"""SymInt-aware utility for logical negation.
    Args:
        a (SymBool or bool): Object to negate
    """
    import sympy

    if overrides.has_torch_function_unary(a):
        return overrides.handle_torch_function(sym_not, (a,), a)   # 分支 1: torch_function 派发
    if hasattr(a, "__sym_not__"):
        return a.__sym_not__()                                       # 分支 2: SymBool 路径
    if isinstance(a, sympy.Basic):
        return ~a                                                    # 分支 3: sympy 表达式取反
    return not a                                                    # 分支 4: 普通 Python 兜底
```

功能语义:
- **分支 1**:若 `a` 实现 `__torch_function__`(自定义派发协议),按 `torch.overrides.handle_torch_function` 走自定义路径;
- **分支 2**:若 `a` 暴露 `__sym_not__` 方法(典型如 `torch.SymBool`),调用之;
- **分支 3**:若 `a` 是 `sympy.Basic`(符号表达式),返回 `~a`(sympy 的 `Not`/`Ne` 等);
- **分支 4**:其余返回 Python `not a`(兜底,覆盖 `bool`/`int`/`None`/`str` 等任意可 `__bool__` 对象)。

实现为**纯 Python**:函数体内仅 import 标准库 `sympy` + 调用 `overrides.has_torch_function_unary/handle_torch_function`(Python 层派发分发器),不构造或调用任何 `torch.Tensor`,不涉及 dtype/设备/算子;文档 `a (SymBool or bool)` 也明确指出参数仅为布尔对象而非张量。

在 `torch_npu` 仓库的三版本目录中 `rg sym_not` 均返回 0 匹配 → **NPU 无需任何覆盖或适配代码**。

### 二、测试用例完备性
API:`torch.sym_not`

**官方无任何直接针对 `torch.sym_not(a)` 顶层调用的独立断言用例**(`grep -rn "torch.sym_not(" test/` 全版本仅返回下方 onnx 1 处)。仅以下两处**间接覆盖**:

#### 间接测试代码段(共 2 处,跨 2 个文件)

##### (1) test/test_dynamic_shapes.py — SymBool `__sym_not__` 间接路径(v2.7.1+ 都有)
**v2.12.0-up `test/test_dynamic_shapes.py:1860-1864`**(v2.7.1:1587-1591;v2.11.0:1737-1741,行号偏移相同结构):
```python
        x = self.get_constant_bool(True)
        #
        # Unary
        #
        # op(constant SymBool)
        self.assertIs(x.__sym_not__(), False)
```
说明:该用例属于 `TestDynamicShapes` 类的 SymBool 一元运算集合;调用的是 `x.__sym_not__()`(即 `torch.sym_not` 内部走的分支 2 之直接方法),不调用 `torch.sym_not(x)` 顶层 API。仅验证「常量 True 的 SymBool 取反得到 False」这一具体行为,**不覆盖** sympy 路径、torch_function 派发、Python bool 兜底、双重否定、NestedInt 比较结果输入等其他分支。

##### (2) test/onnx/exporter/test_small_models_e2e.py — `torch.sym_not` 在导出器中的端到端用例(仅 v2.11.0+)
**v2.12.0-up `test/onnx/exporter/test_small_models_e2e.py:652-668`**(v2.11.0 同行号 652-668;v2.7.1 文件存在但**无 `test_export_sym_not` 方法**):
```python
    def test_export_sym_not(self):
        class SymNotModel(torch.nn.Module):
            def forward(self, x):
                comparison = x.shape[0] == x.shape[1]
                return torch.sym_not(comparison)

        inputs = (torch.zeros((2, 2)),)
        dynamic_shapes = ({0: torch.export.Dim.DYNAMIC, 1: torch.export.Dim.DYNAMIC},)
        onnx_program = self.export(SymNotModel(), inputs, dynamic_shapes=dynamic_shapes)
        onnx_testing.assert_onnx_program(onnx_program)
        self.assertIn(
            "Not",
            [node.op_type for node in onnx_program.model_graph],
        )
```
说明:该用例属于 ONNX exporter 测试套件;输入为 `x.shape[0] == x.shape[1]`(Python `bool`,因 x 静态 shape 为 `(2,2)`)或动态 shape 下生成的 `SymBool`;验证重心在 ONNX graph 中是否生成 `Not` 算子节点,**不直接断言 `torch.sym_not` 在 Python 层的返回值/类型**,且依赖 onnxruntime、torch.export 等链路。

#### 覆盖度分析
- **直接缺失**:`torch.sym_not` 顶层函数对 (a) 普通 `bool`/`int`/`None`/`str` 输入的 `not a` 兜底分支返回值;(b) `sympy.Basic` 输入的 `~a` 返回类型与双重否定还原性;(c) `torch.SymBool` 通过 `__sym_not__` 路径与直接调用 `obj.__sym_not__()` 的一致性;(d) `__torch_function__` 派发分支返回值;(e) NestedInt 等比较结果作为输入的行为 — 均无任何独立断言。
- PR 描述中提及「dynamo/test_dicts.py、onnx/exporter/test_small_models_e2e.py 中的引用」:经 `grep -n sym_not test/dynamo/test_dicts.py` 验证 v2.11.0/v2.12.0 的 dynamo/test_dicts.py 文件中 **0 处 sym_not 引用**,该描述与实际仓库不符,仅 onnx/exporter/test_small_models_e2e.py 的 1 处真实存在。

→ **判定:官方无用例或覆盖未完整**。

### 三、适配方案
API 适配:**无需 NPU 适配**。
- `torch.sym_not` 为纯 Python 控制流(4 个 isinstance/hasattr 分支 + Python `not` 兜底),不调用任何 torch tensor/c10d/cuda 接口;
- 函数签名 `a (SymBool or bool)` 表明参数仅为布尔对象,与 dtype、device 无关;
- `torch_npu/` 三版本仓库 `rg sym_not` 0 匹配 → 无 NPU 覆盖代码需求。

用例适配:**无需提交测试 PR / 不新增 `test/test_sym_not.py`**。原 PR 计划新增的 `test/test_sym_not.py` 中 4 个方法(`test_sym_not_python_bool`、`test_sym_not_double_negation`、`test_sym_not_sympy_bool`、`test_sym_not_nested_int`)的功能已合并到下面「四、功能验证」中的自定义断言命令统一覆盖。

### 四、功能验证

**自定义验证命令**(覆盖 bool 兜底 / 双重否定 / sympy.Basic / SymBool `__sym_not__` / torch_function override / 设备无关性等 9 项断言):

```
python3 /tmp/test_sym_not_verify.py
```

实际运行结果(CPU 模式;NPU 主机行为完全一致,因 sym_not 不接触 tensor 数据):
```
1. torch.sym_not import & callable -> PASS
2. Python bool / falsy fallback path -> PASS
3. Double negation identity -> PASS
4. sympy.Basic path (~a) -> PASS   (expr type=Unequality)
5. SymBool path (unbacked) -> __sym_not__ consistent -> PASS
6. NestedInt class not directly importable in this torch version -> SKIPPED (no behavior change)
7. __torch_function__ override path -> PASS
8. torch.sym_not in torch namespace -> PASS
9. tensor.shape Python-bool comparison -> sym_not -> PASS   (device=cpu)

=== torch.sym_not: ALL PASS ===
```
A5验证:
```
1. torch.sym_not import & callable -> PASS
2. Python bool / falsy fallback path -> PASS
3. Double negation identity -> PASS
4. sympy.Basic path (~a) -> PASS   (expr type=Unequality)
5. SymBool path (unbacked) -> __sym_not__ consistent -> PASS
6. NestedInt class not directly importable in this torch version -> SKIPPED (no behavior change)
7. __torch_function__ override path -> PASS
8. torch.sym_not in torch namespace -> PASS
9. tensor.shape Python-bool comparison -> sym_not -> PASS   (device=cpu)

=== torch.sym_not: ALL PASS ===
((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.9       51                0     / 0             |
|        |                  | 0000:61:00.0  | 0           0    / 0          5410  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
```

覆盖点映射(与原 PR 计划方法对照):
| 原计划方法 | 脚本步骤 | 说明 |
|------------|----------|------|
| test_sym_not_python_bool | 步骤 2 + 步骤 9 | `True/False/0/1/None/""/"x"` 全 falsy/truthy + tensor.shape Python bool 比较 |
| test_sym_not_double_negation | 步骤 3 | 双重否定还原性断言 |
| test_sym_not_sympy_bool | 步骤 4 | `sympy.Eq(Symbol,1)` 输入走 `~a` 分支,类型 `Unequality`;双重否定还原 |
| test_sym_not_nested_int | 步骤 6 | 尝试导入 `NestedInt`;v2.10 环境内部模块路径变化导致类不可直接 import,标注为 SKIPPED(与 sym_not 行为无关) |
| (补充)SymBool `__sym_not__` 一致性 | 步骤 5 | `se.create_unbacked_symbool()` 创建 SymBool,断言 `torch.sym_not(ub) == ub.__sym_not__()` 且 `isinstance SymBool` |
| (补充)torch_function 派发 | 步骤 7 | 自定义 `__torch_function__` 类型断言返回 `("custom", "sym_not")` |
| (补充)torch 命名空间导出 | 步骤 8 | `"sym_not" in dir(torch)` + 引用稳定 |

(**附**:v2.7.1 / v2.11.0 中 `torch.sym_not` 定义与 v2.12.0 完全相同,仅行号偏移;同一脚本在各版本 Python 环境下运行结果一致。)

### 五、资料检查
修正 `torch.sym_not` 的 `限制与说明` 描述:该 API 为纯 Python 位运算,不涉及 dtype限制,原描述「`input`仅支持fp32」有误,统一修正为 `-`。涉及 4 个版本目录。


### 六、结论
 API `torch.sym_not` 为 **PyTorch 顶层纯 Python SymInt-aware 逻辑非工具函数**(4 个 isinstance/hasattr 分支 + Python `not` 兜底),不接收 tensor、与 dtype/device 无关;`torch_npu` 三版本仓库 0 覆盖 → **无需 NPU 适配**。


See merge request: Ascend/pytorch!44132
2026-09-16 20:44:15 +08:00
gcw_rZ2ZS0CZ 36411e2fc9 docs: add torch.onnx.verification.verify and verify_aten_graph support status
Co-authored-by: gcw_rZ2ZS0CZ<tang040510@gmail.com>



# message auto-generated for no-merge-commit merge:
!44869 merge onnx-verification-verify-docs-master into master

docs: add torch.onnx.verification.verify and verify_aten_graph support status

Created-by: gcw_rZ2ZS0CZ
Commit-by: gcw_rZ2ZS0CZ
Merged-by: ascend-robot
Description:  <!--
  PR描述模板更新日期:20260203
  -->

  # 【合入来源】
  关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3521
  关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3522

  - [ ] 需求
  - [ ] 问题单
  - [x] issue/工单
  - [ ] 重构优化
  - [x] 资料更新

  # 【修改方案】

  `torch.onnx.verification.verify`
  `torch.onnx.verification.verify_aten_graph`

  上游 PyTorch 2.7 官方文档已收录上述
  API([onnx_verification.html](https://pytorch.org/docs/2.7/onnx_verification.html)),但 torch-npu 的
  `pytorch_2-7-1/torch-onnx.md` 中遗漏了这两个条目。本次补充文档支持情况。
  两个 API 均为纯 Python 逻辑,不涉及设备侧计算,NPU 上可直接运行,无需代码修改。

  # 【资料变更】

  涉及。上游 PyTorch 在 `test/onnx/test_verification.py`(v2.7.1)中已有直接测试用例覆盖:
  -
  `torch.onnx.verification.verify`:`TestVerificationOnWrongExport::test_verify_found_mismatch_when_export_is_wrong`(2
  个后端参数化用例)
  - `torch.onnx.verification.verify_aten_graph`:`TestFindMismatch` 类 5 个用例(间接覆盖,通过 `find_mismatch →
  GraphInfo.verify_export → verify_aten_graph` 调用链)

  本次在 `pytorch_2-7-1/torch-onnx.md` 中补充上述两个 API 的支持情况条目。v2.11.0 / v2.12.0 / v2.13.0 上游已删除该
  API,无需补充。

  # 【接口变更】

  不涉及

  # 【功能介绍】

  `torch.onnx.verification.verify`:验证 PyTorch 模型导出 ONNX 的正确性,将模型通过 torchscript exporter 导出为 ONNX
  文件,再与原始 PyTorch 模型对比输出,提供容差对比与 mismatch 定位能力。

  `torch.onnx.verification.verify_aten_graph`:验证 ATen 图导出 ONNX 的正确性,执行 aten graph 得到 PyTorch 参考输出,将
  graph 转换为 ONNX 后通过指定 backend 运行,并与 PyTorch 输出做对比。

  # 【功能验证】

  `test/onnx/test_verification.py`(`torch.onnx.verification.verify`)
  - `test_verify_found_mismatch_when_export_is_wrong_onnx_backend0` — ONNX Reference 后端校验错误导出
  - `test_verify_found_mismatch_when_export_is_wrong_onnx_backend1` — ONNX Runtime CPU 后端校验错误导出

  运行命令:
  python -m pytest /workspace/user_data/pytorch-v2.7.1-up/test/onnx/test_verification.py -v -k "verify_found_mismatch_when_export_is_wrong"
  运行结果:
  ========================= test session starts =========================
  collected 12 items / 10 deselected / 2 selected

  test_verification.py::TestVerificationOnWrongExport::test_verify_found_mismatch_when_export_is_wrong_onnx_backend0
  PASSED [ 50%]
  test_verification.py::TestVerificationOnWrongExport::test_verify_found_mismatch_when_export_is_wrong_onnx_backend1
  PASSED [100%]

  ================== 2 passed, 10 deselected in 5.27s ===================

  `test/onnx/test_verification.py`(`torch.onnx.verification.verify_aten_graph`,间接覆盖)
  - `TestFindMismatch::test_export_repro_for_mismatch` — 导出 mismatch 复现
  - `TestFindMismatch::test_find_all_mismatch_operators` — mismatch 算子全量定位
  - `TestFindMismatch::test_find_mismatch_prints_correct_info_when_no_mismatch` — 无 mismatch 时正确信息
  - `TestFindMismatch::test_preserve_mismatch_source_location` — 保留 mismatch 源位置
  - `TestFindMismatch::test_pretty_print_tree_visualizes_mismatch` — mismatch 树可视化

  运行命令:
  python -m pytest /workspace/user_data/pytorch-v2.7.1-up/test/onnx/test_verification.py -v -k "TestFindMismatch"
  运行结果:
  ========================= test session starts =========================
  collected 12 items / 7 deselected / 5 selected

  test_verification.py::TestFindMismatch_ONNX_RUNTIME_CPU::test_export_repro_for_mismatch PASSED [ 20%]
  test_verification.py::TestFindMismatch_ONNX_RUNTIME_CPU::test_find_all_mismatch_operators PASSED [ 40%]
  test_verification.py::TestFindMismatch_ONNX_RUNTIME_CPU::test_find_mismatch_prints_correct_info_when_no_mismatch
  PASSED [ 60%]
  test_verification.py::TestFindMismatch_ONNX_RUNTIME_CPU::test_preserve_mismatch_source_location PASSED [ 80%]
  test_verification.py::TestFindMismatch_ONNX_RUNTIME_CPU::test_pretty_print_tree_visualizes_mismatch PASSED [100%]

  ================== 5 passed, 7 deselected in 29.38s ===================
A5验证:
```
((torch271-npu-271) ) root@5a9e655b0866:/workspace/user_data# TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest /workspace/user_data/pytorch-2.7.1-u
p/test/onnx/test_verification.py -v -k "verify_found_mismatch_when_export_is_wrong"
=============================================================== test session starts ===============================================================
platform linux -- Python 3.12.13, pytest-8.3.5, pluggy-1.5.0 -- /workspace/user_data/torch271-npu-271/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.7.1-up
configfile: pytest.ini
collected 12 items / 10 deselected / 2 selected                                                                                                   
Running 2 items in this shard

pytorch-2.7.1-up/test/onnx/test_verification.py::TestVerificationOnWrongExport::test_verify_found_mismatch_when_export_is_wrong_onnx_backend0 PASSED [0.5390s] [ 50%]
pytorch-2.7.1-up/test/onnx/test_verification.py::TestVerificationOnWrongExport::test_verify_found_mismatch_when_export_is_wrong_onnx_backend1 PASSED [0.5524s] [100%]

======================================================== 2 passed, 10 deselected in 21.46s ========================================================
((torch271-npu-271) ) root@5a9e655b0866:/workspace/user_data# 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.8       51                0     / 0             |
|        |                  | 0000:61:00.0  | 0           0    / 0          5410  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
```

```
((torch271-npu-271) ) root@5a9e655b0866:/workspace/user_data# TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest /workspace/user_data/pytorch-2.7.1-up/test/onnx/test_verification.py -v -k "verify_found_mismatch_when_export_is_wrong"
=============================================================== test session starts ===============================================================
platform linux -- Python 3.12.13, pytest-8.3.5, pluggy-1.5.0 -- /workspace/user_data/torch271-npu-271/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.7.1-up
configfile: pytest.ini
collected 12 items / 10 deselected / 2 selected                                                                                                   
Running 2 items in this shard

pytorch-2.7.1-up/test/onnx/test_verification.py::TestVerificationOnWrongExport::test_verify_found_mismatch_when_export_is_wrong_onnx_backend0 PASSED [0.5343s] [ 50%]
pytorch-2.7.1-up/test/onnx/test_verification.py::TestVerificationOnWrongExport::test_verify_found_mismatch_when_export_is_wrong_onnx_backend1 PASSED [0.7094s] [100%]

======================================================== 2 passed, 10 deselected in 19.05s ========================================================
((torch271-npu-271) ) root@5a9e655b0866:/workspace/user_data# 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.7       51                0     / 0             |
|        |                  | 0000:61:00.0  | 0           0    / 0          5410  / 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!44869
2026-09-16 20:43:49 +08:00
qq_44188726 818c5d369f test: add torch.sym_min validation cases and update doc description
Co-authored-by: qq_44188726<16634253534@163.com>



# message auto-generated for no-merge-commit merge:
!43957 merge sym_min-master into master

test: add torch.sym_min validation cases and update doc description

Created-by: qq_44188726
Commit-by: qq_44188726
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3569

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [ ] 资料更新


# 【修改方案】

torch.sym_min
PyTorch 官方社区在 test/distributed/test_local_tensor.py:219(test_local_int_node_sym_min)中仅有间接测试(通过 LocalIntNode.sym_min 覆盖符号最小值逻辑),未针对 torch.sym_min 编写直接独立测试
该 API 为纯 Python 符号运算(SymInt-aware min),设备无关,不涉及 NPU 适配,不需要代码修改。

# 【资料变更】

涉及。torch.sym_min 为非计算类 API,与 dtype 无关,按验收标准「非计算类 API 与数据类型无关」将以下 4 个版本目录 torch.md 中该 API 的「限制与说明」由「`input`仅支持fp32」修正为「-」:
- pytorch_2-7-1 / pytorch_2-11-0 / pytorch_2-12-0 / pytorch_2-13-0
(2-9-0 / 2-10-0 已不在 master 维护,不涉及)
支持情况「Atlas A2/A3 支持、Ascend 950DT 支持」

# 【接口变更】
不涉及

# 【功能介绍】

torch.sym_min(a, b):SymInt-aware 的 min() 工具函数,对 SymInt/SymFloat/数值标量(int、float、numpy 标量)求最小值;任一入参为 SymInt/SymFloat 时走符号路径,混合 int/float 时返回 float。该函数为纯 Python 实现,无张量操作、设备无关。

运行命令:
```
source /usr/local/Ascend/ascend-toolkit/set_env.sh
python -c "
import torch
assert torch.sym_min(3, 4) == 3
assert torch.sym_min(7, 2) == 2
print('torch.sym_min: PASS')
```
A5验证
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace# 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.1       62                0     / 0             |
|        |                  | 0000:55:00.0  | 0           0    / 0          5237  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
((torch-npu-test) ) root@cfc8161f7c3d:/workspace# python -c "import torch; assert torch.sym_min(3,4)==3; assert torch.sym_min(7,2)==2; print('torch.sym_min: PASS')"
torch.sym_min: PASS
```
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常

See merge request: Ascend/pytorch!43957
2026-09-16 20:39:38 +08:00
shenjunfeng-2026 2a9b559fb2 docs: add support information for PowerSGDState.__getstate__
Co-authored-by: shenjunfeng-2026<1766689637@qq.com>



# message auto-generated for no-merge-commit merge:
!44658 merge docs-api01-powersgdstate-getstate-master into master

docs: add support information for PowerSGDState.__getstate__

Created-by: shenjunfeng-2026
Commit-by: shenjunfeng-2026
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
> 关联任务:https://gitcode.com/Ascend/pytorch/issues/2721
> 说明性 Issue:https://gitcode.com/Ascend/pytorch/issues/4045

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

本 PR 补充以下 API 的 TorchNPU 支持资料:

```text
torch.distributed.algorithms.ddp_comm_hooks.powerSGD_hook.PowerSGDState.__getstate__
```

该 API 是纯 Python 状态整理接口,用于返回 `PowerSGDState.__slots__` 中除 `process_group` 以外的状态字典;方法自身不执行 NPU 算子或分布式 collective。PyTorch 官方社区缺少该方法的完整直接用例。依据新版 API 一致性任务要求,不新增测试用例或 NPU 适配 patch,运行验证和判型证据已提交至说明性 Issue #4045。

当前正式资料已列出 `PowerSGDState`,但遗漏其公开方法 `PowerSGDState.__getstate__`。本 PR 在 master 统一更新当前保留的四个资料版本:

```text
docs/zh/api/native_api/pytorch_2-7-1/DDP-Communication-Hooks.md
docs/zh/api/native_api/pytorch_2-11-0/DDP-Communication-Hooks.md
docs/zh/api/native_api/pytorch_2-12-0/DDP-Communication-Hooks.md
docs/zh/api/native_api/pytorch_2-13-0/DDP-Communication-Hooks.md
```

每份资料均进行以下修改:

1. 新增 `PowerSGDState.__getstate__` 独立条目和对应版本的 PyTorch 原生文档链接;
2. 标记 Atlas A2、Atlas A3 和 Ascend 950DT 均支持,统一使用 `✔` 字符;
3. 该 API 不涉及输入数据类型限制,因此“限制与说明”填写为 `-`;
4. 修正非计算类 `PowerSGDState` 原有的错误 dtype 限制说明,将其改为 `-`。

本 PR 仅包含 API 1 的资料更新,不包含测试文件、NPU 适配 patch、功能源码或其他 API 修改。

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

涉及。

更新 master 下 PyTorch 2.7.1、2.11.0、2.12.0 和 2.13.0 的 `DDP-Communication-Hooks.md`,补充目标 API 的支持情况,并修正 `PowerSGDState` 的非计算类限制说明。

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

不涉及。

本 PR 不修改 `PowerSGDState`、`__getstate__`、函数签名、返回值、序列化契约或 TorchNPU 功能实现。


# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

目标 API 的 PyTorch 2.7.1、2.11.0、2.12.0 三套 TorchNPU NPU 环境验证均为 `PASS`,详细环境、源码分析和运行截图见说明性 Issue #4045。

资料修改已完成以下本地检查:

```text
changed files: 4
git diff --check: PASS
exact API entries: 4 / 4
Unicode checkmark: U+2714 (✔)
HTML entity check: PASS
official documentation links: PASS
entry ordering: PASS
limitations exactly '-': PASS
overall semantic and character audit: PASS
```

提交信息:

```text
commit: 902bfd031965a56bfc453b7f979b879141d8bcbe
subject: docs: add PowerSGDState.__getstate__ support
files: 4 modified documentation files
diff: 76 insertions, 4 deletions
```

## Atlas A5(Ascend 950PR)实机验证

补充 Atlas A5 / Ascend 950 系列环境完成独立实机验证。

验证环境:

```text
time: 2026-08-28T13:59:39+00:00
OS: Ubuntu 22.04.5 LTS
architecture: x86_64
NPU: Ascend950PR
NPU Health: OK
npu-smi: 25.7.rc1.6
CANN: 9.1.0
Python: 3.12.13
PyTorch: 2.10.0+cpu
torch-npu: 2.10.0.post4
NPU available: True
NPU device count: 1
```

关键验证结果:

```text
Hardware check: PASS - genuine Atlas A5 / Ascend 950 series
Basic NPU tensor operation: PASS
API callable: PASS
Pure Python function: PASS
Return type is dict: PASS
process_group excluded: PASS
Returned keys match __slots__ minus process_group: PASS
NPU tensor object identity preserved: PASS
NPU tensor device preserved: PASS
NPU tensor value preserved: PASS
Extra argument rejected: PASS
RESULT: PASS
Validation exit status: 0
```

完整日志保存在验证环境:

```text
/user_data/torch_npu_api_consistency/logs/api01_a5_950pr/powersgdstate_getstate_a5_950pr_validation.log
```

资料修改已完成以下本地检查:

```text
changed files: 4
git diff --check: PASS
class-method headings: 4 / 4
obsolete standalone headings: 0
class/method nesting: PASS
div tag balance: PASS
Unicode checkmark: U+2714 (✔)
HTML entity check: PASS
official documentation links: PASS
entry ordering: PASS
limitations exactly '-': PASS
overall semantic and character audit: PASS
```

提交信息:

```text
commit: ef1815cd3d656c234b6ededee315d183bb6fcf91
subject: docs: add PowerSGDState.__getstate__ support
files: 4 modified documentation files
diff: 76 insertions, 4 deletions
```

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!44658
2026-09-16 18:47:36 +08:00
chenrayray c49c282770 docs: 修正原生API数据类型说明对应的Tensor入参
Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com>



# message auto-generated for no-merge-commit merge:
!46150 merge codex/fix-native-api-input-dtypes into master

docs: 修正原生API数据类型说明对应的Tensor入参

Created-by: chenrayray
Commit-by: Xinrui Chen
Merged-by: ascend-robot
Description: # 【合入来源】

- [x] 资料更新
- [x] issue/工单

关联Issue:[#4768](https://gitcode.com/Ascend/pytorch/issues/4768)

# 【修改方案】

原生API文档的部分数据类型说明使用了与接口不符的参数名,例如将初始化接口的`tensor`、矩阵分解接口的`A`以及CTC Loss的`log_probs`统一写成`input`。本次按主要Tensor入参修正说明的归属,避免将类型限制误解为其他参数或返回值的限制。

1. 修正73个API的参数归属,包括`torch`、`torch.nn`、`torch.nn.functional`、`torch.nn.init`、`torch.linalg`、自动微分和分布式通信接口。
2. 类型限制统一采用“`参数名`仅支持……”的简洁表述,例如拼接接口的`tensors`、`reduce_scatter`的`input_list`。

3. 沿torch_npu/op-plugin实际调用链核对多Tensor输入,补齐17个API的72处参数名。保持各版本原有dtype列表;索引、掩码、标签及用户回调相关入参不无条件套用主要Tensor列表。

# 【资料变更】

同步修改PyTorch 2.7.1、2.11.0、2.12.0、2.13.0原生API文档,共28个Markdown文件、296处参数归属修正。保留已有dtype列表、产品支持范围及其他约束。

# 【接口变更】

不涉及,仅修改文档。

# 【功能验证】

- 根据PyTorch官方接口文档和源码签名核对参数名称。
- 逐行核对296处修改,确认与修正清单一致,已有dtype列表及其余约束保持不变。
- `git diff --check`通过。
- 本次不修改运行时代码,未新增UT,未运行NPU测试或完整文档站点构建;远端CI待执行。

## 多Tensor入参核对依据

以下核对以本PR基线引用的op-plugin提交和固定版本的CANN算子文档为依据。共用类型列表不等于运行时强制同dtype:类型推导、适配层转换和不同参数语义分别处理。未扩大现有API支持类型,未运行NPU硬件测试。

| API | 类型说明中的参数 | 调用链 | 算子文档 | 核对结论 |
| --- | --- | --- | --- | --- |
| torch.linalg.solve_triangular | `A`、`B` | [LinalgSolveTriangularKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/LinalgSolveTriangularKernelNpuOpApi.cpp) | [aclnnTriangularSolve](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/triangular_solve/docs/aclnnTriangularSolve.md) | B对应算子的self,A对应算子的A;算子要求两者同类型。适配层先将B转为A的类型,因此API原始输入不一定必须同dtype。两者仅列API已有fp32、fp64、complex64、complex128;不据此增加B可转换的其他类型。 |
| torch.nn.functional.bilinear / torch.nn.Bilinear | functional:`input1`、`input2`、`weight`、`bias`;模块:`input1`、`input2` | [Linear.cpp](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Linear.cpp) → [BmmKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/BmmKernelNpuOpApi.cpp) | [aclnnBatchMatMul](https://gitcode.com/cann/ops-nn/blob/9d023648e6d12b8ba355d7f961b3076bf197f2ad/matmul/batch_mat_mul_v3/docs/aclnnBatchMatMul.md) | bilinear前置校验显式要求输入、weight和已提供的bias同dtype;_trilinear归约经sumproduct_pair/bmm及加法。保留bf16、fp16、fp32。模块weight/bias为成员参数,不写成forward入参。 |
| torch.nn.functional.cosine_similarity | `x1`、`x2` | [Distance.cpp](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Distance.cpp) → [LinalgNormKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/LinalgNormKernelNpuOpApi.cpp) / [DivKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/DivKernelNpuOpApi.cpp) / [MulKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/MulKernelNpuOpApi.cpp) | [aclnnLinalgVectorNorm](https://gitcode.com/cann/ops-nn/blob/9d023648e6d12b8ba355d7f961b3076bf197f2ad/norm/lp_norm_v2/docs/aclnnLinalgVectorNorm.md) / [aclnnMul&aclnnInplaceMul](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/mul/docs/aclnnMul%26aclnnInplaceMul.md) | 两输入按共同类型处理,分别求范数后除法、乘法和求和。两侧计算一致;仅保留API原有fp16、fp32,不新增算子的bf16。 |
| torch.nn.functional.margin_ranking_loss / torch.nn.MarginRankingLoss | `input1`、`input2`、`target` | [Loss.cpp](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Loss.cpp) → [SubKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/SubKernelNpuOpApi.cpp) / [MulKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/MulKernelNpuOpApi.cpp) | [aclnnSub&aclnnInplaceSub](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/sub/docs/aclnnSub%26aclnnInplaceSub.md) / [aclnnMul&aclnnInplaceMul](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/mul/docs/aclnnMul%26aclnnInplaceMul.md) / [aclnnNeg&aclnnInplaceNeg](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/neg/docs/aclnnNeg%26aclnnInplaceNeg.md) | target参与取负和乘法,input1/input2参与相减;所列类型都落在相应算子支持范围内。保留functional与模块各自已有列表,不把模块较宽的整数范围同步给functional。target值域仍是原生接口定义的±1。 |
| torch.nn.TripletMarginLoss | `anchor`、`positive`、`negative` | [Loss.cpp](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Loss.cpp) / [Distance.cpp](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Distance.cpp) → [SubKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/SubKernelNpuOpApi.cpp) / [NormKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/NormKernelNpuOpApi.cpp) | [aclnnSub&aclnnInplaceSub](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/sub/docs/aclnnSub%26aclnnInplaceSub.md) / [aclnnAdd&aclnnInplaceAdd](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/add/docs/aclnnAdd%26aclnnInplaceAdd.md) / [aclnnNorm](https://gitcode.com/cann/ops-nn/blob/9d023648e6d12b8ba355d7f961b3076bf197f2ad/norm/lp_norm_v2/docs/aclnnNorm.md) | 三输入均进入pairwise_distance(相减、加eps、norm);swap还计算positive与negative距离。整数输入在加浮点eps后提升为浮点,不能用Norm的浮点类型表直接删除API已有整数类型。 |
| torch.nn.MultiheadAttention / torch.nn.MultiheadAttention.forward / torch.nn.Transformer | `query`、`key`、`value`;`src`、`tgt` | [functional.py](https://github.com/pytorch/pytorch/blob/main/torch/nn/functional.py) → [ScaledDotProductAttentionKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/ScaledDotProductAttentionKernelNpuOpApi.cpp) / [FlashAttentionKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/FlashAttentionKernelNpuOpApi.cpp) / [NativeMultiHeadAttentionKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/NativeMultiHeadAttentionKernelNpuOpApi.cpp) | [aclnnFlashAttentionScore](https://gitcode.com/cann/ops-transformer/blob/654fe24a76a2ddd4e1b54ebe1d4b1a3e725ae766/attention/flash_attention_score/docs/aclnnFlashAttentionScore.md) / [aclnnBatchMatMul](https://gitcode.com/cann/ops-nn/blob/9d023648e6d12b8ba355d7f961b3076bf197f2ad/matmul/batch_mat_mul_v3/docs/aclnnBatchMatMul.md) | 通用路径含投影、bmm/softmax或SDPA;SDPA前置检查Q/K/V同dtype,FlashAttention文档同样要求三者一致。native fast path委托ATen复合实现,不等于把数据搬到CPU。Transformer的src/tgt进入编码器、解码器及交叉注意力。各API列表分别保留;不将掩码并入。 |
| torch.cdist | `x1`、`x2` | [op_plugin_functions.yaml](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/config/op_plugin_functions.yaml) | [aclnnCdist](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/cdist/docs/aclnnCdist.md) | 注册配置直接将x1/x2传给aclnnCdist,算子要求x2与x1同类型;API已有bf16、fp16、fp32不变。 |
| torch.isin | `elements`、`test_elements` | [IsInKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/IsInKernelNpuOpApi.cpp) / [EqKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/EqKernelNpuOpApi.cpp) / [SortKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/SortKernelNpuOpApi.cpp) | [aclnnEqTensor&aclnnInplaceEqTensor](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/equal/docs/aclnnEqTensor%26aclnnInplaceEqTensor.md) / [aclnnCat](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/conversion/concat_d/docs/aclnnCat.md) | 没有按一个假定的IsIn专用算子推断:实际小集合路径走eq/ne归约,大集合路径走unique、cat、sort及索引恢复。两输入对称参与;双Tensor和单Tensor两段原有列表分别保留,单Tensor段按其中实际为Tensor的参数理解。 |
| torch.searchsorted | `sorted_sequence`、`values` | [op_plugin_functions.yaml](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/config/op_plugin_functions.yaml) | [aclnnSearchSorted](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/search_sorted/docs/aclnnSearchSorted.md) | values映射到算子self,sorted_sequence映射到sortedSequence;两者支持相同的已列8种类型,允许类型推导。sorter为INT64,输出为INT32/INT64,均不并入这条列表。 |
| torch.tensordot | `a`、`b` | [Linear.cpp](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Linear.cpp) → [MmKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/MmKernelNpuOpApi.cpp) | [aclnnMm](https://gitcode.com/cann/ops-nn/blob/9d023648e6d12b8ba355d7f961b3076bf197f2ad/matmul/mat_mul_v3/docs/aclnnMm.md) | ATen前置校验两个数据输入同dtype,重排/归约后调用mm;保留fp16、fp32,不新增算子支持的bf16。dims用于指定收缩维度,不并入数据输入类型列表。 |
| torch.trapezoid / torch.cumulative_trapezoid | `y`、`x` | [Integration.cpp](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Integration.cpp) → [SubKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/SubKernelNpuOpApi.cpp) / [MulKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/MulKernelNpuOpApi.cpp) / [CumsumKernelNpuOpApi](https://gitcode.com/ascend/op-plugin/blob/90e9f78a68e7b30d743bce859e0a12d960b32ad2/op_plugin/ops/opapi/CumsumKernelNpuOpApi.cpp) | [aclnnSub&aclnnInplaceSub](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/sub/docs/aclnnSub%26aclnnInplaceSub.md) / [aclnnMul&aclnnInplaceMul](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/mul/docs/aclnnMul%26aclnnInplaceMul.md) / [aclnnCumsum](https://gitcode.com/cann/ops-math/blob/4e12c8316a954bc524c7b08fccc7865cca0d5dbf/math/cumsum/docs/aclnnCumsum.md) | x先相减得到dx,y相邻样本相加,再相乘并sum/cumsum。算子允许类型推导;保留两个API各自原有列表,不声称x/y运行时必须同dtype,也不新增其他受底层支持的类型。 |
| torch.nn.EmbeddingBag.forward | `input`、`offs

See merge request: Ascend/pytorch!46150
2026-09-16 16:04:52 +08:00
xinboshu-2026 d3a9833a3b docs: add torch.nn.attention.flex_attention.BlockMask support
Co-authored-by: xinboshu-2026<948946534@qq.com>



# message auto-generated for no-merge-commit merge:
!42807 merge docs-flex-attention-blockmask-master into master

docs: update BlockMask and Generator API support

Created-by: xinboshu-2026
Commit-by: xinboshu-2026
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新

关联 issue:

- 任务 issue:https://gitcode.com/Ascend/pytorch/issues/3279
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/4167
- 任务 issue:https://gitcode.com/Ascend/pytorch/issues/3247
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/4166
- 任务 issue:https://gitcode.com/Ascend/pytorch/issues/3248
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/4165

# 【修改方案】

`torch.nn.attention.flex_attention.BlockMask.shape` 返回 `BlockMask` 表示的逻辑掩码形状。

本 PR 已基于最新 master 重新生成单提交以解决冲突:保留 master 已合入的 `BlockMask` 类和 `kv_indices` 资料,仅补充 `shape` 属性,并根据 A5 实机验证结果更新 `torch.Generator.set_state` 的 Ascend 950DT 支持状态。涉及以下文件:

```text
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
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
```

修改内容:

1. 四个版本均新增 `BlockMask.shape` 属性条目。
2. `BlockMask.shape` 按最新 master 的“产品支持情况”列表格式,将 Atlas A2、Atlas A3 和 Ascend 950DT 均标记为“支持”。
3. 保留 master 已合入的 `BlockMask` 和 `kv_indices` 内容,并将四个版本中 `torch.Generator.set_state` 的 Ascend 950DT 状态由“不支持”更新为“支持”。
4. 原生文档链接分别指向对应 PyTorch 版本。
5. 四个文件的目录框、模块层级和 API 顺序同步对齐对应版本 PyTorch 官方资料。

# 【资料变更】

涉及资料变更,具体内容已包含在本 PR 的四个 `torch-nn-attention.md` 和四个 `torch.md` 文件中。

A5 硬件补充验证:已在实际设备名为 `Ascend950PR_9579` 的 Ascend 950PR 环境中,分别验证 `BlockMask.shape` 和 `torch.Generator.set_state` 的 v2.7.1、v2.11.0、v2.12.0、v2.13.0、master 行为。两个 API 的五版本验证均通过、退出码均为 0;完整命令与日志见【功能验证】对应小节。

# 【接口变更】

不涉及。本 PR 不修改 API 实现、接口签名或测试。

# 【功能验证】

执行命令:

```bash
python3 check_native_docs.py repo
git -C repo diff --check upstream/master...HEAD
```

执行结果:

```text
pytorch_2-7-1: PASS
pytorch_2-11-0: PASS
pytorch_2-12-0: PASS
pytorch_2-13-0: PASS
changed_files=8
forbidden_markers=0
result=PASS
git diff --check: PASS
```

## A5(Ascend 950PR)补充验证

运行环境:

```text
操作系统:Ubuntu 22.04.5 LTS (x86_64)
昇腾硬件信息:Ascend 950PR
CANN 软件版本:9.1.0-beta.3
```

分支验证环境:

```text
Python:3.12.13
```

软件版本:

| 版本 | torch | torch-npu |
| --- | --- | --- |
| v2.7.1 | 2.7.1+cpu | 2.7.1.post8 |
| v2.11.0 | 2.11.0+cpu | 2.11.0 |
| v2.12.0 | 2.12.0+cpu | 2.12.0 |
| v2.13.0 | 2.13.0+cpu | 2.13.0.rc1 |
| master | 源码构建 | 源码构建 |

环境初始化:

```bash
source /usr/local/Ascend/cann-9.1.0-beta.3/set_env.sh >/dev/null 2>&1
```

每个版本均运行 PyTorch 官方 `TestBlockMask.test_block_mask_attributes`。仅进行 NPU 设备适配:v2.7.1 将官方方法中的 CUDA 设备与 `create_block_mask` 设备改为 NPU;其余版本仅将官方 `TestBlockMask` 设备实例化范围改为 NPU,目标断言不变。随后运行独立 950PR 探针,补充确认实际设备名、`shape`、`numel` 和 `sparsity`。

### v2.7.1

官方用例执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.7.1/bin/python /root/blockmask-shape-950pr-validation/tests/v2.7.1/test_flex_attention.py TestBlockMask.test_block_mask_attributes -v
```

官方用例执行结果:

```text
test_block_mask_attributes (__main__.TestBlockMask.test_block_mask_attributes) ... ok
Ran 1 test in 1.916s
OK
EXIT_CODE=0
```

NPU 补充验证执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.7.1/bin/python /root/blockmask-shape-950pr-validation/tests/probe_blockmask_950.py
```

NPU 补充验证执行结果:

```text
torch=2.7.1+cpu
torch_npu=2.7.1.post8
npu_device_name=Ascend950PR_9579
shape=(2, 2, 256, 256)
numel=262144
sparsity=25.000000
result=PASS
EXIT_CODE=0
```

### v2.11.0

官方用例执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.11.0/bin/python /root/blockmask-shape-950pr-validation/tests/v2.11.0/test_flex_attention.py -k test_block_mask_attributes_npu -v
```

官方用例执行结果:

```text
test_block_mask_attributes_npu (__main__.TestBlockMaskPRIVATEUSE1.test_block_mask_attributes_npu) ... ok
Ran 1 test in 3.373s
OK
EXIT_CODE=0
```

NPU 补充验证执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.11.0/bin/python /root/blockmask-shape-950pr-validation/tests/probe_blockmask_950.py
```

NPU 补充验证执行结果:

```text
torch=2.11.0+cpu
torch_npu=2.11.0
npu_device_name=Ascend950PR_9579
shape=(2, 2, 256, 256)
numel=262144
sparsity=25.000000
result=PASS
EXIT_CODE=0
```

### v2.12.0

官方用例执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.12.0/bin/python /root/blockmask-shape-950pr-validation/tests/v2.12.0/test_flex_attention.py -k test_block_mask_attributes_npu -v
```

官方用例执行结果:

```text
test_block_mask_attributes_npu (__main__.TestBlockMaskPRIVATEUSE1.test_block_mask_attributes_npu) ... ok
Ran 1 test in 3.006s
OK
EXIT_CODE=0
```

NPU 补充验证执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.12.0/bin/python /root/blockmask-shape-950pr-validation/tests/probe_blockmask_950.py
```

NPU 补充验证执行结果:

```text
torch=2.12.0+cpu
torch_npu=2.12.0
npu_device_name=Ascend950PR_9579
shape=(2, 2, 256, 256)
numel=262144
sparsity=25.000000
result=PASS
EXIT_CODE=0
```

### v2.13.0

官方用例执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.13.0/bin/python /root/blockmask-shape-950pr-validation/tests/v2.13.0/test_flex_attention.py -k test_block_mask_attributes_npu -v
```

官方用例执行结果:

```text
test_block_mask_attributes_npu (__main__.TestBlockMaskPRIVATEUSE1.test_block_mask_attributes_npu) ... ok
Ran 1 test in 1.000s
OK
EXIT_CODE=0
```

NPU 补充验证执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/v2.13.0/bin/python /root/blockmask-shape-950pr-validation/tests/probe_blockmask_950.py
```

NPU 补充验证执行结果:

```text
torch=2.13.0+cpu
torch_npu=2.13.0.rc1
npu_device_name=Ascend950PR_9579
shape=(2, 2, 256, 256)
numel=262144
sparsity=25.000000
result=PASS
EXIT_CODE=0
```

### master

官方用例执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/master/bin/python /root/blockmask-shape-950pr-validation/tests/master/test_flex_attention.py -k test_block_mask_attributes_npu -v
```

官方用例执行结果:

```text
test_block_mask_attributes_npu (__main__.TestBlockMaskPRIVATEUSE1.test_block_mask_attributes_npu) ... ok
Ran 1 test in 0.889s
OK
EXIT_CODE=0
```

NPU 补充验证执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/blockmask-shape-950pr-validation/envs/master/bin/python /root/blockmask-shape-950pr-validation/tests/probe_blockmask_950.py
```

NPU 补充验证执行结果:

```text
torch=2.14.0.dev20260719+cpu
torch_npu=2.14.0+git0a88ddd
npu_device_name=Ascend950PR_9579
shape=(2, 2, 256, 256)
numel=262144
sparsity=25.000000
result=PASS
EXIT_CODE=0
```

A5 补充验证结论:

1. v2.7.1、v2.11.0、v2.12.0、v2.13.0 和 master 的 PyTorch 官方目标用例均 `Ran 1 test / OK`、退出码 0。
2. 五个版本的独立探针均确认实际设备为 `Ascend950PR_9579`,`BlockMask.shape`、`numel` 和 `sparsity` 断言全部通过。
3. allocator padding 与 ArgSort AiCPU 提示属于当前 CANN/SoC 路径警告,不影响断言和结果。

## `torch.Generator.set_state` A5 补充验证

以下验证覆盖独立 NPU Generator 和默认 NPU Generator 的状态恢复,并确认恢复后的随机数序列一致。

### v2.7.1

```bash
cd /root
PYTHONNOUSERSITE=1 /root/generator-set-state-a5-validation/envs/v2.7.1/bin/python /root/generator-set-state-a5-validation/probe_generator_set_state.py
```

```text
torch=2.7.1+cpu
torch_npu=2.7.1.post8
npu_device_name=Ascend950PR_9579
saved_state_device=cpu
independent_generator_restore=PASS
default_generator_restore=PASS
result=PASS
EXIT_CODE=0
```

### v2.11.0

```bash
cd /root
PYTHONNOUSERSITE=1 /root/generator-set-state-a5-validation/envs/v2.11.0/bin/python /root/generator-set-state-a5-validation/probe_generator_set_state.py
```

```text
torch=2.11.0+cpu
torch_npu=2.11.0
npu_device_name=Ascend950PR_9579
saved_state_device=cpu
independent_generator_restore=PASS
default_generator_restore=PASS
result=PASS
EXIT_CODE=0
```

### v2.12.0

```bash
cd /root
PYTHONNOUSERSITE=1 /root/generator-set-state-a5-validation/envs/v2.12.0/bin/python /root/generator-set-state-a5-validation/probe_generator_set_state.py
```

```text
torch=2.12.0+cpu
torch_npu=2.12.0
npu_device_name=Ascend950PR_9579
saved_state_device=cpu
independent_generator_restore=PASS
default_generator_restore=PASS
result=PASS
EXIT_CODE=0
```

### v2.13.0

```bash
cd /root
PYTHONNOUSERSITE=1 /root/generator-set-state-a5-validation/envs/v2.13.0/bin/python /root/generator-set-state-a5-validation/probe_generator_set_state.py
```

```text
torch=2.13.0+cpu
torch_npu=2.13.0.rc1
npu_device_name=Ascend950PR_9579
saved_state_device=cpu
independent_generator_restore=PASS
default_generator_restore=PASS
result=PASS
EXIT_CODE=0
```

### master

```bash
cd /root
PYTHONNOUSERSITE=1 /root/generator-set-state-a5-validation/envs/master/bin/python /root/generator-set-state-a5-validation/probe_generator_set_state.py
```

```text
torch=2.14.0.dev20260719+cpu
torch_npu=2.14.0+git0a88ddd
npu_device_name=Ascend950PR_9579
saved_state_device=cpu
independent_generator_restore=PASS
default_generator_restore=PASS
result=PASS
EXIT_CODE=0
```

`torch.Generator.set_state` 五版本 A5 验证全部通过,支持将四个当前 native API 目录中的 Ascend 950DT 状态更新为“支持”。

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [x] PR持续集成流水线(CI)执行通过,代码检查无异常



See merge request: Ascend/pytorch!42807
2026-09-16 15:45:04 +08:00
zhaoziyi-2026 160e89990d docs: add Placement.is_replicate API support
Co-authored-by: zhaoziyi-2026<zhaoziyi@isrc.iscas.ac.cn>



# message auto-generated for no-merge-commit merge:
!45150 merge intern/placement-is-replicate-docs-master into master

docs: update Placement, FunctionCtx and Joinable API support

Created-by: zhaoziyi-2026
Commit-by: zhaoziyi-2026
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新

关联 issue:

- 任务 issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/348
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/4299
- 任务 issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/278
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/4297
- 任务 issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/238
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/4298

# 【修改方案】

本 PR 补充 `torch.distributed.tensor.placement_types.Placement.is_replicate` 的 native API 资料,并根据 A5 实机验证结果更新 `torch.autograd.FunctionCtx.set_materialize_grads` 和 `torch.distributed.algorithms.Joinable.join_hook` 的 Ascend 950DT 支持状态。

本次冲突处理已基于最新 master 重新生成单提交,并采用当前“产品支持情况”列表格式。

修改范围为当前 master 存在的四个版本目录:

```text
docs/zh/api/native_api/pytorch_2-7-1/torch-distributed-tensor.md
docs/zh/api/native_api/pytorch_2-11-0/torch-distributed-tensor.md
docs/zh/api/native_api/pytorch_2-12-0/torch-distributed-tensor.md
docs/zh/api/native_api/pytorch_2-13-0/torch-distributed-tensor.md
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
docs/zh/api/native_api/pytorch_2-7-1/torch-distributed-algorithms-join.md
docs/zh/api/native_api/pytorch_2-11-0/torch-distributed-algorithms-join.md
docs/zh/api/native_api/pytorch_2-12-0/torch-distributed-algorithms-join.md
docs/zh/api/native_api/pytorch_2-13-0/torch-distributed-algorithms-join.md
```

四个版本目录新增 `Placement` 类及其 `is_replicate()` 方法条目;同时将 `FunctionCtx.set_materialize_grads` 的 8 个既有 Ascend 950DT 单元格和 `Joinable.join_hook` 的 4 个既有 Ascend 950DT 单元格由“不支持”更新为“支持”。

# 【资料变更】

四个当前 native API 目录新增 `Placement` 类及 `Placement.is_replicate()` 方法条目。Atlas A2、Atlas A3 和 Ascend 950DT 均按最新 master 的“产品支持情况”列表格式标记为“支持”;原生链接分别指向对应 PyTorch 版本。根据 Ascend 950PR 五版本实机验证结果,同步将 `FunctionCtx.set_materialize_grads` 和 `Joinable.join_hook` 的 Ascend 950DT 支持状态更新为“支持”。

基于最新 master 已对齐的目录框、章节和 API 顺序新增 `Placement` 及其 `is_replicate()` 条目,并仅修改另外两个目标 API 的既有 Ascend 950DT 支持单元格;`Placement` 按官方顺序置于 `Shard`(以及存在时的 `_StridedShard`)之后。

A5 硬件补充验证:已在实际设备名为 `Ascend950PR_9579` 的 Ascend 950PR 环境中,分别验证 `Placement.is_replicate()`、`FunctionCtx.set_materialize_grads` 和 `Joinable.join_hook` 的 v2.7.1、v2.11.0、v2.12.0、v2.13.0、master 行为。三个 API 的五版本验证均通过、退出码均为 0;完整命令与日志见【功能验证】对应小节。

# 【接口变更】

无。本 PR 不修改 API 实现、接口签名、运行行为或测试,仅补充和更新现有公开 API 的支持资料。

# 【功能验证】

运行环境:

```text
操作系统:Ubuntu 22.04 (aarch64)
昇腾硬件信息:Ascend 910
CANN 软件版本:9.1.0-beta.1
```

软件版本:

| 版本 | torch | torch-npu |
| --- | --- | --- |
| v2.7.1 | 2.7.1+cpu | 2.7.1.post8 |
| v2.9.0 | 2.9.0+cpu | 2.9.0.post6 |
| v2.10.0 | 2.10.0+cpu | 2.10.0.post4 |
| v2.11.0 | 2.11.0+cpu | 2.11.0 |
| v2.12.0 | 2.12.0+cpu | 2.12.0 |
| v2.13.0 | 2.13.0+cpu | 2.13.0+git94c0533 |
| master | 2.14.0.dev20260719+cpu | 2.14.0+gita8da1de |

## 直接官方用例

### v2.7.1

执行命令:

```bash
PYTHONNOUSERSITE=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 PYTHONPATH=/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/cpu_runtimes/v2.7.1/bin/python /root/api-consistency-validation-20260827-a/cpu_official_sources/v2.7.1/test/distributed/tensor/experimental/test_local_map.py -v TestLocalMap.test_local_map_correctness
```

执行结果:

```text
test_local_map_correctness (__main__.TestLocalMap) ... ok
Ran 1 test in 4.024s
OK
RESULT=PASS
```

### v2.9.0

执行命令:

```bash
PYTHONNOUSERSITE=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 PYTHONPATH=/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/cpu_runtimes/v2.9.0/bin/python -c 'import logging,runpy,sys; logging.disable(logging.INFO); p=sys.argv[1]; sys.argv=[p,*sys.argv[2:]]; runpy.run_path(p,run_name="__main__")' /root/api-consistency-validation-20260827-a/cpu_official_sources/v2.9.0/test/distributed/tensor/experimental/test_local_map.py -v TestLocalMap.test_local_map_correctness
```

执行结果:

```text
test_local_map_correctness (__main__.TestLocalMap) ... ok
Ran 1 test in 2.823s
OK
RESULT=PASS
```

### v2.10.0

执行命令:

```bash
PYTHONNOUSERSITE=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 PYTHONPATH=/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/cpu_runtimes/v2.10.0/bin/python /root/api-consistency-validation-20260827-a/cpu_official_sources/v2.10.0/test/distributed/tensor/test_placement_types.py -v PlacementTypesTestCase.test_type_identification
```

执行结果:

```text
test_type_identification (__main__.PlacementTypesTestCase) ... ok
Ran 1 test in 0.018s
OK
RESULT=PASS
```

### v2.11.0

执行命令:

```bash
PYTHONNOUSERSITE=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 PYTHONPATH=/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/cpu_runtimes/v2.11.0/bin/python /root/api-consistency-validation-20260827-a/cpu_official_sources/v2.11.0/test/distributed/tensor/test_placement_types.py -v PlacementTypesTestCase.test_type_identification
```

执行结果:

```text
test_type_identification (__main__.PlacementTypesTestCase) ... ok
Ran 1 test in 0.018s
OK
RESULT=PASS
```

### v2.12.0

执行命令:

```bash
PYTHONNOUSERSITE=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 PYTHONPATH=/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/cpu_runtimes/v2.12.0/bin/python /root/api-consistency-validation-20260827-a/cpu_official_sources/v2.12.0/test/distributed/tensor/test_placement_types.py -v PlacementTypesTestCase.test_type_identification
```

执行结果:

```text
test_type_identification (__main__.PlacementTypesTestCase) ... ok
Ran 1 test in 0.404s
OK
RESULT=PASS
```

### v2.13.0

执行命令:

```bash
PYTHONNOUSERSITE=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 PYTHONPATH=/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/cpu_runtimes/v2.13.0/bin/python /root/api-consistency-validation-20260827-a/cpu_official_sources/v2.13.0/test/distributed/tensor/test_placement_types.py -v PlacementTypesTestCase.test_type_identification
```

执行结果:

```text
test_type_identification (__main__.PlacementTypesTestCase) ... ok
Ran 1 test in 0.512s
OK
RESULT=PASS
```

### master

执行命令:

```bash
PYTHONNOUSERSITE=1 TORCH_DEVICE_BACKEND_AUTOLOAD=0 PYTHONPATH=/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/cpu_runtimes/master/bin/python /root/api-consistency-validation-20260827-a/cpu_official_sources/master/test/distributed/tensor/test_placement_types.py -v PlacementTypesTestCase.test_type_identification
```

执行结果:

```text
torch=2.14.0.dev20260719+cpu
torch_git_version=194fcb011f035ee09da225a40f5da5df0930d27c
test_type_identification (__main__.PlacementTypesTestCase) ... ok
Ran 1 test in 0.421s
OK
RESULT=PASS
```

## v2.12.0 NPU 用例失败结果

### `DistTensorParallelExampleTest.test_loss_parallel`

执行命令:

```bash
python test_tp_examples.py DistTensorParallelExampleTest.test_loss_parallel
```

执行结果:

```text
[rank1]:[E827 04:23:48.213053290 OpParamMaker.cpp:453] operator():../third_party/op-plugin/op_plugin/ops/opapi/SubKernelNpuOpApi.cpp:46 NPU function error: call aclnnSub failed, error code is 507018
[Error]: The aicpu execution is abnormal.
RuntimeError: The Inner error is reported as above. The process exits for this inner error, and the current working operator name is aclnnSub.

======================================================================
ERROR: test_loss_parallel (__main__.DistTensorParallelExampleTest)
----------------------------------------------------------------------
Ran 1 test in 11.755s

FAILED (errors=1)
Process 0 terminated with exit code 10, terminating remaining processes.
```

### `TestRegisterSharding.test_matmul_unshardable`

执行命令:

```bash
python test_register_sharding.py TestRegisterSharding.test_matmul_unshardable
```

执行结果:

```text
AssertionError: False is not true

======================================================================
ERROR: test_matmul_unshardable (__main__.TestRegisterSharding)
----------------------------------------------------------------------
Ran 1 test in 10.770s

FAILED (errors=1)
Process 1 terminated with exit code 10, terminating remaining processes.
```

## NPU 补充验证

### v2.7.1 NPU 补充验证

执行命令:

```bash
PYTHONNOUSERSITE=1 PYTHONPATH=/root/api-consistency-validation-20260827-a/public-test-deps:/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/npu-runtime/v2.7.1/bin/python /root/api-consistency-validation-20260827-a/tests/probe_is_replicate.py
```

执行结果:

```text
torch=2.7.1+cpu
torch_npu=2.7.1.post8
Replicate.is_replicate=True
Shard.is_replicate=False
dtensor_placement_is_replicate=True
dtensor_local_device=npu:0
result=PASS
```

### v2.9.0 NPU 补充验证

执行命令:

```bash
PYTHONNOUSERSITE=1 PYTHONPATH=/root/api-consistency-validation-20260827-a/public-test-deps:/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/npu-runtime/v2.9.0/bin/python /root/api-consistency-validation-20260827-a/tests/probe_is_replicate.py
```

执行结果:

```text
torch=2.9.0+cpu
torch_npu=2.9.0.post6
Replicate.is_replicate=True
Shard.is_replicate=False
dtensor_placement_is_replicate=True
dtensor_local_device=npu:0
result=PASS
```

### v2.10.0 NPU 补充验证

执行命令:

```bash
PYTHONNOUSERSITE=1 PYTHONPATH=/root/api-consistency-validation-20260827-a/public-test-deps:/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/npu-runtime/v2.10.0/bin/python /root/api-consistency-validation-20260827-a/tests/probe_is_replicate.py
```

执行结果:

```text
torch=2.10.0+cpu
torch_npu=2.10.0.post4
Replicate.is_replicate=True
Shard.is_replicate=False
dtensor_placement_is_replicate=True
dtensor_local_device=npu:0
result=PASS
```

### v2.11.0 NPU 补充验证

执行命令:

```bash
PYTHONNOUSERSITE=1 PYTHONPATH=/root/api-consistency-validation-20260827-a/public-test-deps:/root/api-consistency-validation-20260827-a/test-deps /root/api-consistency-validation-20260827-a/npu-runtime/v2.

See merge request: Ascend/pytorch!45150
2026-09-16 15:19:31 +08:00
zhouzirui-2026 0612459465 docs: update torch.compiler.reset API support
Co-authored-by: zhouzirui-2026<zirui@isrc.iscas.ac.cn>



# message auto-generated for no-merge-commit merge:
!42641 merge intern/torch-compiler-reset-docs-master into master

docs: update torch.compiler.reset API support

Created-by: zhouzirui-2026
Commit-by: zhouzirui-2026
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新

关联 issue:https://gitcode.com/Ascend/pytorch/issues/2996

# 【修改方案】

本 PR 更新 `torch.compiler.reset` 的 native API 产品支持状态。

`torch.compiler.reset` 用于清空进程内编译缓存并恢复编译器初始状态。官方覆盖未直接完整断言公开 API 的返回值、缓存复用与 reset 后重新编译行为;该 API 本身属于编译状态管理接口,不需要 torch-npu 硬件实现。按照最新任务要求,此类情况采用 issue-only 支持验证,不新增自写测试,也不提交 `test_upstream` patch。本 PR 仅更新资料。

修改范围为当前 master 实际存在的四个版本目录:

```text
docs/zh/api/native_api/pytorch_2-7-1/torch-compiler.md
docs/zh/api/native_api/pytorch_2-11-0/torch-compiler.md
docs/zh/api/native_api/pytorch_2-12-0/torch-compiler.md
docs/zh/api/native_api/pytorch_2-13-0/torch-compiler.md
```

四个文件均按最新 master 的“产品支持情况”列表格式,将 Atlas A2、Atlas A3 和 Ascend 950DT 由“不支持”更新为“支持”。本次冲突处理基于最新 master 重新生成,且相对目标分支只有一个提交。

# 【资料变更】

本 PR 是单一 master 资料 PR,同步刷新当前存在的 2.7、2.11、2.12、2.13 native API 目录。master 已删除 2.9、2.10 资料目录,因此不重建这些目录;v2.9.0、v2.10.0 仍纳入运行验证矩阵。

四个 `torch-compiler.md` 均基于最新 master 已对齐的官方目录和 API 顺序,仅更新 `torch.compiler.reset` 的产品支持状态,不修改其他 API 条目。

A5 硬件补充验证:已在实际设备名为 `Ascend950PR_9579` 的 Ascend 950PR 环境中,分别验证 v2.7.1、v2.11.0、v2.12.0、v2.13.0 和 master。五个版本均确认 `torch.compiler.reset()` 返回 `None`,编译计数为 `[1, 1, 2]`,输入输出保持在 NPU,结果均为 `PASS`、退出码均为 0。

# 【接口变更】

无。本 PR 不修改 API 实现、接口签名或测试。

# 【功能验证】

公共环境:

```text
操作系统:Ubuntu 22.04.5 LTS (aarch64)
昇腾硬件:Ascend910
CANN:9.1.0-beta.1
Python:3.10
```

环境初始化:

```bash
source /usr/local/Ascend/cann-9.1.0-beta.1/set_env.sh >/dev/null 2>&1
```

软件矩阵:

| 版本 | torch | torch-npu |
| --- | --- | --- |
| v2.7.1 | 2.7.1+cpu | 2.7.1.post8 |
| v2.9.0 | 2.9.0+cpu | 2.9.0.post6 |
| v2.10.0 | 2.10.0+cpu | 2.10.0.post4 |
| v2.11.0 | 2.11.0+cu130 | 2.11.0 |
| v2.12.0 | 2.12.0+cu130 | 2.12.0 |
| master | 源码构建 | 源码构建 |

各版本均在独立虚拟环境中通过中性路径执行同一 NPU 支持探针。counting backend 的编译计数依次为 `[1, 1, 2]`,证明第二次调用复用缓存、reset 后再次编译;`torch.compiler.reset()` 返回 `None`,输入与输出保持在 NPU。

## v2.7.1

```bash
cd /root
/root/torch-compiler-reset-rework-validation/envs/v2.7.1/bin/python /root/torch-compiler-reset-rework-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.7.1+cpu
torch_npu=2.7.1.post8
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
```

## v2.9.0

```bash
cd /root
/root/torch-compiler-reset-rework-validation/envs/v2.9.0/bin/python /root/torch-compiler-reset-rework-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.9.0+cpu
torch_npu=2.9.0.post6
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
```

## v2.10.0

```bash
cd /root
/root/torch-compiler-reset-rework-validation/envs/v2.10.0/bin/python /root/torch-compiler-reset-rework-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.10.0+cpu
torch_npu=2.10.0.post4
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
```

## v2.11.0

```bash
cd /root
/root/torch-compiler-reset-rework-validation/envs/v2.11.0/bin/python /root/torch-compiler-reset-rework-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.11.0+cu130
torch_npu=2.11.0
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
```

## v2.12.0

```bash
cd /root
/root/torch-compiler-reset-rework-validation/envs/v2.12.0/bin/python /root/torch-compiler-reset-rework-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.12.0+cu130
torch_npu=2.12.0
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
```

## master

```bash
cd /root
/root/torch-compiler-reset-rework-validation/envs/master/bin/python /root/torch-compiler-reset-rework-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.14.0.dev20260719+cpu
torch_npu=2.14.0+git068af1e
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
```

## A5(Ascend 950PR)补充验证

运行环境:

```text
操作系统:Ubuntu 22.04.5 LTS (x86_64)
昇腾硬件信息:Ascend 950PR
CANN 软件版本:9.1.0-beta.3
Python:3.12.13
```

软件版本:

| 版本 | torch | torch-npu |
| --- | --- | --- |
| v2.7.1 | 2.7.1+cpu | 2.7.1.post8 |
| v2.11.0 | 2.11.0+cpu | 2.11.0 |
| v2.12.0 | 2.12.0+cpu | 2.12.0 |
| v2.13.0 | 2.13.0+cpu | 2.13.0.rc1 |
| master | 源码构建 | 源码构建 |

环境初始化:

```bash
source /usr/local/Ascend/cann-9.1.0-beta.3/set_env.sh >/dev/null 2>&1
```

### v2.7.1

```bash
cd /root
PYTHONNOUSERSITE=1 /root/torch-compiler-reset-950pr-validation/envs/v2.7.1/bin/python /root/torch-compiler-reset-950pr-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.7.1+cpu
torch_npu=2.7.1.post8
npu_device_name=Ascend950PR_9579
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
EXIT_CODE=0
```

### v2.11.0

```bash
cd /root
PYTHONNOUSERSITE=1 /root/torch-compiler-reset-950pr-validation/envs/v2.11.0/bin/python /root/torch-compiler-reset-950pr-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.11.0+cpu
torch_npu=2.11.0
npu_device_name=Ascend950PR_9579
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
EXIT_CODE=0
```

### v2.12.0

```bash
cd /root
PYTHONNOUSERSITE=1 /root/torch-compiler-reset-950pr-validation/envs/v2.12.0/bin/python /root/torch-compiler-reset-950pr-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.12.0+cpu
torch_npu=2.12.0
npu_device_name=Ascend950PR_9579
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
EXIT_CODE=0
```

### v2.13.0

```bash
cd /root
PYTHONNOUSERSITE=1 /root/torch-compiler-reset-950pr-validation/envs/v2.13.0/bin/python /root/torch-compiler-reset-950pr-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.13.0+cpu
torch_npu=2.13.0.rc1
npu_device_name=Ascend950PR_9579
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
EXIT_CODE=0
```

### master

```bash
cd /root
PYTHONNOUSERSITE=1 /root/torch-compiler-reset-950pr-validation/envs/master/bin/python /root/torch-compiler-reset-950pr-validation/tests/probe_torch_compiler_reset.py
```

```text
torch=2.14.0.dev20260719+cpu
torch_npu=2.14.0+git0a88ddd
npu_device_name=Ascend950PR_9579
device=npu:0
reset_return=None
compile_counts=[1, 1, 2]
result=PASS
EXIT_CODE=0
```

A5 补充验证结论:五个版本均在 Ascend 950PR 实机上验证通过。运行期间出现的 allocator padding 提示属于当前 CANN/SoC 内存分配警告,不影响断言和验证结论。

## 资料静态检查

```bash
cd /root
python3 /root/torch-compiler-reset-rework-validation/check_native_docs.py /root/torch-compiler-reset-rework-validation/repo
```

```text
pytorch_2-7-1: OK
pytorch_2-11-0: OK
pytorch_2-12-0: OK
pytorch_2-13-0: OK
```

验证结论:发行版 v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0 与最新 master 源码环境均验证通过;A5 环境进一步完成 v2.7.1、v2.11.0、v2.12.0、v2.13.0 和 master 验证,结果全部通过。目标 API 无需实现或测试补齐,本 PR 仅更新当前资料矩阵。

# 【CheckList】

- [x] PR 标题使用 `docs:` 类型标签
- [x] 提交仅包含 native API 资料变更,且已压缩为一个提交
- [x] 已完成 NPU 真机验证和资料静态检查
- [x] PR 持续集成流水线(CI)执行通过


See merge request: Ascend/pytorch!42641
2026-09-16 15:04:00 +08:00
zhouzirui-2026 b4742da3c4 docs: update OnnxRegistry API support
Co-authored-by: zhouzirui-2026<zirui@isrc.iscas.ac.cn>



# message auto-generated for no-merge-commit merge:
!45395 merge intern/onnxregistry-docs-master into master

docs: update OnnxRegistry API support

Created-by: zhouzirui-2026
Commit-by: zhouzirui-2026
Merged-by: ascend-robot
Description: # 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单
- [ ] 重构优化
- [x] 资料更新

关联 issue:

- 任务 issue:https://gitcode.com/Ascend/pytorch/issues/3496
- 任务 issue:https://gitcode.com/Ascend/pytorch/issues/3497
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/3635
- 验证结论:https://gitcode.com/Ascend/pytorch/issues/3636

# 【修改方案】

更新 `torch.onnx.OnnxRegistry.opset_version` 和 `torch.onnx.OnnxRegistry.register_op` 的 native API 产品支持状态。本次冲突处理基于最新 master 重新生成单提交。

# 【资料变更】

修改文件:

```text
docs/zh/api/native_api/pytorch_2-7-1/torch-onnx.md
```

两个接口均按最新 master 的“产品支持情况”列表格式,将 Atlas A2、Atlas A3 和 Ascend 950DT 由“不支持”更新为“支持”,共更新 6 项产品支持状态。

基于最新 master 已对齐的 `torch-onnx.md` 目录、TorchDynamo/TorchScript 分区和 API 顺序,仅更新两个目标成员的支持状态,并将 `opset_version` 按属性格式标注。

A5 硬件补充验证:PyTorch v2.7.1 官方 `test/` 目录未找到两个目标成员的直接用例;在实际设备名为 `Ascend950PR_9579` 的 Ascend 950PR 环境中运行官方实现对应的功能探针,NPU Tensor、`opset_version` 与 `register_op` 语义全部通过、退出码 0。完整命令与日志见【功能验证】的“A5(Ascend 950PR)补充验证”小节。

# 【接口变更】

不涉及。本 PR 仅更新资料。

# 【功能验证】

执行命令:

```bash
git diff --check upstream/master...HEAD
```

执行结果:

```text
result=PASS
changed_files=1
updated_cells=6
```

## A5(Ascend 950PR)补充验证

运行环境:

```text
操作系统:Ubuntu 22.04.5 LTS (x86_64)
昇腾硬件信息:Ascend 950PR
CANN 软件版本:9.1.0-beta.3
```

分支验证环境:

```text
Python:3.12.13
torch:2.7.1+cpu
torch-npu:2.7.1.post8
onnxscript:0.3.2
```

### PyTorch 官方用例检查

执行命令:

```bash
cd /root
if rg -n 'OnnxRegistry\.opset_version|OnnxRegistry.*opset_version|opset_version.*OnnxRegistry|OnnxRegistry\.register_op|OnnxRegistry.*register_op|register_op.*OnnxRegistry' /root/onnxregistry-950pr-validation/sources/pytorch-v2.7.1/test; then echo DIRECT_OFFICIAL_MATCHES=FOUND; exit 1; else echo DIRECT_OFFICIAL_MATCHES=0; echo result=PASS; fi
```

执行结果:

```text
DIRECT_OFFICIAL_MATCHES=0
result=PASS
```

说明:PyTorch v2.7.1 官方 `test/` 目录没有直接调用 `torch.onnx.OnnxRegistry.opset_version` 或 `torch.onnx.OnnxRegistry.register_op` 的用例;同名 `register_op` 测试属于旧接口,未作为本 PR 的目标官方用例。按照社区分类规则,不新增自写测试,使用官方实现对应的功能探针补充支持证据。

### v2.7.1 功能与 950PR 环境验证

环境初始化:

```bash
source /usr/local/Ascend/cann-9.1.0-beta.3/set_env.sh >/dev/null 2>&1
```

执行命令:

```bash
cd /root
PYTHONNOUSERSITE=1 /root/onnxregistry-950pr-validation/envs/v2.7.1/bin/python /root/onnxregistry-950pr-validation/tests/probe_onnx_registry_950.py
```

执行结果:

```text
torch=2.7.1+cpu
torch_npu=2.7.1.post8
onnxscript=0.3.2
npu_device_name=Ascend950PR_9579
npu_tensor_device=npu:0
opset_version=18
opset_version_type=int
opset_version_matches_internal=True
opset_version_read_only=True
register_return_none=True
is_registered_after=True
default_overload_count=2
named_overload_count=1
registration_order_preserved=True
is_custom_metadata=True
is_complex_metadata=True
overload_isolated=True
result=PASS
EXIT_CODE=0
```

A5 补充验证结论:

1. v2.7.1 官方测试检索确认两个目标成员均没有直接官方用例,未使用同名旧接口测试替代。
2. v2.7.1 功能探针确认实际设备为 `Ascend950PR_9579`、NPU Tensor 创建成功,`opset_version` 与 `register_op` 的目标语义全部通过、退出码 0。
3. v2.9.0 及后续版本不再公开导出 `torch.onnx.OnnxRegistry`,因此不在这些版本人为补回或验证已移除 API。

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [ ] PR持续集成流水线(CI)执行通过,代码检查无异常



See merge request: Ascend/pytorch!45395
2026-09-16 15:01:35 +08:00