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)
|
||||
|
||||
Reference in new issue
Block a user