[Diffusion][Feature] Non-Intrusive Sequence Parallelism (SP) Support for Wan2.2 (#966)

Signed-off-by: mxuax <mxuax@connect.ust.hk>
Signed-off-by: XU Mingshi <91017482+mxuax@users.noreply.github.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
XU MingshiandHongsheng Liu authored and GitHub committed 2026-01-27 11:33:38 +08:00
1 parent 5037af1033
commit 1fe8e71433
4 files changed
+97 -4

No files matched your search

@@ -17,6 +17,10 @@ from vllm.model_executor.layers.linear import QKVParallelLinear, ReplicatedLinea
from vllm.model_executor.model_loader.weight_utils import default_weight_loader
from vllm_omni.diffusion.attention.layer import Attention
from vllm_omni.diffusion.distributed.sp_plan import (
SequenceParallelInput,
SequenceParallelOutput,
)
logger = init_logger(__name__)
@@ -497,6 +501,16 @@ class WanTransformer3DModel(nn.Module):
This is an optimized version of the diffusers WanTransformer3DModel that uses
vLLM's efficient QKVParallelLinear and RMSNorm implementations.
Sequence Parallelism:
This model supports non-intrusive SP via _sp_plan. The plan specifies:
- RoPE (cos/sin) splitting via rope module's split_output
- hidden_states splitting at first transformer block input
- Output gathering at proj_out layer
The video sequence (flattened patches) is parallelized across GPUs.
Note: Our "Sequence Parallelism" (SP) corresponds to "Context Parallelism" (CP) in diffusers.
Args:
patch_size: 3D patch dimensions for video embedding (t_patch, h_patch, w_patch)
num_attention_heads: Number of attention heads
@@ -520,6 +534,29 @@ class WanTransformer3DModel(nn.Module):
"to_qkv": ["to_q", "to_k", "to_v"],
}
# Sequence Parallelism for Wan (following diffusers' _cp_plan pattern)
#
# The _sp_plan specifies sharding/gathering at module boundaries:
# - rope: Split both RoPE outputs (freqs_cos, freqs_sin) via split_output=True
# - blocks.0: Split hidden_states input at the first transformer block
# - proj_out: Gather outputs after the final projection layer
#
# Note: _sp_plan corresponds to diffusers' _cp_plan (Context Parallelism)
_sp_plan = {
# Shard RoPE embeddings after rope module computes them
"rope": {
0: SequenceParallelInput(split_dim=1, expected_dims=4, split_output=True), # freqs_cos [1, seq, 1, dim]
1: SequenceParallelInput(split_dim=1, expected_dims=4, split_output=True), # freqs_sin [1, seq, 1, dim]
},
# Shard hidden_states at first transformer block input
# (after patch_embedding + flatten + transpose)
"blocks.0": {
"hidden_states": SequenceParallelInput(split_dim=1, expected_dims=3), # [B, seq, dim]
},
# Gather at proj_out (final linear projection before unpatchify)
"proj_out": SequenceParallelOutput(gather_dim=1, expected_dims=3),
}
def __init__(
self,
patch_size: tuple[int, int, int] = (1, 2, 2),
@@ -613,8 +650,11 @@ class WanTransformer3DModel(nn.Module):
post_patch_height = height // p_h
post_patch_width = width // p_w
# Compute RoPE embeddings (sharded by _sp_plan via split_output=True)
rotary_emb = self.rope(hidden_states)
# Patch embedding and flatten to sequence
# (hidden_states is sharded at blocks.0 input by _sp_plan)
hidden_states = self.patch_embedding(hidden_states)
hidden_states = hidden_states.flatten(2).transpose(1, 2)