Files
rmch 8816d9f89f feat: support triton_experimental in TorchBench
Co-authored-by: rmch<chenruimin2@huawei.com>



# message auto-generated for no-merge-commit merge:
!43627 merge benchmarks/torchbench-triton-experimental into master

feat: support triton_experimental in TorchBench

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

- [x] issue/工单:https://gitcode.com/Ascend/pytorch/issues/4351

- [x] 重构优化

# 【修改方案】

1. TorchBench 的 `--npu-backend` 新增 `triton_experimental`,并显式维护命令行选项到 `TORCHINDUCTOR_NPU_BACKEND` 的映射;原 `triton` 继续映射到默认 Triton 后端。
2. 修复 `nvidia_deeprecommender` 在 NPU 训练和推理模式下的初始化。上游构造器先在 CPU 完成状态初始化,再将模型和输入迁移到真实 NPU,并为训练模型重新绑定 optimizer/scheduler,避免 optimizer 引用旧模型参数。
3. NPU profiler 启用时,在外层采集开始前完成 Inductor 首次编译和 Triton autotune,避免 autotune profiler 与外层 profiler 嵌套造成 CANN trace 缺少 `TASK` 表。
4. 保留训练 shape 的 32 对齐兼容处理(`197951 -> 197952`),并补充 README 使用示例。

# 【资料变更】

涉及。更新 `benchmarks/torchbench/README.md`,补充 `triton_experimental` 后端说明和 DeepRecommender 动态 shape 示例。

# 【接口变更】

TorchBench CLI 的 `--npu-backend` 新增可选值 `triton_experimental`;已有选项行为保持兼容。

# 【功能验证】

验证环境:

- 芯片:Ascend 910B2
- torch:`2.13.0+cpu`
- torch_npu:`2.13.0+git4d712d1`
- triton-ascend:`3.2.2+git814cf49a`
- Python:`/root/miniconda3/envs/ly_inductor/bin/python3`
- TorchBench:`9910b31cc17d175a781412fd9ca6f18a4ee04610`

验证命令:

```bash
ASCEND_RT_VISIBLE_DEVICES=1 \
TORCH_DEVICE_BACKEND_AUTOLOAD=0 \
/root/miniconda3/envs/ly_inductor/bin/python3 -u torchbench.py \
  --accuracy --cold-start-latency --train --float32 \
  --backend inductor \
  --npu-backend triton_experimental \
  --iterations 50 \
  --disable-aclgraph \
  --dynamic-shapes \
  --enable-profiler \
  --only nvidia_deeprecommender
```

验证结果:

- 精度:`pass_accuracy`
- eager 平均耗时(第 16-40 步):23.04 ms
- compile 平均耗时(第 16-40 步):21.14 ms
- 性能:compile 相比 eager 无劣化
- eager/compile profile 均成功生成;`ascend_pytorch_profiler.db` 包含 `TASK` 表,`step_trace_time.csv` 均包含 40 条 step 数据
- 未再出现 `Failed to get acl to npu flow events` 或 `SQLite Error: no such table: TASK`
- 后端映射验证通过:`triton -> default`、`triton_experimental -> triton_experimental`、`mlir -> mlir`、`dvm -> dvm`
- `git diff --check` 和 Python `py_compile` 通过

# 【CheckList】

- [x] 代码注释完备,正确记录错误日志
- [x] 代码实现进行了返回值、空指针等校验
- [x] PR 标题正确使用类型标签,如:feat、fix、refactor、docs、test 等
- [x] 本地相关静态检查和 NPU 功能验证通过;PR 持续集成结果以流水线为准

See merge request: Ascend/pytorch!43627
2026-08-26 14:10:59 +08:00
..
2026-07-17 16:43:21 +08:00
2026-08-21 10:04:05 +08:00