Skip to content

fix: add unsupported testcases to skip#146

Open
yuaiming wants to merge 2086 commits into
Ascend:v2.7.1from
yuaiming:yam/v2.7.1
Open

fix: add unsupported testcases to skip#146
yuaiming wants to merge 2086 commits into
Ascend:v2.7.1from
yuaiming:yam/v2.7.1

Conversation

@yuaiming

Copy link
Copy Markdown
Collaborator

添加跳过用例,生成看板

wang-ziqi-code and others added 30 commits June 8, 2026 16:14
Co-authored-by: wang_ziqi<wangziqi4@huawei.com>



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

fix some failed testcases

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

# 【修改方案】
修复部分测试用例失败问题,当前提交包含两类调整:

1. `test_npu_multi_head_attention.py`
   - 去掉 `test_npu_multi_head_attention` 上的 skip 标记,恢复用例执行。
   - 在用例开始处设置:
     ```python
     torch.npu.config.allow_internal_format = True
     ```
   - 根因是该用例构造了 `FORMAT_NZ` 输入,`npu_multi_head_attention` 相关路径依赖内部 format;未开启 internal format 时,CPU 参考链路与 NPU 算子链路的 format 行为不一致,导致 `assertRtolEqual` 精度对比失败。
   - 删除不再使用的 `import unittest`。

2. `.pytorch-disabled-tests.json`
   - 从 disabled 列表中移除 `_chunk_cat` 相关用例:
     - `test_compare_cpu__chunk_cat_npu_float32`
     - `test_variant_consistency_eager__chunk_cat_npu_float32`
     - `test_operator__chunk_cat_npu_float32`
   - `_chunk_cat` 相关问题已修复,恢复这些用例进入常规测试看护。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及对外接口变更。

本次仅调整测试用例配置和测试执行条件,不新增公开 API,不修改已有接口语义。

# 【功能验证】
- test/custom_ops/test_npu_multi_head_attention.py
  ![image.png](https://raw.gitcode.com/user-images/assets/7404318/af855e3e-2685-4820-a563-364afaf0d23a/image.png 'image.png')
- test_compare_cpu__chunk_cat_npu_float32
  ![image.png](https://raw.gitcode.com/user-images/assets/7404318/5bad08db-7d39-4a06-a94a-f9fa7bbb2628/image.png 'image.png')
- test_variant_consistency_eager__chunk_cat_npu_float32
  ![image.png](https://raw.gitcode.com/user-images/assets/7404318/b0b0f02b-beb2-4939-abba-7a50241985c3/image.png 'image.png')
- test_operator__chunk_cat_npu_float32
  ![image.png](https://raw.gitcode.com/user-images/assets/7404318/d4b6a9c2-2c69-4b2c-8034-66c5046e7f7c/image.png 'image.png')

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


See merge request: Ascend/pytorch!37578
…te_arg.py

Co-authored-by: q15546010075<guangxi12345202302@163.com>



# message auto-generated for no-merge-commit merge:
!37614 merge test-fx-create-args-for-root-master into master

test(fx): add create_args_for_root testcases into test_fx_tracer_create_arg.py

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

# 【合入来源】

- [x] 问题单
> https://gitcode.com/Ascend/pytorch/issues/2235

pytorch社区用例没有验证torch.fx.Tracer.create_args_for_root,故将该API测试用例合入已有的test_fx_tracer_create_arg.py中统一维护。

# 【修改方案】
一、API 功能说明

`torch.fx.Tracer.create_args_for_root(root_fn, is_module, concrete_args=None)` 在符号追踪过程中,根据被追踪函数/模块的签名为每个参数创建 placeholder 代理节点。纯 Python 层操作,不涉及张量计算或硬件驱动。

二、修改内容

在已有的 `test/fx/test_fx_tracer_create_arg.py` 基础上追加 `create_args_for_root` 的 7 个测试方法到 `TestTracerCreateArg` 类中,覆盖 Module 模式、Function 模式、concrete_args(dict/tuple)、默认值参数等核心路径。同时在文件顶部(类外)新增 TwoArgModule、DefaultArgModule 供新用例使用。原有代码零修改。

三、NPU适配

该 API 纯粹操作 Python 函数签名和 FX Graph IR 节点,内部仅调用 inspect 标准库和 PyTorch 纯 Python 层数据结构,不依赖 CUDA/NPU 扩展库或底层驱动,无需 NPU 适配。用例中所有断言均针对 Python 对象属性,无张量创建或设备操作。

# 【资料变更】

已检查 `docs/zh/native_apis` 各版本目录,`torch.fx.Tracer.create_args_for_root` 均已标注为"是"(支持),文档状态与实际一致,无需修改文档。

# 【接口变更】
> 不涉及

# 【功能验证】

在 master 对应环境上执行该用例,通过,日志如下:

```
(venv_2.12.0) root@npu1-2:/tmp# python3 test_fx_tracer_create_arg.py
............
......
----------------------------------------------------------------------
Ran 19 tests in 0.998s

OK
```

# 【CheckList】

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


See merge request: Ascend/pytorch!37614
Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com>



# message auto-generated for no-merge-commit merge:
!37776 merge 2.13ut1 into master

test update ut

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

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

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

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

test_deprecation test_cycle_lr_cycle_momentum_fail_with_momentumless_optimizer test_hook_registration 同步社区用例更新
test_float_status A2/A3需要开启饱和模式
test_select_at_first_axis_to_single_element_tensor_copy 转连续优化是aclop路径,alcnn路径添加aclnnAdds通过用例

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

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

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

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

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


See merge request: Ascend/pytorch!37776
Co-authored-by: ffmh<fengminghao2@huawei.com>



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

[master] cherry-pick v2.7.1_fix_ut: remove unskip

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

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

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

Cherry-pick de67e68db from v2.7.1_fix_ut

移除 test/optim/test_fused_optimizers.py 中 3 处 `@unittest.skip("Temporarily skipping")` 装饰器,重新启用以下测试用例:
1. test_unscale
2. test_simple_model_train_dynamic
3. test_simple_model_train_static

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

不涉及

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

不涉及

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

重新启用 test_fused_optimizers.py 中被跳过的 3 个测试用例,验证 NPU 上 fused optimizer 的 unscale 和 dynamic/static training 功能正常。

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

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

See merge request: Ascend/pytorch!37615
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!37892 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-06-08 22:01:55.

See merge request: Ascend/pytorch!37892
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!37852 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-06-08 18:02:28.

See merge request: Ascend/pytorch!37852
…alname in master

Co-authored-by: Deng_RH<1848477588@qq.com>



# message auto-generated for no-merge-commit merge:
!37555 merge test/fx-create-proxy-qualname-master into master

test(fx): add tests for torch.fx.Tracer.create_proxy and get_fresh_qualname in master

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

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

- [x] issue/工单

# 【修改方案】

一、API功能说明

| API | 功能描述 | 是否涉及张量计算 |
|-----|---------|----------------|
| `torch.fx.Tracer.create_proxy` | 在符号追踪过程中创建 Proxy 对象,根据传入的 kind/target/args/kwargs 调用 create_node 创建 Node 并包装为 Proxy 返回,是 Tracer 的核心方法 | 本身不涉及,但构建的图在 NPU 上执行时涉及 |
| `torch.fx.Tracer.get_fresh_qualname` | 为给定前缀生成唯一的 qualified name,自动跳过模块中已存在的属性名,在 create_arg 中被调用 | 不涉及,纯命名逻辑 |

二、测试用例说明

在 `test/fx/test_fx_tracer_transformer_api.py` 末尾追加两个 TestClass,共4个用例:

**TestTracerCreateProxy**

| 用例 | 验证内容 | 张量设备 |
|------|---------|--------|
| `test_create_proxy_basic` | 子类化 Tracer 重写 create_proxy,验证返回 Proxy 包含有效 Node,node.op 与 kind 一致 | `.npu()` |
| `test_create_proxy_graph_correctness` | 通过 symbolic_trace 构建的图在 NPU 上计算结果与原模块一致 | `device="npu"` |

**TestTracerGetFreshQualname**

| 用例 | 验证内容 | 张量设备 |
|------|---------|--------|
| `test_get_fresh_qualname_skip_existing` | 模块已有 `param0` 时返回 `"param1"` | `device="npu"` |
| `test_get_fresh_qualname_fresh_prefix` | 全新前缀 `"new_attr"` 返回 `"new_attr0"` | `.npu()` |

三、为什么追加到现有文件而非新建

`test/fx/test_fx_tracer_transformer_api.py` 已是 Tracer/Transformer API 的聚合测试文件(含 trace、path_of_module、iter、keys、proxy、to_bool、getattr 等),`create_proxy` 和 `get_fresh_qualname` 同属 Tracer 方法,追加到该文件中可避免文件碎片化,便于后期维护。

四、NPU适配说明

- `create_proxy`:本身是纯 Python 图构建 API,不涉及硬件算子。测试中通过 `.npu()` 将模型和张量放在 NPU 上,验证构建的图在 NPU 执行正确。
- `get_fresh_qualname`:纯命名逻辑,与设备无关。测试中 nn.Parameter 使用 `device="npu"` 确保张量在 NPU 上创建。

# 【资料变更】

已检查文档,https://gitcode.com/Ascend/pytorch/tree/v2.7.1/docs/zh/native_apis 目录下的 pytorch_2-6-0 至 pytorch_2-12-0 文件夹中的 torch-fx.md 均已对 torch.fx.Tracer.create_proxy 标注“是 支持fp32”,对 torch.fx.Tracer.get_fresh_qualname 标注“是”,无需更改。

# 【接口变更】
> 不涉及

# 【功能验证】

**环境信息:**
- 操作系统:Ubuntu
- 昇腾硬件信息:910B1
- CANN软件版本:8.5.0
- torch + torch_npu 版本:master

**测试命令:**
```bash
cd /path/to/torch_npu
python -m pytest test/fx/test_fx_tracer_transformer_api.py::TestTracerCreateProxy test/fx/test_fx_tracer_transformer_api.py::TestTracerGetFreshQualname -v
```

**master 测试日志:**
```
============================= test session starts ==============================
platform linux -- Python 3.11.6, pytest-9.0.3, pluggy-1.6.0 -- /data2/drh/torch_npu_api_drh/.venv_torch271/bin/python
cachedir: .pytest_cache
rootdir: /tmp
collecting ... collected 4 items

test_fx_tracer_transformer_api.py::TestTracerCreateProxy::test_create_proxy_basic PASSED [ 25%]
test_fx_tracer_transformer_api.py::TestTracerCreateProxy::test_create_proxy_graph_correctness PASSED [ 50%]
test_fx_tracer_transformer_api.py::TestTracerGetFreshQualname::test_get_fresh_qualname_fresh_prefix PASSED [ 75%]
test_fx_tracer_transformer_api.py::TestTracerGetFreshQualname::test_get_fresh_qualname_skip_existing PASSED [100%]

=============================== warnings summary ===============================
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================== 4 passed, 14 warnings in 9.56s ========================
```

# 【CheckList】

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

See merge request: Ascend/pytorch!37555
Co-authored-by: huangyunlong2022<huangyunlong4@h-partners.com>



# message auto-generated for no-merge-commit merge:
!37866 merge sync-pr37777-2.7libh-to-master into master

[sync] PR-37777: fix add logging header for libtorch_npu

Created-by: ascend-ds-bot
Commit-by: huangyunlong2022
Merged-by: ascend-robot
Description: 
### 1. Origin pull request:
https://gitcode.com/Ascend/pytorch/merge_requests/37777

### 2. Original pull request related issue(s):
https://gitcode.com/Ascend/pytorch/issues/2290

### 3. Original pull request related commit(s):
| Sha | Datetime | Message |
|---|---|---|
|[3c3d79da](https://gitcode.com/Ascend/pytorch/commit/3c3d79daa447522e82a45d89111748edff4034dd)|2026-06-06 17:23:27 +0800 CST|add logging header for libtorch_npu<br>|


See merge request: Ascend/pytorch!37866
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!37915 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-06-09 10:02:55.

See merge request: Ascend/pytorch!37915
Co-authored-by: kkjocker<hexuanyu1@huawei.com>



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

[bugfix] fix transfer_to_npu get_gpu_type error

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

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

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

# 【资料变更】
> 不涉及

# 【接口变更】
> 不涉及

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

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

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


See merge request: Ascend/pytorch!37859
Co-authored-by: 1479518308<cuiduo1@huawei.com>



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

fix_generate_extern_kernel_alloc

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

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

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

# 【修改方案】
> 修复generate_extern_kernel_alloc在v2.9.0以上版本改名问题

# 【资料变更】
> 不涉及

# 【接口变更】
>不涉及

# 【功能验证】
> 本地验证通过

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

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


See merge request: Ascend/pytorch!37538
Co-authored-by: wangsike<wangsike@huawei.com>



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

fix(ci): pytorch_ci_trigger.yml 修复 shell 引号断裂并改用 reusable workflow 转发事件

Created-by: kerer-sk
Commit-by: wangsike
Merged-by: ascend-robot
Description: ## 变更说明

`pytorch_ci_trigger.yml` 在收到 `repository_dispatch` 事件时存在两个问题,本次一并修复。

## 问题

1. **JSON 打印步骤因 shell 单引号断裂导致失败**:`echo '${{ toJSON(...) }}'` 写法在 payload 含单引号时(如 PR 标题/commit message 中的撇号),会提前闭合 shell 单引号,导致 workflow 语法错误退出。
2. **`workflow_dispatch` API 转发无效**:用 `GITHUB_TOKEN` 通过 `gh api` 调用 `workflow_dispatch` 创建的事件会被 GitHub Actions 反递归机制拦截,无法真正触发目标 workflow。

## 变更内容

- 将 3 处 JSON 打印从 `echo` 单引号包裹改为 heredoc(`cat <<'ENDOFPAYLOAD'`)
- 将事件转发从 `gh api workflow_dispatch` 改为 job 级 `uses:` 可复用工作流调用 → `receive-trigger.yml@ci-test`
- 新增 `ci-test` 分支上的 `receive-trigger.yml` 作为接收端

## 关联 Issue

- Fixes https://gitcode.com/Ascend/pytorch/issues/2300

## 测试计划

- [x] `repository_dispatch` 事件到达后,打印步骤不再因 payload 含特殊字符而中断
- [x] `forward` job 能成功调用 `ci-test` 分支的 `receive-trigger.yml` 并打印完整 payload

See merge request: Ascend/pytorch!37843
Co-authored-by: hz893<zhanghao491@huawei.com>



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

fix: add sparse CSR reduction NPU fallback

Created-by: hz893
Commit-by: hz893
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/2265
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新

# 【修改方案】
1. 新增 `SparseCsrReductionFallbackKernelNpu.cpp`,在 `SparseCsrPrivateUse1` dispatch key 下注册 `_sparse_csr_sum.dim_dtype` 和 `_sparse_csr_prod.dim_dtype`。
2. 对 sparse CSR NPU tensor 采用 CPU fallback:先将 CSR tensor 转 CPU,调用 PyTorch sparse CSR sum/prod 实现,再将结果转回 NPU。
3. 该方案用于补齐 masked sum/prod 的 sparse CSR 正确性路径;后续如有 NPU 原生 kernel,可替换该 fallback 实现。

# 【资料变更】
不涉及。

# 【接口变更】
不涉及。

# 【功能验证】
1. v2.7.1 环境执行 `bash ci/build.sh --python=3.11` 编译 wheel 成功,并安装生成的 `torch_npu-2.7.1.post5-cp311-cp311-manylinux_2_28_aarch64.whl`。
2. 构建日志确认 `SparseCsrReductionFallbackKernelNpu.cpp.o` 已编译。
3. v2.7.1 环境执行 `DISABLED_TESTS_FILE=/home/zhanghao/code/test_pytorch/torch_npu/test_upstream/disabled_testcases.json PYTORCH_TESTING_DEVICE_ONLY_FOR=npu python3 test_masked.py -v -k test_mask_layout`,结果 `Ran 144 tests`,`OK (skipped=112)`。
4. v2.7.1 环境执行 `PYTORCH_TESTING_DEVICE_ONLY_FOR=npu python3 test_masked.py -v -k test_where_hybrid_coo_fill_value_123_npu`,结果 `Ran 1 test`,`OK`。
5. 本目标分支执行 `git diff --check HEAD~1..HEAD`,无格式问题。

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

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


See merge request: Ascend/pytorch!36814
Co-authored-by: zhenyu10<shizhenyu5@huawei.com>



# message auto-generated for no-merge-commit merge:
!37817 merge master-storage-requires-grad-fix into master

Fix NPU tensor rebuild requires_grad load

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

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

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

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

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

报错场景:
1. checkpoint 里保存的是 NPU tensor
2. 这个 NPU tensor 序列化时带着 requires_grad=True
3. 加载时走到 torch_npu.utils.storage._rebuild_npu_tensor
4. 旧代码先创建 requires_grad=True 的临时 leaf tensor
5.  然后对它执行 set_ 这种 in-place 操作
报错:
RuntimeError: a leaf Variable that requires grad is being used in an in-place operation.

修改方式:对齐torch原生社区,empty里不使用requires_grad=True

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

不涉及

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

不涉及

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

可以正常加载权重,验证见issue

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

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


See merge request: Ascend/pytorch!37817
Co-authored-by: TensorLake<l.wenjie@foxmail.com>



# message auto-generated for no-merge-commit merge:
!37638 merge test/script-module-npu-master into master

test(jit): add ScriptModule API alignment test cases [master]

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

Fork: TensorLake/torch-npu
分支: `test/script-module-npu-master` → Ascend/pytorch:`master`

## 【修改方案】

本 PR 为 [#1861](https://gitcode.com/Ascend/pytorch/issues/1861) 的交付。社区用例情况:已在 PyTorch 官方社区 `pytorch/test/jit/` 下搜索 `ScriptModule` 相关测试,无针对这 19 个 API 的独立测试用例,因此自行编写测试用例。

### 一、API 功能说明及行为分类

`torch.jit.ScriptModule` 通过 `torch.jit.script()` 创建,返回 `RecursiveScriptModule` 实例。其方法可见性由双层机制控制:
1. `RecursiveScriptModule` 自己定义的方法(如 `save()`、`extra_repr()`)
2. `_compiled_methods_allowlist` 白名单中的 `nn.Module` 方法(如 `train()`、`to()`、`state_dict()`)
3. 不满足以上两条的方法被 `_make_fail` 替换,调用即抛 `RuntimeError("xxx is not supported on ScriptModules")`

本测试使用 `torch.jit.script()` 作为 canonical 创建方式,正确验证 allowlist 机制的行为。按实测行为将 19 个 API 分为 4 类:

**第一类:allowlist 内正常工作(11 个)**

| API | 来源 | 行为说明 |
|-----|------|---------|
| `train(mode)` | 白名单 | 设置训练模式,返回 self,递归传播到子模块 |
| `eval()` | 白名单 | 等价于 `train(False)`,返回 self |
| `zero_grad(set_to_none)` | 白名单 | 清零所有参数梯度 |
| `float()` | 白名单 | 将参数/buffer 转为 float32,返回 self,递归传播 |
| `double()` | 白名单 | 将参数/buffer 转为 float64。NPU 不支持 float64,自动降级为 float32 |
| `to(dtype/device)` | 白名单 | 支持多参数形式,递归传播 |
| `type(dst_type)` | 白名单 | 转换 dtype |
| `state_dict(...)` | 白名单 | 返回 OrderedDict,支持 `prefix=`、`destination=`、`keep_vars=` 参数 |
| `save(f, _extra_files)` | RSM 自定义 | 委托 C++,无返回值。支持 `_extra_files` 附加文件 |
| `save_to_buffer()` | RSM 自定义 | 序列化到 bytes 并返回 |
| `extra_repr()` | RSM 自定义 | 返回 `"original_name=..."` 格式字符串 |

**第二类:`_make_fail` 封杀(5 个,与 CPU/GPU 行为一致)**

| API | 异常消息(`assertRaisesRegex` 匹配) |
|-----|-----------------------------------|
| `requires_grad_()` | `"requires_grad_ is not supported on ScriptModules"` |
| `to_empty()` | `"to_empty is not supported on ScriptModules"` |
| `xpu()` | `"xpu is not supported on ScriptModules"` |
| `get_buffer()` | `"get_buffer is not supported on ScriptModules"` |
| `set_submodule()` | `"set_submodule is not supported on ScriptModules"` |

**第三类:torch-npu 拦截(3 个)**

| API | CPU 行为 | NPU 行为 |
|-----|---------|---------|
| `share_memory()` | 正常工作 | RuntimeError: "share_memory is not supported in npu" |
| `register_module()` | RuntimeError(PyTorch 限制) | RuntimeError(torch-npu 先拦截) |
| `register_parameter()` | RuntimeError(PyTorch 限制) | RuntimeError(torch-npu 先拦截) |

注:`share_memory` 在 GPU/CUDA 上为 **no-op**(官方文档明确),NPU 行为与 GPU 不一致。

**第四类:PyTorch 内部未完成实现(1 个)**

| API | 行为 |
|-----|------|
| `set_extra_state()` | RuntimeError: "should never be called" |

### 二、测试文件说明

新增文件:`test/jit/test_script_module.py`,共 67 个测试用例,按功能语义分为 10 个测试类:

- `TestScriptModuleTrainEval`(11 个):train/eval 默认状态、显式设置、返回值验证、往返切换、NPU 验证、子模块递归传播
- `TestScriptModuleZeroGrad`(5 个):无梯度不报错、梯度清零、set_to_none 语义、set_to_none=False 清零、backward→zero_grad→backward 链路
- `TestScriptModuleTo`(9 个):dtype/device/device+dtype/dtype_keyword/string_device/no_args 多形式、返回值验证、子模块传播
- `TestScriptModuleFloatDouble`(7 个):float 转换/传播、double 转换/NPU float64 降级 float32/传播
- `TestScriptModuleType`(4 个):float32 正常路径、float64 降级路径、NPU 验证、int32 异常
- `TestScriptModuleStateDict`(7 个):参数/buffer 包含、值匹配、NPU 设备验证、prefix/destination/keep_vars 参数形式
- `TestScriptModuleSave`(6 个):save/load 往返、参数保留、返回 None、NPU 验证、_extra_files、save_to_buffer
- `TestScriptModuleExtraRepr`(3 个):返回字符串、original_name 模式、NPU 验证
- `TestScriptModuleShareMemory`(4 个):CPU 返回 self/makes_shared/幂等、NPU assertRaisesRegex 拦截
- `TestScriptModuleMetadata`(7 个):register_module/register_parameter NPU 拦截、set_submodule _make_fail、get_buffer _make_fail
- `TestScriptModuleUnsupported`(4 个):requires_grad_/to_empty/xpu _make_fail、set_extra_state 未完成实现

所有可预测异常的 API 均使用 `assertRaisesRegex` 精确匹配异常信息内容。

### 三、NPU 适配说明

- 所有涉及张量的测试均在 NPU 设备上运行
- NPU 不支持 float64,`double()`/`to(torch.float64)`/`type(torch.float64)` 自动降级为 float32
- `share_memory` 在 NPU 上被拦截(GPU 为 no-op,行为不一致,已在测试中标注)
- `_make_fail` 封杀的 5 个 API 在所有设备上行为一致

## 【资料变更】

经检查 `docs/zh/native_apis/` 下各版本路径,已有记录的 API 18/19。`set_submodule` 缺失,已通过独立文档 PR 提交。

## 【接口变更】

不涉及

## 【功能验证】

测试文件:`test/jit/test_script_module.py`
测试环境:`torch master` + `torch_npu master` + NPU 910B3(CANN 8.5.0)

```
test_extra_repr_contains_original_name (__main__.TestScriptModuleExtraRepr.test_extra_repr_contains_original_name) ... ok
test_extra_repr_on_npu (__main__.TestScriptModuleExtraRepr.test_extra_repr_on_npu) ... ok
test_extra_repr_returns_str (__main__.TestScriptModuleExtraRepr.test_extra_repr_returns_str) ... ok
test_double_converts_params (__main__.TestScriptModuleFloatDouble.test_double_converts_params) ... [W604 11:34:32.815442779 compiler_depend.ts:164] Warning: Device do not support double dtype now, dtype cast replace with float. (function operator())
ok
test_double_on_npu_fallback_to_float32 (__main__.TestScriptModuleFloatDouble.test_double_on_npu_fallback_to_float32) ... ok
test_double_returns_self (__main__.TestScriptModuleFloatDouble.test_double_returns_self) ... ok
test_float_converts_params (__main__.TestScriptModuleFloatDouble.test_float_converts_params) ... ok
test_float_on_npu (__main__.TestScriptModuleFloatDouble.test_float_on_npu) ... ok
test_float_propagates_to_submodules (__main__.TestScriptModuleFloatDouble.test_float_propagates_to_submodules) ... ok
test_float_returns_self (__main__.TestScriptModuleFloatDouble.test_float_returns_self) ... ok
test_get_buffer_unsupported (__main__.TestScriptModuleMetadata.test_get_buffer_unsupported) ... ok
test_get_buffer_unsupported_nonexistent (__main__.TestScriptModuleMetadata.test_get_buffer_unsupported_nonexistent) ... ok
test_get_buffer_unsupported_on_nested (__main__.TestScriptModuleMetadata.test_get_buffer_unsupported_on_nested) ... ok
test_register_module_raises_on_npu (__main__.TestScriptModuleMetadata.test_register_module_raises_on_npu) ... ok
test_register_parameter_raises_on_npu (__main__.TestScriptModuleMetadata.test_register_parameter_raises_on_npu) ... ok
test_set_submodule_nested_raises (__main__.TestScriptModuleMetadata.test_set_submodule_nested_raises) ... ok
test_set_submodule_raises (__main__.TestScriptModuleMetadata.test_set_submodule_raises) ... ok
test_save_and_load (__main__.TestScriptModuleSave.test_save_and_load) ... ok
test_save_on_npu (__main__.TestScriptModuleSave.test_save_on_npu) ... ok
test_save_preserves_output (__main__.TestScriptModuleSave.test_save_preserves_output) ... ok
test_save_returns_none (__main__.TestScriptModuleSave.test_save_returns_none) ... ok
test_save_to_buffer (__main__.TestScriptModuleSave.test_save_to_buffer) ... ok
test_save_with_extra_files (__main__.TestScriptModuleSave.test_save_with_extra_files) ... ok
test_share_memory_cpu_idempotent (__main__.TestScriptModuleShareMemory.test_share_memory_cpu_idempotent) ... ok
test_share_memory_cpu_makes_shared (__main__.TestScriptModuleShareMemory.test_share_memory_cpu_makes_shared) ... ok
test_share_memory_cpu_returns_self (__main__.TestScriptModuleShareMemory.test_share_memory_cpu_returns_self) ... ok
test_share_memory_on_npu_raises (__main__.TestScriptModuleShareMemory.test_share_memory_on_npu_raises) ... ok
test_state_dict_contains_buffers (__main__.TestScriptModuleStateDict.test_state_dict_contains_buffers) ... ok
test_state_dict_contains_params (__main__.TestScriptModuleStateDict.test_state_dict_contains_params) ... ok
test_state_dict_keep_vars (__main__.TestScriptModuleStateDict.test_state_dict_keep_vars) ... ok
test_state_dict_on_npu (__main__.TestScriptModuleStateDict.test_state_dict_on_npu) ... ok
test_state_dict_values_match (__main__.TestScriptModuleStateDict.test_state_dict_values_match) ... ok
test_state_dict_with_destination (__main__.TestScriptModuleStateDict.test_state_dict_with_destination) ... ok
test_state_dict_with_prefix (__main__.TestScriptModuleStateDict.test_state_dict_with_prefix) ... ok
test_to_device (__main__.TestScriptModuleTo.test_to_device) ... ok
test_to_device_and_dtype (__main__.TestScriptModuleTo.test_to_device_and_dtype) ... ok
test_to_dtype (__main__.TestScriptModuleTo.test_to_dtype) ... ok
test_to_dtype_keyword (__main__.TestScriptModuleTo.test_to_dtype_keyword) ... ok
test_to_no_args_returns_self (__main__.TestScriptModuleTo.test_to_no_args_returns_self) ... ok
test_to_npu_and_dtype (__main__.TestScriptModuleTo.test_to_npu_and_dtype) ... ok
test_to_propagates_to_submodules (__main__.TestScriptModuleTo.test_to_propagates_to_submodules) ... ok
test_to_returns_self (__main__.TestScriptModuleTo.test_to_returns_self) ... ok
test_to_string_device (__main__.TestScriptModuleTo.test_to_string_device) ... ok
test_eval_on_npu (__main__.TestScriptModuleTrainEval.test_eval_on_npu) ... ok
test_eval_propagates_to_submodules (__main__.TestScriptModuleTrainEval.test_eval_propagates_to_submodules) ... ok
test_eval_returns_self (__main__.TestScriptModuleTrainEval.test_eval_returns_self) ... ok
test_eval_sets_training_false (__main__.TestScriptModuleTrainEval.test_eval_sets_training_false) ... ok
test_train_default_is_training (__main__.TestScriptModuleTrainEval.test_train_default_is_training) ... ok
test_train_eval_roundtrip (__main__.TestScriptModuleTrainEval.test_train_eval_roundtrip) ... ok
test_train_on_npu (__main__.TestScriptModuleTrainEval.test_train_on_npu) ... ok
test_train_propagates_to_submodules (__main__.TestScriptModuleTrainEval.test_train_propagates_to_submodules) ... ok
test_train_returns_self (__main__.TestScriptModuleTrainEval.test_train_returns_self) ... ok
test_train_set_false (__main__.TestScriptModuleTrainEval.test_train_set_false) ... ok
test_train_set_true_explicit (__main__.TestScriptModuleTrainEval.test_train_set_true_explicit) ... ok
test_type_float32 (__main__.TestScriptModuleType.test_type_float32) ... ok
test_type_float64 (__main__.TestScriptModuleType.test_type_float64) ... ok
test_type_int32_raises (__main__.TestScriptModuleType.test_type_int32_raises) ... ok
test_type_on_npu (__main__.TestScriptModuleType.test_type_on_npu) ... ok
test_requires_grad_unsupported (__main__.TestScriptModuleUnsupported.test_requires_grad_unsupported) ... ok
test_set_extra_state_raises (__main__.TestScriptModuleUnsupported.test_set_extra_state_raises) ... ok
test_to_e

See merge request: Ascend/pytorch!37638
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!37982 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-06-09 18:02:56.

See merge request: Ascend/pytorch!37982
Co-authored-by: wanlinan<wanlinan@huawei.com>



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

[fix]npu_format_cast in batch_isend_irecv

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

# 【合入来源】
[[Bug]: _batch_isend_irecv接口输入tensor为NZ格式时有精度问题](https://gitcode.com/Ascend/pytorch/issues/2321)

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

# 【修改方案】
当recv输入tensor格式为NZ,调用_batch_isend_irecv接口时,在endcoalescing接口增加类型转换。

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
在调用_batch_isend_irecv前转换数据格式为NZ
![image.png](https://raw.gitcode.com/user-images/assets/7404318/e2d626de-423d-4ac2-83cf-1ad36a0a80ea/image.png 'image.png')
验证通过:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/09350ba1-25b0-4cea-860a-006535f3b0f8/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!37835
Co-authored-by: qq_30230973<821281551@qq.com>



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

提供test目录下torch.jit.ScriptModule类中bfloat16、buffers、children和code的API的测试用例

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

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

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

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

torch.jit.ScriptModules中bfloat16、buffers、children的方法继承自nn.Module中的实现方法,可直接调用nn.Module中实例,初始化torch.jit.script类,且torch.jit.ScriptModules模块在torch版本 2.10.0、2.11.0、2.12.0 及以后已经弃用,建议可直接使用nn.Module中的接口,调用逻辑 torch.jit.script-->nn.Module-->torch_npu。

## API功能介绍
### bfloat16()

功能:将模型的所有参数和 buffer 转换为 BFloat16(Brain Float 16)精度

语法:
```bash
model.bfloat16()  # 就地修改,返回 self
```

特点:
· 就地修改,不创建新模型
· BFloat16:1 bit 符号 + 8 bit 指数 + 7 bit 尾数(相比 Float16 有更大的动态范围)
· 常用于混合精度训练、推理加速

使用场景:
```bash
model = Model().bfloat16()  # 创建时转换
或
model.bfloat16()  # 已有模型转换
```

推理时输入也需匹配
```bash
x = torch.randn(1, 1, 28, 28, dtype=torch.bfloat16)
output = model(x)
```
### buffers()

功能:返回模型中所有注册 buffer 的迭代器

语法:
```bash
for buf in model.buffers():
  print(buf.shape, buf.dtype)
```

使用场景: BatchNorm 的 running_mean/var、位置编码 

注册方式:
注册 buffer
```bash
self.registerbuffer('runningmean', torch.zeros(10))
self.registerbuffer('posencoding', torch.randn(100, 512), persistent=False)
```
persistent=False 表示不保存到 state_dict

相关方法:
```bash
model.named_buffers()  # 返回 (name, buffer) 元组迭代器
model.get_buffer('name')  # 按名称获取 buffer
```

### children()

功能:返回模型的直接子模块迭代器(仅一层,不递归)

语法:
```bash
for child in model.children():
  print(type(child))
```
示例:
```bash
class Model(nn.Module):
  def init(self):
    super().init()
    self.conv1 = nn.Conv2d(1, 20, 5)
    self.conv2 = nn.Conv2d(20, 20, 5)
    self.block = nn.Sequential(nn.Linear(10, 20), nn.Linear(20, 10))

model = Model()
list(model.children())  
```
返回: [Conv2d, Conv2d, Sequential]  ← 仅直接子模块


children() vs modules() vs named_children():

| 方法 | 返回内容 | 是否递归 |
|------|----------|----------|
| children() | 直接子模块 | ❌ |
| modules() | 所有子模块(含自身) | ✅ |
| named_children() | (name, module) 元组 | ❌ |
| named_modules() | (name, module) 元组 | ✅ |

### code(ScriptModule 专属)

功能:返回 JIT 编译后的 forward 方法源码字符串

语法:
```bash
scripted = torch.jit.script(Model())
print(scripted.code)
```
输出示例:
```bash
def forward(self,
  x: Tensor) -> Tensor:
 _0 = self.conv1
 _1 = self.conv2
 input = torch.relu(torch.C.VariableFunctions.conv2d(0.weight, x, 0.bias, [1, 1], [0, 0], [1, 1], 1))
 return torch.relu(torch.C.VariableFunctions.conv2d(1.weight, input, 1.bias, [1, 1], [0, 0], [1, 1], 1))
```
用途:
· 调试:检查 JIT 编译是否正确
· 优化分析:查看算子融合情况
· 验证控制流是否被正确捕获

相关属性:
``` bash
scripted.graph  # 返回计算图(Graph 对象)
scripted.graph_for(input)  # 针对特定输入的优化图
```

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
![2.12.png](https://raw.gitcode.com/user-images/assets/7404318/e341f687-d5e9-4a55-8d2a-6c0e0e59bddd/2.12.png '2.12.png')
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

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


See merge request: Ascend/pytorch!37562
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!38025 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-06-09 22:01:58.

See merge request: Ascend/pytorch!38025
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!38023 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-06-09 22:01:57.

See merge request: Ascend/pytorch!38023
Co-authored-by: 1479518308<cuiduo1@huawei.com>



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

【rfc】mlir_triton_lowering_file_refactoring

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

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

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

# 【修改方案】
> 对lowering部分进行重构,torch_npu/_inductor 在 Lowering 层 的多后端(Triton / MLIR / DVM)共享重构方案及转测要求。核心改动是:将 Triton 与 MLIR/DVM 两套 lowering 中重复的逻辑抽取到 lowering_common.py,通过 lowering_patch.py 实现 同进程 backend 切换时的 lowering 快照/恢复,并配合 _load_backend() 按需加载各后端 lowering 实现,消除原先 inductor_patch/__init__.py import 时整表 monkey-patch 的副作用。详见关联文档

# 【资料变更】
> 不涉及

# 【接口变更】
>不涉及

# 【功能验证】
> 已通过

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

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


See merge request: Ascend/pytorch!37282
…kwargs, torch.fx.node.map_arg, torch.fx.Node.next, torch.fx.Node.prev APIs

Co-authored-by: hantao55_<terry.han27@qq.com>



# message auto-generated for no-merge-commit merge:
!37791 merge test-fx-node-master into master

test(fx): add test cases for torch.fx.node._type_repr, torch.fx.Node.kwargs, torch.fx.node.map_arg, torch.fx.Node.next, torch.fx.Node.prev APIs

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

# 【合入来源】
>[[Usage]: torch.fx.node相关API NPU测试适配说明](https://gitcode.com/Ascend/pytorch/issues/2291)

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

# 【修改方案】
一、API功能说明

API范围:

- torch.fx.node._type_repr
- torch.fx.Node.all_input_nodes
- torch.fx.Node.append
- torch.fx.Node.args
- torch.fx.Node.format_node
- torch.fx.Node.insert_arg
- torch.fx.Node.is_impure
- torch.fx.Node.kwargs
- torch.fx.node.map_aggregate
- torch.fx.node.map_arg
- torch.fx.Node.next
- torch.fx.Node.normalized_arguments
- torch.fx.Node.prepend
- torch.fx.Node.prev
- torch.fx.Node.replace_all_uses_with

torch.fx.Node是torch.fx.Graph中的基本执行单元,以双向链表形式组织。上述15个API属于PyTorch torch.fx框架层的图节点操作与工具函数:

- torch.fx.node._type_repr是模块级私有函数,将Python类型转换为可读字符串,供图的类型注解生成使用;
- torch.fx.Node.all_input_nodes是args中所有Node类型元素的只读视图;
- torch.fx.Node.append/prepend调整节点在链表中的拓扑位置;
- torch.fx.Node.args/kwargs是节点的位置参数和关键字参数,赋值时自动维护use-def关系;
- torch.fx.Node.format_node返回节点的可读字符串表示;
- torch.fx.Node.insert_arg在指定位置插入新参数并更新use-def;
- torch.fx.Node.is_impure判断节点是否有副作用,是DCE等优化pass的判断依据;
- torch.fx.node.map_aggregate对任意嵌套结构(list/tuple/dict)递归应用函数;
- torch.fx.node.map_arg对节点args结构中每个Node递归应用函数;
- torch.fx.Node.next/prev是链表的后继/前驱指针属性;
- torch.fx.Node.normalized_arguments将节点args+kwargs按函数签名规范化为统一格式;
- torch.fx.Node.replace_all_uses_with将所有引用当前节点处替换为另一节点。
- 核心特性:上述15个API均为纯框架层图操作逻辑,操作对象是torch.fx.Graph的节点结构(Node链表、args/kwargs参数列表、use-def依赖关系等Python对象),不直接触发任何CPU/GPU/NPU硬件算子,不涉及Tensor数据的读写或设备相关计算,与计算设备完全解耦。其中torch.fx.node.map_aggregate是唯一一个以Tensor作为被操作数据的API(将函数递归应用于嵌套结构中的每个Tensor),其余14个API均在图结构层面工作,无论底层硬件为何均行为一致。
- NPU适配意义:torch.fx是PyTorch模型编译、图变换、量化、算子融合等核心优化流程的基础设施,在NPU环境下的模型编译与推理优化中被广泛调用。验证上述API在NPU环境下的行为一致性,可确保基于torch.fx构建的图变换pass、自定义优化器、模型导出工具在昇腾NPU上与CPU/GPU环境行为完全一致,避免因图操作层的隐性差异导致NPU上的模型编译失败或优化结果不符合预期。

二、测试用例完备性说明

(一)以下API在PyTorch官方test/test_fx.py中有对应测试函数,且用例全程操作的是图结构对象(Node/Graph),不创建也不执行任何Tensor计算,与设备完全无关,天然兼容NPU环境:

| API | 测试文件 | 测试函数 |
| ---- | ---- | ---- |
| torch.fx.Node.all_input_nodes | test/test_fx.py | test_all_input_nodes |
| torch.fx.Node.append | test/test_fx.py | test_wrong_topo |
| torch.fx.Node.args | test/test_fx.py | test_reassign_args_kwargs_uses |
| torch.fx.Node.format_node | test/test_fx.py | test_pretty_print_node |
| torch.fx.Node.insert_arg | test/test_fx.py | test_insert_arg |
| torch.fx.Node.prepend | test/test_fx.py | test_prepend_does_not_leak, test_prepend_self |
| torch.fx.Node.replace_all_uses_with | test/test_fx.py | test_remove_uses, test_remove_uses_with_custom_filter |

各测试函数无Tensor计算的具体依据:

- test_all_input_nodes:仅调用graph.placeholder/call_module/get_attr/call_function建立图结构,用assertEqual验证all_input_nodes列表内容,无Tensor创建。
- test_wrong_topo:通过nodes[3].append(nodes[2])制造拓扑错误,验证graph.lint()抛出RuntimeError,无Tensor创建。
- test_reassign_args_kwargs_uses:通过Proxy构建图后直接对node.args赋值,验证users字典同步更新,无Tensor创建或执行。注:该函数只操作node.args,未对node.kwargs做任何赋值或断言。
- test_pretty_print_node:对symbolic_trace的图调用format_node(),用FileCheck验证字符串内容;torch.rand(3,4)仅为Module初始化参数,symbolic_trace不执行真实计算。
- test_insert_arg:torch.tensor(0)仅作为torch.nn.Buffer初始值,全程只验证len(output_node.args)、a.users等图结构属性,无任何模型执行。
- test_prepend_does_not_leak:验证节点删除后weakref失效(内存释放),无Tensor计算。
- test_prepend_self:验证b.prepend(b)后图节点数不变,无Tensor计算。
- test_remove_uses / test_remove_uses_with_custom_filter:验证replace_all_uses_with后users字典变化,无Tensor计算。

(二)PyTorch官方有用例且需要NPU适配的API

- torch.fx.node.map_aggregate
  用例文件:test/dynamo/test_functions.py
  测试函数:test_fx_map_aggregate(直接覆盖)
  用例中创建torch.randn(4)并执行y * 2乘法计算,同时通过torch.compile编译执行,Tensor是核心被测对象,需迁移到NPU。

以下2个API在官方测试中有Tensor计算,但经实际验证确认无需NPU适配:

- torch.fx.Node.is_impure
  用例文件:test/fx/test_dce_pass.py
  测试函数:test_impure_nodes_args、test_impure_kwargs、test_impure_custom
  is_impure()是纯Python属性判断(判断节点是否有副作用),与设备无关。测试中的m(*inputs)是验证DCE变换前后模型输出一致的兜底验证,不是验证is_impure本身的NPU行为。
  实际运行原始社区用例(CPU),三个测试函数全部通过,无需NPU适配。
  运行命令:
  python -m unittest \
    fx.test_dce_pass.TestDCE.test_impure_nodes_args \
    fx.test_dce_pass.TestDCE.test_impure_kwargs \
    fx.test_dce_pass.TestDCE.test_impure_custom -v
  运行结果:Ran 3 tests / OK

- torch.fx.Node.normalized_arguments
  用例文件:test/test_fx_experimental.py
  测试函数:test_normalize_modules_exhaustive
  normalized_arguments将节点args+kwargs按函数签名规范化,为纯Python图操作,与设备无关。测试中的traced(*inputs)/mod(*inputs)是归一化变换后的兜底验证,不是验证normalized_arguments的NPU行为。尝试迁移到NPU时,因穷举所有torch.nn模块触发了两类无关报错:
  (1)PadV3算子库未加载(含padding的卷积模块)
  (2)complex128 dtype不支持aclnnIsClose(复数类模块)
  两个报错均与torch.fx.Node.normalized_arguments无关,证明Tensor是配角。
  社区原有CPU测试已充分覆盖该API全部功能,无需NPU适配。

(三)PyTorch官方无用例、需新增用例的API

以下API在PyTorch官方测试目录中无直接测试函数,经全量搜索确认:

- torch.fx.node._type_repr
- torch.fx.Node.kwargs
- torch.fx.node.map_arg
- torch.fx.Node.next
- torch.fx.Node.prev

新增用例文件:test/fx/test_fx_node_api.py
覆盖上述API的核心功能。

三、API适配方案

1. API源码无需修改:上述涉及API均为PyTorch框架层图操作,不涉及NPU kernel开发或算子注册。

2. 情况(一)涉及API:社区原有用例天然兼容NPU环境。

3. 情况(二)涉及API(torch.fx.node.map_aggregate):
   在test_upstream/test/dynamo/test_functions.py.patch中,调用npu(),采用最小化原则,不影响文件内其他测试函数。

4. 情况(三)涉及API:新增test/fx/test_fx_node_api.py,涵盖_type_repr、Node.kwargs(getter/setter/use-def更新)、map_arg(节点收集/非节点穿透/嵌套结构/callable校验)、Node.next/prev(基本顺序/append-prepend后的顺序变化/next-prev一致性)。上述API均为纯图结构/字符串操作,不涉及Tensor,无需设备适配。

# 【资料变更】
已检查API支持清单。变更如下:

(1)以下涉及API在文档中已有记录但标注为"否",本次更正为"是":
torch.fx.Node.all_input_nodes、torch.fx.Node.args、torch.fx.Node.kwargs、
torch.fx.Node.next、torch.fx.Node.prev

(2)以下涉及API在文档中完全缺失,本次新增记录("是"):
torch.fx.node._type_repr、torch.fx.Node.insert_arg、
torch.fx.node.map_arg、torch.fx.node.map_aggregate

# 【接口变更】
不涉及

# 【功能验证】
验证环境如下
操作系统:Ubuntu
昇腾硬件:800I A2
CANN软件版本:8.5.0
2.7.1:torch 2.7.1+cpu   / torch-npu 2.7.1.post2
2.9.0:torch 2.9.0+cpu   / torch-npu 2.9.0
2.10.0:torch 2.10.0+cpu / torch-npu 2.10.0rc2
2.11.0:torch 2.11.0+cpu / torch-npu 2.11.0rc3
2.12.0:torch 2.12.0+cpu / torch-npu 2.12.0rc1

运行命令与结果:

```log
(test27) [root@4e6c21e2fea3 test]# pip list | grep torch
torch                  2.7.1+cpu
torch_npu              2.7.1.post2
(test27) [root@4e6c21e2fea3 test]# python fx/test_fx_node_api.py
...................
----------------------------------------------------------------------
Ran 19 tests in 0.044s

OK
(test29) [root@4e6c21e2fea3 test]# pip list | grep torch
torch                  2.9.0+cpu
torch_npu              2.9.0
(test29) [root@4e6c21e2fea3 test]# python fx/test_fx_node_api.py
...................
----------------------------------------------------------------------
Ran 19 tests in 0.046s

OK
(test210) [root@4e6c21e2fea3 test]# pip list | grep torch
torch                  2.10.0+cpu
torch_npu              2.10.0rc2
(test210) [root@4e6c21e2fea3 test]# python fx/test_fx_node_api.py
...................
----------------------------------------------------------------------
Ran 19 tests in 0.045s

OK
(test211) [root@4e6c21e2fea3 test]# pip list | grep torch
torch                  2.11.0+cpu
torch_npu              2.11.0rc3
(test211) [root@4e6c21e2fea3 test]# python fx/test_fx_node_api.py
...................
----------------------------------------------------------------------
Ran 19 tests in 0.050s

OK
(test212) [root@4e6c21e2fea3 test]# pip list | grep torch
torch                  2.12.0+cpu
torch_npu              2.12.0rc1
(test212) [root@4e6c21e2fea3 test]# python fx/test_fx_node_api.py
...................
----------------------------------------------------------------------
Ran 19 tests in 0.052s

OK
```

# 【CheckList】

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


See merge request: Ascend/pytorch!37791
Co-authored-by: Micke Zhang<18502290727@163.com>



# message auto-generated for no-merge-commit merge:
!37958 merge test-fx-tracer-call-module into master

test(nn): add test for fx.tracer.call_module

Created-by: gcw_cRSfl0he
Commit-by: Micke Zhang
Merged-by: ascend-robot
Description: 
<!--
PR描述模板更新日期:20260203
-->
# 【合入来源】
[[Usage]: pytorch社区用例缺少对torch.fx.Tracer.call_module的测试,在现有test/fx/test_fx_tracer_transformer_api.py中补充用例验证NPU正确性 ](https://gitcode.com/Ascend/pytorch/issues/2245)

# API 功能
## API:
torch.fx.Tracer.call_module
## 功能:
`Tracer.call_module` 是 PyTorch FX 符号追踪(Symbolic Tracing)过程中的核心钩子函数之一,它充当了模块调用行为与 FX 计算图节点之间的转换桥梁。`torch.fx.Tracer.call_module` 的主要职责是在追踪(Trace)阶段,拦截对 `nn.Module `子模块的调用操作,并将其转化为计算图(Graph)中的一个 call_module 节点。在 PyTorch FX 的设计中,Tracer 通过该方法完成模块调用的符号化记录,确保模型中的子模块调用能够被正确转换为计算图节点,同时保留模块名称、参数传递、节点依赖等关键信息,为后续计算图优化、代码生成、模型转换等流程提供可靠的结构支撑,是 FX 追踪流程中模块调用节点生成的核心环节。

# 【修改方案】
一、追加到现有文件而非新建

test/fx/test_fx_tracer_transformer_api.py 已是 Tracer/Transformer API 的聚合测试文件(含 trace、path_of_module、iter、keys、proxy、to_bool、getattr 等),fx.Tracer.call_module 同属 Tracer 方法,追加到该文件中可避免文件碎片化,便于后期维护。

二、在test/fx/test_fx_tracer_transformer_api.py中追加用例进行全场景、全维度、全覆盖测试。
主要内容包含setUp → 初始化 Tracer / Graph、_create_placeholder → 工具函数、13 个完整测试用例。
新增 TestTracerCallModule测试用例说明表
| 测试函数名 | 功能描述 |
| :--- | :--- |
| setUp | 初始化 Tracer、空计算图与根模块,为每个用例提供独立运行环境 |
| _create_placeholder	工具函数 | 创建图占位节点并返回 Proxy,简化用例编写|
| test_call_module_creates_node_in_graph | 验证 call_module 可合法创建图节点并插入计算图 |
| test_call_module_returns_proxy_with_correct_node | 验证返回合法 Proxy,节点类型、目标名称正确 |
| test_call_module_preserves_positional_args | 验证多位置参数能正确绑定到节点 args |
| test_call_module_preserves_kwargs | 验证关键字参数能正确保留到节点 kwargs |
| test_call_module_chains_multiple_calls | 验证多模块连续调用,节点依赖关系正确 |
| test_call_module_same_module_multiple_times | 验证同一模块多次调用生成独立节点 |
| test_call_module_with_nested_module_path | 验证嵌套模块路径解析正确 |
| test_call_module_with_sequential_indexing | 验证 Sequential 容器索引调用正常 |
| test_call_module_result_can_be_used_in_operations | 验证 call_module 输出可参与符号计算 |
| test_call_module_with_different_module_types | 验证多类常见模块(Linear/Conv2d/ReLU 等)兼容调用|
| test_call_module_graph_contains_only_call_module_nodes | 验证纯手动构建图无冗余节点 |
| test_call_module_module_must_be_registered | 验证未注册模块会抛出预期异常 |
| test_call_module_with_single_arg | 验证单参数调用场景参数绑定正确 |
| test_call_module_preserves_output_for_further_tracing | 验证构建的图可执行且计算结果正确 |

三、NPU适配
```
1、纯 Python 层抽象,无硬件相关逻辑
call_module API 仅负责「模块调用 → call_module 图节点」的符号映射,是纯逻辑层接口,不涉及任何硬件相关计算、内存、通信。
2、无底层算子 / 内核依赖
API 内部仅处理模块路径、参数代理、节点创建等图结构逻辑,不依赖 NPU/CUDA 相关扩展、驱动或算子内核。
3、核心逻辑与硬件解耦
- 模块调用解耦:只记录 “调用哪个子模块、传入什么参数”,不执行真实计算
- 参数传递解耦:无论输入是 CPU / NPU Tensor,节点生成逻辑完全一致
- 图结构解耦:生成节点仅保存符号信息,不携带设备标识
4、图构建上下文解耦
Tracer、Graph、root module 均为 FX 纯 Python 抽象,与硬件无关;
call_module 只做符号记录,不执行设备相关内存分配或算子下发。
5、测试验证的硬件无关性体现
- 所有用例均可在 NPU 环境稳定运行:
- NPU 张量输入不影响 call_module 节点生成规则
- 模块、代理、图结构在 NPU 上行为与标准环境完全一致
- 无需针对 NPU 修改任何 API 逻辑
简言之,call_module 是硬件无关的纯 Python 层图构建 API,核心逻辑不耦合任何特定硬件,因此在昇腾 NPU 上可直接复用、无需修改。
```

# 【资料变更】
已经在 https://gitcode.com/Ascend/pytorch/treeN2.7.1/docs/zh/native apis 的文档中进行查找与验证。该目录下的pytorch.2-7.1至pytorch.2-12-0文件夹下的torch-fx.md已经对"torch.fx.Tracer.call_module"全部标注"是"。无需更改。

![image.png](https://raw.gitcode.com/user-images/assets/7404318/311b336e-2774-487b-8d12-acab61bcee34/image.png 'image.png')

![image.png](https://raw.gitcode.com/user-images/assets/7404318/4a070c76-216e-4c3a-b014-9be3d84d77da/image.png 'image.png')

![image.png](https://raw.gitcode.com/user-images/assets/7404318/5bd8746a-d332-4427-bad5-e30ddb1c95af/image.png 'image.png')

![image.png](https://raw.gitcode.com/user-images/assets/7404318/dd466868-6acf-4266-b1ff-9d561fb0398f/image.png 'image.png')

![image.png](https://raw.gitcode.com/user-images/assets/7404318/935769ce-d2ec-4984-8b74-3648d0d2eb26/image.png 'image.png')

# 【接口变更】
> 不涉及

# 【功能验证】
## 测试文件路径
test/fx/test_fx_tracer_transformer_api.py
## 验证环境
对应版本:torch-npu 2.10.0
操作系统:AlmaLinux 8.10
CANN 软件版本:8.5.0
安装的软件版本:torch、torch-npu 2.10.0
## 验证结果
```
[root@b33ba4bec663 test]# python -m pytest fx/test_fx_tracer_transformer_api.py::TestTracerCallModule -v
=================================================================== test session starts ===================================================================
platform linux -- Python 3.11.13, pytest-9.0.2, pluggy-1.6.0 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /home/ph/pytorch
configfile: pyproject.toml
collected 14 items                                                                                                                                        

fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_chains_multiple_calls PASSED                                           [  7%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_creates_node_in_graph PASSED                                           [ 14%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_graph_contains_only_call_module_nodes PASSED                           [ 21%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_module_must_be_registered PASSED                                       [ 28%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_preserves_kwargs PASSED                                                [ 35%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_preserves_output_for_further_tracing PASSED                            [ 42%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_preserves_positional_args PASSED                                       [ 50%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_result_can_be_used_in_operations PASSED                                [ 57%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_returns_proxy_with_correct_node PASSED                                 [ 64%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_same_module_multiple_times PASSED                                      [ 71%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_with_different_module_types 
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_with_different_module_types PASSED                                     [ 78%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_with_nested_module_path PASSED                                         [ 85%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_with_sequential_indexing PASSED                                        [ 92%]
fx/test_fx_tracer_transformer_api.py::TestTracerCallModule::test_call_module_with_single_arg PASSED                                                 [100%]

==================================================================== warnings summary =====================================================================
../../../../opt/_internal/cpython-3.11.13/lib/python3.11/site-packages/torch/jit/_script.py:365: 14 warnings
  /opt/_internal/cpython-3.11.13/lib/python3.11/site-packages/torch/jit/_script.py:365: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 14 passed, 14 warnings, 5 subtests passed in 8.73s ====================================================
[root@b33ba4bec663 test]# 
``` 
## 结果说明
测试用例执行通过。

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

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

See merge request: Ascend/pytorch!37958
Co-authored-by: zhaoyu65<nanzhaogang@qq.com>



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

torch_npu support configure NPUAllocator via PYTORCH_ALLOC_CONF

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

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

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

# 【修改方案】
参考设计文档[#1935](https://gitcode.com/Ascend/pytorch/issues/1935) 

这次重构使 NPU 内存分配器的配置系统与 PyTorch 通用的 `AcceleratorAllocatorConfig` 机制对齐:

1. **避免重复实现**:通用配置项(如 `max_split_size_mb`、`garbage_collection_threshold`、`expandable_segments` 等)统一由 `AcceleratorAllocatorConfig` 处理,减少了代码冗余
2. **保持 NPU 特性**:NPU 专属配置项(如 `pin_memory_expandable_segments`、`pinned_mem_register`、`base_addr_aligned_kb` 等)仍由 `NPUAllocatorConfig` 自行管理
3. **统一环境变量入口**:用户可以通过 `PYTORCH_ALLOC_CONF`(PyTorch 标准)或 `PYTORCH_NPU_ALLOC_CONF`(NPU 专用)来配置内存分配行为,两者会自动同步
4. **支持 Hook 注册机制**:通过 `REGISTER_ALLOCATOR_CONFIG_PARSE_HOOK` 宏,使 NPU 配置能够接入 PyTorch 通用的配置解析框架

保证修改前后的逻辑一致:
1、所有配置的读取,统一调用NPUAllocatorConfig实例读取,可以通过日志观察到值。PTA代码中除了NPUAllocatorConfig外其他地方没有调用AcceleratorAllocatorConfig。
2、所有配置的写入(变更),统一在NPUAllocatorConfig::parseArgs函数实现。而该函数在NPUAllocatorConfig实例化时和setAllocatorConfig两个地方调用,都有日志记录。保证变更能观察到。

# 【资料变更】
资料在后续PR中修改

# 【接口变更】
不涉及

# 【功能验证】
验证查看配置是否生效,验证结果为PASS。
```shell
export PYTORCH_NPU_ALLOC_CONF=max_split_size_mb:18446744073709551615,garbage_collection_threshold:0.611,roundup_power2_divisions:16,expandable_segments:False,pinned_use_background_threads:True,large_segment_size_mb:777777777,pin_memory_expandable_segments:True,pinned_mem_register:True,base_addr_aligned_kb:14,page_size:1g,segment_size_mb:40,multi_stream_lazy_reclaim:True,pinned_reserve_segment_size_mb:48,per_process_memory_fraction:0.7777
```

![image.png](https://raw.gitcode.com/user-images/assets/7404318/0e4ce326-e38d-4094-bd99-63021d27bd0b/image.png 'image.png')

```shell
export PYTORCH_ALLOC_CONF=max_split_size_mb:18446744073709551615,garbage_collection_threshold:0.611,roundup_power2_divisions:16,expandable_segments:False,pinned_use_background_threads:True,large_segment_size_mb:777777777,pin_memory_expandable_segments:True,pinned_mem_register:True,base_addr_aligned_kb:14,page_size:1g,segment_size_mb:40,multi_stream_lazy_reclaim:True,pinned_reserve_segment_size_mb:48,per_process_memory_fraction:0.7777
```
![image.png](https://raw.gitcode.com/user-images/assets/7404318/58c89d66-c081-44ee-bf02-af05cb2edff0/image.png 'image.png')

验证代码修改前后对网络精度的影响,验证结果为PASS
在qwen3-8b模型上做微调,前后loss对比结果一致。

```text
修改前:
 [2026-06-09 21:01:38] iteration       20/      20 | consumed samples:          320 | elapsed time per iteration (ms): 3675.3 | learning rate: 1.320656E-07 | global batch size:    16 | lm loss: 1.260875E+00 | loss scale: 1.0 | grad norm: 4.908 | num zeros: 0 | number of skipped iterations:   0 | number of nan iterations:   0
修改后:
 [2026-06-09 21:42:52] iteration       20/      20 | consumed samples:          320 | elapsed time per iteration (ms): 3640.7 | learning rate: 1.320656E-07 | global batch size:    16 | lm loss: 1.260875E+00 | loss scale: 1.0 | grad norm: 4.908 | num zeros: 0 | number of skipped iterations:   0 | number of nan iterations:   0 
 ```
 
 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/8a3a123f-cadb-46f0-b0a4-e88db636c1db/image.png 'image.png')
 plog日志:
 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/92e56222-dcb8-40d6-ae8e-2f75c20a8141/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!33621
Co-authored-by: fengyixing<fengyixing@huawei.com>



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

op_plugin ut exclude common npu files among branches

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

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

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

# 【修改方案】
> 1.在ci_gitcode仓库中维护一个重复用例名的文件,在op-plugin流水线执行时,如果PTA分支不是master,将文件拷贝到PTA的代码中
> 2.在PTA执行用例时,判断文件是否存在,如果文件存在,则在筛选完要执行的用例之后,排除这个文件中维护的用例名

# 【资料变更】
> 不涉及

# 【接口变更】
> 不涉及

# 【功能验证】
> 在PTA识别文件的测试中,先在PR中手动创建一个文件,验证文件在流水线中是否生效
>在ci_gitcode拷贝这个文件的测试中,验证是否拷贝到了指定位置

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

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


See merge request: Ascend/pytorch!37665
Co-authored-by: wanlinan<wanlinan@huawei.com>



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

[fix]add Ascend910_9392 in batch_isend_irecv supported_device_name

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

# 【合入来源】
[[Bug]: group下发send/recv的机器限制导致9392机型走不到新特性下](https://gitcode.com/Ascend/pytorch/issues/2344)

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

# 【修改方案】
已和HCCL确认Ascend910_9392 机型支持group下发send/recv,在机型条件判断中加入该机型。

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
无

# 【CheckList】

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


See merge request: Ascend/pytorch!38073
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!38139 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-06-10 18:02:21.

See merge request: Ascend/pytorch!38139
Co-authored-by: hehongzhe<935062458@qq.com>



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

[feat]profiler remove safe interrupt

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

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

- [x] 需求
- [ ] 问题单
- [x] issue/工单

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

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

- [ ] 重构优化
- [ ] 资料更新

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

安全易用性提升,逐步清理可清理的一些安全校验

1、去除权限、属主校验的打断
2、去除软链接校验的打断
3、去除文件路径长度校验的打断
4、去除export_chrome_trace对.json结尾的校验

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

不涉及,原有的安全声明里面没有提到这些相关的内容

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

不涉及,都是内部校验接口

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

![image.png](https://raw.gitcode.com/user-images/assets/7404318/c452b8ab-edaa-4868-8f17-91f4c1d57076/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!38141
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!38179 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-06-10 22:02:00.

See merge request: Ascend/pytorch!38179
Co-authored-by: s50057208<shiyunhan1@huawei.com>



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

docs:修改镜像tag表述

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

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

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

# 【修改方案】
修改镜像tag表述对齐,以及英文版不恰当表述

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

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

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

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

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


See merge request: Ascend/pytorch!37533
Sean1840 and others added 28 commits July 14, 2026 19:07
Co-authored-by: Seanesmhxocism<617225691@qq.com>



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

【fix】【PROFILING】set gc.disable in analysis subprocesses

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

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

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

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

在进程拉起时,关闭子进程中的gc能力。避免在子进程中触发gc,和fork产生冲突

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

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

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

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

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


See merge request: Ascend/pytorch!41600
Co-authored-by: zhaoyu65<nanzhaogang@qq.com>



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

support irq bind

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

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

- [x] 需求
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新
[#2139](https://gitcode.com/Ascend/pytorch/issues/2139) 
# 【修改方案】
1、在环境变量CPU_AFFINITY_CONF中新增选项bind_irq;
2、对指定NPU的irq中断绑核,独占2个CPU核

# 【资料变更】
后续在2.7.1分支合入资料

# 【接口变更】
环境变量CPU_AFFINITY_CONF中新增选项bind_irq;

# 【功能验证】
验证OK

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

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


See merge request: Ascend/pytorch!39977
Co-authored-by: chenshuai<chenshuai81@huawei.com>



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

[fix] npu_praph err

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

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

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

# 【修改方案】
to_copy_的默认逻辑变更后,Npu_graph此处调用可能导致触发copy_h2h,进而导致aclgraph入图失败,需要显式的指定contiguous_format

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
相关自动化脚本已通过
![image.png](https://raw.gitcode.com/user-images/assets/7404318/4d938680-e223-4245-8fa1-c835cf642d2e/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!41470
Co-authored-by: bellatan<tanmei2@huawei.com>



# message auto-generated for no-merge-commit merge:
!40571 merge 0706_docs into master

fix doc for fuse_add_softmax_dropout

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

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

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

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

# 【修改方案】
| api名字 | 文档 | 问题 | 修改处 |
|---|---|---|---|
| `torch_npu.contrib.function.fuse_add_softmax_dropout` | `fuse_add_softmax_dropout.py` | docstring 示例代码把第五个入参写成 `alpha`,与接口参数 `attn_head_size` 不一致;调用中把 `p` 误传为 `axis`,且缺少 `dim=axis`,示例会误导用户。 | `alpha = 0.125` 改为 `attn_head_size = 64`;调用参数 `alpha, p=axis` 改为 `attn_head_size, p=0.1, dim=axis`。 |

# 【资料变更】
修改内容如【修改方案】展示

# 【接口变更】
不涉及

# 【功能验证】
ci pass

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

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


See merge request: Ascend/pytorch!40571
Co-authored-by: cuiduo<cuiduo1@huawei.com>



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

Fix NPU inductor while_loop lowering on PyTorch 2.13

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

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

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

# 【修改方案】
修复 PyTorch 2.13 上 NPU inductor 对 `while_loop` / `while_loop_stack_output` 高阶算子(HOO)lowering 缺失问题:原先这两个 HOO 没有专用 lowering,落入 auto-fallback,反向(`while_loop_backward`)会触发 `Subgraph` 走 `FallbackKernel` 路径并报 `'Subgraph' object has no attribute 'get_traced_graph'`。本 PR 为其注册专用 lowering 并从 fallback 排除表里放出,涉及 3 个文件:

1. `torch_npu/_inductor/ascend_npu_ir/ascend_npu_ir/npu/inductor_patch/lowering.py`
   - 改写 `while_loop` lowering:新增 `stack_output: bool = False` 参数并透传给 `ir.WhileLoop.create(...)`,输出改用 `ir.WhileLoop._maybe_wrap_as_tensor_box` 包装,并对返回值 `assert isinstance(result, Sequence)`。
   - 新增 `while_loop_stack_output` lowering 注册:`register_lowering(torch.ops.higher_order.while_loop_stack_output)(functools.partial(while_loop, stack_output=True))`,复用 `while_loop` 实现(与上游 `torch/_inductor/lowering.py` 写法一致),补上之前缺失的 `while_loop_stack_output` lowering。
   - 删除冗余的旧 `@register_lowering(aten.rsqrt) def rsqrt` 块(被后续 `rsqrt = register_pointwise_numeric(aten.rsqrt)` 经 `register_pointwise→register_lowering` 覆盖,属死代码)。
   - 顺带 lint 清理:`merge_traced_graphs` 多行格式、注释拼写(`Implmented→Implemented`、`splitted→split`)、未用 import 清理、`_low_memory_max_pool2d_offsets_to_indices` 加 `# noqa: F821`(forward-port 待补)。

2. `torch_npu/_inductor/dvm/mlir_fusion.py`
   - DVM 模式下 `anir_config.GENERATE_LIST`(fallback 排除表)加入 `torch.ops.higher_order.while_loop` 与 `while_loop_stack_output`,使其在 DVM 下不被 `make_fallback` 覆盖,保留下方注册的专用 lowering 生效。

3. `torch_npu/utils/_dynamo.py`
   - 新增 `register_npu_graphsafe_rng()`:调用上游 `register_graphsafe_rng_device_type("npu")`,将 NPU 注册进 GraphSafe RNG(与 CUDA 同契约),保证含 RNG 的反向图(如 while_loop backward)在 graph 模式下正确保存/恢复 RNG 状态;在 `add_dynamo_methods()` 中触发。

# 【资料变更】
不涉及

# 【接口变更】
不涉及(仅 inductor 内部 lowering/注册逻辑,不改变对外 API)

# 【功能验证】
![image.png](https://raw.gitcode.com/user-images/assets/7404318/ec790740-b864-4120-a9fd-5ad0e0ffce3f/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!41523
…C0格式的转换。

Co-authored-by: xiaoqi-zhou<zhouxiaoqi9@h-partners.com>



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

在A5环境上输入数据类型是int类型时调用tensor.div_加rounding_mode=trunc;在A5环境跳过ND->NC1HWC0格式的转换。

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

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

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

# 【修改方案】
1. aclnnNpuFormatCastCalculateSizeAndFormat不支持在A5环境上数据从ND->NC1HWC0格式的转换,需要在A5环境跳过执行这样格式转换的用例。
2. aclnnInplaceDivs在A5环境上不支持输入为int类型的数据除以一个scalar类型的数据,需要在调用tensor.div的位置加上rounding_mode='trunc'

# 【资料变更】
不涉及

# 【接口变更】
不涉及

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

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

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


See merge request: Ascend/pytorch!41481
Co-authored-by: 1479518308<cuiduo1@huawei.com>



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

eager_init_variable_builder_builtin

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

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

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

# 【修改方案】
1. 将 `patch_builtin_variable`(及 v2.9.0 上的 `patch_variable_builder`)从懒触发函数 `add_dynamo_methods_init()`(首次 `torch.compile` 时触发)迁移至 import 期执行的 `add_dynamo_methods()`,确保这两个 Dynamo 内部类 patch 在任何 tracing 启动前就位,避免时序竞态。
2. 在 `patch_dynamo_optimize` 包裹的 `npu_optimize` 首行新增 `add_dynamo_methods_init()` 调用,把懒触发入口从 `torch.compile` 扩展到 `torch._dynamo.optimize` 路径,覆盖不经过 inductor wrapper 的 optimize 调用。
3. `patch_dynamo_optimize` 中 `from torch._dynamo import optimize` + `src_optimize = optimize` 合并为 `src_optimize = torch._dynamo.optimize` 模块内联引用,减少局部名污染。
4. 删除测试文件 `test_aclgraph_update_plan_compile.py` 中未使用的 `import torch_npu._inductor`(其余 `from torch_npu._inductor.* import` 自动导入父包,无影响)。

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
- 验证场景:`torch.compile` 与 `torch._dynamo.optimize(backend="npu")` 两条编译入口均能正确触发 NPU dynamo patch 初始化。
- 验证方法:复用 `test/_inductor` 下既有 dynamo/inductor UT 用例看护,重点跑 `test_aclgraph_update_plan_compile.py` 及 dynamo trace 相关用例。
- UT 看护:本次为 patch 执行时机重构,无新增对外行为,由既有 UT 覆盖;已自验证 `import torch_npu` 后 `patch_builtin_variable` 在 eager 阶段生效。

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


See merge request: Ascend/pytorch!41623
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!40587 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-07-09 18:03:04.

See merge request: Ascend/pytorch!40587
Co-authored-by: liujunzhu<liujunzhu@huawei.com>



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

[fix] fix memory config testcase

Created-by: liujunzhu
Commit-by: liujunzhu
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能力等内容)

修复 `throw_on_npumalloc_oom` 、 `pinned_max_round_threshold_mb` 和 `pinned_max_cached_size_mb`的用例问题。

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

不涉及

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

不涉及

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

通过CI验证。

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

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


See merge request: Ascend/pytorch!41705
Co-authored-by: 车云飞<842934933@qq.com>



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

fix:修复示例代码中的index_put错误,示例代码中变量x1结果是0,非预期

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

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

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

# 【修改方案】
1、修改示例代码
当前代码:
x1 = copy.deepcopy(x)[condition] = value

实际应为:
x1 = copy.deepcopy(x)
x1[condition] = value

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
本次修改仅针对示例代码中的pytorch原生index_put操作示例,测试通过
![image.png](https://raw.gitcode.com/user-images/assets/7404318/88dd1abc-0544-4d5f-b41d-7d91d7fbb082/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!40174
Co-authored-by: huawuyi<liuxuehui4@huawei.com>



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

fix: catch AKG runtime errors during accuracy compare and fallback to FX

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

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

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

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

# 【修改方案】
1、添加了akg后端在launch的时候若失败则fallback的逻辑

# 【资料变更】
不涉及

# 【接口变更】
不涉及

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

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

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


See merge request: Ascend/pytorch!41758
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41569 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-07-14 10:02:11.

See merge request: Ascend/pytorch!41569
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41778 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-07-15 18:02:39.

See merge request: Ascend/pytorch!41778
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41784 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-07-15 22:02:35.

See merge request: Ascend/pytorch!41784
Co-authored-by: xiu_21<caixiuxiu1@huawei.com>



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

fix: add PyObject_ClearWeakRefs in NPU Stream/Event tp_dealloc

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

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

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

# 【修改方案】
PyTorch 基础类 THPStream / THPEvent 中增加了 weakref 支持(添加了 weakreflist 字段),但 NPU 后端的 tp_dealloc 覆盖函数未同步更新。
CPython 对静态 PyType 不会自动链式调用父类 tp_dealloc,因此 THNPEvent_dealloc 和 THNPStream_dealloc 一直缺少:
  1. PyObject_ClearWeakRefs() — 未清理 weakref,导致 wr_object 悬空指向已释放内存
  2. Py_CLEAR(self->context)(仅 Stream)— lazy stream context 泄漏

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
pytest test/dynamo/test_stream.py -k test_npu_stream_event_weakref_callback
修改前:
![ScreenShot_20260714192241.JPG](https://raw.gitcode.com/user-images/assets/7404318/a55781d3-7477-4919-9ec9-b31c1cdd3975/ScreenShot_20260714192241.JPG 'ScreenShot_20260714192241.JPG')
修改后:
![ScreenShot_20260714192439.JPG](https://raw.gitcode.com/user-images/assets/7404318/2eb3df91-cbc7-4f2c-8088-01b80d296e8f/ScreenShot_20260714192439.JPG 'ScreenShot_20260714192439.JPG')

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

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


See merge request: Ascend/pytorch!41736
Co-authored-by: pianyl<pianyaolong@huawei.com>



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

[refactor]decomp_master

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

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

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

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

对decomposition代码进行重构,将原先两个文件中的decomp逻辑都合并至torch_npu_inductor\decomposition.py文件,并提取公共注册函数。重构不改变原注册函数调用点。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

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

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

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

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

See merge request: Ascend/pytorch!40557
Co-authored-by: wang_ziqi<wangziqi4@huawei.com>



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

Add compatible key config query

Created-by: wang-ziqi-code
Commit-by: wang_ziqi
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/2853
- [ ] 问题单
- [ ] issue/工单
- [ ] 重构优化
- [ ] 资料更新

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

1. 新增 `CompatibleKey`,当前支持 `CompatibleKey::Randomness`,用于标识 API 级 compatible 配置项。
2. 新增环境变量 `TORCH_NPU_LEGACY_IMPL_LIST`,用于配置需要使用 legacy 实现的 compatible key。
3. 新增 `CompatibleConfig`,记录 `compatible_impl_black_list`,配置在首次查询 compatible config 时初始化并缓存。
4. 新增 `CheckCompatibleImplBlackListFor(CompatibleKey key)`,用于查询指定 key 是否命中 compatible impl blacklist。
5. 新增 `CheckCompatibleImplFor(CompatibleKey key)`,用于查询指定 key 的 compatible 状态。若 key 命中 blacklist,则返回 `false`;否则返回现有全局开关 `CheckCompatibleImpl()` 的结果。
6. `TORCH_NPU_LEGACY_IMPL_LIST` 支持逗号分隔、空白裁剪、空 token 忽略和重复 token 去重;key 大小写敏感,当前支持项为 `randomness`。
7. `TORCH_NPU_LEGACY_IMPL_LIST` 配置非法 key 时抛出异常,错误信息包含原始配置、非法 key 和当前支持的 key。
8. compatible config 初始化成功后打印 INFO 日志,记录 `TORCH_NPU_LEGACY_IMPL_LIST` 解析得到的 blacklist 内容。

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

不涉及。

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

涉及跨仓 C++ 接口和环境变量配置。

新增 C++ 查询接口:

```cpp
enum class CompatibleKey {
    Randomness,
};

bool CheckCompatibleImplFor(CompatibleKey compatible_key);
bool CheckCompatibleImplBlackListFor(CompatibleKey compatible_key);
```

新增环境变量:

```bash
TORCH_NPU_LEGACY_IMPL_LIST=randomness
```

配置含义:`TORCH_NPU_LEGACY_IMPL_LIST` 中配置的 key 使用 legacy 实现;未配置的 key 按现有全局 compatible 开关判断。

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

已执行静态检查:

```bash
git -C pytorch-wzq diff --check HEAD
```

验证场景:

1. 未配置 `TORCH_NPU_LEGACY_IMPL_LIST` 时,`CheckCompatibleImplBlackListFor(Randomness)` 返回 `false`。
2. `TORCH_NPU_LEGACY_IMPL_LIST=randomness` 时,`CheckCompatibleImplBlackListFor(Randomness)` 返回 `true`。
3. `TORCH_NPU_USE_COMPATIBLE_IMPL=1` 且 `TORCH_NPU_LEGACY_IMPL_LIST=randomness` 时,`CheckCompatibleImplFor(Randomness)` 返回 `false`。
4. `TORCH_NPU_USE_COMPATIBLE_IMPL=1` 且未配置 `TORCH_NPU_LEGACY_IMPL_LIST` 时,`CheckCompatibleImplFor(Randomness)` 返回 `true`。
5. `TORCH_NPU_LEGACY_IMPL_LIST=" randomness,,randomness "` 时,空 token 忽略,重复 token 去重,`randomness` 生效。
6. `TORCH_NPU_LEGACY_IMPL_LIST=foo` 或 `TORCH_NPU_LEGACY_IMPL_LIST=Randomness` 时,首次查询抛出配置错误异常。

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

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


See merge request: Ascend/pytorch!41742
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41857 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-07-16 18:02:34.

See merge request: Ascend/pytorch!41857
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41895 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-07-16 22:02:36.

See merge request: Ascend/pytorch!41895
Co-authored-by: huangchengnuo<huangchengnuo1@huawei.com>



# message auto-generated for no-merge-commit merge:
!41824 merge dvm-graph-mode-master into master

[refactor][master] Refactor DVM Inductor configuration

Created-by: SorryNaCN
Commit-by: huangchengnuo
Merged-by: ascend-robot
Description: # 【合入来源】
> (如有)请关联需求文档/issue链接

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

图模式增强:Fixes https://gitcode.com/Ascend/pytorch/issues/1962

# 【修改方案】

1. 新增 `torch_npu/_inductor/dvm/config.py`,集中定义 DVM 图模式配置,并说明各配置项用途。
2. 新增 `NpuDvmKernel` 和 `NpuDvmScheduling`,继承 MLIR 实现,通过 `meta_kernel_type` 和 DVM backend 注册接入图模式,移除对 MLIR 类方法的 monkey patch。
3. 保留原有 MLIR backend 注册流程;DVM 模块加载后注册 `NpuDvmScheduling`,使 DVM 图模式使用专属 scheduling。
4. 统一 view-load、FX case 和图融合路径的配置使用方式;生成的 FX case 显式关闭 `dump_fx_test`,避免递归生成。
5. 更新 `third_party/dvm/dvm` 至 r2.10 最新提交。

# 【资料变更】

不涉及

# 【接口变更】

不涉及

# 【功能验证】

已执行:

```bash
python3 -m py_compile torch_npu/_inductor/dvm/__init__.py torch_npu/_inductor/dvm/config.py torch_npu/_inductor/dvm/fx_test.py torch_npu/_inductor/dvm/graph_build.py torch_npu/_inductor/dvm/graph_fusion.py torch_npu/_inductor/dvm/mlir_fusion.py torch_npu/_inductor/dvm/util.py
git diff --check
```

# 【CheckList】

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

See merge request: Ascend/pytorch!41824
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41916 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-07-17 10:02:23.

See merge request: Ascend/pytorch!41916
Co-authored-by: ylw1234<lwying007@126.com>



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

Bugfix: add tuple support for device_ids in transfer_to_npu

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

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

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

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

问题: _wrapper_cuda 和 _patch_nametuple 对 device_ids 只处理了 list 类型,tuple 类型会被跳过,cuda→npu 替换不生效。

修复: 在两处各新增 elif isinstance(device_ids, tuple) 分支,将 tuple 转 list 做替换后再转回 tuple 写回 kwargs。同时将 type() is list 改为 isinstance() ,并修复局部变量未回写 kwargs 的 bug。
# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

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

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

![image.png](https://raw.gitcode.com/user-images/assets/7404318/a470a1ba-c0bd-4b49-aed8-3c12b21d342d/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!41521
Co-authored-by: LG<luguang6@huawei.com>



# message auto-generated for no-merge-commit merge:
!40570 merge migrate-benchmarks-v2.7.1-to-master into master

migrate-benchmarks-to-master

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

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

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

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

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

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

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

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

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


See merge request: Ascend/pytorch!40570
Co-authored-by: 21xiu<caixiuxiu1@huawei.com>



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

fix: Remove base_sizes vs sizes consistency check in NZ-to-ND fallback

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

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

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

# 【修改方案】
当前判断会影响reshape、transpose、slice等场景正常做formatcast,1D的场景仅保留src_desc.base_sizes_.size() < 2即可。

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
门禁用例均通过

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

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


See merge request: Ascend/pytorch!41883
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41888 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-07-16 22:01:47.

See merge request: Ascend/pytorch!41888
Co-authored-by: liuyutong_bury<liuyutong25@huawei.com>



# message auto-generated for no-merge-commit merge:
!41734 merge feat/empty-strided-npu-fastpath into master

feat(inductor): dispatcher-free _empty_strided_npu fast-path allocation

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

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

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

# 【修改方案】

Add a torch_npu._C._empty_strided_npu binding that mirrors upstream's
_empty_strided_ (CUDA/XPU/MTIA) fast path for inductor-generated
wrappers, bypassing the operator dispatcher.

- InitNpuBindings.cpp: THPModule_empty_strided_npu METH_VARARGS stub that
  parses the (sizes, strides, dtype) 3-tuple directly and calls the native
  factory; registered in TorchNpuMethods.
- TensorFactories.{h,cpp}: TORCH_NPU_API empty_strided_npu — inlines the
  essential empty_strided steps (storage byte-size from size/stride, single
  allocate, set sizes/strides, one SetDesc) without empty({0})'s
  RECORD_FUNCTION / NPURecordFunction guard / 0-byte resize round-trip.

at::empty_strided(device='npu') is dispatched (~2us/alloc). Inductor backward
graphs allocate many buffers per step, so this host overhead dominates; the
fast path removes it while keeping the NPU storage-descriptor setup.

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
#### 基础功能测试
  | 测试用例 | 状态 | 验证功能 |
  |---------|------|---------|
  | `test/npu/test_tensor.py::TestTensor::test_empty_strided` | ✅ PASSED | 基本empty_strided功能、各种shape/stride组合、空tensor处理、storage大小计算正确性 |

  #### API兼容性测试  
  | 测试用例 | 状态 | 验证功能 |
  |---------|------|---------|
  | `test/npu/test_npu.py::TestNpu::test_function_torch_empty_strided` | ✅ PASSED | `torch.empty_strided` API、不同dtype支持 |
  | `test/test_tensor_creation_ops.py::TestTensorCreationPRIVATEUSE1::test_empty_strided_npu` | ✅ PASSED | 通用tensor创建、跨设备一致性 |

#### 新增测试用例验证

  新增 `test/npu/test_empty_strided_npu.py` 测试文件,包含9个测试用例全面验证 `_empty_strided_npu` fast path 功能。

  **测试覆盖:**
  - 基础功能、空tensor、多dtype支持 (float32/16, int32/8, uint8, bool)
  - 复杂stride模式、广播stride
  - 确定性计算场景torch.empty_strided一致性验证、Storage大小计算正确性
  - new_empty_strided API集成、@Dtypes装饰器测试

  **测试结果:** 9/9 passed ✅

  **文件信息:**
  - 路径: `test/npu/test_empty_strided_npu.py`
  - 行数: 200行
  - 运行: `pytest test/npu/test_empty_strided_npu.py -v`

  该测试套件确保了inductor NPU内存分配fast path的功能正确性和兼容性。
  
# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

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


See merge request: Ascend/pytorch!41734
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41993 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-07-17 22:02:19.

See merge request: Ascend/pytorch!41993
Co-authored-by: pta-robot<pta_robot@163.com>



# message auto-generated for no-merge-commit merge:
!41980 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-07-17 18:02:44.

See merge request: Ascend/pytorch!41980
@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

yuaiming, thanks for your pull request. All authors of the commits have signed the CLA. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.