已关闭
[Bug]: torch.compile 大 grid kernel 编译报错 "ValueError: 'auto_blockify_size' is not in list"(mobilevit_s / mobilenetv3_large_100 等大 batch 模型触发 #4176
AllenGuan创建于 21 天前关闭于 19 天前
21 天前 添加了label:triage-review
21 天前 添加了label:bug
TorchNPU-Bot
21 天前 评论:
21 天前 评论:
issue待分派,添加triage-review标签


21 天前 修改标题为 “[Bug]: torch.compile 大 grid kernel 编译报错 "ValueError: 'auto_blockify_size' is not in list"(mobilevit_s / mobilenetv3_large_100 等大 batch 模型触发”,原标题为“[Bug]: ”
20 天前 添加了label:bot-triaged;删除了label:triage-review
TorchNPU-Bot
20 天前 评论:
20 天前 评论:
检测到当前 issue 已关联 PR !44846,自动添加标签:bot-triaged


19 天前 关闭了 issue
19 天前 添加了label:resolved
在提交新问题之前,请确保您已经在社区中搜索过相关问题,并使用了社区中提供的资源/工具后,仍未找到满意的解决方式。
⚠️ 安全信息提醒:请仔细检查提供的文本内容,确保其不包含敏感数据信息,包括但不限于:
在分享配置信息或代码示例时,请将敏感信息脱敏处理,或使用
<TOKEN>等占位符替代原有内容。环境信息
🐛 问题描述
触发条件:
torch.compile(Inductor 后端)遇到 grid>65535 的 1D pointwise 融合 kernel——当张量元素数在 UB 预算封顶的 XBLOCK 下满足ceildiv(numel, XBLOCK) > 65535时(例如 numel=2^28、XBLOCK=4096 → grid=65536),1D 启发式会生成携带auto_blockify_size∈{2,4,8}的 autotune 候选;该值被当作 kernel constexpr 传入编译常量,而 kernel 签名中没有这个参数,ast_to_ttir解析常量键名时直接抛ValueError。该异常不在 autotuner 的可跳过编译失败白名单内,单个坏候选即导致整个 warmup 失败、模型不可用。最小复现:
import torch import torch_npu # noqa: F401 def five_load_add(a, b, c, d, e): return a + b + c + d + e n = 2 ** 28 # 5 个 fp32 load,UB 预算封顶 XBLOCK=4096 → grid=65536 > 65535 xs = [torch.randn(n, dtype=torch.float32, device="npu") for _ in range(5)] compiled = torch.compile(five_load_add, options={"npu_backend": "triton_experimental"}) out = compiled(*xs) # warmup 即崩模型级触发(更常见入口):timm benchmark 的
mobilevit_s(bs=128,崩溃 kerneltriton_unk_fused__native_batch_norm_legit_no_training_convolution_silu_3,size_hints x=2^28)与mobilenetv3_large_100(bs=512,..._relu_3,x=411041792)等大 batch/大特征图模型。实际行为(关键报错栈):
期望行为:
auto_blockify_size作为 triton-ascend 编译选项(NPUOptions.auto_blockify_size,配合TRITON_ALL_BLOCKS_PARALLEL的 >65535 grid 折叠机制调优最左维分块粒度)应经 triton.compile 的 options 通道送达后端,kernel 正常编译并可参与 autotune 竞速,模型得到 compiled 结果。根因分析(供维护者参考):torch_npu 前端在
npu_triton_config中将auto_blockify_size写入Config.kwargs;_precompile_config将全部 cfg kwargs 灌入compile_meta["constants"]并传入ASTSource,而 triton-ascend 侧将其定义为编译选项(options 通道),kernel 签名不含该参数 → 常量键名经fn.arg_names.index()解析必失败。修复方向:值改经Config.extra_options(上游为第三方后端预留的官方槽位,AutotuneCache原生序列化/恢复)注入,编译时转发进 options dict。欢迎加入社区,感谢您对社区的贡献 🎉!