已关闭
[Bug-Report|缺陷反馈]: Inductor LayerNorm 双链多引用断图方向不一致导致 SortSubGraphsByDependency 依赖环编译失败 #293
czways创建于  7 天前关闭于  6 天前
czways
czways成员
7 天前 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

Inductor 场景执行用例 tc_af_inductor_layernorm_backend_0193(shape=(128,6,23),两条 LayerNorm 路径 + 三路 sum/mean/abs 输出,融合为单张 HintGraph)时,Autofuse Optimize 阶段在 SortSubGraphsByDependencysorted[4] != total[7],拓扑排序卡死,整体编译以 Optimize fail ret 1343225857 中断。

根因:ReducePartitionMultipleCitations 对多输出共享节点(÷23 常量 broadcast2、beta 广播 broadcast8、gamma 广播 broadcast9)分别独立决定断图方向,且各节点保留的 consumer 遍历顺序不一致——broadcast2 保留 A 链 consumer(产生 A→B 依赖),broadcast8/broadcast9 保留 B 链 consumer(产生 B→A 依赖),反向依赖对叠加后子图 1 与子图 3 互相等待,形成真实的跨子图数据依赖闭环。原图为无环 DAG,环完全由断图方向不一致制造。

Environment / 环境信息 (Mandatory / 必填)

  • 昇腾硬件环境(bugshot 复现于真实设备环境)
  • TorchInductor + torch_npu,Autofuse Inductor 入口,静态 shape
  • Autofuse 组件(含 2026-08-27 f8cf01e 引入的 tiling cache 旁路逻辑版本)

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 在 Inductor 环境下运行 tc_af_inductor_layernorm_backend_0193(模型:sum(layernorm(input.transpose(0,1)))mean(layernorm(input))abs(layernorm(input)) 三路输出);
  2. 观察编译流程在 Optimize 阶段中断,plog 报 SortSubGraphsByDependency 失败:sorted[4] != total[7]
  3. 检查日志可见子图依赖 1 -> 3(来源断点 broadcast2_to_truediv1)与 3 -> 1(来源断点 broadcast8_to_mul5broadcast9_to_add3)同时存在,即双向依赖成环。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

多输出共享节点流向不同 Reduce 时的断图方向应由全局机制统一裁决:共享引用链内按唯一 anchor(最小 Reduce ID)统一保留 anchor 侧路径、剪断非 anchor 侧路径,保证子图依赖图无环,拓扑排序可完成,LayerNorm 三路输出编译及执行正常。

SortSubGraphsByDependency: sorted[4] != total[7]
Optimize fail ret 1343225857

子图依赖环(故障时):

0 ──→ 4 ──→ 1 ⇄ 3 ──→ 6
2 ──→ 5 ──↗
  • 1→3 来源:broadcast2_to_truediv1(÷23 保留 A 链 consumer,A 供 B)
  • 3→1 来源:broadcast8_to_mul5broadcast9_to_add3(beta/gamma 保留 B 链 consumer,B 供 A)

Special notes for this issue/备注 (Optional / 选填)

修复已提交 PR:https://gitcode.com/cann/graph-autofusion/pull/1891(`fix reduce layer norm`),包含两层修复:

  1. 根因修复:ReducePartitionMultipleCitations 重写为两阶段——图改写前按数据边收集 citation(显式过滤 Load/Store/Workspace synthetic 节点),共享 Reduce 的 citation 组用 Union-Find 合并,每链取最小 Reduce ID 为唯一 anchor,非 anchor 路径统一断开,(source, reduce) 对去重防止重复切分;
  2. 下游传导修复:根因修复新增的 Workspace 边界激活了 ATT tiling cache 既有缺陷(body/tail 对 cache_reuse_info 过滤不一致,生成的 schedule_group_tail.cpp 引用未定义的 GroupLevelCache 导致 host C++ 编译失败),已在 GetCacheReuseInfo 入口统一过滤。

真实 LayerNorm bugshot 回归已确认:原 1 <-> 3 依赖环消失,SortSubGraphsByDependency 通过,流程推进至 host C++ 编译阶段。配套 UT:双 Reduce 交叉引用链、同源同 Reduce 去重、Workspace 复用组 body/tail 一致性等 4 条。

likedislike
Ggaoxin成员
6 天前 issue状态由 进行中 改变为 已解决
Ggaoxin成员
6 天前 关闭了 issue
CANN-robotCANN-robot成员
6 天前 添加了label:resolved