Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/diffusers/models/transformers/transformer_anyflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ def forward(
attn1_kwargs["kv_cache"] = kv_cache
attn1_kwargs["kv_cache_flag"] = kv_cache_flag
attn_output = self.attn1(**attn1_kwargs)
hidden_states = (hidden_states.float() + attn_output * gate_msa).type_as(hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of hidden_states)
hidden_states = (hidden_states + attn_output * gate_msa).type_as(hidden_states)

# 2. Cross-attention
norm_hidden_states = self.norm2(hidden_states.float()).type_as(hidden_states)
Expand All @@ -499,7 +500,7 @@ def forward(
hidden_states
)
ff_output = self.ffn(norm_hidden_states)
hidden_states = (hidden_states.float() + ff_output.float() * c_gate_msa).type_as(hidden_states)
hidden_states = (hidden_states + ff_output * c_gate_msa).type_as(hidden_states)

return hidden_states

Expand Down
5 changes: 3 additions & 2 deletions src/diffusers/models/transformers/transformer_anyflow_far.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@ def forward(
attn1_kwargs["kv_cache"] = kv_cache
attn1_kwargs["kv_cache_flag"] = kv_cache_flag
attn_output = self.attn1(**attn1_kwargs)
hidden_states = (hidden_states.float() + attn_output * gate_msa).type_as(hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of hidden_states)
hidden_states = (hidden_states + attn_output * gate_msa).type_as(hidden_states)

# 2. Cross-attention
norm_hidden_states = self.norm2(hidden_states.float()).type_as(hidden_states)
Expand All @@ -612,7 +613,7 @@ def forward(
hidden_states
)
ff_output = self.ffn(norm_hidden_states)
hidden_states = (hidden_states.float() + ff_output.float() * c_gate_msa).type_as(hidden_states)
hidden_states = (hidden_states + ff_output * c_gate_msa).type_as(hidden_states)

return hidden_states

Expand Down
5 changes: 3 additions & 2 deletions src/diffusers/models/transformers/transformer_chronoedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ def forward(
# 1. Self-attention
norm_hidden_states = (self.norm1(hidden_states.float()) * (1 + scale_msa) + shift_msa).type_as(hidden_states)
attn_output = self.attn1(norm_hidden_states, None, None, rotary_emb)
hidden_states = (hidden_states.float() + attn_output * gate_msa).type_as(hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of hidden_states)
hidden_states = (hidden_states + attn_output * gate_msa).type_as(hidden_states)

# 2. Cross-attention
norm_hidden_states = self.norm2(hidden_states.float()).type_as(hidden_states)
Expand All @@ -514,7 +515,7 @@ def forward(
hidden_states
)
ff_output = self.ffn(norm_hidden_states)
hidden_states = (hidden_states.float() + ff_output.float() * c_gate_msa).type_as(hidden_states)
hidden_states = (hidden_states + ff_output * c_gate_msa).type_as(hidden_states)

return hidden_states

Expand Down
5 changes: 3 additions & 2 deletions src/diffusers/models/transformers/transformer_helios.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ def forward(
rotary_emb,
original_context_length,
)
hidden_states = (hidden_states.float() + attn_output * gate_msa).type_as(hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of hidden_states)
hidden_states = (hidden_states + attn_output * gate_msa).type_as(hidden_states)

# 2. Cross-attention
if self.guidance_cross_attn:
Expand Down Expand Up @@ -493,7 +494,7 @@ def forward(
hidden_states
)
ff_output = self.ffn(norm_hidden_states)
hidden_states = (hidden_states.float() + ff_output.float() * c_gate_msa).type_as(hidden_states)
hidden_states = (hidden_states + ff_output * c_gate_msa).type_as(hidden_states)

return hidden_states

Expand Down
5 changes: 3 additions & 2 deletions src/diffusers/models/transformers/transformer_skyreels_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ def forward(
# 1. Self-attention
norm_hidden_states = (self.norm1(hidden_states.float()) * (1 + scale_msa) + shift_msa).type_as(hidden_states)
attn_output = self.attn1(norm_hidden_states, None, attention_mask, rotary_emb)
hidden_states = (hidden_states.float() + attn_output * gate_msa).type_as(hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of hidden_states)
hidden_states = (hidden_states + attn_output * gate_msa).type_as(hidden_states)

# 2. Cross-attention
norm_hidden_states = self.norm2(hidden_states.float()).type_as(hidden_states)
Expand All @@ -510,7 +511,7 @@ def forward(
hidden_states
)
ff_output = self.ffn(norm_hidden_states)
hidden_states = (hidden_states.float() + ff_output.float() * c_gate_msa).type_as(hidden_states)
hidden_states = (hidden_states + ff_output * c_gate_msa).type_as(hidden_states)

return hidden_states

Expand Down
5 changes: 3 additions & 2 deletions src/diffusers/models/transformers/transformer_wan.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ def forward(
# 1. Self-attention
norm_hidden_states = (self.norm1(hidden_states.float()) * (1 + scale_msa) + shift_msa).type_as(hidden_states)
attn_output = self.attn1(norm_hidden_states, None, None, rotary_emb)
hidden_states = (hidden_states.float() + attn_output * gate_msa).type_as(hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of hidden_states)
hidden_states = (hidden_states + attn_output * gate_msa).type_as(hidden_states)

# 2. Cross-attention
norm_hidden_states = self.norm2(hidden_states.float()).type_as(hidden_states)
Expand All @@ -499,7 +500,7 @@ def forward(
hidden_states
)
ff_output = self.ffn(norm_hidden_states)
hidden_states = (hidden_states.float() + ff_output.float() * c_gate_msa).type_as(hidden_states)
hidden_states = (hidden_states + ff_output * c_gate_msa).type_as(hidden_states)

return hidden_states

Expand Down
5 changes: 3 additions & 2 deletions src/diffusers/models/transformers/transformer_wan_animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,8 @@ def forward(
# 1. Self-attention
norm_hidden_states = (self.norm1(hidden_states.float()) * (1 + scale_msa) + shift_msa).type_as(hidden_states)
attn_output = self.attn1(norm_hidden_states, None, None, rotary_emb)
hidden_states = (hidden_states.float() + attn_output * gate_msa).type_as(hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of hidden_states)
hidden_states = (hidden_states + attn_output * gate_msa).type_as(hidden_states)

# 2. Cross-attention
norm_hidden_states = self.norm2(hidden_states.float()).type_as(hidden_states)
Expand All @@ -978,7 +979,7 @@ def forward(
hidden_states
)
ff_output = self.ffn(norm_hidden_states)
hidden_states = (hidden_states.float() + ff_output.float() * c_gate_msa).type_as(hidden_states)
hidden_states = (hidden_states + ff_output * c_gate_msa).type_as(hidden_states)

return hidden_states

Expand Down
7 changes: 3 additions & 4 deletions src/diffusers/models/transformers/transformer_wan_vace.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def forward(
control_hidden_states
)
attn_output = self.attn1(norm_hidden_states, None, None, rotary_emb)
control_hidden_states = (control_hidden_states.float() + attn_output * gate_msa).type_as(control_hidden_states)
# gate_msa is float32, so the residual add is float32 through type promotion (no float32 copy of the input)
control_hidden_states = (control_hidden_states + attn_output * gate_msa).type_as(control_hidden_states)

# 2. Cross-attention
norm_hidden_states = self.norm2(control_hidden_states.float()).type_as(control_hidden_states)
Expand All @@ -124,9 +125,7 @@ def forward(
control_hidden_states
)
ff_output = self.ffn(norm_hidden_states)
control_hidden_states = (control_hidden_states.float() + ff_output.float() * c_gate_msa).type_as(
control_hidden_states
)
control_hidden_states = (control_hidden_states + ff_output * c_gate_msa).type_as(control_hidden_states)

conditioning_states = None
if self.proj_out is not None:
Expand Down
Loading