Repository navigation
Fix LTX-2 context parallel plan and Ulysses attn mask head sharding #14317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2395,6 +2395,10 @@ def forward( | |
| mask_list = [torch.empty_like(attn_mask) for _ in range(world_size)] | ||
| dist.all_gather(mask_list, attn_mask, group=group) | ||
| attn_mask = torch.cat(mask_list, dim=-1) | ||
| if attn_mask is not None and attn_mask.ndim == 4 and attn_mask.shape[1] == H: | ||
| # QKV carry H // world_size heads after the all-to-all; shard the mask's head axis to match. | ||
| local_rank = _parallel_config.context_parallel_config._ulysses_local_rank | ||
| attn_mask = attn_mask.chunk(world_size, dim=1)[local_rank] | ||
|
Comment on lines
+2398
to
+2401
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this only applicable for LTX2? Are models affected by this? |
||
|
|
||
| out = forward_op( | ||
| ctx, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1091,18 +1091,6 @@ class LTX2VideoTransformer3DModel( | |
| _supports_gradient_checkpointing = True | ||
| _skip_layerwise_casting_patterns = ["norm"] | ||
| _repeated_blocks = ["LTX2VideoTransformerBlock"] | ||
| _cp_plan = { | ||
| "": { | ||
| "hidden_states": ContextParallelInput(split_dim=1, expected_dims=3, split_output=False), | ||
| "encoder_hidden_states": ContextParallelInput(split_dim=1, expected_dims=3, split_output=False), | ||
| "encoder_attention_mask": ContextParallelInput(split_dim=1, expected_dims=2, split_output=False), | ||
| }, | ||
| "rope": { | ||
| 0: ContextParallelInput(split_dim=1, expected_dims=3, split_output=True), | ||
| 1: ContextParallelInput(split_dim=1, expected_dims=3, split_output=True), | ||
| }, | ||
| "proj_out": ContextParallelOutput(gather_dim=1, expected_dims=3), | ||
| } | ||
|
|
||
| @register_to_config | ||
| def __init__( | ||
|
|
@@ -1318,6 +1306,37 @@ def __init__( | |
|
|
||
| self.gradient_checkpointing = False | ||
|
|
||
| # RoPE modules return (cos, sin) shaped (B, T, D) for rope_type="interleaved" and (B, H, T, D // 2) | ||
| # for rope_type="split", so the sequence dim to shard depends on the config. | ||
| if rope_type == "split": | ||
| rope_plan = { | ||
| 0: ContextParallelInput(split_dim=2, expected_dims=4, split_output=True), | ||
| 1: ContextParallelInput(split_dim=2, expected_dims=4, split_output=True), | ||
| } | ||
| else: | ||
| rope_plan = { | ||
| 0: ContextParallelInput(split_dim=1, expected_dims=3, split_output=True), | ||
| 1: ContextParallelInput(split_dim=1, expected_dims=3, split_output=True), | ||
| } | ||
| self._cp_plan = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to make this an instance attribute. If we set _rope_cp_plan = {
0: ContextParallelInput(split_dim=-2, expected_dims=None, split_output=True),
1: ContextParallelInput(split_dim=-2, expected_dims=None, split_output=True),
}this should work for both layouts and with the existing class attribute cp plan. |
||
| "": { | ||
| "hidden_states": ContextParallelInput(split_dim=1, expected_dims=3, split_output=False), | ||
| "timestep": ContextParallelInput(split_dim=1, expected_dims=2, split_output=False), | ||
| "audio_hidden_states": ContextParallelInput(split_dim=1, expected_dims=3, split_output=False), | ||
| "audio_timestep": ContextParallelInput(split_dim=1, expected_dims=2, split_output=False), | ||
| "encoder_hidden_states": ContextParallelInput(split_dim=1, expected_dims=3, split_output=False), | ||
| "encoder_attention_mask": ContextParallelInput(split_dim=1, expected_dims=2, split_output=False), | ||
| "audio_encoder_hidden_states": ContextParallelInput(split_dim=1, expected_dims=3, split_output=False), | ||
| "audio_encoder_attention_mask": ContextParallelInput(split_dim=1, expected_dims=2, split_output=False), | ||
| }, | ||
| "rope": rope_plan, | ||
| "audio_rope": rope_plan, | ||
| "cross_attn_rope": rope_plan, | ||
| "cross_attn_audio_rope": rope_plan, | ||
| "proj_out": ContextParallelOutput(gather_dim=1, expected_dims=3), | ||
| "audio_proj_out": ContextParallelOutput(gather_dim=1, expected_dims=3), | ||
| } | ||
|
|
||
| @apply_lora_scale("attention_kwargs") | ||
| def forward( | ||
| self, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this change in a simple manner?