Skip to content

Commit e87e780

Browse files
committed
fp4 done
1 parent 87bc743 commit e87e780

2 files changed

Lines changed: 4 additions & 8 deletions

File tree

nunchaku/models/normalization.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def forward(
4040
scale_mlp.add_(self.scale_shift)
4141

4242
norm_x_scaled = norm_x * scale_msa[:, None] + shift_msa[:, None]
43-
# torch.addcmul(shift_msa[:, None], norm_x, scale_msa[:, None], value=1, out=norm_x)
4443
return norm_x_scaled, gate_msa, shift_mlp, scale_mlp, gate_mlp
4544

4645

nunchaku/models/transformers/transformer_flux_v2.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,10 @@ def __init__(self, block: FluxSingleTransformerBlock, scale_shift: float = 1, **
188188
def forward(
189189
self,
190190
hidden_states: torch.Tensor,
191-
encoder_hidden_states: torch.Tensor,
192191
temb: torch.Tensor,
193192
image_rotary_emb: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
194193
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
195194
) -> torch.Tensor:
196-
text_seq_len = encoder_hidden_states.shape[1]
197-
hidden_states = torch.cat([encoder_hidden_states, hidden_states], dim=1)
198195

199196
residual = hidden_states
200197
norm_hidden_states, gate = self.norm(hidden_states, emb=temb)
@@ -222,8 +219,7 @@ def forward(
222219
if hidden_states.dtype == torch.float16:
223220
hidden_states = hidden_states.clip(-65504, 65504)
224221

225-
encoder_hidden_states, hidden_states = hidden_states[:, :text_seq_len], hidden_states[:, text_seq_len:]
226-
return encoder_hidden_states, hidden_states
222+
return hidden_states
227223

228224

229225
class NunchakuFluxTransformer2DModelV2(FluxTransformer2DModel, NunchakuModelLoaderMixin):
@@ -374,10 +370,10 @@ def forward(
374370
if controlnet_block_samples is not None:
375371
raise NotImplementedError("Controlnet is not supported for FluxTransformer2DModelV2 for now")
376372

373+
hidden_states = torch.cat([encoder_hidden_states, hidden_states], dim=1)
377374
for index_block, block in enumerate(self.single_transformer_blocks):
378-
encoder_hidden_states, hidden_states = block(
375+
hidden_states = block(
379376
hidden_states=hidden_states,
380-
encoder_hidden_states=encoder_hidden_states,
381377
temb=temb,
382378
image_rotary_emb=rotary_emb_single,
383379
joint_attention_kwargs=joint_attention_kwargs,
@@ -387,6 +383,7 @@ def forward(
387383
if controlnet_single_block_samples is not None:
388384
raise NotImplementedError("Controlnet is not supported for FluxTransformer2DModelV2 for now")
389385

386+
hidden_states = hidden_states[:, txt_tokens:]
390387
hidden_states = self.norm_out(hidden_states, temb)
391388
output = self.proj_out(hidden_states)
392389

0 commit comments

Comments
 (0)