Closed
triton_experimental: eager-first 流程 ≥2 kernel 编译必死(SubprocPool fork 后 NPU 二次初始化) #4979
huyuchaoAdd on  Sep 21Closed at  Sep 29
huyuchao
huyuchaoCollaborators
Sep 21 Create

现象

torch_npu._inductor 转为懒加载后,eager-first 流程(所有 benchmark runner 的固定形态:先跑 eager 再 compile)中任何 ≥2 个 triton kernel 的 triton_experimental 编译必然失败:

torch._inductor.exc.InductorError: SubprocException: An exception occurred in a subprocess:
RuntimeError: Cannot re-initialize NPU in forked subprocess.
To use NPU with multiprocessing, you must use the 'spawn' start method

单 kernel 图走内联编译不经过进程池——简单冒烟测不出,首个真实模型即命中。

根因

  • 旧版 import torch_npu 会传递性地急切导入 torch_npu._inductor,其 AsyncCompile.warm_pool() 在 NPU 初始化之前预 fork 干净的编译 worker;
  • 懒加载后 _load_backend() 在 _inductor 首次 import 期即执行,时机早于/晚于首个 NPU op 均有可能——不存在「load 时能证明进程池安全」的判定点(is_initialized() 门控对 import-早-于-NPU-op 的顺序失效,实测复现)。

修复

PR #46616:_load_triton_experimental_backend() 无条件 pin compile_threads=1 进程内串行编译(与 dvm 后端 _configure_dvm_compile_threads() 同款)。两种 import 顺序 + 四模型 huggingface runner 回归均通过。

likedislike
TorchNPU-BotTorchNPU-BotCollaborators
Sep 21 Added label: triage-review
TorchNPU-Bot
TorchNPU-BotCollaborators
Sep 21 Comments:

issue待分派,添加triage-review标签

likedislike
TorchNPU-BotTorchNPU-BotCollaborators
Sep 21 Added label: bot-triaged; Removed label: triage-review
TorchNPU-Bot
TorchNPU-BotCollaborators
Sep 21 Comments:

检测到当前 issue 已关联 PR,自动添加标签:bot-triaged

likedislike
huyuchaohuyuchaoCollaborators
Sep 23 Associated pull request
chenrayraychenrayrayCollaborators
Sep 24 Associated milestone: v26.2.0
chenrayray
chenrayrayCollaborators
Sep 29 Comments:

因为本单相关实施 PR 已全部结束(1 个已合入、1 个已关闭),按照本轮 issue 整理规则,先关闭此单。其中关闭但未合入的 PR 不代表对应修复已交付。

核对的 PR:

如仍有问题或需要继续推进,请重新打开,并补充当前 PyTorch / TorchNPU / CANN 版本、硬件环境、复现步骤及相关日志;需求类请补充尚未完成的具体内容。

likedislike
chenrayraychenrayrayCollaborators
Sep 29 Close issue
chenrayraychenrayrayCollaborators
Sep 29 changed custom state from TODO to DONE
ascend-robotascend-robotCollaborators
Sep 29 Added label: resolved