Open
[Bug]: DVM causal FlexAttention 编译报 NoValidChoicesError #5414
SorryNaCNAdd on 24 days ago
24 days ago Added label: bug
24 days ago Added label: triage-reviewmodule: graph-mode; Removed label: bug
TorchNPU-Bot
24 days ago Comments:
24 days ago Comments:
DVM 后端 + torch.compile 编译 FlexAttention 报 NoValidChoicesError,属图编译/图模式问题
添加分类标签:module: graph-mode。
当前分类由社区bot提供,如分类有误请在评论中回复。


24 days ago Added label: bug
24 days ago Added label: bot-triaged; Removed label: triage-review
TorchNPU-Bot
24 days ago Comments:
24 days ago Comments:
检测到当前 issue 已关联 PR,自动添加标签:bot-triaged


环境信息
以下信息整理自 PR #47833 中记录的排查与验证:
7eb2fe2f7。TORCHINDUCTOR_NPU_BACKEND=dvm。[8, 128, 2048, 128]。🐛 问题描述
使用 DVM 后端,通过
torch.compile(..., fullgraph=True)编译 causal FlexAttention 时,原实现禁止 DVM 使用 mask-out,进入 mask-in 路径后编译失败,最终报NoValidChoicesError,无法完成该场景的前向和反向计算。启用 mask-out 后,反向还会调用
sum(axis=-1);公共 MLIR reduction lowering 的sum_()未将整数 axis 规范化为列表,负轴处理尝试遍历整数时会抛出TypeError。复现步骤
TORCHINDUCTOR_NPU_BACKEND=dvm,加载torch_npu._inductor。[8, 128, 2048, 128]的 BF16 Q/K/V,并启用梯度。q_idx >= kv_idx构造 causal block mask。flex_attention的函数执行torch.compile(..., backend="inductor", fullgraph=True),运行前向及反向。实际结果:未修复时在编译阶段报
NoValidChoicesError;仅启用 mask-out 后还需处理反向 reduction 的整数 axis。预期结果与修复方向
该 causal 场景能够完成编译、前向和反向,输出及 Q/K/V 梯度均为有限值,梯度形状与输入一致。
sum_()lowering 入口将整数 axis 转为列表,再执行负轴处理。关联 PR 与验证范围
修复 PR:https://gitcode.com/Ascend/pytorch/pull/47833
PR 已记录该大形状 causal 前向/反向通过,以及现有 MLIR reduction 回归通过。本 Issue 聚焦上述编译问题;自定义 score 的精度问题、进程内后端切换问题和未使用
torch.compile时的 eager HBM OOM 不作为本 Issue 的验收项。