Closed
[Bug] FlexAttention deferred epilogue fusion skips cold-start compilation validation #4708
stonexxxAdd on Sep 9Closed at Sep 29
Sep 9 Added label: triage-review
Sep 9 Added label: bug
TorchNPU-Bot
Sep 9 Comments:
Sep 9 Comments:
issue待分派,添加triage-review标签


Sep 9 Associated pull request
Sep 9 Added label: bot-triaged; Removed label: triage-review
TorchNPU-Bot
Sep 9 Comments:
Sep 9 Comments:
检测到当前 issue 已关联 PR,自动添加标签:bot-triaged


chenrayray
Sep 29 Comments:
Sep 29 Comments:
因为本单相关实施 PR 已全部结束(1 个已合入、0 个已关闭),按照本轮 issue 整理规则,先关闭此单。
核对的 PR:
- pytorch !46091:已合入
如仍有问题或需要继续推进,请重新打开,并补充当前 PyTorch / TorchNPU / CANN 版本、硬件环境、复现步骤及相关日志;需求类请补充尚未完成的具体内容。


Sep 29 Close issue
Sep 29 changed custom state from TODO to DONE
Sep 29 Added label: resolved
问题现象
在
torch_npu: 2.13.0、NPU: Ascend 950环境中,FlexAttention 输出与cos发生 epilogue fusion 时,融合 kernel 需要的 UB 超过可用容量:对应测试:
FlexAttention template 已设置
_npu_deferred_epilogue_compile_only=True,预期 scheduler 在接受融合前先编译 fused kernel;如果编译失败,应拒绝融合并回退为独立的 attention 和 pointwisecoskernel。触发条件
_npu_deferred_epilogue_compile_only=True。AsyncCompile进程池冷启动、ready future 尚未完成时。定位过程与根因
探针确认 lowering 和 scheduler 获取的是同一个
TritonTemplateBuffer,且 deferred 标记在 scheduler 中仍为True,因此不是标记传播问题。AsyncCompile.use_process_pool()在首次调用时会提交进程池 ready task,并立即返回ready_future.done()。ready task 尚未完成时返回False。现有 speculative compile 逻辑在该分支只执行PyCodeCache.load(),未调用 Triton 编译,并用future=None表示结果。后续 callback 只在 future 非空时等待编译,因此直接返回成功,错误接受了 fused kernel。预热进程池后的对照探针显示:
use_process_pool()返回True,创建真实LambdaFuture后,callback 能捕获 UB overflow 并返回False。这证明问题是冷启动同步分支跳过了真实编译。期望行为
仅对带
_npu_deferred_epilogue_compile_only标记的 template,无论进程池是否已经 ready,都必须执行真实 Triton 编译检查。同步编译异常或异步 future 异常都应使 scheduler 拒绝 fusion,并回退到未融合 kernel。普通 fusion benchmark 行为保持不变。
验证状态
11 passed。poi_fused_cos,计算和更新后的测试断言通过。