Skip to content

feat(wan): SP communication-computation overlap for Wan2.2 I2V.#1945

Open
nie-linfeng wants to merge 1 commit into
xLLM-AI:mainfrom
nie-linfeng:feat/wan-sp-communication-overlap
Open

feat(wan): SP communication-computation overlap for Wan2.2 I2V.#1945
nie-linfeng wants to merge 1 commit into
xLLM-AI:mainfrom
nie-linfeng:feat/wan-sp-communication-overlap

Conversation

@nie-linfeng

@nie-linfeng nie-linfeng commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

背景

Wan2.2 I2V 模型在 SP (Sequence Parallel) 模式下,attention 层的 all2all 通信与计算串行执行,导致通信开销无法被掩盖。

优化方案

通过 async all2all 将通信与计算 overlap,分两个层面优化:

1. Self-Attention (forward_async)

基线流程(串行):

Q matmul -> norm Q -> Q all2all
K matmul -> norm K -> K all2all
V matmul -> V all2all (to_v_ sp_before)
reshape -> RoPE
attention
O all2all -> to_out matmul (to_out_ sp_after)

CMO 流程(async overlap):

Q matmul -> norm Q -> async Q all2all
K matmul -> norm K -> async K all2all
V matmul -> async V all2all
Wait Q/K -> reshape -> RoPE (V all2all overlap)
Wait V
attention
async O all2all
return handler (wait O -> to_out matmul)

关键点:

  • Q/K/V 三个 all2all 以 async 模式发起
  • V all2all 与 Q/K reshape+RoPE overlap(部分掩盖)
  • O all2all async,handler 返回给调用方

2. Cross-Attention (forward_cross)

基线流程(串行):

Q matmul -> norm Q -> Q all2all
K matmul -> norm K -> sp_slice_heads
V matmul -> sp_slice_heads
attention
O all2all -> to_out matmul

CMO 流程(async overlap):

Q matmul -> norm Q -> async Q all2all
K matmul -> norm K -> sp_slice_heads (overlap with Q all2all)
V matmul -> sp_slice_heads
img K/V matmul -> sp_slice_heads
Wait Q
attention
O all2all -> wait -> to_out matmul

关键点:

  • Q all2all async 后立即计算 K/V(text+img) matmul+norm+slice
  • K/V matmul 计算掩盖 Q all2all 通信

3. 配置改动

  • CMO 启用时 to_v_ 从 TP+SP(sp_before) 改为 TP-only
  • CMO 启用时 to_out_ 从 TP+SP(sp_after) 改为 TP-only
  • wan_use_sp_overlap() 控制

改动文件

  • transformer_wan.h: 新增 WanAttnProcessorCMO(forward_async + forward_cross)
  • dit_parallel_linear.h: TP+SP combined linear 支持

性能数据

配置 稳定平均 vs 基线
基线 (main) ~106.4s --
CMO ~103.1s -3.1%

测试条件: 8 dieNPU, tp1, sp4, vae_size 4 ;40 steps

Profiling

优化后:
self-attn之前qkv的all-to-all
image
cross-attn之前q的all-to-all
image

@ethan686 ethan686 changed the title feat(wan): SP communication-computation overlap for Wan2.2 I2V feat(wan): SP communication-computation overlap for Wan2.2 I2V. Jul 15, 2026
Self-attn: Q/K/V async all2all overlapped with norm+RoPE
- Q/K all2all overlapped with each other (async)
- V all2all overlapped with Q/K norm+RoPE
- O all2all async, handler returned for caller to wait

Cross-attn: Q all2all overlapped with K/V matmul
- Q all2all async, K/V matmul (text+img) computed in parallel
- Removed precompute_cross_kv/forward_cross_with_kv (simpler design)

Block forward: simplified, no precompute logic
@nie-linfeng nie-linfeng force-pushed the feat/wan-sp-communication-overlap branch from 19b5964 to 4c86830 Compare July 15, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant