已开启
[Bug]: Flex Attention cppwrapper fails in mask_out backward on v2.7.1 #4431
Xuan Peng创建于  20 天前
Xuan Peng
20 天前 创建

问题描述

torch_npu v2.7.1 分支开启 Torch Inductor cpp_wrapper,运行带 mask_out 的 Flex Attention 动态 backward 场景时,C++ wrapper 无法完成代码生成与后续 kernel 启动。

适用范围

  • 软件分支:torch_npu v2.7.1
  • 编译路径:Torch Inductor + NPU Triton + cpp_wrapper

实际表现

动态 backward 的 call size 进入 PyTorch 2.7.1 Flex Attention backward template 后触发:

AssertionError: cpp_wrapper requires SymbolicGridFn

此外,Triton 编译元数据中的 workspace_sizelock_numlock_init_val 没有传递给 NPU C++ launcher;需要 workspace 或同步锁的 kernel 会收到空的 workspace_addr/sync_block_lock

原因分析

  1. PyTorch 2.7.1 的 Flex Attention backward template 使用普通 grid function。动态 call size 下,C++ wrapper 只能通过 SymbolicGridFn 生成 grid 表达式。
  2. NPUCachingAutotuner 未转发 runtime workspace/lock 元数据,CppWrapperNpu 也未据此分配并初始化对应 buffer。

期望结果

  1. Flex Attention backward template 在动态 shape 下能够为 C++ wrapper 生成符号化 grid。
  2. NPU C++ launcher 根据 Triton metadata 分配 workspace 和同步锁,并按 lock_init_val 初始化锁。
  3. mask_out 场景不再因 SymbolicGridFn 断言或空 runtime buffer 失败。

验证情况

  • 修复需覆盖现有 Flex Attention mask_out 动态 backward + cpp_wrapper 复现场景。
  • 修改文件已通过 Python 语法检查和 Git diff 空白检查。
likedislike
ascend-robotascend-robot成员
20 天前 添加了label:bug
TorchNPU-BotTorchNPU-Bot成员
20 天前 添加了label:triage-review;删除了label:bug
TorchNPU-Bot
TorchNPU-Bot成员
20 天前 评论:

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

likedislike
ascend-robotascend-robot成员
20 天前 添加了label:bug
XXuan Peng
20 天前 关联了pull request:fix(inductor): support Flex Attention mask_out cppwrapper
TorchNPU-BotTorchNPU-Bot成员
20 天前 添加了label:bot-triaged;删除了label:triage-review
TorchNPU-Bot
TorchNPU-Bot成员
20 天前 评论:

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

likedislike
XXuan Peng
18 天前 关联了pull request:fix(inductor): support Flex Attention mask_out cppwrapper
XXuan Peng
18 天前 关联了pull request:fix(inductor): support Flex Attention mask_out cppwrapper