已合并
feat: support triton_experimental in TorchBench #43627
feat: support triton_experimental in TorchBench #43627
已合并
rmch创建于 8月3日
rmch成员
8月3日

【合入来源】

【修改方案】

  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

验证命令:

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 eventsSQLite Error: no such table: TASK
  • 后端映射验证通过:triton -> defaulttriton_experimental -> triton_experimentalmlir -> mlirdvm -> dvm
  • git diff --check 和 Python py_compile 通过

【CheckList】

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 rmch 的贡献)
Rrmch成员
8月3日 创建了 pull request,commit 2812a9fc
atomgit-bot
atomgit-bot
8月3日 评论:

变更摘要

此 PR 为 TorchBench 的 NPU 后端新增了 triton_experimental 选项,显式维护命令行参数到 TORCHINDUCTOR_NPU_BACKEND 环境变量的映射关系;同时修复了 nvidia_deeprecommender 在 NPU 上的训练/推理初始化流程,并解决了 NPU profiler 与 Triton autotune profiler 嵌套导致 CANN trace 损坏的问题。

主要改动

  • --npu-backend 新增 triton_experimental 选项:在 common.py 中,parse_argschoices 列表增加了 "triton_experimental"configure_compile_options 中将原来直接赋值的逻辑改为字典映射("triton""default""triton_experimental""triton_experimental"),确保不同 CLI 选项正确对应到 TORCHINDUCTOR_NPU_BACKEND 环境变量。

  • NPU profiler 与 Inductor 编译/autotune 的解耦:在 run_n_iterations 中,若 NPU 可用且启用了 profiler,则在外层 profiler 启动前先执行一次模型迭代,使 Inductor 首次编译和 Triton autotune 的 profiler 会话在外层采集之前完成,避免嵌套 profiler 导致 CANN trace 缺失 TASK 表;同时将 profiler 的 active 参数由 n 调整为 max(1, n - 10),以匹配预执行的迭代。

  • nvidia_deeprecommender NPU 兼容补丁重构:在 npu_support.py 中,将原先仅 patch DeepRecommenderTrainBenchmark__init__ 改为同时处理训练类 nvtrain.DeepRecommenderTrainBenchmark 和推理类 nvinfer.DeepRecommenderInferenceBenchmark,统一采用"先在 CPU 完成构造、再将模型与输入迁移到 NPU、训练模型重新绑定 optimizer/scheduler"的策略,并通过 _npu_patch_applied 标记防止重复 patch。

  • 训练 shape 的 32 对齐保留与 optimizer 重建:patch 中保留了 toyvocab 从 197951 到 197952 的对齐调整,并在设备迁移后调用 reset_optimizer 为新创建的 rencoder 重新绑定 optimizer 和 scheduler,避免 optimizer 引用旧模型参数。

likedislike
不准确?
atomgit-bot
atomgit-bot
8月3日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
ascend-robotascend-robot成员
8月3日 添加了label:ascend-cla/yes
此处折叠了64条消息 查看更多
ascend-robotascend-robot成员
17 天前 添加了label:lgtm
ascend-robotascend-robot成员
17 天前 关闭了关联的issue
ascend-robotascend-robot成员
17 天前 合入了pull request
ascend-robot
ascend-robot成员
17 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
17 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14533 [ commitID:7ffcdfcc ] 已完成
likedislike