@@ -837,18 +837,13 @@ def __init__(
837837 def forward (
838838 self ,
839839 hidden_states : torch .Tensor ,
840- encoder_hidden_states : torch .Tensor | None ,
840+ encoder_hidden_states : torch .Tensor ,
841841 temb_mod : torch .Tensor ,
842842 image_rotary_emb : tuple [torch .Tensor , torch .Tensor ] | None = None ,
843843 joint_attention_kwargs : dict [str , Any ] | None = None ,
844- split_hidden_states : bool = False ,
845- text_seq_len : int | None = None ,
846844 ) -> tuple [torch .Tensor , torch .Tensor ]:
847- # If encoder_hidden_states is None, hidden_states is assumed to have encoder_hidden_states already
848- # concatenated
849- if encoder_hidden_states is not None :
850- text_seq_len = encoder_hidden_states .shape [1 ]
851- hidden_states = torch .cat ([encoder_hidden_states , hidden_states ], dim = 1 )
845+ text_seq_len = encoder_hidden_states .shape [1 ]
846+ hidden_states = torch .cat ([encoder_hidden_states , hidden_states ], dim = 1 )
852847
853848 mod_shift , mod_scale , mod_gate = Flux2Modulation .split (temb_mod , 1 )[0 ]
854849
@@ -866,11 +861,8 @@ def forward(
866861 if hidden_states .dtype == torch .float16 :
867862 hidden_states = hidden_states .clip (- 65504 , 65504 )
868863
869- if split_hidden_states :
870- encoder_hidden_states , hidden_states = hidden_states [:, :text_seq_len ], hidden_states [:, text_seq_len :]
871- return encoder_hidden_states , hidden_states
872- else :
873- return hidden_states
864+ encoder_hidden_states , hidden_states = hidden_states [:, :text_seq_len ], hidden_states [:, text_seq_len :]
865+ return encoder_hidden_states , hidden_states
874866
875867
876868class Flux2TransformerBlock (nn .Module ):
@@ -1374,12 +1366,9 @@ def forward(
13741366 joint_attention_kwargs = kv_attn_kwargs ,
13751367 )
13761368
1377- # Concatenate text and image streams for single-block inference
1378- hidden_states = torch .cat ([encoder_hidden_states , hidden_states ], dim = 1 )
1379-
13801369 # Blend single block modulation for extract mode: [txt_mod, ref_mod, img_mod]
13811370 if kv_cache_mode == "extract" and num_ref_tokens > 0 :
1382- total_single_len = hidden_states .shape [1 ]
1371+ total_single_len = num_txt_tokens + hidden_states .shape [1 ]
13831372 single_stream_mod = _blend_single_block_mods (
13841373 single_stream_mod , ref_single_mod , num_txt_tokens , num_ref_tokens , total_single_len
13851374 )
@@ -1396,28 +1385,26 @@ def forward(
13961385 kv_attn_kwargs_single ["kv_cache" ] = kv_cache .get_single (index_block )
13971386
13981387 if torch .is_grad_enabled () and self .gradient_checkpointing :
1399- hidden_states = self ._gradient_checkpointing_func (
1388+ encoder_hidden_states , hidden_states = self ._gradient_checkpointing_func (
14001389 block ,
14011390 hidden_states ,
1402- None ,
1391+ encoder_hidden_states ,
14031392 single_stream_mod ,
14041393 concat_rotary_emb ,
14051394 kv_attn_kwargs_single ,
14061395 )
14071396 else :
1408- hidden_states = block (
1397+ encoder_hidden_states , hidden_states = block (
14091398 hidden_states = hidden_states ,
1410- encoder_hidden_states = None ,
1399+ encoder_hidden_states = encoder_hidden_states ,
14111400 temb_mod = single_stream_mod ,
14121401 image_rotary_emb = concat_rotary_emb ,
14131402 joint_attention_kwargs = kv_attn_kwargs_single ,
14141403 )
14151404
1416- # Remove text tokens (and ref tokens in extract mode) from concatenated stream
1405+ # Remove ref tokens ( extract mode only ) from the image stream
14171406 if kv_cache_mode == "extract" and num_ref_tokens > 0 :
1418- hidden_states = hidden_states [:, num_txt_tokens + num_ref_tokens :, ...]
1419- else :
1420- hidden_states = hidden_states [:, num_txt_tokens :, ...]
1407+ hidden_states = hidden_states [:, num_ref_tokens :, ...]
14211408
14221409 # 7. Output layers
14231410 hidden_states = self .norm_out (hidden_states , temb )
0 commit comments