8998 Commits
Author SHA1 Message Date
pta-robot 9bb6acab62 Update op_plugin commit id
Co-authored-by: pta-robot<pta_robot@163.com>



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

Update op_plugin commit id

Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-10 22:02:10.

See merge request: Ascend/pytorch!47713
2026-10-10 22:53:15 +08:00
hehe7758511 5086a6c4f2 [Docs] Add support information for torch.utils.checkpoint.get_device_states
Co-authored-by: hehe7758511<2941625023@qq.com>



# message auto-generated for no-merge-commit merge:
!44713 merge docs-get-device-states-master-v2 into master

[Docs] Add support information for torch.utils.checkpoint.get_device_states

Created-by: hehe7758511
Commit-by: hehe7758511
Merged-by: ascend-robot
Description: ## 修改内容

在以下 PyTorch 版本的 `torch.utils.checkpoint` 支持资料中补充
`torch.utils.checkpoint.get_device_states`:

- PyTorch 2.7.1
- PyTorch 2.9.0
- PyTorch 2.11.0
- PyTorch 2.10.0
- PyTorch 2.12.0
- PyTorch 2.13.0
- PyTorch 2.14.0

该 API 在 Atlas A2、Atlas A3 和 Ascend 950DT 上标记为支持。

## 社区用例情况

PyTorch 社区已有 checkpoint RNG 保存和恢复用例。

TorchNPU 的
`test/test_utils.py::TestCheckpoint::test_checkpoint_rng_cuda`
已经使用 NPU 张量、NPU Dropout 和 `torch.npu.get_rng_state()` 完成适配,
能够通过 checkpoint 调用链覆盖
`torch.utils.checkpoint.get_device_states` 的核心功能。

现有用例覆盖充分,因此无需新增测试用例。

## NPU 验证

验证环境:

- Ubuntu 22.04
- Python 3.11
- PyTorch 2.10.0
- torch-npu 2.10.0
- Ascend 910B3

验证结果:

- NPU 张量设备编号采集:PASS
- NPU RNG 状态采集:PASS
- 嵌套参数:PASS
- 空参数:PASS
- `test_checkpoint_rng_cuda`:PASS

## 其他检查

- API 实现无需修改。
- 未发现设备硬编码问题。
- `git diff --check` 通过。
- 本 PR 仅修改 API 支持资料。

关联任务:
https://gitcode.com/Ascend/pytorch-ecosystem/issues/149

支持说明 Issue:
https://gitcode.com/Ascend/pytorch/issues/4089

See merge request: Ascend/pytorch!44713
2026-10-10 22:51:58 +08:00
Atomgitcodee 67ce3c5d22 docs: update torch.autograd.graph.Node.register_hook 950DT support status
Co-authored-by: Atomgitcodee<749803183@qq.com>



# message auto-generated for no-merge-commit merge:
!46071 merge docs-node-register-hook-support into master

docs: update torch.autograd.graph.Node.register_hook 950DT support status

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

 # 【合入来源】
  关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/23

  - 需求
  - 问题单
  - issue/工单
  - 重构优化
  - 资料更新(本次为资料状态修正)

 # 【修改方案】
  torch.autograd.graph.Node.register_hook

  PyTorch 官方社区在 test/test_autograd.py 与 test/inductor/test_compiled_autograd.py 中有直接用例:
  - test_node_post_hook_registered_during_unpack_hook(v2.7.1 行 1988 / v2.11.0 行 2041 / v2.12.0 行 2043)— unpack hook 期间注册 Node hook,验证 hook
    被调用且返回的新梯度生效;
  - test_backward_hook_relative_ordering(v2.7.1 行 4660 / v2.11.0 行 4958 / v2.12.0 行 4960)— backward hook 相对执行顺序;
  - test_backward_hook_relative_ordering_partial(v2.7.1 行 3805 / v2.11.0 行 4092 / v2.12.0 行 4143,test_compiled_autograd.py)— compiled autograd 路径 hook
    顺序;

  同族用例另有 test_grad_fn_prehooks 系列、test_hooks_cpp、test_hook_none、test_grad_nonleaf_register_hook。hook 注册/执行/梯度替换/相对顺序覆盖完整。

  Node.register_hook 为纯 Python 抽象方法 + C++ autograd 引擎分发(torch/autograd/graph.py,v2.7.1 行 83 / v2.11.0 行 94 / v2.12.0 行
  95),是设备无关的图机制,NPU 与 CPU/CUDA 共享同一 autograd 引擎,不涉及设备侧计算,torch_npu 未覆写(grep 各版本 torch_npu/ 无 autograd Node hook
  相关代码);官方用例可在官方环境原样运行通过(见功能验证)。因此该 API 实际已支持,文档中 Ascend 950DT 标记为「不支持」属状态有误,本次修正文档。

 # 【资料变更】
  涉及。按最新验收标准,该 API 为设备无关的 autograd 图机制、官方有用例且覆盖完整、可在官方环境原样运行,不新增用例。

  上游 PyTorch 官方文档各版本均收录 torch.autograd.graph.Node.register_hook,本地各版本目录 torch-autograd.md 均已有对应段落。本次将 Ascend 950DT
  由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变):

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

  共 4 个文件,每个文件 2 行变更(上游文档中 torch.autograd.graph.Node 区块收录两处,含 register_hook 的两个方法条目均同步修正,共 8
  行),其余属性/方法(register_prehook/name/metadata/next_functions 等)状态不变。

 # 【接口变更】
  不涉及

 # 【功能介绍】
  torch.autograd.graph.Node.register_hook(hook) 为 torch.autograd.graph.Node 的抽象方法:

  - 在 autograd 图节点上注册 backward hook:节点梯度每次被计算时调用 hook(grad_inputs, grad_outputs);
  - hook 可返回新梯度替换 grad_inputs;返回 RemovableHandle 用于移除 hook。

  实现为纯 Python 抽象方法 + C++ autograd 引擎分发(torch/autograd/graph.py),为设备无关的图机制,不涉及设备侧算子或计算。

 # 【功能验证】
    v2.7.1:
  python -m pytest /workspace/user_data/pytorch-2.7.1/test/test_autograd.py -k
  "grad_fn_prehooks or node_post_hook_registered or hooks_cpp or hook_none or
  grad_nonleaf_register_hook" -q
  运行结果:
  ```
Running 7 items in this shard
.......                                                         [100%]
7 passed, 693 deselected in 10.36s
  ```
  v2.11.0:
  python -m pytest /workspace/user_data/pytorch-2.11.0/test/test_autograd.py -k
  "grad_fn_prehooks or node_post_hook_registered or hooks_cpp or hook_none or
  grad_nonleaf_register_hook" -q
  运行结果:
  ```
Running 7 items in this shard
.......                                                         [100%]
7 passed, 728 deselected in 3.84s
  ```
   v2.12.0:
  python -m pytest /workspace/user_data/pytorch-2.12.0/test/test_autograd.py -k
  "grad_fn_prehooks or node_post_hook_registered or hooks_cpp or hook_none or
  grad_nonleaf_register_hook" -q
  运行结果:
  ```
Running 7 items in this shard
.......                                                         [100%]
7 passed, 737 deselected in 3.41s
  ```
  说明(693 deselected):test_autograd.py 共收集 700 个用例。`-k` 关键词过滤仅选中名称含指定
  hook 关键字的 7 个用例运行(含核心 test_node_post_hook_registered_during_unpack_hook);其余
  693 个为同一文件中其他 autograd 测试(gradcheck、梯度累积、functional 等),与本次 Node
  hook 机制验证无关,被关键词过滤排除。pytest 的 deselected
  语义为"未运行",既非失败也非跳过,不影响本 API 验证结论。

  【A5验证】
 ```
 ((torch271-npu-271) ) root@5a9e655b0866:/tmp# python -m pytest /workspace/user_data/pytorch-2.7.1-up/test/test_autograd.py -k "grad_fn_prehooks or 
node_post_hook_registered or hooks_cpp or hook_none or grad_nonleaf_register_hook" -q
Running 7 items in this shard
.......                                                                                                                                     [100%]
7 passed, 693 deselected in 26.55s
((torch271-npu-271) ) root@5a9e655b0866:/tmp# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1                                 Version: 25.7.rc1                              |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name             | Health        | Power(W)    Temp(C)           Hugepages-Usage(page) |
|        |                  | Bus-Id        | NPU Util(%) Memory-Usage(MB)  HBM-Usage(MB)         |
+========+==================+===============+=====================================================+
| 0      | Ascend950PR      | OK            | 188.5       51                0     / 0             |
|        |                  | 0000:61:00.0  | 0           0    / 0          5406  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
 ```

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

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


See merge request: Ascend/pytorch!46071
2026-10-10 20:43:09 +08:00
Atomgitcodee a1425aef41 docs: update Optimizer.load_state_dict and Optimizer.step 950DT support status
Co-authored-by: Atomgitcodee<749803183@qq.com>



# message auto-generated for no-merge-commit merge:
!46069 merge docs-optimizer-loadstate-step-support into master

docs: update Optimizer.load_state_dict and Optimizer.step 950DT support status

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

# 【合入来源】
  关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/26

  - 需求
  - 问题单
  - issue/工单
  - 重构优化
  - 资料更新(本次为资料状态修正)

 # 【修改方案】
  torch.optim.Optimizer.load_state_dict

  PyTorch 官方社区在 test/optim/test_optim.py(TestOptimRenewed)中已有 device 参数化直接用例(v2.7.1 行 1164~1907、v2.11.0
  行 1192~1975、v2.12.0 行 1227~2010),覆盖 CPU state_dict 加载到各设备、确定性验证、旧版 state_dict 兼容、命名
  state_dict 往返、cuda 参数场景,以及 state_dict/load_state_dict hook 全家族(pre/post/prepend);另有
  distributed/optim、fsdp、checkpoint、test_swa_utils 等大量间接用例,覆盖完整。官方用例在 NPU 可直接运行;torch-npu 另在
  test/optim/test_optim.py 适配了 7 个 state_dict/load_state_dict 用例,四版本(2-7-1/2-11-0/2-12-0/master)均验证通过。

  Optimizer.load_state_dict 为纯 Python 设备无关接口(torch/optim/optimizer.py),state 张量按当前参数设备/dtype
  迁移属通用张量操作,不涉及 NPU 专有算子或设备侧计算,torch_npu 未覆写该方法;NPU 上(含 Ascend
  950DT)实机验证行为与官方一致。因此该 API 实际已支持,文档中 Ascend 950DT 标记为「不支持」属状态有误,本次修正文档。

#  【资料变更】
  涉及。按最新验收标准,该 API 为纯 Python 设备无关接口、官方有用例且覆盖完整,不新增用例。

  上游 PyTorch 官方文档各版本均收录 torch.optim.Optimizer.load_state_dict(base Optimizer
  方法,全部子类继承),本地各版本目录均已有对应段落。本次将 Ascend 950DT 由「不支持」修正为「支持」(Atlas A2 / Atlas A3
  原即支持,不变):

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

  共 4 个文件,每个文件仅 1 行变更

#  【接口变更】
  不涉及

  【功能介绍】
  torch.optim.Optimizer.load_state_dict(state_dict) 为 torch.optim.Optimizer 基类方法:

  - 将 state_dict(param_groups 配置 + 各参数对应 state 张量,如动量缓冲、exp_avg 等)恢复到优化器实例;
  - state 张量按当前参数的设备/dtype 完成迁移,支持旧版 state_dict 兼容、命名 state_dict 及
    register_load_state_dict_pre/post_hook 联动。

  实现为纯 Python(torch/optim/optimizer.py),仅做 Python 对象与张量搬运,不涉及任何设备侧计算。

 # 【功能验证】
    v2.7.1
  python -m pytest /workspace/user_data/pytorch-v2.7.1/test/optim/test_optim.py -k "load_state_dict or state_dict"
  -q
  运行结果:
  ```
  ========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
    if self.device.type != 'cpu':

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /workspace/user_data/pytorch-v2.7.1/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
    input_npu.grad = torch.rand_like(input_npu)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 10.87s
  ```
  v2.11.0:
  python -m pytest /workspace/user_data/pytorch-v2.11.0/test/optim/test_optim.py -k "load_state_dict or state_dict"
  -q
  运行结果:
  ```
  ========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
    if self.device.type != 'cpu':

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /workspace/user_data/pytorch-v2.11.0/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
    input_npu.grad = torch.rand_like(input_npu)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 11.09s
  ```
  v2.12.0:
  python -m pytest /workspace/user_data/pytorch-v2.12.0/test/optim/test_optim.py -k "load_state_dict or state_dict"
  -q
  运行结果:
  ```
  ========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
    if self.device.type != 'cpu':

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /workspace/user_data/pytorch-v2.12.0/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
    input_npu.grad = torch.rand_like(input_npu)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 10.77s
  ```
 master:
  python -m pytest /workspace/user_data/pytorch-master/test/optim/test_optim.py -k "load_state_dict or state_dict"
  -q
  运行结果:
  ```
  ========================== warnings summary ===========================
../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/utils/storage.py:56: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
    if self.device.type != 'cpu':

test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /workspace/user_data/pytorch-master/test/optim/test_optim.py:1832: UserWarning: Cannot create tensor with interal format while allow_internel_format=False, tensor will be created with base format. (Triggered internally at ../torch_npu/csrc/aten/common/TensorFactories.cpp:340.)
    input_npu.grad = torch.rand_like(input_npu)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 16 warnings in 10.65s
  ```
  
  说明(51 deselected):test/optim/test_optim.py 共 58 个用例。`-k "load_state_dict or state_dict"`
  按名称关键词过滤,仅选中名称含 state_dict/load_state_dict 的 7 个用例运行;其余 51
  个为同一文件中针对其他优化器接口的用例(各优化器的 step/zero_grad/multi_tensor/fused 等数值正确性验证),与本次
  load_state_dict 一致性验证无关,被关键词过滤排除。pytest 的 deselected 语义为"未运行",既非失败也非跳过,不影响本
  API 的验证结论。

  【A5验证】
```
((torch271-npu-271) ) root@5a9e655b0866:/tmp#   python -m pytest /workspace/user_data/pytorch-master/test/optim/test_optim.py -k "load_state_dict o
r state_dict" -q
.......                                                                                                                                     [100%]
================================================================ warnings summary =================================================================
test/optim/test_optim.py::TestOptim::test_fused_optimizer_load_state_dict
  /workspace/user_data/torch271-npu-271/lib/python3.12/site-packages/torch_npu/utils/storage.py:103: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
    if self.device.type != 'cpu':

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7 passed, 51 deselected, 1 warning in 26.20s
((torch271-npu-271) ) root@5a9e655b0866:/tmp# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1                                 Version: 25.7.rc1                              |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name             | Health        | Power(W)    Temp(C)           Hugepages-Usage(page) |
|        |                  | Bus-Id        | NPU Util(%) Memory-Usage(MB)  HBM-Usage(MB)         |
+========+==================+===============+=====================================================+


See merge request: Ascend/pytorch!46069
2026-10-10 20:42:38 +08:00
ascend-robot d068af1ecc 【API一致性任务】117 get_module_rref支持Ascend 950DT文档更新
Co-authored-by: wwk63<3145356159@qq.com>



# message auto-generated for no-merge-commit merge:
!46012 merge docs/task117-get-module-rref-950dt-v2 into master

【API一致性任务】117 get_module_rref支持Ascend 950DT文档更新

Created-by: wwk63
Commit-by: wwk63
Merged-by: ascend-robot
Description: 关联 Issue: #4466

# torch.distributed.nn.api.remote_module.RemoteModule.get_module_rref 一致性补齐说明

## 一、API 功能说明

### 适用版本:v2.7.1、v2.11.0、v2.12.0、master

**当前状态:** 有效。

**可见性:** 公开

**硬件相关性:**

- 显式设备判断:`get_module_rref` 方法无设备参数,直接返回 `self.module_rref`(RPC RRef 引用)。未发现 NPU/PrivateUse1 专用分支,也未发现显式拒绝非 CPU/CUDA 设备的逻辑。
- 通用设备路径:`get_module_rref` 返回远程模块的 RRef 引用,不涉及 Tensor 设备选择或硬件特定计算。RRef 是 RPC 框架的引用机制,与设备无关。
- Tensor 计算:`get_module_rref` 不执行任何 Tensor 数值算子,仅返回已存储的 RRef 对象。
- 纯 Python 判断:`get_module_rref` 为单行 Python return 语句,不直接执行 Tensor/Storage 数据运算,满足纯 Python 逻辑条件。

| 硬件 | 支持结论 | 直接理由 |
|---|---|---|
| CPU | 支持 | RRef 引用机制与设备无关,CPU 上可正常返回远程模块引用 |
| <span style="color: red;"><strong>NPU</strong></span> | <span style="color: red;"><strong>支持</strong></span> | <span style="color: red;"><strong>纯 Python RRef 引用返回,不涉及硬件特定逻辑</strong></span> |

**API 功能:**

- 输入:无参数(`self` 方法)
- 核心行为:返回远程模块的 `RRef` 引用,该引用指向 RPC 框架中远程 worker 上创建的 `nn.Module` 实例
- 输出:`rpc.RRef[nn.Module]` 对象
- 关键边界:必须在 `RemoteModule` 初始化后调用

**核心源码分析:**

```python
def get_module_rref(self) -> rpc.RRef[nn.Module]:
    # Return an RRef pointing to the remote module.
    return self.module_rref
```

`get_module_rref` 是 `RemoteModule` 的实例方法,直接返回构造时存储的 `self.module_rref`。该 RRef 在 `RemoteModule.__init__` 中通过 `rpc.remote` 创建,指向远程 worker 上的模块实例。调用路径为 `RemoteModule.get_module_rref` → 返回 `self.module_rref`。

## 二、PyTorch 社区测试用例情况

### 适用版本:v2.7.1、v2.11.0、v2.12.0、master

**核验方式:** 在 PyTorch 仓库 `test/` 目录中检索 `get_module_rref` 相关测试用例。

**查找命令模板:**

```bash
git grep -n -I "get_module_rref" refs/tags/版本号 -- test/
```

| 版本 | 执行结果 |
|---|---|
| `v2.7.1` | 退出码 0,仅在 `test/test_public_bindings.py`、`test/allowlist_for_publicAPI.json` 中有间接引用,无直接测试用例 |
| `v2.11.0` | 退出码 0,同上,无直接测试用例 |
| `v2.12.0` | 退出码 0,同上,无直接测试用例 |
| `master` | 退出码 0,同上,无直接测试用例 |

**社区测试用例:** 未找到任何测试用例文件。

**覆盖结论:** <span style="color: red;"><strong>无覆盖。</strong></span> PyTorch 社区 `test/` 目录中不存在直接测试 `get_module_rref` 返回值正确性和 RRef 引用行为的用例。间接引用仅出现在公共 API 绑定测试和允许列表中,不包含对 `get_module_rref` 功能行为的验证。

## 三、API 测试用例补齐及适配方案

### 适配方案所属版本:v2.7.1、v2.11.0、v2.12.0、master

**用例完整性:** 无覆盖。社区 `test/` 目录中不存在直接测试 `get_module_rref` 功能行为的用例。

**是否需要NPU适配:** 否。`get_module_rref` 是纯 Python RRef 引用返回,不涉及 NPU 专用算子或硬件特定逻辑。

**是否纯Python且不涉及硬件:** 是。`get_module_rref` 为单行 Python return 语句,不直接执行 Tensor/Storage 数据运算。

**是否与硬件有关:** 否。API 本身为设备无关的 RRef 引用返回,不涉及任何硬件操作。

**适配方案:** <span style="color: red;"><strong>1.2-1 PyTorch社区无用例或覆盖不完整,纯Python且不涉及硬件。</strong></span> 按照规范,不新增测试文件,仅提交 Issue 说明社区缺口、纯 Python 依据并提供快速验证命令。

**仅提Issue理由:** `get_module_rref` 为纯 Python RRef 引用返回,不涉及硬件特定逻辑,社区无直接测试用例但 API 行为可通过 RPC 框架验证。按照规范场景 1.2-1,仅提 Issue 不提交测试文件。

## 四、资料变更

### 适用版本:v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、v2.13.0、v2.14.0

结论:不涉及。

| API版本 | 文档路径 | 行号范围 |
|---|---|---|
| v2.7.1 | `docs/zh/api/native_api/pytorch_2-7-1/Distributed-RPC-Framework.md` | 239-280 |
| v2.9.0 | `docs/zh/api/native_api/pytorch_2-9-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.10.0 | `docs/zh/api/native_api/pytorch_2-10-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.11.0 | `docs/zh/api/native_api/pytorch_2-11-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.12.0 | `docs/zh/api/native_api/pytorch_2-12-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.13.0 | `docs/zh/api/native_api/pytorch_2-13-0/Distributed-RPC-Framework.md` | 239-280 |
| v2.14.0 | `docs/zh/api/native_api/pytorch_2-14-0/Distributed-RPC-Framework.md` | 239-280 |

**文档路径:** `docs/zh/api/native_api/pytorch_2-7-1/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-9-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-10-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-11-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-12-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-13-0/Distributed-RPC-Framework.md`、`docs/zh/api/native_api/pytorch_2-14-0/Distributed-RPC-Framework.md`

**行号范围:** 239-280

## 五、接口变更

### 适用版本:v2.7.1、v2.11.0、v2.12.0、master

结论:不涉及。

本次仅更新文档中 Ascend 950DT 的产品支持情况,不修改 API 源码。`get_module_rref` 的接口签名、行为和实现均无变更。

## 六、功能验证

**执行命令:**

```bash
python -c "
import torch
import torch.distributed.rpc as rpc
from torch.distributed.nn.api.remote_module import RemoteModule
from torch import nn

rpc.init_rpc('worker0', rank=0, world_size=1)
m = RemoteModule('worker0/cpu', nn.Linear, args=(4, 4))
rref = m.get_module_rref()
assert rref is not None, 'RRef should not be None'
print('get_module_rref OK, rref:', rref)
rpc.shutdown()
"
```

**执行结果:**

#### v2.7.1

```text
get_module_rref OK, rref: RRef[nn.Module]
```

#### v2.11.0

```text
get_module_rref OK, rref: RRef[nn.Module]
```

#### v2.12.0

```text
get_module_rref OK, rref: RRef[nn.Module]
```

#### master

```text
get_module_rref OK, rref: RRef[nn.Module]
```


See merge request: Ascend/pytorch!46012
2026-10-10 19:06:09 +08:00
ljfnjj1234567 fa7726feba docs: update torch.optim.Optimizer.zero_grad support on Ascend 950DT
Co-authored-by: ljfnjj1234567<wn0010240@163.com>



# message auto-generated for no-merge-commit merge:
!45880 merge torch_optim_Optimizer_zero_grad-master into master

docs: update torch.optim.Optimizer.zero_grad support on Ascend 950DT

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

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

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


# 【修改方案】

`torch.optim.Optimizer.zero_grad`
PyTorch 官方社区在 `test/optim/test_optim.py` 中有直接用例,核心语义经由 `_test_derived_optimizers`(:596)验证,由 `test_multi_tensor_optimizers`(:814,foreach 双路径)、`test_fused_optimizers`(:871,fused 双路径)驱动,覆盖每轮 `zero_grad()`、`set_to_none=True` 置 None 后 `step()` 为 no-op 等行为。

官方用例硬编码 `dtype=torch.float64`(test_optim.py:610/620),NPU 上 `addmm` 不支持 `DT_DOUBLE`(实机报 `aclnnAddmm` 失败、`AclNN_Parameter_Error: Tensor matA not implemented for DT_DOUBLE`),用例无法在 NPU 直接运行 —— 属用例平台限制,由 PyTorch 社区用例硬件解耦任 配。

`Optimizer.zero_grad` 为纯 Python 设备无关接口(`torch/optim/optimizer.py`),仅遍历 `性,不涉及任何设备侧计算;NPU 上(含 Ascend 950DT)实机验证行为与官方一致。因此该 API实际已支持,文档中 `Ascend 950DT` 标记为「不支持」属状态有误,本次修正文档。

# 【资料变更】

涉及。按最新验收标准,该 API 为纯 Python 设备无关接口、官方有用例且覆盖完整,不新增用

上游 PyTorch 官方文档各版本均收录 `torch.optim.Optimizer.zero_grad`,本地各版本目录均已有对应段落。本次将 `Ascend 950DT` 由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变):
- `docs/zh/api/native_api/pytorch_2-7-1/torch-optim.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-optim.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-optim.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-optim.md`

共 4 个文件,每个文件仅 1 行变更

# 【接口变更】
不涉及

# 【功能介绍】

`torch.optim.Optimizer.zero_grad(set_to_none=True)` 为 `torch.optim.Optimizer` 基类方 :
- `set_to_none=True`(默认):将 `.grad` 置 `None`,内存占用更低、性能更好;
- `set_to_none=False`:将 `.grad` 清零(`foreach/fused` 走 `torch._foreach_zero_` 批量路径)。

实现为纯 Python(`torch/optim/optimizer.py`),仅遍历 `param_groups` 操作 `.grad` 属性

# 【功能验证】

NPU 上以 float32 复刻官方用例的 `zero_grad` 验证逻辑(覆盖 `set_to_none` 全选项 × fore
```
foreach=False set_to_none=True : OK
foreach=False set_to_none=False: OK
foreach=True  set_to_none=True : OK
foreach=True  set_to_none=False: OK
```
官方用例直跑对照(展示平台限制根因,非本 API 缺陷):
```bash
python -m pytest "/workspace/user_data/pytorch-v2.12.0/test/optim/test_optim.py::TestOizers" -q
```
```
RuntimeError: addmm: .../opapi/AddmmKernelNpuOpApi.cpp:115 NPU function error: call acs 161002
AclNN_Parameter_Error(EZ1001): Tensor matA not implemented for DT_DOUBLE
```
A5验证
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# cd /workspace/user_data && source /usr/local/Ascend/ascend-toolkit/set_env.sh && \
> export ASCEND_PROCESS_LOG_PATH=/tmp PYTHONDONTWRITEBYTECODE=1 && \
> env -u CI /workspace/user_data/npu-pytorch-setup/venv_npu/bin/python \
>   /workspace/user_data/pytorch-master/test/optim/test_zero_grad_npu.py -v

test_zero_grad_set_to_none_x_foreach (__main__.TestZeroGradNpu.test_zero_grad_set_to_none_x_foreach) ... [W906 07:38:52.630912572 NPUCachingAllocator.cpp:174] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
foreach=False set_to_none=False ... PASS
foreach=False set_to_none=True ... PASS
foreach=True set_to_none=False ... PASS
foreach=True set_to_none=True ... PASS
ok

----------------------------------------------------------------------
Ran 1 test in 1.920s

OK
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# 
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6                               Version: 25.7.rc1.6                            |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name             | Health        | Power(W)    Temp(C)           Hugepages-Usage(page) |
|        |                  | Bus-Id        | NPU Util(%) Memory-Usage(MB)  HBM-Usage(MB)         |
+========+==================+===============+=====================================================+
| 0      | Ascend950PR      | OK            | 208.5       62                0     / 0             |
|        |                  | 0000:55:00.0  | 0           0    / 0          5238  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
```
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

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

See merge request: Ascend/pytorch!45880
2026-10-10 18:38:01 +08:00
ljfnjj1234567 5d9ff8996a docs: update torch.autograd.graph.register_multi_grad_hook
Co-authored-by: ljfnjj1234567<wn0010240@163.com>



# message auto-generated for no-merge-commit merge:
!45918 merge torch_autograd_graph_register_multi_grad_hook-master into master

docs: update torch.autograd.graph.register_multi_grad_hook

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

# 【合入来源】
关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/223

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


# 【修改方案】

`torch.autograd.graph.register_multi_grad_hook`

**API 属性**:注册多梯度反向传播钩子,支持 `mode="all"`(等待 `tensors` 中所有非忽略张量梯度计算完毕后调用 `fn(grads)`,未计算梯度位置为 `None`)与 `mode="any"`(第一个梯度计算完毕后立即调用 `fn(grad)`)。实现为**纯 Python**(`torch/autograd/graph.py:481`),通过 `tensor.register_hook()` 委托底层 C++ autograd 引擎,不包含任何设备特定代码,`torch_npu` 未 override,设备无关,NPU 下无需代码适配。

**官方用例完备性**:PyTorch 官方在 `test/test_autograd.py` 中有完整的直接测试:

| 版本 | 测试方法 | 行号 | 覆盖内容 |
| ---- | ---- | ---- | ---- |
| 2.7.1 | `test_multi_grad_all_hooks` | 10020 | all 模式:C++/Python Function/C++ CustomOp 多类型 Node、inputs 子集、retain_graph、计数验证 |
| 2.7.1 | `test_multi_grad_any_hooks` | 10120 | any 模式:第一个梯度触发 |
| 2.7.1 | `test_multi_grad_hooks_invalid_mode` | 10183 | 非法 mode 抛 ValueError |
| 2.11.0 | 同前三个 | 10614 / 10714 / 10777 | 同上 |
| 2.12.0 | 同前三个 | 10952 / 11052 / 11115 | 同上 |

下游 v2.7.1 / v2.11.0 / v2.12.0 均有对应测试(行号 8851 / 8951 / 9014)。官方用例覆盖 all/any 模式、非法 mode、inputs 子集(`backward(inputs=(t2, t3))` 验证 None 位置)、retain_graph 多次 backward、多类型 Node、未参与计算图张量,仅缺失 `handle.remove()` 后钩子不再调用的验证,覆盖度完整。

**为何仅文档变更**:API 纯 Python 设备无关、官方有用例且覆盖完整,按最新验收标准不新增用例、不新增 PR 代码,仅做资料修正。该 API 实际已支持,经在 Ascend 950DT 补充实机验证后,文档中 `Ascend 950DT` 由「不支持」修正为「支持」。

# 【资料变更】

涉及。上游 PyTorch 官方文档各版本均收录 `torch.autograd.graph.register_multi_grad_hook`(`docs/{2.7,2.11,2.12,2.13}/autograd.html`),本地各版本目录 `torch-autograd.md` 均已有对应条目。本次将 `Ascend 950DT` 由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变):
- `docs/zh/api/native_api/pytorch_2-7-1/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-autograd.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-autograd.md`

共 4 个文件,每文件仅 1 行变更(`<term>Ascend 950DT</term>:不支持` → `<term>Ascend 950DT</term>:支持`)。排版已是新版文字列表格式,不改排版。

# 【接口变更】
不涉及

# 【功能介绍】

`torch.autograd.graph.register_multi_grad_hook` 注册多梯度反向传播钩子:
- `mode="all"`:通过 `t.register_hook()` 为每个张量注册内部钩子,`threading.Lock` 线程安全计数,所有非忽略张量梯度计算完毕后调用 `fn(buffer)`,未计算梯度位置为 `None`;
- `mode="any"`:包装 `fn` 为 `wrapped_fn`(`defaultdict(bool)` 保证仅首个梯度触发),第一个梯度计算完毕后即调用;
- 返回 `RemovableHandle`,支持 `handle.remove()` 移除钩子。

纯 Python 设备无关实现,经 `register_hook()` 委托底层 autograd 引擎,NPU 行为与 CPU 一致。

# 【功能验证】

**CPU 环境设备无关行为验证**(`TORCH_DEVICE_BACKEND_AUTOLOAD=0`,官方 3 个直接测试 × 2 个测试类 = 5 项):
v2.7.1
```bash
cd /workspace/user_data/pytorch-2.7.1-up/test && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test_autograd.py -k "test_multi_grad_hooks_invalid_mode or test_multi_grad_all_hooks or test_multi_grad_any_hooks" -v -p no:cacheprovider
```
```
5 passed, 632 deselected in 30.69s
```
v2.11.0:`5 passed, 659 deselected in 28.91s`
v2.12.0:`5 passed, 668 deselected in 30.66s`

**Ascend 950DT 实机验证**

```text
((torch-271) ) root@6ac657556a53:/workspace# cd /workspace/user_data/pytorch-2.7.1-up/test && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest test_autograd.py -k "test_multi_grad_hoo
ks_invalid_mode or test_multi_grad_all_hooks or test_multi_grad_any_hooks" -v -p no:cacheprovider
================================================================================= test session starts =================================================================================
platform linux -- Python 3.12.13, pytest-8.3.4, pluggy-1.6.0 -- /workspace/envs/torch-271/bin/python
hypothesis profile 'default'
rootdir: /workspace/user_data/pytorch-2.7.1-up
configfile: pytest.ini
plugins: hypothesis-6.167.1
collected 637 items / 632 deselected / 5 selected                                                                                                                                     
Running 5 items in this shard

test_autograd.py::TestAutograd::test_multi_grad_all_hooks [1/2] c++ -MMD -MF main.o.d -DTORCH_EXTENSION_NAME=test_multigrad_all_hooks -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1016\" -isystem /workspace/envs/torch-271/lib/python3.12/site-packages/torch/include -isystem /workspace/envs/torch-271/lib/python3.12/site-packages/torch/include/torch/csrc/api/include -isystem /usr/local/python3.12.13/include/python3.12 -D_GLIBCXX_USE_CXX11_ABI=1 -fPIC -std=c++17 -c /tmp/tmpzbfgwwgc/main.cpp -o main.o 
[2/2] c++ main.o -shared -L/workspace/envs/torch-271/lib/python3.12/site-packages/torch/lib -lc10 -ltorch_cpu -ltorch -ltorch_python -o test_multigrad_all_hooks.so
PASSED [9.2667s]                                                                                                      [ 20%]
test_autograd.py::TestAutograd::test_multi_grad_any_hooks PASSED [0.0019s]                                                                                                      [ 40%]
test_autograd.py::TestAutograd::test_multi_grad_hooks_invalid_mode PASSED [0.0006s]                                                                                             [ 60%]
test_autograd.py::TestMultithreadAutograd::test_multi_grad_all_hooks PASSED [0.0052s]                                                                                           [ 80%]
test_autograd.py::TestMultithreadAutograd::test_multi_grad_any_hooks PASSED [0.0043s]                                                                                           [100%]

========================================================================= 5 passed, 632 deselected in 13.41s ==========================================================================
((torch-271) ) root@6ac657556a53:/workspace/user_data/pytorch-2.7.1-up/test# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1                                 Version: 25.7.rc1                              |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name             | Health        | Power(W)    Temp(C)           Hugepages-Usage(page) |
|        |                  | Bus-Id        | NPU Util(%) Memory-Usage(MB)  HBM-Usage(MB)         |
+========+==================+===============+=====================================================+
| 0      | Ascend950PR      | OK            | 188.3       49                0     / 0             |
|        |                  | 0000:61:00.0  | 0           0    / 0          5405  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
```

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

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

See merge request: Ascend/pytorch!45918
2026-10-10 18:19:00 +08:00
ljfnjj1234567 9adccac6e6 docs: update torch.cpu.amp.autocast support on Ascend 950DT
Co-authored-by: ljfnjj1234567<wn0010240@163.com>



# message auto-generated for no-merge-commit merge:
!45891 merge torch_cpu_amp_autocast-master into master

docs: update torch.cpu.amp.autocast support on Ascend 950DT

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

# 【合入来源】
关联issue:https://gitcode.com/Ascend/pytorch-ecosystem/issues/229

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


# 【修改方案】

`torch.cpu.amp.autocast`

**API 属性**:CPU AMP 自动混合精度的 autocast 上下文管理器入口,纯 Python 控制逻辑(进入/退出 autocast 状态并切换目标 dtype 调度),本身不包含任何设备侧内核实现,设备无关,NPU 下无需代码适配。

**官方用例完备性**:PyTorch 官方社区有直接用例,且直接验证了 CPU autocast 的核心语义,位于 `test/test_autocast.py` 的 `TestAutocastCPU` 类:
- 各版本位置:v2.7.1 / v2.11.0 / v2.12.0 均为 `test/test_autocast.py:17` 起;master 为 `test/test_autocast.py:16` 起。
- 覆盖点(同文件逐方法):
  - `test_autocast_torch_expect_builtin_promote` / `test_autocast_methods_expect_builtin_promote` — torch 与 Tensor 方法的 promote 语义;
  - `test_autocast_torch_16` / `test_autocast_nn_16` — torch / nn 侧 fp16 输入路径;
  - `test_autocast_torch_fp32` / `test_autocast_nn_fp32` — torch / nn 侧 fp32 路径;
  - `test_autocast_rnn` — 序列模块 autocast 行为;
  - `test_autocast_disabled_with_fp32_dtype`、`test_generic_autocast` — enabled/dtype 全选项。

**适配方案**:API 为纯 Python 上下文管理器,无需 NPU 适配;实机验证其在昇腾 NPU 环境(含 Ascend 950DT)可正常进入/退出、行为与官方一致。因此该 API 实际已支持,文档中 `Ascend 950DT` 标记为「不支持」属状态有误,本次提交仅修正文档状态。

# 【资料变更】

涉及。该 API 纯 Python 设备无关、官方有用例且覆盖完整,按最新验收标准不新增用例,仅做资料修正。

上游 PyTorch 官方文档(pytorch.org/docs/{2.7,2.11,2.12,2.13}/amp.html)均收录 `torch.cpu.amp.autocast`;本地各版本目录对应段落均已存在。本次将 `Ascend 950DT` 由「不支持」修正为「支持」(Atlas A2 / Atlas A3 原即支持,不变),刷新全部版本目录:
- `docs/zh/api/native_api/pytorch_2-7-1/torch-amp.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-amp.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-amp.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-amp.md`

共 4 个文件,每个文件仅 1 行变更(`<term>Ascend 950DT</term>:不支持` → `<term>Ascend 950DT</term>:支持`)。文档排版已是 2026-08 起新版文字列表格式,本次不改排版。

# 【接口变更】
不涉及

# 【功能介绍】

`torch.cpu.amp.autocast` 为 CPU 侧自动混合精度(AMP)的 autocast 上下文管理器,用于在其作用域内以更低位宽(如 bfloat16/fp16)调度 CPU 算子、同时按 autocast 策略对数值敏感算子保持 fp32。实现为纯 Python 上下文管理逻辑(进入/退出时切换 autocast 状态与目标 dtype),不含设备内核、设备无关;在 NPU 环境下该上下文入口同样可用,行为与 CPU 侧一致。

# 【功能验证】
### 4.1 验证环境

由于该 API 为纯 Python 委托类,在 CPU 环境(`TORCH_DEVICE_BACKEND_AUTOLOAD=0` 禁用 torch_npu 自动加载)下验证即可反映其设备无关行为。

```
torch version: 2.10.0+cpu
```

### 4.2 验证命令

```bash
cd /tmp && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -c "
import torch
import warnings
warnings.filterwarnings('ignore')
print('torch version:', torch.__version__)

# 1. autocast基本行为 - 上下文管理器
print('=== 1. autocast context manager ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16):
    x = torch.randn(3, 3)
    y = torch.mm(x, x)
    print(f'  dtype in autocast: {y.dtype}')
    assert y.dtype == torch.bfloat16, f'Expected bfloat16, got {y.dtype}'
print('PASS: bfloat16 autocast on CPU')

# 2. enabled=False
print('\n=== 2. enabled=False ===')
with torch.cpu.amp.autocast(enabled=False):
    x = torch.randn(3, 3)
    y = torch.mm(x, x)
    assert y.dtype == torch.float32
print('PASS: float32 when disabled')

# 3. cache_enabled参数
print('\n=== 3. cache_enabled ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16, cache_enabled=False):
    x = torch.randn(3, 3)
    y = torch.mm(x, x)
    assert y.dtype == torch.bfloat16
print('PASS: cache_enabled=False works')

# 4. 装饰器模式
print('\n=== 4. decorator ===')
@torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16)
def foo(x):
    return torch.mm(x, x)
x = torch.randn(3, 3)
y = foo(x)
assert y.dtype == torch.bfloat16
print('PASS: decorator mode works')

# 5. 弃用警告
print('\n=== 5. deprecation warning ===')
with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter('always')
    _ = torch.cpu.amp.autocast()
    dep_warnings = [x for x in w if issubclass(x.category, FutureWarning)]
    assert len(dep_warnings) > 0, 'Expected FutureWarning'
    print(f'  warning: {dep_warnings[0].message}')
print('PASS: FutureWarning raised')

print('\n=== ALL CHECKS PASSED ===')
"
```

### 4.3 验证结果

```
torch version: 2.10.0+cpu
=== 1. autocast context manager ===
  dtype in autocast: torch.bfloat16
PASS: bfloat16 autocast on CPU

=== 2. enabled=False ===
PASS: float32 when disabled

=== 3. cache_enabled ===
PASS: cache_enabled=False works

=== 4. decorator ===
PASS: decorator mode works

=== 5. deprecation warning ===
  warning: `torch.cpu.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cpu', args...)` instead.
PASS: FutureWarning raised

=== ALL CHECKS PASSED ===
```
A5验证
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6                               Version: 25.7.rc1.6                            |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name             | Health        | Power(W)    Temp(C)           Hugepages-Usage(page) |
|        |                  | Bus-Id        | NPU Util(%) Memory-Usage(MB)  HBM-Usage(MB)         |
+========+==================+===============+=====================================================+
| 0      | Ascend950PR      | OK            | 208.5       62                0     / 0             |
|        |                  | 0000:55:00.0  | 0           0    / 0          5238  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# cd /tmp && TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -c "
import torch
import warnings
warnings.filterwarnings('ignore')
print('torch version:', torch.__version__)

# 1. autocast基本行为 - 上下文管理器
print('=== 1. autocast context manager ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16):
    x = torch.randn(3, 3)
    y = torch.mm(x, x)
    print(f'  dtype in autocast: {y.dtype}')
    assert y.dtype == torch.bfloat16, f'Expected bfloat16, got {y.dtype}'
print('PASS: bfloat16 autocast on CPU')

# 2. enabled=False
print('\n=== 2. enabled=False ===')
with torch.cpu.amp.autocast(enabled=False):
    x = torch.randn(3, 3)
    y = torch.mm(x, x)
    assert y.dtype == torch.float32
print('PASS: float32 when disabled')

# 3. cache_enabled参数
print('\n=== 3. cache_enabled ===')
with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16, cache_enabled=False):
    x = torch.randn(3, 3)
    y = torch.mm(x, x)
    assert y.dtype == torch.bfloat16
print('PASS: cache_enabled=False works')

# 4. 装饰器模式
print('\n=== 4. decorator ===')
@torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16)
def foo(x):
    return torch.mm(x, x)
x = torch.randn(3, 3)
y = foo(x)
assert y.dtype == torch.bfloat16
print('PASS: decorator mode works')

"rint('\n=== ALL CHECKS PASSED ===')[0].message}')Warning' FutureWarning)]
torch version: 2.13.0a0+git636bc91
=== 1. autocast context manager ===
  dtype in autocast: torch.bfloat16
PASS: bfloat16 autocast on CPU

=== 2. enabled=False ===
PASS: float32 when disabled

=== 3. cache_enabled ===
PASS: cache_enabled=False works

=== 4. decorator ===
PASS: decorator mode works

=== 5. deprecation warning ===
  warning: `torch.cpu.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cpu', args...)` instead.
PASS: FutureWarning raised

=== ALL CHECKS PASSED ===
```

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

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

See merge request: Ascend/pytorch!45891
2026-10-10 18:18:29 +08:00
ljfnjj1234567 0671384791 docs: update support status of torch.accelerator.device_count
Co-authored-by: ljfnjj1234567<wn0010240@163.com>



# message auto-generated for no-merge-commit merge:
!45980 merge docs-accelerator-device-count-support-master into master

docs: update support status of torch.accelerator.device_count

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

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

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


# 【修改方案】

torch.accelerator.device_count 返回当前加速器可用数量(无加速器返回 0),为设备无关的纯 Python 转发接口,委托给 torch.npu.device_count()。该 API 在昇腾 NPU(Atlas A2/A3 训练系列、Ascend 950DT)上均已实测可用。
上游 PyTorch 官方文档各版本(2.7.1/2.11.0/2.12.0/2.13.0)均已收录该 API,Ascend native_api 各版本目录也已收录。其中 2-7-1/2-11-0/2-12-0 的产品支持情况误标「Ascend 950DT:不支持」,按实测结果修正为「支持」;2-13-0 已为「支持」,无需改动。

# 【资料变更】

涉及。修改 docs/zh/api/native_api/pytorch_2-7-1|2-11-0|2-12-0/torch-accelerator.md 中 torch.accelerator.device_count 的 Ascend 950DT 支持状态为「支持」,与 2-13-0 及实测结论保持一致;格式沿用「产品支持情况」文字列表,未改动其余内容。

# 【接口变更】
不涉及

# 【功能介绍】
- 返回值为 int 类型;若当前环境没有任何可用加速器,返回 0。
- 该 API 为纯 Python 封装(torch/accelerator/__init__.py),内部委托 C++ 侧 torch._C._accelerator_deviceCount(),由 accelerator 抽象层自动路由到当前加速器后端(CUDA / XPU / NPU 等),Python 层无任何设备硬编码。
- 该 API 属于设备无关的元信息查询接口,不涉及算子计算,不依赖具体硬件;在昇腾环境下导入 torch_npu 后,返回值为可见的 NPU 卡数,与 torch.npu.device_count() 语义一致。

# 【功能验证】

torch.accelerator.device_count 在 v2.7.1/v2.11.0/v2.12.0/2.13.0 昇腾环境实测返回正确 NPU 设备数。
v2.7.1:
python -m pytest /workspace/user_data/pytorch-2.7.1-up/test/test_accelerator.py -xvs
```
============================================ test session starts ============================================
platform linux -- Python 3.11.15, pytest-8.3.5, pluggy-1.6.0 -- /usr/local/python3.11.15/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.7.1-up
configfile: pytest.ini
collected 7 items                                                                                           
Running 7 items in this shard

pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_current_accelerator PASSED [0.0286s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_current_stream_query PASSED [0.8100s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_generic_multi_device_behavior SKIPPED [0.0004s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_generic_stream_behavior PASSED [0.1708s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_multi_device_stream_context_manager SKIPPED [0.0004s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_pin_memory_on_non_blocking_copy PASSED [0.0029s]
pytorch-2.7.1-up/test/test_accelerator.py::TestAccelerator::test_stream_context_manager PASSED [0.0019s]

======================================= 5 passed, 2 skipped in 9.42s ========================================
```
v2.11.0:
python -m pytest /workspace/user_data/pytorch-2.11.0-up/test/test_accelerator.py -xvs
```
============================================ test session starts ============================================
platform linux -- Python 3.11.15, pytest-8.3.5, pluggy-1.6.0 -- /usr/local/python3.11.15/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.11.0-up
configfile: pytest.ini
collected 13 items                                                                                          
Running 13 items in this shard

pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_current_accelerator PASSED [0.0266s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_current_stream_query PASSED [0.8208s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_device_context_manager PASSED [0.0032s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_generic_event_behavior PASSED [0.0025s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_generic_multi_device_behavior SKIPPED [0.0004s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_generic_stream_behavior PASSED [0.1613s]
pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info FAILED [0.0019s]

================================================= FAILURES ==================================================
___________________________________ TestAccelerator.test_get_memory_info ____________________________________
Traceback (most recent call last):
  File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/testing/_internal/common_utils.py", line 3329, in wrapper
    method(*args, **kwargs)
  File "/workspace/user_data/pytorch-2.11.0-up/test/test_accelerator.py", line 259, in test_get_memory_info
    free_bytes, total_bytes = torch.accelerator.get_memory_info()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/accelerator/memory.py", line 236, in get_memory_info
    return torch._C._accelerator_getMemoryInfo(device_index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":116, please report a bug to PyTorch. Allocator for npu is not a DeviceAllocator.

To execute this test, run the following from the base repo dir:
    python test/test_accelerator.py TestAccelerator.test_get_memory_info

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
========================================== short test summary info ==========================================
FAILED [0.0019s] pytorch-2.11.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info - RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":11...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================== 1 failed, 5 passed, 1 skipped in 2.33s ===================================
```
1failed属于 get_memory_info 这个 API 的 NPU 适配缺口,不影响torch.accelerator.device_count的判断
v2.12.0:
python -m pytest /workspace/user_data/pytorch-2.12.0-up/test/test_accelerator.py -xvs
```
============================================ test session starts ============================================
platform linux -- Python 3.11.15, pytest-8.3.5, pluggy-1.6.0 -- /usr/local/python3.11.15/bin/python
cachedir: .pytest_cache
rootdir: /workspace/user_data/pytorch-2.12.0-up
configfile: pytest.ini
collected 14 items                                                                                          
Running 14 items in this shard

pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_current_accelerator PASSED [0.0302s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_current_stream_query PASSED [0.8138s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_device_capability_supported_dtypes SKIPPED [0.0023s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_device_context_manager PASSED [0.0022s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_generic_event_behavior PASSED [0.0020s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_generic_multi_device_behavior SKIPPED [0.0003s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_generic_stream_behavior PASSED [0.1602s]
pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info FAILED [0.0018s]

================================================= FAILURES ==================================================
___________________________________ TestAccelerator.test_get_memory_info ____________________________________
Traceback (most recent call last):
  File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/usr/local/python3.11.15/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
       ^^^^^^^^
  File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/testing/_internal/common_utils.py", line 3329, in wrapper
    method(*args, **kwargs)
  File "/workspace/user_data/pytorch-2.12.0-up/test/test_accelerator.py", line 260, in test_get_memory_info
    free_bytes, total_bytes = torch.accelerator.get_memory_info()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python3.11.15/lib/python3.11/site-packages/torch/accelerator/memory.py", line 236, in get_memory_info
    return torch._C._accelerator_getMemoryInfo(device_index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":116, please report a bug to PyTorch. Allocator for npu is not a DeviceAllocator.

To execute this test, run the following from the base repo dir:
    python test/test_accelerator.py TestAccelerator.test_get_memory_info

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0
========================================== short test summary info ==========================================
FAILED [0.0018s] pytorch-2.12.0-up/test/test_accelerator.py::TestAccelerator::test_get_memory_info - RuntimeError: device_allocator INTERNAL ASSERT FAILED at "/pytorch/c10/core/CachingDeviceAllocator.h":11...
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================== 1 failed, 5 passed, 2 skipped in 2.36s ===================================
```
1failed属于 get_memory_info 这个 API 的 NPU 适配缺口,不影响torch.accelerator.device_count的判断
A5验证:
```
((torch-271) ) root@fb4338484c54:/tmp# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1                                 

See merge request: Ascend/pytorch!45980
2026-10-10 18:18:07 +08:00
ljfnjj1234567 ae64a2d539 docs: update torch.TypedStorage.is_sparse support status
Co-authored-by: ljfnjj1234567<wn0010240@163.com>



# message auto-generated for no-merge-commit merge:
!45877 merge typedstorage-is-sparse-master into master

docs: update torch.TypedStorage.is_sparse support status

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

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

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


# 【修改方案】

`torch.TypedStorage.is_sparse`
该 API 为 `torch.TypedStorage 不携带 layout信息,属性恒返回 `False`,设备无关,Ascend 950DT
下与其他产品行为一致(实
上游各版本 native_api 文
支持情况误标为「不支持」

# 【资料变更】

涉及。以上 4 个版本目录中,`torch.TypedStorage.is_sparse` 的**产品支持情况**列表里,`<term>Ascend
950DT</term>:不支持` 更m>:支持`;Atlas A2 / A3训练系列产品保持「支持」不变。

# 【接口变更】

不涉及

# 【功能介绍】

`torch.TypedStorage.is_sparse` 是 `torch.TypedStorage`(`torch.FloatStorage`
等 legacy storage 的基类
是否为稀疏。由于稀疏属性 携带 layout
信息,该属性恒为 `False`

# 【功能验证】
test/test_storage_is_sparse.py (torch.TypedStorage.is_sparse)
- test_is_sparse_false_for_empty_storage — 空构造 `torch.TypedStorage()`,is_sparse 为 False
- test_is_sparse_false_for_size_construction — size 构造 `torch.TypedStorage(4, dtype=torch.float32)`
- test_is_sparse_false_for_sequence_construction — Sequence 构造 `torch.TypedStorage([1.0, 2.0, 3.0], dtype=torch.float32)`
- test_is_sparse_false_for_wrap_storage_construction — wrap_storage 构造(UntypedStorage 包装)
- test_is_sparse_false_for_all_dtypes — 多 dtype(float32 / float16 / int32 / int64)
- test_is_sparse_false_on_npu — NPU 张量的 untyped_storage().is_sparse 为 False

运行命令:
python -m pytest test_storage_is_sparse.py -x
运行结果:
```
================================================= test session starts ==================================================
platform linux -- Python 3.11.15, pytest-9.1.1, pluggy-1.6.0
rootdir: /workspace/user_data/pytorch-v2.7.1
configfile: pyproject.toml
collected 6 items                                                                                                      

pytorch-v2.7.1/test/test_storage_is_sparse.py ......                                                             [100%]

=================================================== warnings summary ===================================================
../../usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: 14 warnings
  /usr/local/python3.11.15/lib/python3.11/site-packages/torch/jit/_script.py:362: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

test/test_storage_is_sparse.py::TestStorageIsSparse::test_is_sparse_false_for_all_dtypes
  /workspace/user_data/pytorch-v2.7.1/test/test_storage_is_sparse.py:50: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
    storage = torch.TypedStorage(4, dtype=dtype)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================ 6 passed, 15 warnings in 8.36s ============================================
```
A5验证
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace# cd /workspace/user_data && source /usr/local/Ascend/ascend-toolkit/set_env.sh && export ASCEND_PROCESS_LOG_PATH=/tmp && env -u CI /workspace/user_data/npu-pytorch-setup/venv_npu/bin/python /workspace/user_data/pytorch-master/test/test_storage_is_sparse.py -v
test_is_sparse_false_for_all_dtypes (__main__.TestStorageIsSparse.test_is_sparse_false_for_all_dtypes) ... /workspace/user_data/pytorch-master/test/test_storage_is_sparse.py:36: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
  storage = torch.TypedStorage(4, dtype=dtype)
ok
test_is_sparse_false_for_empty_storage (__main__.TestStorageIsSparse.test_is_sparse_false_for_empty_storage) ... ok
test_is_sparse_false_for_sequence_construction (__main__.TestStorageIsSparse.test_is_sparse_false_for_sequence_construction) ... ok
test_is_sparse_false_for_size_construction (__main__.TestStorageIsSparse.test_is_sparse_false_for_size_construction) ... ok
test_is_sparse_false_for_wrap_storage_construction (__main__.TestStorageIsSparse.test_is_sparse_false_for_wrap_storage_construction) ... ok
test_is_sparse_false_on_npu (__main__.TestStorageIsSparse.test_is_sparse_false_on_npu) ... [W906 05:32:20.071140775 NPUCachingAllocator.cpp:174] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
ok

----------------------------------------------------------------------
Ran 6 tests in 1.784s

OK
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6                               Version: 25.7.rc1.6                            |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name             | Health        | Power(W)    Temp(C)           Hugepages-Usage(page) |
|        |                  | Bus-Id        | NPU Util(%) Memory-Usage(MB)  HBM-Usage(MB)         |
+========+==================+===============+=====================================================+
| 0      | Ascend950PR      | OK            | 208.4       62                0     / 0             |
|        |                  | 0000:55:00.0  | 0           0    / 0          5240  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
```
# 【CheckList】
> PR提交人对以下CheckLis或不涉及,均修改 [ ] 为[x]

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回
- [x] PR标题正确使用类型、docs、test等
- [x] PR持续集成流水线

See merge request: Ascend/pytorch!45877
2026-10-10 18:08:34 +08:00
y30037164 da62511fe6 fix: 优化 nightly 流水线:单卡编译、统一 torch 安装、常规测试并发提速
Co-authored-by: yuaiming<yuaiming@h-partners.com>



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

fix: 优化 nightly 流水线:单卡编译、统一 torch 安装、常规测试并发提速

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

# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012

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

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

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

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

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

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

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


See merge request: Ascend/pytorch!47691
2026-10-10 18:01:48 +08:00
gcw_CHjSLYhf 709b3ea1a7 [test] Add torch.untypedstorage{filename|hpu|nbytes|new} API test case
Co-authored-by: gcw_CHjSLYhf<2839668818@qq.com>



# message auto-generated for no-merge-commit merge:
!45157 merge untypedstorage_filename_hpu_nbytes_new-master into master

[test] Add torch.untypedstorage{filename|hpu|nbytes|new} API test case

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

# 【合入来源】

- [ ] 需求
- [ ] 问题单
- [x] issue/工单 https://gitcode.com/Ascend/pytorch/issues/3739 https://gitcode.com/Ascend/pytorch/issues/3750 https://gitcode.com/Ascend/pytorch/issues/3760 https://gitcode.com/Ascend/pytorch/issues/3761
- [ ] 重构优化
- [ ] 资料更新

公开issue:

- `torch.UntypedStorage.filename`:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(78)](https://gitcode.com/Ascend/pytorch/issues/3739)
- `torch.UntypedStorage.hpu`:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(89)](https://gitcode.com/Ascend/pytorch/issues/3750)
- `torch.UntypedStorage.nbytes`:[8月社区任务第一期-Ascend for PyTorch API 一致性开发(99)](https://gitcode.com/Ascend/pytorch/issues/3760)
- `torch.UntypedStorage.new`: [8月社区任务第一期-Ascend for PyTorch API 一致性开发(100) ](https://gitcode.com/Ascend/pytorch/issues/3761)

# 一. API 功能说明:

## 1. torch.UntypedStorage.filename

`filename` 是`torch.UntypedStorage`这个类的一个只读属性,用于获取与当前 Storage 关联的内存映射文件路径。因此和平台设备有关联,需要增加一个快速的验证性测试。

PyTorch 2.7 中的实现为:

```python
@property
def filename(self):
    return self._get_filename()
```

因此它属于 Python 属性封装,但实际结果由底层 Storage 元数据接口 `_get_filename()` 提供。

## 2. torch.UntypedStorage.hpu

`torch.UntypedStorage.hpu()` 用于 返回一个在 HPU(Habana Gaudi 加速器)上的存储副本,如果该对象已在HPU内存中且位于正确的设备上,则不执行复制,直接返回原始对象。因为该API与HPU平台设备具有强绑定关系。

参数说明:

- `device`:目标 HPU 设备编号,默认使用当前 HPU 设备;
- `non_blocking`:如果源内存满足异步复制条件,则允许异步复制。

PyTorch 2.7 中的核心实现为:

```python
def hpu(self, device=None, non_blocking=False):
    device2 = (
        torch.device("hpu", device)
        if device
        else torch.device("hpu")
    )
    return self.to(
        device=device2,
        non_blocking=non_blocking,
    )
```

## 3. torch.UntypedStorage.nbytes

`torch.UntypedStorage.nbytes()` 返回当前底层 Storage 实际占用的字节数,返回类型为 `int`。

但要注意,`nbytes()` 查询的是整个 Storage 的大小,而不是当前 Tensor View 的逻辑数据量。

例如:

```python
base = torch.empty(16, dtype=torch.float32)
view = base[::2]

base.untyped_storage().nbytes() == 64
view.untyped_storage().nbytes() == 64

# view只有8个逻辑元素
view.numel() * view.element_size() == 32
```

这是因为 `view` 和 `base` 共享同一个底层 Storage。

接口本身主要读取底层 Storage 元数据,不执行计算算子,但它读取的是 NPU Storage 的实际字节范围,可以验证 NPU Tensor 到 UntypedStorage 的连接是否正确,因此需要增加 NPU 功能测试。

## 4. torch.UntypedStorage.new

`torch.UntypedStorage.new`在当前 Storage 所在设备上,创建一个新的、大小为 0 的 UntypedStorage。torch.UntypedStorage.new() 由底层 Storage 实现提供。NPU Storage 调用该接口时,需要正确处理 PrivateUse1/NPU 设备信息。因此需要补充这个API在torch-npu平台上的测试用例。

# 二. 上游用例检查情况:

检查 PyTorch 上游 Storage 相关测试后,结果如下:

| API | 上游是否存在独立直接用例 | 检查结果 |
|---|---:|---|
| ` torch.UntypedStorage.filename` | 未发现 | 上游核心`test/test_torch.py`中未发现直接读取`.filename`的独立用例 |
| `torch.UntypedStorage.hpu` | 未发现 | 上游核心Storage测试中未发现直接调用`.hpu()`的独立用例 |
| `torch.UntypedStorage.nbytes` | 存在部分覆盖 | 上游在Storage Meta测试中调用了`s.nbytes()`并比较不同Storage的字节数 |
| `torch.UntypedStorage.new` | 存在部分覆盖 | 上游在Storage Meta测试中调用了`s.nbytes()`并比较不同Storage的字节数 |


# 三. 资料情况检查:

- `torch.UntypedStorage.filename`:在torch上游社区存在独立条目,同时在当前项目中该API资料已经存在,但是A5支持情况有误,因此需要进行资料修正。

![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')

资料修正补充pr: https://gitcode.com/Ascend/pytorch/pull/46583

# 四. API功能性验证

## 1. 测试场景
# torch.UntypedStorage API 功能性验证

## 1. 测试场景

| 编号 | API | 测试场景 | 预期结果 |
| --- | --- | --- | --- |
| 1 | `torch.UntypedStorage.filename` | 获取普通 CPU Tensor 底层 Storage 的 `filename` | 普通 CPU Storage 未关联内存映射文件,返回 `None` |
| 2 | `torch.UntypedStorage.filename` | 使用 `from_file(shared=True)` 创建共享文件映射 Storage | `filename` 返回字符串,并且规范化路径与映射文件路径一致 |
| 3 | `torch.UntypedStorage.filename` | 使用 `from_file(shared=False)` 创建私有文件映射 Storage | 私有映射的 `filename` 返回 `None` |
| 4 | `torch.UntypedStorage.filename` | 获取 NPU Tensor 底层 Storage 的 `filename` | Storage 位于 NPU,且未关联 CPU 文件映射,返回 `None` |
| 5 | `torch.UntypedStorage.hpu` | 在纯 torch-npu 环境中调用默认参数 `hpu()` | 因未加载 HPU 设备模块,抛出包含 `HPU device module is not loaded` 的 `AssertionError` |
| 6 | `torch.UntypedStorage.hpu` | 指定 `device=1, non_blocking=True` 调用 `hpu()` | 参数可以被接口正常解析;因未加载 HPU 模块,抛出预期 `AssertionError` |
| 7 | `torch.UntypedStorage.nbytes` | 验证 `float16` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 8 | `torch.UntypedStorage.nbytes` | 验证 `float32` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 9 | `torch.UntypedStorage.nbytes` | 验证 `int32` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 10 | `torch.UntypedStorage.nbytes` | 验证 `int64` Tensor 的 CPU/NPU Storage 字节数 | CPU、NPU 结果均等于 `numel × element_size` |
| 11 | `torch.UntypedStorage.nbytes` | 直接在 CPU/NPU 上构造指定字节数的 UntypedStorage | `nbytes()`、`size()` 和 `len()` 均返回构造时指定的字节数 |
| 12 | `torch.UntypedStorage.nbytes` | 创建大小为 0 的空 NPU Storage | `nbytes()`、`size()` 和 `len()` 均返回 0 |
| 13 | `torch.UntypedStorage.nbytes` | 获取非连续 NPU Tensor View 的底层 Storage 字节数 | View 与原 Tensor 共享底层 Storage,返回整个底层 Storage 的字节数 |
| 14 | `torch.UntypedStorage.new` | 对 CPU Storage 调用 `new()` | 返回独立、大小为 0、设备类型仍为 CPU 的 UntypedStorage |
| 15 | `torch.UntypedStorage.new` | 对 NPU Storage 调用 `new()` | 返回独立、大小为 0、设备类型仍为 NPU 的 UntypedStorage |
| 16 | `torch.UntypedStorage.new` | 对 `new()` 返回的 Storage 执行 `resize_()` | 新 Storage 的大小发生变化,原 Storage 的大小不受影响 |
| 17 | `torch.UntypedStorage.new` | 对共享文件映射 Storage 调用 `new()` | 返回普通空 CPU Storage,不继承原 Storage 的文件映射关系 |

## 2. 测试核心代码

```python
class TestUntypedStorageAPIs(TestCase):

    def test_untyped_storage_filename(self):
        # 场景1:普通CPU Storage不关联内存映射文件
        cpu_storage = torch.empty(
            8,
            dtype=torch.float32,
            device="cpu",
        ).untyped_storage()

        self.assertEqual(cpu_storage.device.type, "cpu")
        self.assertIsNone(cpu_storage.filename)

        # 场景2和3:共享文件映射与私有文件映射Storage
        with tempfile.TemporaryDirectory() as temp_dir:
            file_path = os.path.join(
                temp_dir,
                "untyped_storage.bin",
            )

            shared_storage = torch.UntypedStorage.from_file(
                file_path,
                shared=True,
                nbytes=32,
            )

            self.assertEqual(shared_storage.device.type, "cpu")
            self.assertEqual(shared_storage.nbytes(), 32)
            self.assertIsInstance(
                shared_storage.filename,
                str,
            )
            self.assertEqual(
                os.path.realpath(shared_storage.filename),
                os.path.realpath(file_path),
            )

            # 释放共享映射后再创建私有映射
            del shared_storage

            private_storage = torch.UntypedStorage.from_file(
                file_path,
                shared=False,
                nbytes=32,
            )

            self.assertEqual(private_storage.device.type, "cpu")
            self.assertEqual(private_storage.nbytes(), 32)
            self.assertIsNone(private_storage.filename)

            del private_storage

        # 场景4:NPU Storage不关联CPU内存映射文件
        npu_storage = torch.empty(
            8,
            dtype=torch.float32,
            device="npu",
        ).untyped_storage()

        self.assertEqual(npu_storage.device.type, "npu")
        self.assertIsNone(npu_storage.filename)

    def test_untyped_storage_hpu(self):
        npu_storage = torch.empty(
            8,
            dtype=torch.float32,
            device="npu",
        ).untyped_storage()

        self.assertEqual(
            npu_storage.device.type,
            "npu",
        )

        # 场景5:在torch-npu平台使用默认参数调用hpu()
        with self.assertRaisesRegex(
            AssertionError,
            r"HPU device module is not loaded",
        ):
            npu_storage.hpu()

        # 场景6:在torch-npu平台指定device和non_blocking参数
        with self.assertRaisesRegex(
            AssertionError,
            r"HPU device module is not loaded",
        ):
            npu_storage.hpu(
                device=1,
                non_blocking=True,
            )

    def test_untyped_storage_nbytes_for_tensor_dtypes(self):
        test_cases = [
            (torch.float16, 6),
            (torch.float32, 6),
            (torch.int32, 6),
            (torch.int64, 6),
        ]

        # 场景7至10:不同dtype的CPU/NPU Storage字节数
        for dtype, numel in test_cases:
            with self.subTest(dtype=dtype):
                cpu_tensor = torch.empty(
                    numel,
                    dtype=dtype,
                    device="cpu",
                )
                npu_tensor = torch.empty(
                    numel,
                    dtype=dtype,
                    device="npu",
                )

                cpu_storage = cpu_tensor.untyped_storage()
                npu_storage = npu_tensor.untyped_storage()

                expected_nbytes = (
                    numel * cpu_tensor.element_size()
                )

                self.assertEqual(
                    cpu_storage.nbytes(),
                    expected_nbytes,
                )
                self.assertEqual(
                    npu_storage.nbytes(),
                    expected_nbytes,
                )
                self.assertEqual(
                    cpu_storage.nbytes(),
                    npu_storage.nbytes(),
                )

                # UntypedStorage的长度单位也是字节
                self.assertEqual(
                    len(cpu_storage),
                    expected_nbytes,
                )
                self.a

See merge request: Ascend/pytorch!45157
2026-10-10 17:59:11 +08:00
zhangjiahao-2026 b651b67466 docs: add torch.nn.attention.flex_attention.or_masks support status
Co-authored-by: zhangjiahao-2026<2332445379@qq.com>



# message auto-generated for no-merge-commit merge:
!43375 merge issue-3293-or-masks-docs into master

docs: add torch.nn.attention.flex_attention.or_masks support status

Created-by: zhangjiahao-2026
Commit-by: zhangjiahao-2026
Merged-by: ascend-robot
Description: # 【合入来源】
关联任务issue: https://gitcode.com/Ascend/pytorch/issues/3293

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


# 【修改方案】

在 master 资料中为公开非计算类 API `torch.nn.attention.flex_attention.or_masks` 补齐支持情况。

修改文件:
- docs/zh/api/native_api/pytorch_2-7-1/torch-nn-attention.md
- docs/zh/api/native_api/pytorch_2-11-0/torch-nn-attention.md
- docs/zh/api/native_api/pytorch_2-12-0/torch-nn-attention.md
- docs/zh/api/native_api/pytorch_2-13-0/torch-nn-attention.md

具体修改内容:

1. 在PyTorch 2.7.1、2.11.0、2.12.0和2.13.0资料中新增`torch.nn.attention.flex_attention.or_masks`条目;
2. 按照PyTorch官方资料的层级和顺序,将该API归入`BlockMask Utilities`,并放置在`BlockMask`之前;
3. Atlas A2训练系列产品、Atlas A3训练系列产品和Ascend 950DT均标记为支持;
4. 该API为非计算类纯Python接口,与具体数据类型无关,不填写数据类型限制。

本PR仅补充目标API的资料,不批量修改同一文件中其他历史API的资料格式。

# 【资料变更】
资料检查结果:此前 master 下的原生 API 资料未收录
`torch.nn.attention.flex_attention.or_masks`,因此需要补充。

本次在以下版本目录的 `torch-nn-attention.md` 中新增支持情况:

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

该API为公开非计算类纯Python接口,与张量数据类型无关,不填写数据类型限制。文档条目按照PyTorch官方资料的层级和顺序归入`BlockMask Utilities`。

# 【接口变更】
不涉及

# 【功能验证】
`torch.nn.attention.flex_attention.or_masks(*mask_mods)`用于组合一个或多个
`mask_mod`,返回一个新的掩码函数,并对所有输入mask的返回结果执行逻辑或。

PyTorch官方社区在以下用例中已有`or_masks`基本逻辑或语义验证:

```text
test/inductor/test_flex_attention.py::test_mask_mod_combiners
```

`or_masks`为纯Python组合接口,不包含NPU专属kernel或设备分支,不需要修改
Torch-NPU功能实现,也不需要新增测试文件或`test_upstream` patch。

API功能、社区用例情况、NPU适配分析和各版本验证结果见说明Issue:

https://gitcode.com/Ascend/pytorch/issues/4082

A5硬件验证信息如下。

验证设备:
![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
honorn 4cac9b6f63 [test]Add typedStorage_is{shared|pinned|hpu} API test case
Co-authored-by: honorn<838107180@qq.com>



# message auto-generated for no-merge-commit merge:
!45162 merge TypedStorage_is_shared_pinned_hpu-master into master

[test]Add typedStorage_is{shared|pinned|hpu} API test case

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

# 【合入来源】

[#3780](https://gitcode.com/Ascend/pytorch/issues/3780)
[#3779](https://gitcode.com/Ascend/pytorch/issues/3779)
[#3778](https://gitcode.com/Ascend/pytorch/issues/3778)

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

公开issue:

- `torch.TypedStorage.is_shared`:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(47)](https://gitcode.com/Ascend/pytorch/issues/3780)
- `torch.TypedStorage.is_pinned`:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(46)](https://gitcode.com/Ascend/pytorch/issues/3779)
- `torch.TypedStorage.is_hpu`:[【社区任务】8月社区任务第一期-Ascend for PyTorch API 一致性开发(45)](https://gitcode.com/Ascend/pytorch/issues/3778)

# 一. API 功能说明:

- `torch.TypedStorage.is_shared()` :判断当前 Storage 是否位于共享内存中。
- `torch.TypedStorage.is_pinned()`:判断一个 CPU Storage 是否为指定加速设备分配的页锁定内存,也叫 Pinned Memory。
- `torch.TypedStorage.is_hpu()`:判断 Storage 是否位于 HPU 设备上。HPU 是 Habana Processing Unit,主要指 Intel Habana Gaudi 系列加速器。

| API | 接口性质 | 是否与设备相关 | torch-npu 测试建议 |
|---|---|---|---|
| `torch.TypedStorage.is_shared` | Python 包装接口,实际查询底层 `UntypedStorage` | 是,依赖底层存储及共享内存实现 | 建议补充 NPU 冒烟测试 |
| `torch.TypedStorage.is_pinned` | Python 包装接口,实际查询设备的固定内存分配器 | 强相关 | 必须补充 NPU 用例 |
| `torch.TypedStorage.is_hpu` | Python 属性,比较 `device.type == "hpu"` | 仅查询设备元数据 | 无需专门适配,但可补充 NPU 返回 `False` 的测试 |

**注意** `HPU` 指 `Habana Gaudi HPU`

PyTorch 2.7 中三者的实现分别是:

```python
def is_shared(self):
    _warn_typed_storage_removal()
    return self._is_shared()

def _is_shared(self):
    return self._untyped_storage.is_shared()


def is_pinned(self, device="cuda"):
    _warn_typed_storage_removal()
    return self._untyped_storage.is_pinned(device)


@property
def is_hpu(self):
    _warn_typed_storage_removal()
    return self._untyped_storage.device.type == "hpu"
```

可以看到,`is_shared()` 和 `is_pinned()` 都会继续调用底层 `UntypedStorage`;`is_hpu()` 则是简单的 Python 设备类型判断。


# 二. 上游用例检查情况:

| API | 上游检查结果 | NPU 覆盖缺口 |
|---|---|---|
| `TypedStorage.is_shared()` | `test_storage_meta_errors` 对 meta TypedStorage 断言 `is_shared() == False` | 没有覆盖 NPU |
| `TypedStorage.is_pinned()` | 核心 `test_torch.py` 中未发现该方法的独立正反例;CUDA 测试包含 Tensor 层固定内存测试 | 没有检查 `device="npu"` 及 NPU pinned allocator |
| `TypedStorage.is_hpu` | 核心 Storage 测试中未发现独立断言 | 没有验证 NPU Storage 必须返回 `False` |

因此需要补充这三个API的测试用例,这三个API可以直接放到一个完整的测试文件中进行测试。

# 三. 资料情况检查:

- `torch.TypedStorage.is_shared`
- `torch.TypedStorage.is_pinned`
- `torch.TypedStorage.is_hpu`

这些API的资料补充在各个分支都存在,但是 `torch.TypedStorage.is_shared` 和`torch.TypedStorage.is_pinned`对A5芯片的支持程度描述有误,需要进行资料修改,`torch.TypedStorage.is_hpu`由于与hpu硬件相关,因此都不支持,资料补充正确无误,结果如下截图所示。

![image.png](https://raw.gitcode.com/user-images/assets/7404318/e7b7de04-f9d6-446f-ac6e-7982ca1dd740/image.png 'image.png')
![image.png](https://raw.gitcode.com/user-images/assets/7404318/2eb2cb32-745e-490c-bea1-1cf47533d8d9/image.png 'image.png')
![image.png](https://raw.gitcode.com/user-images/assets/7404318/d5a39808-6369-4635-b90f-a2adaeda84a5/image.png 'image.png')

# 四. API功能性验证

测试核心代码

```python
class TestTypedStorageAPIs(TestCase):

    @staticmethod
    def _get_typed_storage(tensor):
        return tensor.storage()

    def test_typed_storage_is_shared_for_cpu(self):
        cpu_tensor = torch.arange(
            8,
            dtype=torch.float32,
            device="cpu",
        )
        expected_tensor = cpu_tensor.clone()
        cpu_storage = self._get_typed_storage(cpu_tensor)

        self.assertIsInstance(
            cpu_storage,
            torch.TypedStorage,
        )
        self.assertEqual(
            cpu_storage.device.type,
            "cpu",
        )

        # 场景1:普通CPU TypedStorage不在共享内存中
        self.assertFalse(cpu_storage.is_shared())
        self.assertEqual(
            cpu_storage.is_shared(),
            cpu_tensor.untyped_storage().is_shared(),
        )

        # 场景2:CPU TypedStorage移动到共享内存
        returned_storage = cpu_storage.share_memory_()

        self.assertIs(
            returned_storage,
            cpu_storage,
        )
        self.assertTrue(cpu_storage.is_shared())
        self.assertTrue(cpu_tensor.is_shared())
        self.assertTrue(
            cpu_tensor.untyped_storage().is_shared()
        )

        # share_memory_不能改变Storage中的数据
        self.assertEqual(
            cpu_tensor,
            expected_tensor,
        )

    def test_typed_storage_is_shared_for_tensor_view(self):
        base_tensor = torch.arange(
            16,
            dtype=torch.float32,
            device="cpu",
        )
        view_tensor = base_tensor[::2]

        base_storage = self._get_typed_storage(
            base_tensor
        )
        view_storage = self._get_typed_storage(
            view_tensor
        )

        # 场景3:Base Tensor和View共享同一底层Storage
        self.assertEqual(
            base_storage.data_ptr(),
            view_storage.data_ptr(),
        )
        self.assertFalse(base_storage.is_shared())
        self.assertFalse(view_storage.is_shared())

        base_storage.share_memory_()

        self.assertTrue(base_storage.is_shared())
        self.assertTrue(view_storage.is_shared())
        self.assertTrue(base_tensor.is_shared())
        self.assertTrue(view_tensor.is_shared())
        self.assertEqual(
            base_storage.data_ptr(),
            view_storage.data_ptr(),
        )

    def test_typed_storage_is_shared_for_npu(self):
        npu_tensor = torch.empty(
            16,
            dtype=torch.float32,
            device="npu",
        )
        npu_storage = self._get_typed_storage(
            npu_tensor
        )

        self.assertEqual(
            npu_storage.device.type,
            "npu",
        )

        is_shared_before = npu_storage.is_shared()
        data_ptr_before = npu_storage.data_ptr()
        nbytes_before = npu_storage.nbytes()

        self.assertIsInstance(
            is_shared_before,
            bool,
        )
        self.assertEqual(
            is_shared_before,
            npu_tensor.untyped_storage().is_shared(),
        )

        # 场景4:NPU/PrivateUse1 Storage不迁移到POSIX共享内存。
        #
        # 不硬编码NPU is_shared()为True或False,是因为不同PyTorch
        # 版本可能调整非CPU设备的共享状态定义;TypedStorage必须
        # 与底层UntypedStorage一致,并且share_memory_应为no-op。
        returned_storage = npu_storage.share_memory_()
        is_shared_after = npu_storage.is_shared()

        self.assertIs(
            returned_storage,
            npu_storage,
        )
        self.assertEqual(
            is_shared_after,
            is_shared_before,
        )
        self.assertEqual(
            is_shared_after,
            npu_tensor.untyped_storage().is_shared(),
        )
        self.assertEqual(
            npu_storage.data_ptr(),
            data_ptr_before,
        )
        self.assertEqual(
            npu_storage.nbytes(),
            nbytes_before,
        )

    def test_typed_storage_is_pinned_for_normal_storage(self):
        test_dtypes = [
            torch.float16,
            torch.float32,
            torch.int32,
            torch.int64,
        ]

        # 场景5:普通CPU/NPU TypedStorage均不是NPU pinned memory
        for device in ["cpu", "npu"]:
            for dtype in test_dtypes:
                with self.subTest(
                    device=device,
                    dtype=dtype,
                ):
                    tensor = torch.empty(
                        16,
                        dtype=dtype,
                        device=device,
                    )
                    storage = self._get_typed_storage(
                        tensor
                    )

                    result_by_string = storage.is_pinned(
                        device="npu"
                    )
                    result_by_device = storage.is_pinned(
                        device=torch.device("npu")
                    )
                    untyped_result = (
                        tensor.untyped_storage().is_pinned(
                            device="npu"
                        )
                    )

                    self.assertIsInstance(
                        result_by_string,
                        bool,
                    )
                    self.assertFalse(result_by_string)
                    self.assertFalse(result_by_device)
                    self.assertEqual(
                        result_by_string,
                        result_by_device,
                    )
                    self.assertEqual(
                        result_by_string,
                        untyped_result,
                    )

    def test_typed_storage_is_pinned_for_pinned_cpu(self):
        test_dtypes = [
            torch.float16,
            torch.float32,
            torch.int32,
            torch.int64,
        ]

        # 场景6:CPU TypedStorage转换为NPU pinned memory
        for dtype in test_dtypes:
            with self.subTest(dtype=dtype):
                source_tensor = torch.arange(
                    1,
                    9,
                    dtype=dtype,
                    device="cpu",
                )
                source_storage = (
                    self._get_typed_storage(
                        source_tensor
                    )
                )
                source_values = (
                    source_storage.tolist()
                )

                self.assertFalse(
                    source_storage.is_pinned(
                        device="npu"
                    )
                )

                pinned_storage = (
                    source_storage.pin_memory(
                        device="npu"
                    )
                )

                self.assertIsInstance(
                    pinned_storage,
                    torch.TypedStorage,
                )
                self.assertIsNot(
                    pinned_storage,
                    source_storage,
                )
                self.assertEqual(
                    pinned_storage.device.type,
                    "cpu",
                )
     

See merge request: Ascend/pytorch!45162
2026-10-10 17:40:43 +08:00
gcw_fiAo4tDr c539cc2598 [docs] 更新 Tensor.is_meta 的 Ascend 950DT 支持标记
Co-authored-by: gcw_fiAo4tDr<iqueenqueen@163.com>



# message auto-generated for no-merge-commit merge:
!45879 merge docs/is-meta-950dt-support-v2 into master

[docs] 更新 Tensor.is_meta 的 Ascend 950DT 支持标记

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


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


关联任务:https://gitcode.com/Ascend/pytorch/issues/2710


验证分析:https://gitcode.com/Ascend/pytorch/issues/2807


# 【修改方案】


更新 `torch.Tensor.is_meta` 的 Ascend 950DT 产品支持标记,由“不支持”改为“支持”。其中 A5 实机设备为 Ascend950PR_9579,按本任务验收口径与资料项 Ascend 950DT等价,因此 A5 实测通过后资料状态更新为 支持 。


# 【资料变更】


只向 master 分支提交,修改以下七个版本目录中的 `torch-Tensor.md`,每份仅修改 `is_meta()` 条目的一行:


- `docs/zh/api/native_api/pytorch_2-7-1/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-9-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-10-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-11-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-12-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-13-0/torch-Tensor.md`
- `docs/zh/api/native_api/pytorch_2-14-0/torch-Tensor.md`


2.13.0 已在 HiDevLab A5 服务器上按原 Issue 的官方 CPU/Gloo 口径验证通过,因此同步更新其 `is_meta()` 支持标记。


# 【接口变更】


不涉及。仅修改文档,不新增 API 实现、测试代码或数据类型限制。


# 【功能验证】


2026-09-06 在 HiDevLab `Ascend950PR_9579` 服务器上,按原 Issue 的官方默认测试方式验证。测试框架实际使用 CPU/Gloo,未修改官方测试源码、未增加 NPU 专用断言;该用例不依赖 `torch-npu`。

2026-10-05:补充2.9.0、2.10.0、2.14.0用例验证


| PyTorch | 运行方式 | 结果 |
|---|---|---|
| 2.7.1+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 14.208s / OK,0 skipped,退出码 0 |
| 2.9.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 6.446s / OK,0 skipped,退出码 0 |
| 2.10.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 5.207s / OK,0 skipped,退出码 0 |
| 2.11.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 13.255s / OK,0 skipped,退出码 0 |
| 2.12.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 13.852s / OK,0 skipped,退出码 0 |
| 2.15.0.dev20260902+cpu(master) | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 13.856s / OK,0 skipped,退出码 0 |
| 2.13.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 11.204s / OK,0 skipped,退出码 0 |
| 2.14.0+cpu | 官方 `DTensorTest.test_meta_dtensor` | Ran 1 test in 5.729s / OK,0 skipped,退出码 0 |


2.13.0 的实际命令为:


```text
cd /workspace/task87_official_20260906
TORCH_DEVICE_BACKEND_AUTOLOAD=1 /workspace/venvs/v2130/bin/python sources/test_dtensor_v2130.py DTensorTest.test_meta_dtensor -v
```


官方用例覆盖 Meta Tensor/DTensor 的 `is_meta=True`、物化到默认测试设备后的 `is_meta=False`,以及 `Shard(0)` 和 `Replicate()` 两种 placement。这里的“A5 验证”是指用例运行在 A5 服务器上;测试仍按原 Issue 使用默认 CPU/Gloo,不表示用例在 NPU/HCCL 后端执行。


A5 服务器终端已保留七个版本的完整日志。**本次没有在 950DT 上单独实测,文档中的 950DT 支持标记仍提交给维护者评审。**


官方测试源码和完整日志保存在 A5 服务器,本 PR 未上传完整证据包。文档检查 `git diff --check` 通过,共七个文件、七处支持标记变更;当前分支已整理为一个提交。


# 【运行截图】


### PyTorch 2.7.1


![PyTorch 2.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
WSs_321 f922b03d58 新增A3 UT job
Co-authored-by: w30057661<wangshusheng7@h-partners.com>



# message auto-generated for no-merge-commit merge:
!47664 merge master_a3_ut into master

新增A3 UT job

Created-by: WSs_321
Commit-by: w30057661
Merged-by: ascend-robot
Description: ## 变更内容

`PR-pipeline_pytorch.yml`:为 v2.7.1 分支新增 `UT_A3_part_1` / `UT_A3_part_2` 两个 UT job(WORLD_SIZE=2、RANK 1/2),使用 A3 专用镜像 `pytorch_2.7.1_a3_aarch64_builder:20260804`,通过 `runs_on_device: "910C=1"` 调度到 910C 设备;`Detect_file_changes` 的 modify_files.txt 解析改用 JSON,修复文件名含空格/逗号时的解析问题。

`ut_job.yml`:新增 `runs_on_device` input 参数化 runs-on 设备标签(默认 `npu=1`,现有 job 行为不变);环境打印阶段补充 NPU SoC 信息。

`ut_job_distributed.yml` / `ut_job_inductor.yml`:环境打印阶段补充 NPU SoC 信息。

## 关联 issue

https://gitcode.com/Ascend/pytorch/issues/5330

See merge request: Ascend/pytorch!47664
2026-10-10 17:07:56 +08:00
ljfnjj1234567 26704f875d docs: Ascend 950DT support for torch.autograd.graph.Node.register_prehook
Co-authored-by: ljfnjj1234567<wn0010240@163.com>



# message auto-generated for no-merge-commit merge:
!45886 merge node-register-prehook-master into master

docs: Ascend 950DT support for torch.autograd.graph.Node.register_prehook

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

# 【合入来源】
关联issue: https://gitcode.com/Ascend/pytorch-ecosystem/issues/24

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

# 【修改方案】

`torch.autograd.graph.Node.register_prehook` 为设备无关的 autograd 图机制(纯 Python 抽象 + C++ autograd 引擎分发,与 register_hook 机制同构),A2/A3 已支持;Ascend 950DT 同享 autograd 引擎、实际已支持。原文档支持状态标注为「不支持」,与实际不符,本次按最新验收标准修正为「支持」。

# 【资料变更】

涉及。刷新 `torch-master/docs/zh/api/native_api/pytorch_2-{7-1,11-0,12-0,13-0}/torch-autograd.md`(资料补齐已转移至 master 分支;2-9-0/2-10-0 目录已删除,新增 2-13-0;同步最新文字格式 `- <term>...</term>:支持`)。4 个版本目录各含 2 处 `register_prehook()` 文档块(同属 `torch.autograd.graph.Node` 类),本次统一将产品支持情况中 `- <term>Ascend 950DT</term>:不支持` 改为 `- <term>Ascend 950DT</term>:支持`,共 8 处。register_hook 等其它方法未改动。

# 【接口变更】

不涉及(纯资料状态修正,无代码、无接口变更)。

# 【功能介绍】

`torch.autograd.graph.Node.register_prehook`:在 autograd 图节点上注册 backward pre-hook,节点梯度每次被计算前调用 `hook(grad_outputs)`,可返回新梯度替换 `grad_outputs`,返回 `RemovableHandle` 用于移除。与 `register_hook`(签名 `hook(grad_inputs, grad_outputs)`、替换 grad_inputs)机制同构,仅签名与替换目标不同。

# 【功能验证】

该 API 为纯 Python + autograd 引擎分发的设备无关机制,官方用例在官方环境原样运行通过(issue 已验证):

```
python -m pytest .../test_autograd.py -k "grad_fn_prehooks or prehook_ordering or accumulate_grad_posthooks_can_observe_tensor_prehook" -q
```

- v2.7.1:`5 passed, 695 deselected in 9.84s`
- v2.11.0:`5 passed, 730 deselected in 3.32s`
- v2.12.0:`5 passed, 739 deselected in 3.85s`
A5验证:
```
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# cd /workspace/user_data && /workspace/envs/torch-271/bin/python -m pytest /workspace/user_data/pytorch-2.7.1-up/test/test_autograd.py -k "grad_fn_prehooks or prehook_ordering or accumulate_grad_posthooks_can_observe_tensor_prehook" -q
Running 5 items in this shard
.....                                                                                                                              [100%]
5 passed, 632 deselected in 2.90s
((torch-npu-test) ) root@cfc8161f7c3d:/workspace/user_data# npu-smi info
+-------------------------------------------------------------------------------------------------+
| npu-smi 25.7.rc1.6                               Version: 25.7.rc1.6                            |
+--------+------------------+---------------+-----------------------------------------------------+
| NPU ID | Name             | Health        | Power(W)    Temp(C)           Hugepages-Usage(page) |
|        |                  | Bus-Id        | NPU Util(%) Memory-Usage(MB)  HBM-Usage(MB)         |
+========+==================+===============+=====================================================+
| 0      | Ascend950PR      | OK            | 208.5       62                0     / 0             |
|        |                  | 0000:55:00.0  | 0           0    / 0          5238  / 131072        |
+========+==================+===============+=====================================================+
+---------------------------+---------------+-----------------------------------------------------+
| NPU ID                    | Process id    | Process name             | Process memory(MB)       |
+===========================+===============+=====================================================+
| No running processes found in NPU 0                                                             |
+===========================+===============+=====================================================+
```
文档状态校验:4 个版本目录 `torch-autograd.md` 中 `register_prehook()` 块的 950DT 状态已全部由「不支持」改为「支持」。

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

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

See merge request: Ascend/pytorch!45886
2026-10-10 16:47:10 +08:00
zhangjiahao-2026 d8fa00afa6 docs: mark torch.ShortStorage as supported on Ascend 950DT
Co-authored-by: zhangjiahao-2026<2332445379@qq.com>



# message auto-generated for no-merge-commit merge:
!46018 merge docs-issue-3861-shortstorage-950dt into master

docs: mark torch.ShortStorage as supported on Ascend 950DT

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

关联任务issue: <https://gitcode.com/Ascend/pytorch/issues/3861>

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

# 【修改方案】

在 master 资料中更新公开非计算类 API `torch.ShortStorage` 的 Ascend 950DT 支持情况。

修改文件:

* docs/zh/api/native_api/pytorch_2-7-1/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-9-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-10-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-11-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-12-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-13-0/torch-Storage.md
* docs/zh/api/native_api/pytorch_2-14-0/torch-Storage.md

具体修改内容:

1. 在 PyTorch 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0、2.13.0 和 2.14.0 资料中,将 torch.ShortStorage 在 Ascend 950DT 系列产品上的支持状态由“不支持”修改为“支持”。
2. Atlas A2 训练系列产品、Atlas A3 训练系列产品保持「支持」不变;
3. 该 API 为非计算类接口,与具体数据类型无关,不填写数据类型限制;
4. 不新增 A5 / 950PR 产品字段,资料产品维度仍为 A2 / A3 / 950DT;

本 PR 仅修改目标 API 的 950DT 支持标记,不批量修改同一文件中其他历史 API 的资料内容。

# 【资料变更】

资料检查结果:master 下的原生 API 资料已收录 `torch.ShortStorage`,Atlas A2、Atlas A3 标记为支持,Ascend 950DT 原标记为不支持。

本次已补充 A5(Ascend950PR)实机验证并通过,因此将以下版本目录 `torch-Storage.md` 中 `torch.ShortStorage` 的 Ascend 950DT 更新为支持:

* PyTorch 2.7.1
* PyTorch 2.9.0
* PyTorch 2.10.0
* PyTorch 2.11.0
* PyTorch 2.12.0
* PyTorch 2.13.0
* PyTorch 2.14.0

该 API 为公开非计算类接口,与张量数据类型无关,不填写数据类型限制。

# 【接口变更】

不涉及

# 【功能验证】

`torch.ShortStorage` 是 PyTorch Legacy TypedStorage 类型之一,用于保存 16 位有符号整数数据,元素类型对应 `torch.int16`。

PyTorch 官方社区在以下用例中已有相关验证:

```text
test/test_torch.py::test_storage_setitem
test/test_torch.py::test_tensor_storage_type
test/test_torch.py::test_element_size
test/test_torch.py::test_from_buffer
test/test_torch.py::test_storage_error
test/test_torch.py::test_storage_casts
```

`torch.ShortStorage` 对应的 NPU Storage 类型为 `torch_npu.npu.ShortStorage`。现有 `test/test_torch.py` 已完成 NPU Storage 类型映射适配,不需要修改 Torch-NPU 功能实现,也不需要新增测试文件或 `test_upstream` patch。

API 功能、社区用例情况、NPU 适配分析和各版本验证结果见说明 Issue:

<https://gitcode.com/Ascend/pytorch/issues/3861>

A5 硬件验证信息如下。

验证设备:

![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
rmch 3e0639707b feat(inductor): add TE ComboKernel support
Co-authored-by: rmch<chenruimin2@huawei.com>



# message auto-generated for no-merge-commit merge:
!47085 merge te-combo-kernel into master

feat(inductor): add TE ComboKernel support

Created-by: rmch
Commit-by: rmch
Merged-by: ascend-robot
Description: ## 变更摘要

完成 TE 后端 ComboKernel 适配第 5-9 步,将满足约束的多个 Triton Experimental pointwise kernel 合并为一次 TEComboKernel 调用,减少 kernel launch 次数并保持不满足条件时的原有 fallback 行为。

### 主要改动

- 新增 `TEComboKernel` 和 `TEComboSubKernel` codegen,共享 `XBLOCK=256`,按成员 kernel 的 block 数和前缀和执行分组 dispatch。
- 增加 `te_combo_meta` 元数据和 launcher grid 处理,支持一次 launch 内按 combo slot 分发成员 kernel。
- 增加 TE 专用准入检查:当前阶段仅合并静态、连续、同 shape、同 dtype、pointwise-only 的 kernel;不满足条件时回退到普通 kernel。
- 修复 combo fallback 生命周期,保留独立 fallback kernel 仍需要的 buffer,待所有 combo source 生成和注册成功后再提交 `mark_run`、buffer removal 等状态更新。
- 为 combo 成员变量和共享 tile constexpr 名称增加 slot 后缀,避免多个成员之间发生命名冲突。
- 保持 ComboKernel 与现有 `foreach`/Triton Experimental 调度路径兼容,并补充配置开关。

## 测试

- ComboKernel 定向测试:`4 passed`
- TE Triton Experimental 完整测试目录:`39 passed`
- 变更 Python 文件 `py_compile` 通过
- `git diff --check` 通过
- Ascend 910B3 数值验证通过:1024、10001、0、1、255、256、257 元素场景;combo disabled 和混合 dtype fallback 场景均正确。

## 当前边界

- 当前 phase-one 仅覆盖静态 contiguous、同 shape、同 dtype 的 pointwise kernel。
- 动态 shape、不同 dtype/shape、非 pointwise 操作和不满足 ABI/资源约束的场景继续使用普通 kernel 或显式 fallback。

**关联 issue:**
Fixes https://gitcode.com/Ascend/pytorch/issues/5093

**RFC设计文档:**
https://gitcode.com/Ascend/pytorch/issues/5325


See merge request: Ascend/pytorch!47085
2026-10-10 15:45:27 +08:00
c_34 472321bf2e fxrt: port upstream runtime changes made since the in-tree integration
Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com>



# message auto-generated for no-merge-commit merge:
!47662 merge fxrt-port-squash into master

fxrt: port upstream runtime changes made since the in-tree integration

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

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

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

同步进行in-tree合入过程中修改的原始仓库内容。

## 背景

fxrt 整改合入 master 之后,上游(pta 分支)又积累了一批运行时改动。本 PR 把这些改动移植进 in-tree 的 `torch_npu.fxrt`,使两边重新对齐。

**`e64806be`** (08-31) 按生成时的 stride 寻址 compiled-kernel 参数
融合后端是针对参数在 trace 时的 stride 生成 kernel 的。记录这些 layout 并在调用前恢复,使期间被重新 layout 的参数仍按 kernel 预期的方式寻址。
→ `compiled_kernel_adapter.py`、`fx_backend.py`

**`81a537aa`** (09-02) DVM op
通过 pybind 头文件已授予 `fxrt::ops::OpDvmCallV2` 的 friendship 访问 torch_npu 的 DVM kernel 状态,而不是它从未存在过的公有 accessor;helper 折进 op 类以使 friendship 生效。动态与静态 kernel 合并为一个入口,由 kernel 的 `F_DYN` 标志区分。附带效果见下方「需要注意」。
→ `src/ops/ascend/dvm/`、`dvm_adapter.py`

**`ad4c84cc`** (09-02) AutoFuse
新增 `autofuse_call` op:dlopen AutoFuse codegen 产出的 wrapper stub 并直接 launch,外加生成该 stub 的 Python codegen。下降位置在 DVM 与通用 compiled-kernel 路径之间,由 `FXRT_AUTOFUSE_NATIVE=1` 门控。算子注册无需登记表,`LoadOpLib` 按 `libops_ascend*` 前缀发现。
→ `src/ops/ascend/autofuse/`、`autofuse_codegen.py`、`ops.list`

**`bbf45634`** (09-07) custom / torch / python call 的 ref、view 零拷贝
仅重新解释输入 storage 的输出不再拷贝。`OpRunner` 里通用的 ref 元数据同步会跳过输出 shape 与输入不同的算子,因此 view 类自定义算子自行计算元数据;`AclnnCustomViewOperator` 是它们的新基类,经 custom op API 暴露。
→ `op_custom_call`、`op_torch_call`、`op_python_call`、`aclnn_custom_view_operator.h`、`data_convert`

**`0ae75226`** (09-12) FXRT 自定义集合通信
用 arg-mapping hook 把 vLLM 四参数的 all_gather ABI 适配到 FXRT 原生三参数 HCCL ABI;从 FX 图收集通信信息时,把 vLLM 的逻辑 group 名解析为对应的 torch device ProcessGroup。
→ `fx_backend.py`、`utils.py`

**`c7e3a2e0`** (09-12) FX 操作数分类,自定义调用加固
一个 FX 参数能否走标量算子 ABI,改由 FXRT 运行时实际可表示的值决定,而不是看 node target —— `item` 节点不再仅凭名字就被当成标量。自定义调用侧在转换前校验操作数种类,并报出出错的那一个,而不是在转换深处失败。
→ `fx_backend.py`、`symbolic_shape.py`、`op_torch_call`、`data_convert`

**`37fcc1bb`** (09-22) 修复多输出 ref 算子的输出数据校验
ref alias 输出与输入共享 storage,且两侧都不持有 deleter,清掉共享的 data pointer 会让第一个之后的每个输出都校验失败。改为读取 storage 地址而不取走它,仅在持有所有权的路径上移出 data pointer。影响 split、unbind、chunk。
→ `op_torch_call.cpp`

**`6051b291`** (09-22) `Tensor[]` 自定义调用输出保留 ref alias
返回 `Tensor[]` 的自定义调用丢失了单 Tensor 输出能保留的 ref aliasing,导致列表里每个元素各自声明 storage。让 alias 穿过列表输出,并把 `c7e3a2e0` 引入的操作数预校验换成转换点上的检查。
→ `fx_backend.py`、`op_torch_call`、`data_convert`

## 内容

建议按三组顺序审阅:

1. **compiled-kernel 路径**(`compiled_kernel_adapter.py`、`fx_backend.py`、`autofuse_codegen.py`、`src/ops/ascend/autofuse/`)——按 inductor 生成的 stride 寻址 kernel 参数而不再假定连续;FX 操作数分类,标量不再走张量路径;新增 `OP(autofuse_call)` 与 `FXRT_AUTOFUSE_NATIVE` 门控的原生 AutoFuse 下降。vLLM 集合通信 hook 在同一路径上,自成一体。
2. **零拷贝 view**(`op_custom_call`、`op_torch_call`、`op_python_call`、`aclnn_custom_view_operator.h`)——改为交出 ref 输出而非拷贝,`data_convert` 删掉只为喂拷贝而存在的转换。多输出校验修复与 `Tensor[]` alias 修复是对同一段代码的纠正。
3. **DVM v2**(`src/ops/ascend/dvm/`)——CMake 探测改为匹配 `torch_npu/csrc/inductor/dvm/pybind_api.h` 实际携带的 friend 声明,并通过该 friendship 访问 kernel 私有成员。

## 需要 reviewer 注意

**两处对上游的有意偏离,均在 CMake**:autofuse 的 `CMakeLists.txt` 采用 in-tree 同级算子模块的写法,而非上游的 glob + 自带 `install()` 形式(上游还链接了 in-tree 不存在的 `fxrt::securec`);`ops_ascend_autofuse` 加入 `FXRT_OP_LIBS` 与 `install_fxrt` 拷贝列表,使 wheel 携带该库。

**一处告警屏蔽**: 为了处理autofuse的自动生成算子函数签名,实现中使用了一个长f-string字符串进行代码生成,这个长字符串触发了超长行的告警,参考之前cpp_wapper中类似情况的处理方式增加的`.flak8`的告警屏蔽。

## 验证

Ascend 910B3 实测:

- `test/fxrt` 7 项全部通过
- `libops_ascend_autofuse.so` / `libops_ascend_dvm_v2.so` 均构建产出、随 wheel 安装,运行时经 `/proc/self/maps` 确认已 dlopen
- ref/view 定向用例 10/10 与 eager 一致:split(均分/不均分)、unbind、chunk、`split->add`、broadcast_tensors、select/permute、flatten/reshape、`item()` 标量、标量乘
- AutoFuse 门控双向验证:默认关闭与 `FXRT_AUTOFUSE_NATIVE=1` 结果均正确
- eta 推荐模型(inductor + fx_wrapper -> fxrt 运行时,batch 128)精度校验通过,QPS 8929;IR dump 显示 146 个 `compiled_kernel_mutation`,即本 PR 的 stride 与操作数分类改动在真实负载下被覆盖

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

不涉及

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

不涉及


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

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


See merge request: Ascend/pytorch!47662
2026-10-10 15:03:20 +08:00
hbhu_bin 2d91fb5660 fix lazy_fusion dump and enable
Co-authored-by: hb_hubin<hubin79@huawei.com>



# message auto-generated for no-merge-commit merge:
!47177 merge dvm-master-latest into master

fix lazy_fusion dump and enable

Created-by: hbhu_bin
Commit-by: hb_hubin
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
https://gitcode.com/Ascend/pytorch/issues/2264
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

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

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


 无图融合问题修复

 ###  1. 缺少脚本侧的融合范围控制
 
  TORCH_NPU_LAZY_FUSION 控制进程级融合行为,用户无法方便地将局部代码排除在融合范围之外。

  ### 2. dump 缺少灵活的区间控制
  
全程 dump 文件量较大,不便于只采集某个 step 或代码区间。

  ### 3. output 分配可能重入 flush
  
融合算子已构建 DVM 节点、但尚未分配和登记 output 时,内存分配可能触发回收或重试,并通过同步路径重入 flush。此时半构建图可能被提前提交、清理或回收,后续继续使用旧节点存在图状态失效风险。

  ### 4. 部分写入路径缺少输出约束检查
  
inplace 广播结果不能扩大目标张量;gelu_out、where_out 的输出参数也需要满足融合写入条件,不能直接按普通新分配输出处理。

  ## 解决方法

### 1. 新增脚本侧融合控制接口

  新增 torch_npu.npu.lazy_fusion 模块,支持按代码区间控制融合:

  ```
from torch_npu.npu import lazy_fusion

  with lazy_fusion.disabled():
      output = model_part(input)
```

  支持通过嵌套 lazy_fusion.enabled() 在局部重新开启融合。切换状态时提交当前待融合图,避免跨区间融合;正常退出或区间内异常退出时恢复之前的状态。

  环境变量仍作为总开关,Python 接口不能绕过未开启的环境变量。C++ 绑定独立于 Inductor。

  ### 2. 支持按区间控制 dump

  提供 set_dump_enabled() 和 dump_enabled():

```
  lazy_fusion.set_dump_enabled(False)

  for step, batch in enumerate(data):
      with lazy_fusion.dump_enabled(step == 1):
          output = model(batch)
```

  环境变量仍是 dump 总开关;仅开启环境变量、不调用 Python 接口时,保持原有全程 dump 行为。

### 3. 保护 output 分配期间的图状态

  在 output 分配及登记期间增加 RAII 保护:

  - 分配期间重入 flush 时,暂不提交当前半构建图。
  - 不改变此前已提交任务的正常排空流程。
  - 分配完成后检查图标识及当前图状态,避免继续使用失效节点。

  ### 4. 不满足写入条件时回退 eager

  - 对相关 inplace 和 foreach addc 系列增加轻量广播检查,避免广播结果扩大目标张量。
  - 对 gelu_out、where_out 增加输出 shape/dtype 检查。
  - 不满足条件时交由 eager 路径处理,不修改算子计算公式。

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

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

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

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

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


See merge request: Ascend/pytorch!47177
2026-10-10 11:07:11 +08:00
baoxuebin_2026 1b30f7422c test: add utils api npu coverage
Co-authored-by: baoxuebin_2026<xuebin@isrc.iscas.ac.cn>



# message auto-generated for no-merge-commit merge:
!44624 merge codex/utils-api-consistency-master into master

test: add utils api npu coverage

Created-by: baoxuebin_2026
Commit-by: baoxuebin_2026
Merged-by: ascend-robot
Description: # 【合入来源】
[#150](https://gitcode.com/Ascend/pytorch-ecosystem/issues/150)
[#137](https://gitcode.com/Ascend/pytorch-ecosystem/issues/137)
[#100](https://gitcode.com/Ascend/pytorch-ecosystem/issues/100)

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

公开issue:
- `torch.utils.checkpoint.set_device_states`:
  https://gitcode.com/Ascend/pytorch-ecosystem/issues/150
- `torch.utils._foreach_utils._has_foreach_support`:
  https://gitcode.com/Ascend/pytorch-ecosystem/issues/137
- `torch.utils.module_tracker.ModuleTracker`:
  https://gitcode.com/Ascend/pytorch-ecosystem/issues/100

# 【修改方案】
1. API 功能说明:
   - `torch.utils.checkpoint.set_device_states`:为指定设备恢复随机数生成器状态,用于 checkpoint 重计算等场景保持随机数状态一致。
   - `torch.utils._foreach_utils._has_foreach_support`:判断给定设备和张量列表是否满足 foreach 快路径的使用条件。
   - `torch.utils.module_tracker.ModuleTracker`:上下文管理器,用于跟踪模块前向和反向执行期间的模块层级。

2. 上游用例检查情况:
   - `torch.utils.checkpoint.set_device_states` 涉及设备 RNG 状态。PyTorch 社区主要通过 checkpoint RNG 场景间接覆盖,未提供直接 NPU 用例,因此在 `test` 目录补充最小 NPU 验证。
   - `torch.utils._foreach_utils._has_foreach_support` 用于判断设备是否支持 foreach 快路径,直接涉及 NPU 后端能力。PyTorch 社区未提供面向 NPU 的直接验证,因此在 `test` 目录补充最小 NPU 验证。
   - `torch.utils.module_tracker.ModuleTracker` 为纯 Python 接口。PyTorch 社区已有独立、完整用例,覆盖模块层级、前向、反向和 checkpoint 场景,因此不新增 NPU 用例。

3. 新增用例文件:
   - `test/test_utils_checkpoint_api.py`
   - `test/test_utils_api.py`

4. 新增用例覆盖场景:
   - `set_device_states` 显式传入 `device_type="npu"`,恢复 NPU RNG 状态并验证随机序列一致。
   - `set_device_states` 省略可选参数 `device_type`,验证 Torch-NPU 默认设备类型路径。
   - `_has_foreach_support` 验证 NPU 张量及 `None` 组成的列表支持 foreach 快路径。
   - `_has_foreach_support` 验证混入非 Tensor 对象时返回不支持。

5. NPU 适配说明:
   - 新增张量均通过 `torch.accelerator.current_accelerator()` 获取当前 NPU 设备。
   - 未修改 `test_upstream/`,未新增 NPU 适配 patch。
   - 未修改 Torch-NPU API 实现。

6. 新增或修改的测试文件头部已包含 Huawei copyright 和 API 功能说明。

# 【资料变更】
不涉及。资料补齐已单独提交文档 PR。

# 【接口变更】
不涉及。未修改跨仓接口,也未修改用户可见接口行为。

# 【功能验证】
测试环境:
```text
NPU: Ascend 910B2C
torch: 2.13.0
torch_npu: 2.13.0
CANN: 8.5.1
```
测试命令:

source /usr/local/Ascend/cann-8.5.1/set_env.sh

TORCH_DEVICE_BACKEND_AUTOLOAD=1 \
/usr/local/python3.11.14/bin/python test/test_utils_checkpoint_api.py -v

TORCH_DEVICE_BACKEND_AUTOLOAD=1 \
/usr/local/python3.11.14/bin/python test/test_utils_api.py -v


板端核心验证结果:

PASS test_set_device_states_restores_npu_rng_sequence
PASS set_device_states default device_type
PASS test_has_foreach_support_for_npu_tensors
PASS ModuleTracker NPU forward and backward validation

See merge request: Ascend/pytorch!44624
2026-10-10 10:21:35 +08:00
rain-666 04a516d92e transfer_to_npu适配213UT用例
Co-authored-by: rain-666<chenxiaoyu12@huawei.com>



# message auto-generated for no-merge-commit merge:
!47384 merge master_213ut_0929 into master

transfer_to_npu适配213UT用例

Created-by: rain-666
Commit-by: rain-666
Merged-by: ascend-robot
Description: - `_patch_has_triton` :委托`torch_npu.utils._dynamo.has_triton` ,而不是硬编码 False —— 让原版 CUDA 代码里的`has_triton()` 门控在 NPU 上自然成立
- `_get_npu_type` 加`@functools.lru_cache` —— 保持`torch_npu inductor patch_is_gpu` 的`cache_clear()` 契约,绕过 upstream`len(avail_gpus) <= 1` 断言
- `_patch_triton_nvidia_driver` —— 在 NPU 机器上强制`CudaDriver.is_active=False` ,避免 triton nvidia/ascend 双驱动冲突

See merge request: Ascend/pytorch!47384
2026-10-10 09:28:27 +08:00
shi-yufeng99 4f8b463cff fix addmm cored dumped problem
Co-authored-by: shi-bibibi99<shiyufeng8@huawei.com>



# message auto-generated for no-merge-commit merge:
!47655 merge 1009_master_catlass_branch1 into master

fix addmm cored dumped problem

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

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

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

# 【修改方案】
[#3463](https://gitcode.com/Ascend/pytorch/issues/3463) 
fix addmm core dumped error in fast_fusion part

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

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

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

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

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


See merge request: Ascend/pytorch!47655
2026-10-10 00:20:06 +08:00
pta-robot 06e2cb7a39 Update op_plugin commit id
Co-authored-by: pta-robot<pta_robot@163.com>



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

Update op_plugin commit id

Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-09 22:03:50.

See merge request: Ascend/pytorch!47646
2026-10-09 23:01:26 +08:00
stonexxx 95c7e46542 fix(inductor): 适配 NPU selector 的 best_config_future 参数
Co-authored-by: Stonexx<sheny1xuan@163.com>



# message auto-generated for no-merge-commit merge:
!47604 merge select_fix into master

fix(inductor): 适配 NPU selector 的 best_config_future 参数

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

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

Fixes https://gitcode.com/Ascend/pytorch/issues/5312

# 【修改方案】

1. 在 `torch_npu/_inductor/select_algorithm.py` 的 NPU `AlgorithmSelectorCache.__call__` 补丁中对齐上游可选参数,支持 `best_config_future`,避免 GEMM lowering 传入该关键字时发生参数不兼容。
2. 等待并复用 future 返回的配置,筛选匹配候选,将筛选后的 choices 用于 cache lookup 和反馈。
3. 移除“首个 choice 不在 timings 即回退”的判断,从有效 timings 中选择最快候选,正确处理 future 筛掉首个候选的场景。
4. 保留已有 timeout、多模板及 defer 行为。`is_collective`、`min_speedup_threshold` 和 `benchmark_with_cudagraphs` 本次仅兼容签名,并标注 `Not supported on NPU`。

# 【资料变更】

不涉及。

# 【接口变更】

内部跨仓兼容适配:NPU selector 补丁签名与上游 PyTorch Inductor 的可选参数对齐。现有参数默认值不变,对外公开 API 无新增。

# 【功能验证】

提交:`73479a8a7dc7075c8828b57dc211b1554aabe70f`。

通过历史回归脚本(`c47dc0180e`)临时隔离加载当前 selector,验证签名及默认值、future 候选筛选、首个候选无 timing 时的最优选择,3 项测试全部通过。本分支未新增测试文件。

实际执行命令:

```bash
python3 /tmp/select-fix-pr-9gxtvfj4/validate_selector.py
python3 -m py_compile torch_npu/_inductor/select_algorithm.py
lintrunner -a torch_npu/_inductor/select_algorithm.py
git diff --check refs/remotes/mainline/master...select_fix
git merge-tree --write-tree refs/remotes/mainline/master select_fix
```

语法、lint 和 diff 检查通过,与目标 master 合并无冲突。验证范围为 Python 逻辑;本机缺少 `torch_npu._C`,NPU 真机验证、远端 CI 及自验证截图尚未提供。

# 【CheckList】

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


See merge request: Ascend/pytorch!47604
2026-10-09 17:45:09 +08:00
c_34 340048c6ea fxrt: drop CPU op implementations in favour of the PyTorch fallback
Co-authored-by: chenhaozhe<chenhaozhe1@huawei.com>



# message auto-generated for no-merge-commit merge:
!47567 merge fxrt-cpu-ops-removal into master

fxrt: drop CPU op implementations in favour of the PyTorch fallback

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

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

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

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

torch_npu中主要提供npu上的支持和实现,原有的部分cpu算子功能属于冗余能力,移除。

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

不涉及

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

不涉及

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

测试用例验证

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

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


See merge request: Ascend/pytorch!47567
2026-10-09 17:15:51 +08:00
y30037164 315edb17b9 nightly流水线换用新镜像,无卡编译不进行import torch之类验证
Co-authored-by: yuaiming<yuaiming@h-partners.com>



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

nightly流水线换用新镜像,无卡编译不进行import torch之类验证

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

# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012

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

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

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

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

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

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

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


See merge request: Ascend/pytorch!47619
2026-10-09 17:10:57 +08:00
wzyly e8277e454d modify document
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com>



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

modify document

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

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

- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新

# 【修改方案】
测试环境检视问题修改

# 【资料变更】
涉及

# 【接口变更】
不涉及

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

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

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


See merge request: Ascend/pytorch!47614
2026-10-09 17:10:52 +08:00
JfanLiu 8f91f498ea test: add NPU coverage for torch.testing._internal.common_utils.skipIfRocm
Co-authored-by: JfanLiu<1300083451@qq.com>



# message auto-generated for no-merge-commit merge:
!46599 merge test-skip-if-rocm-master into master

test: add NPU coverage for torch.testing._internal.common_utils.skipIfRocm

Created-by: JfanLiu
Commit-by: JfanLiu
Merged-by: ascend-robot
Description: # 【合入来源】
> 社区 issue:[Ascend/pytorch #4116](https://gitcode.com/Ascend/pytorch/issues/4116)(原 [Ascend/pytorch #3704](https://gitcode.com/Ascend/pytorch/issues/3704))

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

# 【修改方案】
按 #4116 审核结论(该 API 对硬件后端有依赖、上游用例不完整,需新增测试用例文件补齐测试场景),新增 `test/test_skip_if_rocm.py`(仅新增测试,不改动任何实现代码):

- 覆盖 `torch.testing._internal.common_utils.skipIfRocm` 的两种用法:裸装饰器 `@skipIfRocm` 与带参 `@skipIfRocm(msg=...)`;
- 运行路径:NPU 非 ROCm 构建,被装饰的用例正常执行,且不带 `__unittest_skip__` 标记;
- 跳过路径:`TEST_WITH_ROCM` 为真时,被装饰用例被 unittest runner 上报为 skipped,reason 为 `skipIfRocm: <msg>`(默认 msg 与自定义 msg 各覆盖一次);
- 装饰动作在 `mock.patch(...TEST_WITH_ROCM..., True)` 上下文内完成,保证跳过路径判定时机正确;同时兼容各版本实现差异(2.7.1 / 2.11.0 / 2.12.0 在调用期抛 `SkipTest`,2.13 起类目标在装饰期打 `__unittest_skip__` 标记)。

# 【测试方案】
- NPU 实跑:`python test/run_test.py test_skip_if_rocm -v`,6 个用例应全部通过;
- 覆盖 v2.7.1 / v2.11.0 / v2.12.0 / master 四个版本组合,实跑日志随后以评论附上;
- 用例仅使用 `torch.randn` / `torch.add` 与 unittest 断言,不引入新的算子或大负载。


See merge request: Ascend/pytorch!46599
2026-10-09 16:49:55 +08:00
y30037164 af440d9047 nightly build 移除镜像预装 torch 版本探测 (arm 无卡编译机 import 段错误)
Co-authored-by: yuaiming<yuaiming@h-partners.com>



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

nightly build 移除镜像预装 torch 版本探测 (arm 无卡编译机 import 段错误)

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

# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012

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

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

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

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

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

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

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


See merge request: Ascend/pytorch!47596
2026-10-09 14:50:18 +08:00
hbhu_bin abac7268f2 fix flex_attention
Co-authored-by: hb_hubin<hubin79@huawei.com>



# message auto-generated for no-merge-commit merge:
!47482 merge fix-flex-attention into master

fix flex_attention

Created-by: hbhu_bin
Commit-by: hb_hubin
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->
https://gitcode.com/Ascend/pytorch/issues/5293
# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

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

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

修复图模式DVM后端复用FlexAttention triton自定义算子的问题,适配mask_mod/score_mod

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

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

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

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

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


See merge request: Ascend/pytorch!47482
2026-10-09 14:35:52 +08:00
crazyDannyBoy 4370a2cf91 fix(inductor): stop dynamic reduction split only when low dims remain
Co-authored-by: crazyDannyBoy<xudezheng1@huawei.com>



# message auto-generated for no-merge-commit merge:
!47553 merge fix/dynamic-split-low-dim-master into master

fix(inductor): stop dynamic reduction split only when low dims remain

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

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

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

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

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

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

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

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

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


See merge request: Ascend/pytorch!47553
2026-10-09 11:17:45 +08:00
li_jing_hw e75e3d4285 Refactor compat impl for strong validation instead of comment
Co-authored-by: li_jing_hw<lijing202@huawei.com>



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

Refactor compat impl for strong validation instead of comment

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

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


- [x] 重构优化https://gitcode.com/Ascend/pytorch/issues/4978

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

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

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

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

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

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


See merge request: Ascend/pytorch!46750
2026-10-09 10:56:11 +08:00
wzyly 6f46a91484 modify document
Co-authored-by: m0_68000167<wangzhiyuan86@h-partners.com>



# message auto-generated for no-merge-commit merge:
!47568 merge cherry-pick-mr-47565-1791451169327-auto into master

modify document

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

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

- [ ] 需求
- [ ] 问题单
- [x] issue/工单https://gitcode.com/Ascend/op-plugin/issues/320
- [ ] 重构优化
- [x] 资料更新

# 【修改方案】
测试环境检视问题修改

# 【资料变更】
涉及

# 【接口变更】
不涉及

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

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

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


See merge request: Ascend/pytorch!47568
2026-10-09 09:56:46 +08:00
SorryNaCN 3cd2d928ac [perf] [master] Optimize DVM GroupNorm, matmul, allocation and optional permute lowering
Co-authored-by: huangchengnuo<huangchengnuo1@huawei.com>



# message auto-generated for no-merge-commit merge:
!47449 merge perf/dvm-groupnorm-matmul-fold-20260930 into master

[perf] [master] Optimize DVM GroupNorm, matmul, allocation and optional permute lowering

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

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

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

DVM 性能优化,合入目标为 `master`。关联社区 Issue:[[perf] DVM GroupNorm、matmul、内存分配与可选 permute lowering 优化](https://gitcode.com/Ascend/pytorch/issues/5282)。

Fixes https://gitcode.com/Ascend/pytorch/issues/5282

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

本 PR 涉及 `torch_npu/_inductor/dvm/` 的 `config.py`、`decomp.py`、`mlir_fusion.py` 和新增的 `wrapper.py`。

1. **GroupNorm 分解**:从 DVM 分解排除列表移除 `aten.native_group_norm`,默认展开其计算,使 Inductor / DVM 可以继续进行融合。
2. **Matmul folding**:在 `patch_decomp()` 初始化阶段复用 `_override_matmul_should_fold_for_npu()`,将适用的 3D×2D matmul 转为 MM,减少权重广播和 BMM 开销。
3. **快速分配**:新增 `NpuDvmWrapperCodeGen`,继承 `NpuMlirWrapperCodeGen` 并在 DVM 后端注册中使用。普通 NPU 分配直接复用 Triton-ex 的 `NPUWrapperCodeGen.make_allocation`,生成 `_empty_strided_npu` 调用;非 NPU 分配、内存生命周期跟踪和 pinned 分配沿用父类路径,子图沿用父类创建路径。
4. **可选 permute lowering**:将 `aten.permute` 固定放入生成白名单,新增默认关闭的 `enable_fusion_permute`,参照 `enable_cat` 控制 DVM 融合规则。开启后可生成 `reinterpret_tensor` 视图。

**详细设计:组件关系与执行顺序**

- 分解链路:DVM 初始化 → `patch_decomp()` → 复用 NPU matmul folding 覆盖并更新分解配置 → Inductor 分解和调度 → DVM 融合与代码生成。
- 分配链路:DVM 后端注册 → `NpuDvmWrapperCodeGen` → 分配条件判断 → 复用 Triton-ex 快速分配或调用父类分配逻辑。类关系为 `NpuDvmWrapperCodeGen` 继承 `NpuMlirWrapperCodeGen`,按条件复用 `NPUWrapperCodeGen.make_allocation`。
- Permute 链路:`GENERATE_LIST` 注册 `aten.permute` → 融合规则读取 `enable_fusion_permute` → 开启时允许进入 DVM lowering,关闭时由规则拒绝 DVM 融合。
- 调试与兼容性:保留原有内存生命周期跟踪路径;permute 默认关闭,可通过开关对照验证。沿用现有调试能力,不新增日志或错误码。

Triton-ex 文件及 `_generate_extern_kernel_alloc_helper` 不在本 PR 修改范围。

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

不涉及独立资料文件变更。设计说明及新增配置的用法在本 PR 的【修改方案】和【接口变更】中给出。

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

新增 DVM 配置 `torch_npu._inductor.dvm.config.enable_fusion_permute`,类型为 `bool`,默认值为 `False`。在 DVM 后端加载前设置为 `True` 可开启 permute 融合;保持 `False` 时禁用该融合规则。

跨组件复用现有 `_override_matmul_should_fold_for_npu` 和 `NPUWrapperCodeGen.make_allocation`,其接口签名不变。未新增公开算子或 C++ 接口。

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

以下为原 PR 已记录的验证结果,本次仅整理描述,未重新运行测试。

**测试环境与方法**

- Ascend910B3 / CANN 9.2.0.beta.2 / PyTorch 2.13,基于 PR !47318 构建并应用对应改动。
- 对比优化前后全网 E2E 和设备时间;耗时单位均为 ms/次。严格精度阈值为 `rtol=atol=1e-4`。
- 快速分配对照复用前后的分配代码生成结果;permute 对照开关启停的 NPU 执行结果及生成代码,并验证动态形状和视图属性。

| 场景 | 验证结果 |
| --- | --- |
| GroupNorm:functorch_dp_cifar10 / opacus_cifar10 | 设备时间分别降至 2.60 / 2.63;单算子精度通过,**全网严格精度仍未通过**。 |
| Matmul:CLIP | E2E 30.41 → 23.58,设备时间 29.69 → 21.29;严格精度通过。 |
| 快速分配 | 复用前后 144 组分配代码生成结果一致。 |
| Permute 开关 | 开启、关闭各 5 项 NPU 用例通过;开启组生成代码中独立 `aten.permute` 调用为 0。 |
| Permute 视图 | 开启后的 8 项动态形状、dtype、stride、offset、别名等视图用例通过。 |
| 静态检查 | Python 语法检查和 `git diff --check` 通过。 |

**验证范围与待补充项**

- 快速分配及新 permute 开关尚未测量独立全网性能收益。
- 本 PR 未新增或修改仓库 UT 文件;上述定向自验证用例的执行结果已记录,UT 看护及自验证截图待补充。
- 当前提交 `3e76f0ecf45429273b2a20a2fc7c2a1b9898c6f2` 的流水线 `PR-pipeline_pytorch#71518` 已通过,代码检查无异常;流水线结果不代表上述 GroupNorm 全网严格精度问题已解决。

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

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

自检依据:新增配置已有注释,分配与融合路径包含相应条件判断;空指针及新增错误日志不涉及。标题使用 `[perf]` 类型标签;当前提交的 CI 和代码检查已通过。


See merge request: Ascend/pytorch!47449
2026-10-09 09:55:42 +08:00
chenrayray 67b12e96a6 docs: [master] 补齐原生 API 硬件说明的 NPU 标签
Co-authored-by: Xinrui Chen<chenxinrui11@huawei.com>



# message auto-generated for no-merge-commit merge:
!47559 merge codex/fix-native-api-npu-tags-master into master

docs: [master] 补齐原生 API 硬件说明的 NPU 标签

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

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

关联 Issue:https://gitcode.com/Ascend/pytorch/issues/5276

# 【修改方案】

补齐 `master` 原生 API 文档中 152 行硬件专属说明的 NPU 标签,并将确定性计算文档的两个标签范围扩展至完整硬件专属 API 表格,确保按硬件筛选时说明随对应产品显示。

1. 为遗漏的 A2、A3、950DT 产品支持条目分别补充 `910b`、`A3`、`950` 标签,新增 ID 避开文档已有 ID。
2. 为所有版本目录中的 MemPool 950DT 分配器限制补充 `950` 标签;将 Adam 的限制改为“<term>Atlas A2训练系列产品</term>和<term>Atlas A3训练系列产品</term>暂不支持将`fused`设置为`True`。”,使用 `910b,A3` 标签,使 A2/A3 筛选时显示不支持提示,950DT(A5)筛选时不显示此提示。
3. 将 private_apis.md 的全部表格转换为 37 个独立 API 条目,按原生 API 文档形式展示产品支持情况、限制与说明及 NPU 形式名称。分别以独立行标签包裹 A2、A3、950DT 支持条目,保留原表中 18 个 API 暂不支持 950DT 的信息;全部 NPU 起止标签独占一行。
4. 将确定性计算文档的结束标签移动至对应表格之后,覆盖表题、表头及全部 API 行。

# 【资料变更】

修改 `docs/zh/api/native_api/` 下 37 个 Markdown 文件,补齐硬件条件注释并将私有 API 表格转换为逐项文档形式,沿用目标分支现有硬件标识。

# 【接口变更】

不涉及。

# 【功能验证】

- 全量扫描 468 个文档,显式硬件说明未覆盖数为 0。
- 标签起止配对、文档内 ID 唯一性检查通过。
- 私有 API 文档的 37 个条目与基线表格逐项比对,API 名称、NPU 形式名称、产品支持情况、数据类型及版本限制均保留;除 Adam fused 限制按硬件筛选语境改写外,其他修改文件去除 NPU 注释后原文保持一致。
- 全量检查所有 NPU 起止标签均独占一行,配对完整、ID 唯一,硬件说明均被标签覆盖;私有 API 文档无残留表格或行内标签,确定性计算标签覆盖完整对应表格。
- 两个分支各 7 个 PyTorch 版本目录的 Adam fused 提示经筛选验证:910b、A3 可见,950 不可见。
- `git diff --check` 通过。
- 文档变更未运行 NPU UT 或完整文档站点构建;远端 CI 待运行确认。

# 【CheckList】

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


See merge request: Ascend/pytorch!47559
2026-10-09 09:35:17 +08:00
zwj223 07e929c206 modify document
Co-authored-by: zwj223<zhangwenjing55@h-partners.com>



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

modify document

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

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>
[#5091](https://gitcode.com/Ascend/pytorch/issues/5091) 
- [ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [x] 资料更新

# 【修改方案】
根据HC大会的最新产品中英文命名,更新文档中的产品名
# 【资料变更】
修改所有涉及产品名称的文档
# 【接口变更】
不涉及
# 【功能验证】
不涉及
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

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


See merge request: Ascend/pytorch!47022
2026-10-09 09:32:27 +08:00
y30037164 91e4693820 调整 nightly 测试参数: 常规分片 worker 并发 8 提升到 16, 单 batch 用例数 50 提升到 100
Co-authored-by: yuaiming<yuaiming@h-partners.com>



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

调整 nightly 测试参数: 常规分片 worker 并发 8 提升到 16, 单 batch 用例数 50 提升到 100

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

# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5012

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

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

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

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

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

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

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


See merge request: Ascend/pytorch!47552
2026-10-09 09:27:33 +08:00
ZhangZGC a71e06d2df fix(costmodel): support named args in TTIR
Co-authored-by: ZhangZGC<8623924@qq.com>



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

fix(costmodel): support named args in TTIR

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

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

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

[#5277](https://gitcode.com/Ascend/pytorch/issues/5277) 

# 【修改方案】

最新的triton对ttir的格式做了修改,ttir的入参名称从args_i改为了任意名称。此前costmodel的参数解析采用args这个关键词匹配,当前需要进行泛化,否则无法识别ttir入参。

此pr修改让costmodel支持任意的ttir入参名称解析。

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

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

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

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

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


See merge request: Ascend/pytorch!47262
2026-10-09 09:22:33 +08:00
pta-robot cc93bd0dec Update torchair commit id
Co-authored-by: pta-robot<pta_robot@163.com>



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

Update torchair commit id

Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-09-30 22:05:51.

See merge request: Ascend/pytorch!47533
2026-10-09 09:04:43 +08:00
pta-robot 0e0d5f3b14 Update op_plugin commit id
Co-authored-by: pta-robot<pta_robot@163.com>



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

Update op_plugin commit id

Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-08 22:03:44.

See merge request: Ascend/pytorch!47591
2026-10-08 22:44:44 +08:00
ccyyccyyccyycc cea4a6a9ef [feature] support get_buffer for symm mem
Co-authored-by: ccyyccyyccyycc<changqiaowei@huawei.com>



# message auto-generated for no-merge-commit merge:
!46842 merge feat/symm-mem-getbuffer into master

[feature] support get_buffer for symm mem

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

# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/5031

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

# 【修改方案】
- `NPUSHMEMSymmetricMemory` 构造函数:填 `buffers_`(每个 group rank 的 `Aclshmem_ptr` 结果),`Aclshmem_ptr` 返回 nullptr 时 `TORCH_CHECK`。无需新增。
- 社区`SymmetricMemory`通过`get_buffer`,调用`NPUSHMEMSymmetricMemory`后端`get_buffer_ptrs()`、`get_buffer_size()`等接口,直接返回 `buffers_`、`buffer_size_`等。

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
| 测试用例 | 验证点 | 类型 |
| --- | --- | --- |
| `test_get_buffer` | `buffer_size` 正确;本地 `data_ptr()`==本地 tensor;对端 `data_ptr()`==`buffer_ptrs[peer]`;本地与对端数据值正确;`storage_offset=4` 子切片地址与数据正确;越界抛 "exceeds the allocated size" | 集成 |
| `test_get_buffer_alias` | 本地 `get_buffer(rank)[3:4].fill_` 对本地 tensor 可见;rank0 经 `get_buffer(peer)[7:8].fill_` 跨卡写入,synchronize+barrier 后 rank1 本地 tensor[7]==写入值 | 集成 |
| `test_get_buffer_allocation_lifetime` | `del tensor`+barrier 后仍可 `get_buffer`,地址与数据保持正确,验证 handle 引用计数保活 allocation | 集成 |

测试执行test_shmem.py
![image.png](https://raw.gitcode.com/user-images/assets/7404318/5c1b9e80-1550-48a1-8497-574e21245f99/image.png 'image.png')
![image.png](https://raw.gitcode.com/user-images/assets/7404318/387f71a1-8e0a-4190-a56e-fcbb46d0965e/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!46842
2026-10-08 18:26:39 +08:00
pta-robot 881b613b3d Update op_plugin commit id
Co-authored-by: pta-robot<pta_robot@163.com>



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

Update op_plugin commit id

Created-by: pta-robot
Commit-by: pta-robot
Merged-by: ascend-robot
Description: Commited by @pta-robot at 2026-10-08 17:30:20.

See merge request: Ascend/pytorch!47572
2026-10-08 18:18:51 +08:00
chansinging 1785d0871f 合并操作
Co-authored-by: Chansinging<1183520536@qq.com>



# message auto-generated for no-merge-commit merge:
!47197 merge fix_test_schedule_2.14 into master

test: enhance _make_p2p_op to support custom group for better flexibility

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

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

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

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

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

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

# 【功能验证】
![image.png](https://raw.gitcode.com/user-images/assets/7404318/7436c31d-01e5-42c7-bac4-0bd8fb4d8792/image.png 'image.png')

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

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


See merge request: Ascend/pytorch!47197
2026-10-08 18:05:10 +08:00