[Model] Add LingBot World Ulysses sequence parallelism (#6841)
Signed-off-by: wtz2333 <2955110911@qq.com> Co-authored-by: Zhou Taichang <tzhouam@connect.ust.hk>
This commit is contained in:
1 parent
de9a133d48
commit
02aaa34059
8 files changed
+659
-45
No files matched your search
@@ -18,7 +18,6 @@ import torch.nn.functional as F
|
||||
from diffusers.utils.torch_utils import randn_tensor
|
||||
from torch import nn
|
||||
from transformers import AutoTokenizer, UMT5EncoderModel
|
||||
from vllm.distributed import get_tensor_model_parallel_world_size
|
||||
from vllm.model_executor.models.utils import AutoWeightsLoader
|
||||
|
||||
from vllm_omni.diffusion.data import DiffusionOutput, OmniDiffusionConfig
|
||||
@@ -203,7 +202,6 @@ def _validate_parallel_config(od_config: OmniDiffusionConfig) -> None:
|
||||
return
|
||||
unsupported_sizes = {
|
||||
"pipeline_parallel_size": "pipeline parallelism",
|
||||
"sequence_parallel_size": "sequence parallelism",
|
||||
"cfg_parallel_size": "CFG parallelism",
|
||||
"vae_patch_parallel_size": "VAE parallelism",
|
||||
}
|
||||
@@ -211,6 +209,25 @@ def _validate_parallel_config(od_config: OmniDiffusionConfig) -> None:
|
||||
size = getattr(parallel_config, field, 1) or 1
|
||||
if size > 1:
|
||||
raise NotImplementedError(f"LingBot World v1 does not support {feature} ({field}={size}).")
|
||||
sequence_parallel_size = getattr(parallel_config, "sequence_parallel_size", 1) or 1
|
||||
ulysses_degree = getattr(parallel_config, "ulysses_degree", 1) or 1
|
||||
ring_degree = getattr(parallel_config, "ring_degree", 1) or 1
|
||||
allgather_degree = getattr(parallel_config, "allgather_degree", 1) or 1
|
||||
ulysses_mode = getattr(parallel_config, "ulysses_mode", "strict")
|
||||
ulysses_a2a_permute = bool(getattr(parallel_config, "ulysses_a2a_permute", False))
|
||||
if (
|
||||
sequence_parallel_size != ulysses_degree
|
||||
or ring_degree != 1
|
||||
or allgather_degree != 1
|
||||
or ulysses_mode != "strict"
|
||||
or ulysses_a2a_permute
|
||||
):
|
||||
raise NotImplementedError(
|
||||
"LingBot World sequence parallelism requires pure Ulysses with ulysses_a2a_permute disabled: "
|
||||
f"sequence_parallel_size={sequence_parallel_size}, ulysses_degree={ulysses_degree}, "
|
||||
f"ring_degree={ring_degree}, allgather_degree={allgather_degree}, ulysses_mode={ulysses_mode!r}, "
|
||||
f"ulysses_a2a_permute={ulysses_a2a_permute}."
|
||||
)
|
||||
if getattr(parallel_config, "use_hsdp", False):
|
||||
raise NotImplementedError("LingBot World v1 does not support HSDP.")
|
||||
if getattr(parallel_config, "enable_expert_parallel", False):
|
||||
@@ -557,8 +574,6 @@ class LingBotWorldCausalDMDPipeline(
|
||||
latent_height = self._ar_height // spatial
|
||||
latent_width = self._ar_width // spatial
|
||||
tokens_per_frame = (latent_height // patch_height) * (latent_width // patch_width)
|
||||
tp_size = get_tensor_model_parallel_world_size()
|
||||
num_local_heads = int(self.transformer.config.num_attention_heads) // tp_size
|
||||
total_window_frames = (
|
||||
int(self.transformer.config.local_attn_size)
|
||||
if int(self.transformer.config.local_attn_size) != -1
|
||||
@@ -579,7 +594,7 @@ class LingBotWorldCausalDMDPipeline(
|
||||
)
|
||||
return ARDiffusionKVCacheSpec(
|
||||
num_layers=int(self.transformer.config.num_layers),
|
||||
num_kv_heads=num_local_heads,
|
||||
num_kv_heads=int(self.transformer.blocks[0].self_attn.num_sp_heads),
|
||||
head_size=int(self.transformer.config.attention_head_dim),
|
||||
tokens_per_frame=tokens_per_frame,
|
||||
frames_per_block=int(self.transformer.config.num_frames_per_block),
|
||||
@@ -960,20 +975,11 @@ class LingBotWorldCausalDMDPipeline(
|
||||
def layer_kv() -> Iterator[tuple[torch.Tensor, torch.Tensor]]:
|
||||
for block in self.transformer.blocks:
|
||||
cross_attention = block.cross_attn
|
||||
key = cross_attention.norm_k(cross_attention.k(projected_text)).unflatten(
|
||||
2,
|
||||
(
|
||||
cross_attention.num_local_heads,
|
||||
cross_attention.head_dim,
|
||||
),
|
||||
)
|
||||
value = cross_attention.v(projected_text).unflatten(
|
||||
2,
|
||||
(
|
||||
cross_attention.num_local_heads,
|
||||
cross_attention.head_dim,
|
||||
),
|
||||
shape = (cross_attention.num_local_heads, cross_attention.head_dim)
|
||||
key = cross_attention.shard_kv_heads(
|
||||
cross_attention.norm_k(cross_attention.k(projected_text)).unflatten(2, shape)
|
||||
)
|
||||
value = cross_attention.shard_kv_heads(cross_attention.v(projected_text).unflatten(2, shape))
|
||||
yield key, value
|
||||
|
||||
state.populate_cross_attention(
|
||||
|
||||
Reference in new issue
Block a user