Merge branch 'main' into codex-vae-spatial-decode-auto
This commit is contained in:
186 files changed
+10814
-1165
No files matched your search
@@ -208,8 +208,17 @@ def reshard_from_trimmed_extent(
|
||||
return x
|
||||
|
||||
dim = _spatial_dim(split_dim)
|
||||
ctx = _SPATIAL_SHARD_CONTEXT.get()
|
||||
if ctx is not None and ctx.rank != rank:
|
||||
raise RuntimeError(
|
||||
"Wan VAE spatial-shard rank mismatch while resharding: "
|
||||
f"group_rank={rank}, context_rank={ctx.rank}, split_dim={split_dim!r}."
|
||||
)
|
||||
|
||||
valid_extent = _local_valid_extent(local_extent)
|
||||
start = rank * local_extent
|
||||
actual_extent = x.shape[dim]
|
||||
start = min(rank * local_extent, actual_extent)
|
||||
valid_extent = min(valid_extent, actual_extent - start)
|
||||
local = _narrow_along_dim(x, dim, start, valid_extent).contiguous()
|
||||
if valid_extent < local_extent:
|
||||
local = _pad_along_dim(local, local_extent - valid_extent, dim=dim)
|
||||
@@ -659,10 +668,22 @@ def _patch_attention_block(module: nn.Module, group: dist.ProcessGroup) -> None:
|
||||
dim = _spatial_dim(split_dim)
|
||||
local_extent = x.shape[dim]
|
||||
gathered = all_gather_along_dim(x, group=group, dim=dim).contiguous()
|
||||
gathered_extent = gathered.shape[dim]
|
||||
full_extent = _current_full_extent(local_extent)
|
||||
if full_extent is not None:
|
||||
gathered = _narrow_along_dim(gathered, dim, 0, full_extent).contiguous()
|
||||
trim_extent = min(full_extent, gathered_extent)
|
||||
gathered = _narrow_along_dim(gathered, dim, 0, trim_extent).contiguous()
|
||||
else:
|
||||
trim_extent = gathered_extent
|
||||
out = orig_forward(gathered, *args, **kwargs)
|
||||
if out.shape[dim] != trim_extent:
|
||||
raise RuntimeError(
|
||||
"Wan VAE attention changed the spatial extent during global gather: "
|
||||
f"rank={_rank_world(group)[0]}, split_dim={split_dim!r}, "
|
||||
f"local_extent={local_extent}, gathered_extent={gathered_extent}, "
|
||||
f"trimmed_extent={trim_extent}, output_extent={out.shape[dim]}, "
|
||||
f"context={_SPATIAL_SHARD_CONTEXT.get()!r}."
|
||||
)
|
||||
return reshard_from_trimmed_extent(out, local_extent=local_extent, split_dim=split_dim, group=group)
|
||||
|
||||
module.forward = MethodType(_forward, module)
|
||||
|
||||
@@ -28,6 +28,8 @@ If you only need to use the distributed environment without model parallelism,
|
||||
you can skip the model parallel initialization and destruction steps.
|
||||
"""
|
||||
|
||||
import inspect
|
||||
|
||||
import torch
|
||||
import torch.distributed
|
||||
import vllm.distributed.parallel_state as vllm_parallel_state
|
||||
@@ -524,13 +526,23 @@ def init_vllm_model_parallel_group(
|
||||
local_rank: int,
|
||||
backend: str,
|
||||
group_name: str,
|
||||
use_all2all: bool = False,
|
||||
) -> vllm_parallel_state.GroupCoordinator:
|
||||
# vLLM 0.27's MoE oracle (make_unquantized_moe_kernel ->
|
||||
# get_ep_all2all_manager) asserts that the EP group's device communicator
|
||||
# carries an all2all_manager, and vLLM only builds one when the group is
|
||||
# created with use_all2all=True. Older vLLM has neither the kwarg nor the
|
||||
# requirement, so forward it only when supported.
|
||||
kwargs = {}
|
||||
if use_all2all and "use_all2all" in inspect.signature(vllm_parallel_state.init_model_parallel_group).parameters:
|
||||
kwargs["use_all2all"] = True
|
||||
return vllm_parallel_state.init_model_parallel_group(
|
||||
group_ranks=group_ranks,
|
||||
local_rank=local_rank,
|
||||
backend=backend,
|
||||
group_name=group_name,
|
||||
use_device_communicator=True,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
@@ -954,6 +966,7 @@ def initialize_model_parallel(
|
||||
local_rank=get_world_group().local_rank,
|
||||
backend=backend,
|
||||
group_name="ep",
|
||||
use_all2all=True,
|
||||
)
|
||||
|
||||
init_dit_group(dit_parallel_size, backend)
|
||||
|
||||
Reference in new issue
Block a user