已合并
fix: support to_sparse on non-default NPU devices #35947
hz893创建于 5月18日
fix: support to_sparse on non-default NPU devices #35947
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 hz893 的贡献)ascend-robot
5月18日 评论:
5月18日 评论:
ascend-robot
5月18日 评论:
5月18日 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/pytorch | ✅ liujunzhu, chujinjin (2/2) | ✅ liujunzhu (1/1) |
| test | ✅ chujinjin, wanglijun55, liujunzhu (3/2) | ✅ liujunzhu (1/1) |
| torch_npu/csrc/inductor | ✅ liujunzhu, chujinjin (2/2) | ✅ liujunzhu (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
hz893, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月18日 添加了label:ascend-cla/yes
ascend-robot
5月18日 评论:
5月18日 评论:
当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.11.0 | ||
| v2.10.0 | ||
| v2.9.0 | ||
| v2.12.0 |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


5月18日 添加了label:ci-pipeline-running
5月18日 删除了label:ci-pipeline-running
5月18日 添加了label:ci-pipeline-failed
ascend-robot
5月18日 评论:
5月18日 评论:
流水线 PR-pipeline_pytorch#23339 运行失败
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ❌ | >>> |
| Build_ARM | ❌ | >>> | |
| Build_LibTorch_x86 | ❌ | >>> | |
| Build_LibTorch_ARM | ❌ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| 开源片段检查 | SCA | 🕚 | >>> |
| 开发者测试 | UT_X86_Part_01 | 🕚 | >>> |
| UT_X86_Part_02 | 🕚 | >>> | |
| UT_ARM_A3_Part_01 | 🕚 | >>> | |
| UT_ARM_A3_Part_02 | 🕚 | >>> | |
| UT_ARM_A2_Part_01 | 🕚 | >>> | |
| UT_ARM_A2_Part_02 | 🕚 | >>> | |
| UT_ARM_A2_Part_03 | 🕚 | >>> | |
| UT_inductor_Part_01_pool | 🕚 | >>> | |
| UT_inductor_Part_02_pool | 🕚 | >>> | |
| UT_inductor_Part_03_pool | 🕚 | >>> | |
| UT_inductor_Part_04_pool | 🕚 | >>> | |
| UT_DIST_ARM_Part_01 | 🕚 | >>> | |
| UT_DIST_ARM_Part_02 | 🕚 | >>> | |
| UT_DIST_ARM_Part_03 | 🕚 | >>> | |
| UT_DIST_ARM_Part_04 | 🕚 | >>> | |
| 流水线 | PR-pipeline_pytorch | ❌ | >>> |


5月19日 添加了label:stat/needs-squash
ascend-robot
5月19日 评论:
5月19日 评论:
Ascend docs pipeline is running...


5月19日 添加了label:docs-ci-pipeline-running
ascend-robot
5月19日 评论:
5月19日 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


5月19日 删除了label:docs-ci-pipeline-running
5月19日 添加了label:docs-ci-pipeline-success
5月19日 删除了label:ci-pipeline-failed
5月19日 添加了label:ci-pipeline-running
5月19日 删除了label:stat/needs-squash
ascend-robot
5月19日 评论:
5月19日 评论:
Ascend docs pipeline is running...


5月19日 删除了label:docs-ci-pipeline-success
5月19日 添加了label:docs-ci-pipeline-running
ascend-robot
5月19日 评论:
5月19日 评论:
✅ 跳过 docs ci 检查,没有需要检查的文档文件


5月19日 删除了label:docs-ci-pipeline-running
5月19日 添加了label:docs-ci-pipeline-success
5月19日 删除了label:ci-pipeline-running
ascend-robot
5月19日 评论:
5月19日 评论:
流水线 PR-pipeline_pytorch#23468 已终止运行
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | 🟨 | >>> |
| Build_ARM | 🟨 | >>> | |
| Build_LibTorch_x86 | 🟨 | >>> | |
| Build_LibTorch_ARM | 🟨 | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| 开源片段检查 | SCA | 🕚 | >>> |
| 开发者测试 | UT_X86_Part_01 | 🕚 | >>> |
| UT_X86_Part_02 | 🕚 | >>> | |
| UT_ARM_A3_Part_01 | 🕚 | >>> | |
| UT_ARM_A3_Part_02 | 🕚 | >>> | |
| UT_ARM_A2_Part_01 | 🕚 | >>> | |
| UT_ARM_A2_Part_02 | 🕚 | >>> | |
| UT_ARM_A2_Part_03 | 🕚 | >>> | |
| UT_inductor_Part_01_pool | 🕚 | >>> | |
| UT_inductor_Part_02_pool | 🕚 | >>> | |
| UT_inductor_Part_03_pool | 🕚 | >>> | |
| UT_inductor_Part_04_pool | 🕚 | >>> | |
| UT_DIST_ARM_Part_01 | 🕚 | >>> | |
| UT_DIST_ARM_Part_02 | 🕚 | >>> | |
| UT_DIST_ARM_Part_03 | 🕚 | >>> | |
| UT_DIST_ARM_Part_04 | 🕚 | >>> | |
| 流水线 | PR-pipeline_pytorch | 🟨 | >>> |


5月19日 添加了label:ci-pipeline-running
5月19日 删除了label:ci-pipeline-running
5月19日 添加了label:ci-pipeline-passed
ascend-robot
5月19日 评论:
5月19日 评论:
流水线 PR-pipeline_pytorch#23484 已完成
| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01_pool | 🛑 | >>> | |
| UT_inductor_Part_02_pool | 🛑 | >>> | |
| UT_inductor_Part_03_pool | 🛑 | >>> | |
| UT_inductor_Part_04_pool | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |


wanglijun55
5月30日 评论:
5月30日 评论:
/lgtm


liujunzhu
5月30日 评论:
5月30日 评论:
/approve


5月30日 添加了label:approved
6月1日 添加了label:lgtm
6月1日 合入了pull request
ascend-robot
6月1日 评论:
6月1日 评论:
流水线 pytorch_gitcode_PR_multiVersion#9748 [ commitID:9f519489 ] 已完成


【合入来源】
【修改方案】
aten::_to_sparse和aten::_to_sparse.sparse_dim加入 NPU supported 注册,避免 dense NPU Tensor 转 sparse 时走 CPU fallback。_to_sparse实现,复用at::native::dense_to_sparse,使 sparse tensor、indices、values 保持在输入 Tensor 所在 NPU 设备上。npu:1时to_sparse结果的 device 和数值一致性。【资料变更】
不涉及。
【接口变更】
不涉及。
【功能验证】
torch_npu.__version__为2.7.1.post5。aten::_to_sparse和aten::_to_sparse.sparse_dim的PrivateUse1dispatcher 注册到RegisterNPU.cpp [kernel],不再走 CPU fallback。python -m pytest test_ops.py -v -k test_multiple_devices_to_sparse_npu_float32:1 passed。python -m pytest test/test_sparse_coo.py -v -k test_sparse_to_sparse_non_default_npu_device:1 passed。补充验证:
fix_to_sparse_master分支完成编译并安装生成的torch_npu-2.13.0-cp311-cp311-manylinux_2_28_aarch64.whl。aoti_torch_npu__to_sparse,在当前 device 为npu:0、输入 tensor 位于npu:1的场景下验证返回 sparse tensor、indices、values 均保持在npu:1,且to_dense()与输入一致。PASS aoti_torch_npu__to_sparse device=npu:1 nnz=3。【CheckList】