[Feature] Add AllGather-KV sequence-parallel attention str… (#4968)

Signed-off-by: zhuhh97 <zhuhonghan@huawei.com>
Signed-off-by: dph97 <nenbaying@163.com>
Signed-off-by: zhuhh97 <zhh@unknown>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: dengyunyang <584797741@qq.com>
This commit is contained in:
authored and GitHub committed 2026-07-24 14:45:26 +00:00
1 parent 8927ec057c
commit 84bbd57e4d
33 files changed
+1181 -135

No files matched your search

+22 -7
View File
@@ -156,7 +156,9 @@ class DiffusionParallelConfig:
"""Enable expert parallelism for MoE layers (TP is still used for non-MoE layers)."""
sequence_parallel_size: int | None = None
"""Number of sequence parallel groups. sequence_parallel_size = ring_degree * ulysses_degree"""
"""Number of sequence parallel groups.
sequence_parallel_size = ulysses_degree * ring_degree, or allgather_degree
when AllGather-KV is enabled."""
ulysses_degree: int = 1
"""Number of GPUs used for ulysses sequence parallelism."""
@@ -164,6 +166,9 @@ class DiffusionParallelConfig:
ring_degree: int = 1
"""Number of GPUs used for ring sequence parallelism."""
allgather_degree: int = 1
"""Number of GPUs used for AllGather-KV sequence parallelism (causal=False only)."""
ulysses_mode: str = "strict"
"""Ulysses sequence-parallel mode.
@@ -225,6 +230,7 @@ class DiffusionParallelConfig:
assert self.sequence_parallel_size > 0, "Sequence parallel size must be > 0"
assert self.ulysses_degree > 0, "Ulysses degree must be > 0"
assert self.ring_degree > 0, "Ring degree must be > 0"
assert self.allgather_degree > 0, "AllGather degree must be > 0"
assert self.cfg_parallel_size > 0, "CFG parallel size must be > 0"
assert self.cfg_parallel_size in [1, 2, 3], (
f"CFG parallel size must be 1, 2, or 3, but got {self.cfg_parallel_size}"
@@ -234,9 +240,17 @@ class DiffusionParallelConfig:
"vae_parallel_mode must be one of {'tile', 'spatial_shard_height', 'spatial_shard_width'}, "
f"but got {self.vae_parallel_mode!r}."
)
assert self.sequence_parallel_size == self.ulysses_degree * self.ring_degree, (
"Sequence parallel size must be equal to the product of ulysses degree and ring degree,"
f" but got {self.sequence_parallel_size} != {self.ulysses_degree} * {self.ring_degree}"
if self.allgather_degree > 1:
assert self.ulysses_degree == 1 and self.ring_degree == 1, (
"AllGather-KV (allgather_degree>1) is mutually exclusive with Ulysses/Ring in v1. "
f"Got ulysses_degree={self.ulysses_degree}, ring_degree={self.ring_degree}, "
f"allgather_degree={self.allgather_degree}."
)
expected_sp_size = (
self.allgather_degree if self.allgather_degree > 1 else self.ulysses_degree * self.ring_degree
)
assert self.sequence_parallel_size == expected_sp_size, (
f"Sequence parallel size must be {expected_sp_size}, but got {self.sequence_parallel_size}"
)
assert self.ulysses_mode in {"strict", "advanced_uaa"}, (
f"ulysses_mode must be one of {{'strict','advanced_uaa'}}, but got {self.ulysses_mode!r}."
@@ -250,15 +264,16 @@ class DiffusionParallelConfig:
def __post_init__(self) -> None:
if self.sequence_parallel_size is None:
self.sequence_parallel_size = self.ulysses_degree * self.ring_degree
self.sequence_parallel_size = (
self.allgather_degree if self.allgather_degree > 1 else self.ulysses_degree * self.ring_degree
)
# Calculate world_size from other parallelism dimensions
other_parallel_world_size = (
self.pipeline_parallel_size
* self.data_parallel_size
* self.tensor_parallel_size
* self.ulysses_degree
* self.ring_degree
* self.sequence_parallel_size
* self.cfg_parallel_size
)