Skip to content
Open
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
8 changes: 8 additions & 0 deletions wan/modules/animate/face_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def attention(
pre_attn_layout, post_attn_layout = MEMORY_LAYOUT[mode]

if mode == "torch":
# Apply the layout transformation
q = pre_attn_layout(q)
k = pre_attn_layout(k)
v = pre_attn_layout(v)
if attn_mask is not None and attn_mask.dtype != torch.bool:
attn_mask = attn_mask.to(q.dtype)
x = F.scaled_dot_product_attention(q, k, v, attn_mask=attn_mask, dropout_p=drop_rate, is_causal=causal)
Expand All @@ -77,6 +81,10 @@ def attention(
)
x = x.view(batch_size, max_seqlen_q, x.shape[-2], x.shape[-1]) # reshape x to [b, s, a, d]
elif mode == "vanilla":
# Apply the layout transformation
q = pre_attn_layout(q)
k = pre_attn_layout(k)
v = pre_attn_layout(v)
scale_factor = 1 / math.sqrt(q.size(-1))

b, a, s, _ = q.shape
Expand Down