已开启
Inductor Triton 动态 std 存在尾块越界和 f64 编译失败 #4437
Xuan Peng创建于 9 天前
9 天前 添加了label:triage-review
TorchNPU-Bot
9 天前 评论:
9 天前 评论:
issue待分派,添加triage-review标签


9 天前 添加了label:bot-triaged;删除了label:triage-review
TorchNPU-Bot
9 天前 评论:
9 天前 评论:
检测到当前 issue 已关联 PR,自动添加标签:bot-triaged


环境信息
问题描述
torch.ops.aten.std.dim(x, [1], True, False)经 Inductor Triton 后端编译时存在两个 NPU 代码生成问题:NPUTritonKernel。上游_has_constant_mask基于 Triton block 为 2 的幂的假设删除尾块 mask,但 NPU autotune 可以选择非 2 的幂 block。例如xnumel=262144时选择XBLOCK=4688,最后一个 block 存在 384 个越界 lane,可能引发 MTE 越界或越界写。NPUIndexTritonKernel。上游TritonPrinter将 shape 相关的sympy.Float/ToFloat打印为tl.float64,而 Triton-Ascend 无法合法化对应的 f64 向量运算,最终报MLIRCompilationError/NoTritonConfigsError。问题 DSL:
tmp13 = (tl.full([], -1.00000000000000, tl.float64)) + ks0 tmp14 = tmp13.to(tl.float32)后续转换到 float32 发生在 f64 加法之后,无法避免编译失败。
复现方式
import torch def fn(x): return torch.ops.aten.std.dim(x, [1], True, False) x = torch.randn((256, 8192, 1024), device="npu", dtype=torch.float32) static_fn = torch.compile(fn, dynamic=False) dynamic_fn = torch.compile(fn, dynamic=True) static_fn(x) dynamic_fn(x)预期行为
std(dim=1)均可正确编译和执行。验证结果
Ascend_910B 上动态
std(dim=1)编译、执行成功,结果与 eager 在atol=1e-2, rtol=1e-2下相符。全新 Inductor 缓存生成 6 个 Python 文件,
tl.float64命中数为 0。修复后关键 DSL 为:
tmp13 = (tl.full([], -1.00000000000000, tl.float32)) + ks0