Pull Request已成功合入, 合并人@ascend-robot
(感谢 Xuan Peng 的贡献)变更摘要
该 PR 主要让 NPU Inductor 的 group autotune 分组调优结果能够适配 cpp wrapper 的代码生成路径:NPUSymbolicGroupedAutotuner 在保存 kernel 前把各组胜出候选与各 variant 的加载元信息记录下来,DeferredNpuTritonCallWrapper 在生成 C++ 代码时据此解析分组、计算运行时 block 并生成按分组和 variant 的 switch 分发与加载/启动逻辑,同时只收集实际被选中的 variant 对应的 cubin 文件。新增的测试文件对生成的 C++ 代码内容及动态 shape 下的功能与精度进行了校验。
主要改动
- cpp wrapper 分组代码生成:
DeferredNpuTritonCallWrapper新增_generate_grouped_feature_inputs、_generate_grouped_group_id、_generate_grouped_selection、_generate_grouped_variant_launch等方法,在group_enabled时生成分组特征计算、grouped_group_id解析、switch (grouped_group_id)分发以及运行时 block(如XBLOCK)的resolve_grouped_runtime_block计算逻辑。 - kernel 加载与启动拆分:将原
generate_load_kernel/generate_launch_kernel的单 kernel 逻辑抽出为_generate_single_kernel_load/_generate_single_kernel_launch,并在分组场景下改为先声明各grouped_kernel_<variant_id>静态指针,再按switch (grouped_variant_index)分别加载和启动被选中的 variant。 - 分组计划的元信息记录:
NPUSymbolicGroupedAutotuner新增_grouped_variant_load_meta与_record_grouped_cpp_wrapper_plan,在save_npu_kernel前写入best_by_group及每个选中 variant 的load_meta(包含mangled_name、cubin_path、shared_mem、mix_mode等)。 - cubin 文件按需收集:
generate中根据_grouped_active_variants计算实际用到的cubin_paths,仅将这些路径加入additional_files,并移除不再需要的默认cubin_path,避免打包未选中的 variant。 - 运行时 kernel 保存补充:在
NPUSymbolicGroupedAutotuner的 launch 分支中新增launcher.store_cubin条件下的save_gpu_kernel调用,确保 cpp wrapper 需要时保存 kernel 二进制。 - 测试覆盖:新增
test/_inductor/test_grouped_cpp_wrapper.py,验证生成代码包含分组switch、grouped_kernel_v0/v1、resolve_grouped_runtime_block等结构,并覆盖未选中 variant 的省略以及动态序列长度下的功能与精度测试。


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 |
|---|---|---|
| test | ✅ crazyDannyBoy, weizhan4 (2/2) | ✅ crazyDannyBoy (1/1) |
| torch_npu/_inductor | ✅ crazyDannyBoy, weizhan4 (2/2) | ✅ weizhan4, crazyDannyBoy (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
HinPeng, thanks for your pull request. All authors of the commits have signed the CLA. 👍


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


Linking Issue Notice
@HinPeng , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| check_error | ✅ | >>> | |
| lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | 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 | ✅ | >>> | |
| UT_inductor_Part_02 | ✅ | >>> | |
| UT_inductor_Part_03 | ✅ | >>> | |
| UT_inductor_Part_04 | ❌ | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ❌ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| check_error | ✅ | >>> | |
| lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | 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 | ✅ | >>> | |
| UT_inductor_Part_02 | ✅ | >>> | |
| UT_inductor_Part_03 | ✅ | >>> | |
| UT_inductor_Part_04 | ✅ | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


libing-pipeline创建中,请等待……


/lgtm
/approve


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
zhucehw


The following users do not have permission to comment /lgtm or /approve on any module in this PR:
zhucehw


/lgtm




Issue: https://gitcode.com/Ascend/pytorch/issues/4098
Summary
Enable symbolic-shape grouped autotune to work with the NPU C++ wrapper.
【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】