@@ -751,18 +751,30 @@ def test_unconditional_batch_drops_positive_attention_mask_when_negative_has_non
751751
752752 self .assertNotIn ("encoder_attention_mask" , unconditional_batch )
753753
754- def test_unconditional_batch_drops_model_specific_conditioning_aliases (self ):
754+ def test_unconditional_batch_swaps_model_specific_conditioning_aliases (self ):
755755 batch = _prepared_batch ()
756756 batch ["prompt_embeds" ] = torch .ones (2 , 7 , 4 )
757757 batch ["attention_mask" ] = torch .ones (2 , 7 , dtype = torch .bool )
758758 batch ["attention_masks" ] = torch .ones (2 , 7 , dtype = torch .bool )
759759
760760 unconditional_batch = AnyFlowDistiller ._unconditional_batch (batch )
761761
762- self .assertNotIn ( "prompt_embeds" , unconditional_batch )
762+ self .assertIs ( unconditional_batch [ "prompt_embeds" ], batch [ "negative_encoder_hidden_states" ] )
763763 self .assertNotIn ("attention_mask" , unconditional_batch )
764764 self .assertNotIn ("attention_masks" , unconditional_batch )
765765
766+ def test_unconditional_batch_swaps_alias_masks_when_negative_mask_present (self ):
767+ batch = _prepared_batch ()
768+ batch ["prompt_embeds" ] = torch .ones (2 , 7 , 4 )
769+ batch ["attention_mask" ] = torch .ones (2 , 7 , dtype = torch .bool )
770+ batch ["attention_masks" ] = torch .ones (2 , 7 , dtype = torch .bool )
771+ batch ["negative_encoder_attention_mask" ] = torch .zeros (2 , 5 , dtype = torch .bool )
772+
773+ unconditional_batch = AnyFlowDistiller ._unconditional_batch (batch )
774+
775+ self .assertIs (unconditional_batch ["attention_mask" ], batch ["negative_encoder_attention_mask" ])
776+ self .assertIs (unconditional_batch ["attention_masks" ], batch ["negative_encoder_attention_mask" ])
777+
766778 def test_onpolicy_initializes_separate_discriminator_adapter_and_optimizer (self ):
767779 model = _FlowModel ()
768780 distiller = AnyFlowDistiller (
@@ -1071,7 +1083,7 @@ def test_get_scheduler_wraps_conditional_transformer_pipeline(self):
10711083
10721084
10731085class AnyFlowUnconditionalBatchTests (unittest .TestCase ):
1074- def test_unconditional_batch_drops_stale_mask_and_model_specific_aliases (self ):
1086+ def test_unconditional_batch_drops_stale_mask_and_swaps_model_specific_aliases (self ):
10751087 batch = _prepared_batch ()
10761088 batch ["encoder_attention_mask" ] = torch .ones (2 , 5 , dtype = torch .long )
10771089 batch ["prompt_embeds" ] = torch .ones (2 , 7 , 4 )
@@ -1082,7 +1094,7 @@ def test_unconditional_batch_drops_stale_mask_and_model_specific_aliases(self):
10821094
10831095 self .assertIs (unconditional_batch ["encoder_hidden_states" ], batch ["negative_encoder_hidden_states" ])
10841096 self .assertNotIn ("encoder_attention_mask" , unconditional_batch )
1085- self .assertNotIn ( "prompt_embeds" , unconditional_batch )
1097+ self .assertIs ( unconditional_batch [ "prompt_embeds" ], batch [ "negative_encoder_hidden_states" ] )
10861098 self .assertNotIn ("attention_mask" , unconditional_batch )
10871099 self .assertNotIn ("attention_masks" , unconditional_batch )
10881100
@@ -1162,3 +1174,16 @@ def __init__(self):
11621174 )
11631175 with tempfile .TemporaryDirectory () as temp_dir :
11641176 save_file (state , str (Path (temp_dir ) / "adapter.safetensors" ))
1177+
1178+ def test_unconditional_batch_swaps_negative_pooled_embeds (self ):
1179+ batch = _prepared_batch ()
1180+ batch ["add_text_embeds" ] = torch .ones (2 , 8 )
1181+ batch ["added_cond_kwargs" ] = {"text_embeds" : batch ["add_text_embeds" ], "time_ids" : torch .zeros (2 , 6 )}
1182+ batch ["negative_add_text_embeds" ] = torch .zeros (2 , 8 )
1183+
1184+ unconditional_batch = AnyFlowDistiller ._unconditional_batch (batch )
1185+
1186+ self .assertIs (unconditional_batch ["add_text_embeds" ], batch ["negative_add_text_embeds" ])
1187+ self .assertIs (unconditional_batch ["added_cond_kwargs" ]["text_embeds" ], batch ["negative_add_text_embeds" ])
1188+ self .assertIs (unconditional_batch ["added_cond_kwargs" ]["time_ids" ], batch ["added_cond_kwargs" ]["time_ids" ])
1189+ self .assertIs (batch ["added_cond_kwargs" ]["text_embeds" ], batch ["add_text_embeds" ])
0 commit comments