Skip to content

torch.compile fullgraph compatibility for Hunyuan Video #11457

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

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/diffusers/models/transformers/transformer_hunyuan_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,17 +1068,15 @@ def forward(
latent_sequence_length = hidden_states.shape[1]
condition_sequence_length = encoder_hidden_states.shape[1]
sequence_length = latent_sequence_length + condition_sequence_length
attention_mask = torch.zeros(
attention_mask = torch.ones(
batch_size, sequence_length, device=hidden_states.device, dtype=torch.bool
) # [B, N]

effective_condition_sequence_length = encoder_attention_mask.sum(dim=1, dtype=torch.int) # [B,]
effective_sequence_length = latent_sequence_length + effective_condition_sequence_length

for i in range(batch_size):
attention_mask[i, : effective_sequence_length[i]] = True
# [B, 1, 1, N], for broadcasting across attention heads
attention_mask = attention_mask.unsqueeze(1).unsqueeze(1)
indices = torch.arange(sequence_length, device=hidden_states.device).unsqueeze(0) # [1, N]
mask_indices = indices >= effective_sequence_length.unsqueeze(1) # [B, N]
attention_mask = attention_mask.masked_fill(mask_indices, False)
attention_mask = attention_mask.unsqueeze(1).unsqueeze(1) # [B, 1, 1, N]

# 4. Transformer blocks
if torch.is_grad_enabled() and self.gradient_checkpointing:
Expand Down
Loading