@@ -775,99 +775,6 @@ def test_padded_video_valid_outputs_match_unpadded(self):
775775 atol = 1e-4 ,
776776 )
777777
778- def test_padded_video_valid_outputs_match_unpadded_batched (self ):
779- """Padded tokens do not change valid outputs anywhere in the ViT for batched inputs."""
780- raw_grid_1 = (2 , 2 , 2 )
781- raw_grid_2 = (1 , 4 , 4 )
782- max_grid = (3 , 4 , 4 )
783- config = pyconfig .initialize (
784- ["" , base_config_path ],
785- model_name = "qwen3-omni-30b-a3b" ,
786- attention = "dot_product" ,
787- attention_type = "full" ,
788- dtype = "float32" ,
789- dtype_mm = "float32" ,
790- weight_dtype = "float32" ,
791- override_model_config = True ,
792- attention_for_vit = "dot_product" ,
793- hidden_size_for_vit = 16 ,
794- num_attention_heads_for_vit = 2 ,
795- intermediate_size_for_vit = 32 ,
796- num_hidden_layers_for_vit = 1 ,
797- deepstack_visual_indexes_for_vit = [],
798- video_max_grid_t = max_grid [0 ],
799- video_max_grid_h = max_grid [1 ],
800- video_max_grid_w = max_grid [2 ],
801- )
802- patch_size = config .patch_size_for_vit
803- temporal_patch_size = config .temporal_patch_size_for_vit
804-
805- # Generate raw videos
806- raw_shape_1 = (
807- 1 ,
808- config .num_channels_for_vit ,
809- raw_grid_1 [0 ] * temporal_patch_size ,
810- raw_grid_1 [1 ] * patch_size ,
811- raw_grid_1 [2 ] * patch_size ,
812- )
813- raw_shape_2 = (
814- 1 ,
815- config .num_channels_for_vit ,
816- raw_grid_2 [0 ] * temporal_patch_size ,
817- raw_grid_2 [1 ] * patch_size ,
818- raw_grid_2 [2 ] * patch_size ,
819- )
820- raw_video_1 , _ = create_random_jax_torch (* raw_shape_1 )
821- raw_video_2 , _ = create_random_jax_torch (* raw_shape_2 )
822-
823- # Pad them individually
824- padded_video_1 , _ , video_mask_1 = maybe_pad_video_values_to_max_grid (
825- np .asarray (raw_video_1 ), np .asarray ([raw_grid_1 ]), config
826- )
827- padded_video_2 , _ , video_mask_2 = maybe_pad_video_values_to_max_grid (
828- np .asarray (raw_video_2 ), np .asarray ([raw_grid_2 ]), config
829- )
830-
831- # Batch them
832- batched_padded_video = jnp .concatenate ([padded_video_1 , padded_video_2 ], axis = 0 )
833- batched_video_mask = jnp .concatenate ([video_mask_1 , video_mask_2 ], axis = 0 )
834- batched_grid_thw = jnp .array ([raw_grid_1 , raw_grid_2 ], dtype = jnp .int32 )
835-
836- encoder = JaxQwen3OmniMoeVisionEncoder (config = config , mesh = self .mesh , rngs = nnx .Rngs (42 ))
837-
838- # Run individual unpadded
839- raw_output_1 , _ = encoder (raw_video_1 )
840- raw_output_2 , _ = encoder (raw_video_2 )
841-
842- # Run batched padded
843- batched_padded_output , _ = encoder (
844- batched_padded_video ,
845- video_mask = batched_video_mask ,
846- video_grid_thw = batched_grid_thw ,
847- )
848-
849- # Verify equivalence for batch item 0
850- patch_mask_1 = (
851- np .asarray (video_mask_1 ).reshape (1 , - 1 , temporal_patch_size * patch_size * patch_size ).max (- 1 ).astype (bool )
852- )
853- np .testing .assert_allclose (
854- np .asarray (raw_output_1 ).reshape (- 1 , config .hidden_size_for_vit ),
855- np .asarray (batched_padded_output [0 ])[np .asarray (patch_mask_1 )[0 ]],
856- rtol = 1e-4 ,
857- atol = 1e-4 ,
858- )
859-
860- # Verify equivalence for batch item 1
861- patch_mask_2 = (
862- np .asarray (video_mask_2 ).reshape (1 , - 1 , temporal_patch_size * patch_size * patch_size ).max (- 1 ).astype (bool )
863- )
864- np .testing .assert_allclose (
865- np .asarray (raw_output_2 ).reshape (- 1 , config .hidden_size_for_vit ),
866- np .asarray (batched_padded_output [1 ])[np .asarray (patch_mask_2 )[0 ]],
867- rtol = 1e-4 ,
868- atol = 1e-4 ,
869- )
870-
871778 def test_padded_video_projected_outputs_match_unpadded_batched (self ):
872779 """Padded tokens do not change valid projected outputs for batched inputs."""
873780 raw_grid_1 = (2 , 2 , 2 )
0 commit comments