@@ -1166,6 +1166,12 @@ def __call__(
11661166 # Determine timestep for audio.
11671167 audio_timestep = audio_timestep if audio_timestep is not None else timestep
11681168
1169+ a2v_cross_attention_mask = None
1170+ v2a_cross_attention_mask = None
1171+ if attention_kwargs is not None :
1172+ a2v_cross_attention_mask = attention_kwargs .get ("a2v_cross_attention_mask" , None )
1173+ v2a_cross_attention_mask = attention_kwargs .get ("v2a_cross_attention_mask" , None )
1174+
11691175 if self .attention_kernel == "dot_product" :
11701176 if encoder_attention_mask is not None and encoder_attention_mask .ndim == 2 :
11711177 encoder_attention_mask = (1 - encoder_attention_mask .astype (self .dtype )) * - 10000.0
@@ -1175,6 +1181,14 @@ def __call__(
11751181 audio_encoder_attention_mask = (1 - audio_encoder_attention_mask .astype (self .dtype )) * - 10000.0
11761182 audio_encoder_attention_mask = jnp .expand_dims (audio_encoder_attention_mask , axis = 1 )
11771183
1184+ if a2v_cross_attention_mask is not None and a2v_cross_attention_mask .ndim == 2 :
1185+ a2v_cross_attention_mask = (1 - a2v_cross_attention_mask .astype (self .dtype )) * - 10000.0
1186+ a2v_cross_attention_mask = jnp .expand_dims (a2v_cross_attention_mask , axis = 1 )
1187+
1188+ if v2a_cross_attention_mask is not None and v2a_cross_attention_mask .ndim == 2 :
1189+ v2a_cross_attention_mask = (1 - v2a_cross_attention_mask .astype (self .dtype )) * - 10000.0
1190+ v2a_cross_attention_mask = jnp .expand_dims (v2a_cross_attention_mask , axis = 1 )
1191+
11781192 batch_size = hidden_states .shape [0 ]
11791193
11801194 # 1. Prepare RoPE positional embeddings
@@ -1291,10 +1305,12 @@ def __call__(
12911305 ca_audio_rotary_emb = audio_cross_attn_rotary_emb ,
12921306 encoder_attention_mask = encoder_attention_mask ,
12931307 audio_encoder_attention_mask = audio_encoder_attention_mask ,
1308+ a2v_cross_attention_mask = a2v_cross_attention_mask ,
1309+ v2a_cross_attention_mask = v2a_cross_attention_mask ,
12941310 modality_mask = modality_mask ,
12951311 )
12961312
1297- def apply_block (block , context : LTX2BlockContext , mask , rngs_carry ):
1313+ def apply_block (block , context : LTX2BlockContext , mask ):
12981314 orig_perturbation_mask = context .perturbation_mask
12991315 context = dataclasses .replace (context , perturbation_mask = mask )
13001316 with jax .named_scope ("Transformer Layer" ):
@@ -1305,13 +1321,13 @@ def apply_block(block, context: LTX2BlockContext, mask, rngs_carry):
13051321 audio_hidden_states = audio_hidden_states_out .astype (context .audio_hidden_states .dtype ),
13061322 perturbation_mask = orig_perturbation_mask ,
13071323 )
1308- return context , rngs_carry
1324+ return context
13091325
13101326 if perturbation_mask is None :
13111327
13121328 def scan_fn_ltx2 (carry , block ):
13131329 context , rngs_carry = carry
1314- context , rngs_carry = apply_block (block , context , None , rngs_carry )
1330+ context = apply_block (block , context , None )
13151331 return (context , rngs_carry ), None
13161332
13171333 if self .scan_layers :
@@ -1333,7 +1349,7 @@ def scan_fn_ltx2(carry, block):
13331349 else :
13341350 current_context = base_context
13351351 for block in self .transformer_blocks :
1336- current_context , _ = apply_block (block , current_context , None , None )
1352+ current_context = apply_block (block , current_context , None )
13371353 hidden_states = current_context .hidden_states
13381354 audio_hidden_states = current_context .audio_hidden_states
13391355 else :
@@ -1346,7 +1362,7 @@ def scan_fn_ltx2(carry, block):
13461362 def scan_fn_ltx23 (carry , block_and_mask ):
13471363 block , mask = block_and_mask
13481364 context , rngs_carry = carry
1349- context , rngs_carry = apply_block (block , context , mask , rngs_carry )
1365+ context = apply_block (block , context , mask )
13501366 return (context , rngs_carry ), None
13511367
13521368 if self .scan_layers :
@@ -1369,7 +1385,7 @@ def scan_fn_ltx23(carry, block_and_mask):
13691385 current_context = base_context
13701386 for i , block in enumerate (self .transformer_blocks ):
13711387 mask = perturbation_mask_per_layer [i ] if perturbation_mask_per_layer is not None else None
1372- current_context , _ = apply_block (block , current_context , mask , None )
1388+ current_context = apply_block (block , current_context , mask )
13731389 hidden_states = current_context .hidden_states
13741390 audio_hidden_states = current_context .audio_hidden_states
13751391
0 commit comments