已开启
[FlexAttention][v2.7.1]: load balance of forward and dQ #4783
ZhangZGC创建于  12 天前
ZhangZGC成员
12 天前 创建

1. 概述

在不生成运行时 task table 的前提下,编译期识别 mask_mod 的静态结构,估算每个 Q tile 的任务量,模拟三种公式化遍历方式在实际 AI Core 数量下的最长核负载,并只在扣除模型不确定度后仍有足够收益时,为前向和 dQ 选择 snake 调度;否则保持原始 RR。

2. 总体流程

用户调用 flex_attention(mask_mod, kernel_options, ...)
                         │
                         ▼
             Dynamo/AOTAutograd 捕获 mask_mod
                         │
                         ▼
              Inductor 得到 mask FX 子图
                         │
                         ▼
       infer_static_mask_pattern(mask_graph)
                         │
              ┌──────────┴──────────┐
              │                     │
         图结构可识别            图结构未知/捕获运行时值
              │                     │
              ▼                     ▼
       生成 tiling 候选             RR
              │
              ▼
   对每个 tiling 估算 Q tile cost
              │
              ▼
    模拟 RR/head-snake/wave-snake
              │
              ▼
     计算 raw gain 与 robust gain
              │
       ┌──────┴───────┐
       │              │
 robust gain >= 2%   其余情况
       │              │
       ▼              ▼
  选择最优 snake      RR
       │              │
       └──────┬───────┘
              ▼
 将 LB_STRATEGY_ID 写入该 tiling choice
              │
              ▼
  默认选首个可编译大 tiling,或 autotune 实测
              │
              ▼
 tiling 与负载均衡策略共同固化进编译缓存
likedislike
TorchNPU-BotTorchNPU-Bot成员
12 天前 添加了label:triage-review
TorchNPU-Bot
TorchNPU-Bot成员
12 天前 评论:

issue待分派,添加triage-review标签

likedislike
ZZhangZGC成员
12 天前 修改了issue 的描述
ZZhangZGC成员
12 天前 修改了issue 的描述
TorchNPU-BotTorchNPU-Bot成员
12 天前 添加了label:bot-triaged;删除了label:triage-review
TorchNPU-Bot
TorchNPU-Bot成员
12 天前 评论:

检测到当前 issue 已关联 PR,自动添加标签:bot-triaged

likedislike
chenrayraychenrayray成员
2 天前 关联了里程碑:v26.2.0