HunyuanVideo: A Systematic Framework For Large Video Generation Model
suppoort more parallelization configurations
Xibo Sun0b2582d84151
diff --git a/README.md b/README.mdindex 145072b..40916e3 100644--- a/README.md+++ b/README.md@@ -314,30 +314,29 @@ You can change the `--ulysses-degree` and `--ring-degree` to control the paralle<details><summary>Supported Parallel Configurations (Click to expand)</summary>-| --video-size | --video-length | supported --ulysses-degree x --ring-degree | --nproc-per-node |-|--------------|----------------|--------------------------------------------|------------------|-| 1280 720 | 129 | 8x1,4x2,2x4,1x8 | 8 |-| 1280 720 | 129 | 4x1,2x2,1x4 | 4 |-| 1280 720 | 129 | 2x1,1x2 | 2 |-| 1104 832 | 129 | 3x1,1x3 | 3 |-| 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |-| 960 960 | 129 | 4x1,2x2,1x4 | 4 |-| 960 960 | 129 | 3x1,1x3 | 3 |-| 960 960 | 129 | 1x2,2x1 | 2 |-| 832 1104 | 129 | 4x1,2x2,1x4 | 4 |-| 832 1104 | 129 | 2x1,1x2 | 2 |-| 720 1280 | 129 | 1x5 | 5 |-| 720 1280 | 129 | 3x1,1x3 | 3 |-| 960 544 | 129 | 6x1,3x2,2x3,1x6 | 6 |-| 960 544 | 129 | 4x1,2x2,1x4 | 4 |-| 960 544 | 129 | 3x1,1x3 | 3 |-| 960 544 | 129 | 1x2,2x1 | 2 |-| 832 624 | 129 | 4x1,2x2,1x4 | 4 |-| 832 624 | 129 | 2x1,1x2 | 2 |-| 720 720 | 129 | 1x5 | 5 |-| 720 720 | 129 | 3x1,1x3 | 3 |-| 624 832 | 129 | 3x1,1x3 | 3 |-| 544 960 | 129 | 2x1,1x2 | 2 |+| --video-size | --video-length | --ulysses-degree x --ring-degree | --nproc_per_node |+|----------------------|----------------|----------------------------------|------------------|+| 1280 720 or 720 1280 | 129 | 8x1,4x2,2x4,1x8 | 8 |+| 1280 720 or 720 1280 | 129 | 1x5 | 5 |+| 1280 720 or 720 1280 | 129 | 4x1,2x2,1x4 | 4 |+| 1280 720 or 720 1280 | 129 | 3x1,1x3 | 3 |+| 1280 720 or 720 1280 | 129 | 2x1,1x2 | 2 |+| 1104 832 or 832 1104 | 129 | 4x1,2x2,1x4 | 4 |+| 1104 832 or 832 1104 | 129 | 3x1,1x3 | 3 |+| 1104 832 or 832 1104 | 129 | 2x1,1x2 | 2 |+| 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |+| 960 960 | 129 | 4x1,2x2,1x4 | 4 |+| 960 960 | 129 | 3x1,1x3 | 3 |+| 960 960 | 129 | 1x2,2x1 | 2 |+| 960 544 or 544 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |+| 960 544 or 544 960 | 129 | 4x1,2x2,1x4 | 4 |+| 960 544 or 544 960 | 129 | 3x1,1x3 | 3 |+| 960 544 or 544 960 | 129 | 1x2,2x1 | 2 |+| 832 624 or 624 832 | 129 | 4x1,2x2,1x4 | 4 |+| 624 832 or 624 832 | 129 | 3x1,1x3 | 3 |+| 832 624 or 624 832 | 129 | 2x1,1x2 | 2 |+| 720 720 | 129 | 1x5 | 5 |+| 720 720 | 129 | 3x1,1x3 | 3 |</details>diff --git a/README_zh.md b/README_zh.mdindex 06ba024..d0e0068 100644--- a/README_zh.md+++ b/README_zh.md@@ -301,30 +301,29 @@ torchrun --nproc_per_node=8 sample_video_parallel.py \<details><summary>支持的并行配置 (点击查看详情)</summary>-| --video-size | --video-length | supported --ulysses-degree x --ring-degree | --nproc-per-node |-|--------------|----------------|--------------------------------------------|------------------|-| 1280 720 | 129 | 8x1,4x2,2x4,1x8 | 8 |-| 1280 720 | 129 | 4x1,2x2,1x4 | 4 |-| 1280 720 | 129 | 2x1,1x2 | 2 |-| 1104 832 | 129 | 3x1,1x3 | 3 |-| 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |-| 960 960 | 129 | 4x1,2x2,1x4 | 4 |-| 960 960 | 129 | 3x1,1x3 | 3 |-| 960 960 | 129 | 1x2,2x1 | 2 |-| 832 1104 | 129 | 4x1,2x2,1x4 | 4 |-| 832 1104 | 129 | 2x1,1x2 | 2 |-| 720 1280 | 129 | 1x5 | 5 |-| 720 1280 | 129 | 3x1,1x3 | 3 |-| 960 544 | 129 | 6x1,3x2,2x3,1x6 | 6 |-| 960 544 | 129 | 4x1,2x2,1x4 | 4 |-| 960 544 | 129 | 3x1,1x3 | 3 |-| 960 544 | 129 | 1x2,2x1 | 2 |-| 832 624 | 129 | 4x1,2x2,1x4 | 4 |-| 832 624 | 129 | 2x1,1x2 | 2 |-| 720 720 | 129 | 1x5 | 5 |-| 720 720 | 129 | 3x1,1x3 | 3 |-| 624 832 | 129 | 3x1,1x3 | 3 |-| 544 960 | 129 | 2x1,1x2 | 2 |+| --video-size | --video-length | --ulysses-degree x --ring-degree | --nproc_per_node |+|----------------------|----------------|----------------------------------|------------------|+| 1280 720 或 720 1280 | 129 | 8x1,4x2,2x4,1x8 | 8 |+| 1280 720 或 720 1280 | 129 | 1x5 | 5 |+| 1280 720 或 720 1280 | 129 | 4x1,2x2,1x4 | 4 |+| 1280 720 或 720 1280 | 129 | 3x1,1x3 | 3 |+| 1280 720 或 720 1280 | 129 | 2x1,1x2 | 2 |+| 1104 832 或 832 1104 | 129 | 4x1,2x2,1x4 | 4 |+| 1104 832 或 832 1104 | 129 | 3x1,1x3 | 3 |+| 1104 832 或 832 1104 | 129 | 2x1,1x2 | 2 |+| 960 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |+| 960 960 | 129 | 4x1,2x2,1x4 | 4 |+| 960 960 | 129 | 3x1,1x3 | 3 |+| 960 960 | 129 | 1x2,2x1 | 2 |+| 960 544 或 544 960 | 129 | 6x1,3x2,2x3,1x6 | 6 |+| 960 544 或 544 960 | 129 | 4x1,2x2,1x4 | 4 |+| 960 544 或 544 960 | 129 | 3x1,1x3 | 3 |+| 960 544 或 544 960 | 129 | 1x2,2x1 | 2 |+| 832 624 或 624 832 | 129 | 4x1,2x2,1x4 | 4 |+| 624 832 或 624 832 | 129 | 3x1,1x3 | 3 |+| 832 624 或 624 832 | 129 | 2x1,1x2 | 2 |+| 720 720 | 129 | 1x5 | 5 |+| 720 720 | 129 | 3x1,1x3 | 3 |</details>diff --git a/hyvideo/inference.py b/hyvideo/inference.pyindex cd42213..3f120a6 100644--- a/hyvideo/inference.py+++ b/hyvideo/inference.py@@ -53,18 +53,27 @@ def parallelize_transformer(pipe):guidance: torch.Tensor = None, # Guidance for modulation, should be cfg_scale x 1000.return_dict: bool = True,):- temporal_size = x.shape[2]- x = torch.chunk(x, get_sequence_parallel_world_size(),dim=-2)[get_sequence_parallel_rank()]- #text_states = torch.chunk(text_states, get_sequence_parallel_world_size(),dim=-2)[get_sequence_parallel_rank()]- #text_mask = torch.chunk(text_mask, get_sequence_parallel_world_size(),dim=-1)[get_sequence_parallel_rank()]-+ if x.shape[-2] // 2 % get_sequence_parallel_world_size() == 0:+ # try to split x by height+ split_dim = -2+ elif x.shape[-1] // 2 % get_sequence_parallel_world_size() == 0:+ # try to split x by width+ split_dim = -1+ else:+ raise ValueError(f"Cannot split video sequence into ulysses_degree x ring_degree ({get_sequence_parallel_world_size()}) parts evenly")++ # patch sizes for the temporal, height, and width dimensions are 1, 2, and 2.+ temporal_size, h, w = x.shape[2], x.shape[3] // 2, x.shape[4] // 2++ x = torch.chunk(x, get_sequence_parallel_world_size(),dim=split_dim)[get_sequence_parallel_rank()]+dim_thw = freqs_cos.shape[-1]- freqs_cos = freqs_cos.reshape(temporal_size, -1, dim_thw)- freqs_cos = torch.chunk(freqs_cos, get_sequence_parallel_world_size(),dim=-2)[get_sequence_parallel_rank()]+ freqs_cos = freqs_cos.reshape(temporal_size, h, w, dim_thw)+ freqs_cos = torch.chunk(freqs_cos, get_sequence_parallel_world_size(),dim=split_dim - 1)[get_sequence_parallel_rank()]freqs_cos = freqs_cos.reshape(-1, dim_thw)dim_thw = freqs_sin.shape[-1]- freqs_sin = freqs_sin.reshape(temporal_size, -1, dim_thw)- freqs_sin = torch.chunk(freqs_sin, get_sequence_parallel_world_size(),dim=-2)[get_sequence_parallel_rank()]+ freqs_sin = freqs_sin.reshape(temporal_size, h, w, dim_thw)+ freqs_sin = torch.chunk(freqs_sin, get_sequence_parallel_world_size(),dim=split_dim - 1)[get_sequence_parallel_rank()]freqs_sin = freqs_sin.reshape(-1, dim_thw)from xfuser.core.long_ctx_attention import xFuserLongContextAttention@@ -86,7 +95,7 @@ def parallelize_transformer(pipe):return_dict = not isinstance(output, tuple)sample = output["x"]- sample = get_sp_group().all_gather(sample, dim=-2)+ sample = get_sp_group().all_gather(sample, dim=split_dim)output["x"] = samplereturn output