Pull Request已成功合入, 合并人@ascend-robot
(感谢 rmch 的贡献)变更摘要
此 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_args的choices列表增加了"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_deeprecommenderNPU 兼容补丁重构:在npu_support.py中,将原先仅 patchDeepRecommenderTrainBenchmark的__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 引用旧模型参数。


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.




【合入来源】
【修改方案】
--npu-backend新增triton_experimental,并显式维护命令行选项到TORCHINDUCTOR_NPU_BACKEND的映射;原triton继续映射到默认 Triton 后端。nvidia_deeprecommender在 NPU 训练和推理模式下的初始化。上游构造器先在 CPU 完成状态初始化,再将模型和输入迁移到真实 NPU,并为训练模型重新绑定 optimizer/scheduler,避免 optimizer 引用旧模型参数。TASK表。197951 -> 197952),并补充 README 使用示例。【资料变更】
涉及。更新
benchmarks/torchbench/README.md,补充triton_experimental后端说明和 DeepRecommender 动态 shape 示例。【接口变更】
TorchBench CLI 的
--npu-backend新增可选值triton_experimental;已有选项行为保持兼容。【功能验证】
验证环境:
2.13.0+cpu2.13.0+git4d712d13.2.2+git814cf49a/root/miniconda3/envs/ly_inductor/bin/python39910b31cc17d175a781412fd9ca6f18a4ee04610验证命令:
验证结果:
pass_accuracyascend_pytorch_profiler.db包含TASK表,step_trace_time.csv均包含 40 条 step 数据Failed to get acl to npu flow events或SQLite Error: no such table: TASKtriton -> default、triton_experimental -> triton_experimental、mlir -> mlir、dvm -> dvmgit diff --check和 Pythonpy_compile通过【CheckList】