@@ -496,9 +496,13 @@ def _qwen25o_sidecar() -> _FakeSidecar:
496496}
497497
498498
499- def _build_package (projector_type : str , * , dtype : str | None = None ):
500- factory , target , _ = _ROUTES [projector_type ]
501- sidecar = factory ()
499+ def _build_package_from_sidecar (
500+ projector_type : str ,
501+ sidecar : _FakeSidecar ,
502+ * ,
503+ dtype : str | None = None ,
504+ ):
505+ _ , target , _ = _ROUTES [projector_type ]
502506 with (
503507 mock .patch (
504508 "mobius.integrations.gguf._mmproj._resolve_mmproj_companion_path" ,
@@ -516,6 +520,11 @@ def _build_package(projector_type: str, *, dtype: str | None = None):
516520 return sidecar , package
517521
518522
523+ def _build_package (projector_type : str , * , dtype : str | None = None ):
524+ factory , _ , _ = _ROUTES [projector_type ]
525+ return _build_package_from_sidecar (projector_type , factory (), dtype = dtype )
526+
527+
519528@pytest .mark .parametrize ("projector_type" , tuple (_ROUTES ))
520529def test_every_route_builds_only_its_declared_components (projector_type : str ) -> None :
521530 _ , _ , expected = _ROUTES [projector_type ]
@@ -531,6 +540,96 @@ def test_every_route_builds_only_its_declared_components(projector_type: str) ->
531540 )
532541
533542
543+ def test_public_dispatch_preflights_qwen_route_once () -> None :
544+ from mobius .integrations .gguf import _mmproj
545+
546+ sidecar = _qwen2a_sidecar ()
547+ with (
548+ mock .patch (
549+ "mobius.integrations.gguf._mmproj._resolve_mmproj_companion_path" ,
550+ return_value = "synthetic.gguf" ,
551+ ),
552+ mock .patch ("mobius.integrations.gguf._builder._validate_gguf_model" ),
553+ mock .patch (
554+ "mobius.integrations.gguf._mmproj._preflight_standalone_mmproj" ,
555+ wraps = _mmproj ._preflight_standalone_mmproj ,
556+ ) as preflight ,
557+ ):
558+ build_mmproj_from_gguf (
559+ "synthetic.gguf" ,
560+ projector_type = "qwen2a" ,
561+ target_architecture = "qwen2" ,
562+ _mmproj_gguf_model = sidecar ,
563+ )
564+
565+ preflight .assert_called_once_with (
566+ sidecar ,
567+ projector_type = "qwen2a" ,
568+ target_architecture = "qwen2" ,
569+ )
570+
571+
572+ @pytest .mark .parametrize ("projector_type" , ("qwen2a" , "qwen3a" , "qwen2.5o" , "qwen3tts_spkenc" ))
573+ def test_unrelated_silu_metadata_does_not_change_nonconsumer_graph (
574+ projector_type : str ,
575+ ) -> None :
576+ factory , _ , _ = _ROUTES [projector_type ]
577+ baseline_sidecar = factory ()
578+ unrelated_sidecar = factory ()
579+ unrelated_sidecar .metadata ["clip.use_silu" ] = {"invalid" : "but unrelated" }
580+ _ , baseline = _build_package_from_sidecar (projector_type , baseline_sidecar )
581+ _ , unrelated = _build_package_from_sidecar (projector_type , unrelated_sidecar )
582+
583+ def signature (package ) -> dict [str , tuple [object , ...]]:
584+ return {
585+ role : (
586+ tuple ((node .domain , node .op_type ) for node in model .graph ),
587+ tuple (
588+ (value .name , str (value .type ), str (value .shape ))
589+ for value in model .graph .inputs
590+ ),
591+ tuple (
592+ (value .name , str (value .type ), str (value .shape ))
593+ for value in model .graph .outputs
594+ ),
595+ tuple (model .graph .initializers ),
596+ )
597+ for role , model in package .items ()
598+ }
599+
600+ assert baseline .config == unrelated .config
601+ assert signature (baseline ) == signature (unrelated )
602+
603+
604+ @pytest .mark .parametrize ("projector_type" , ("glm4v" , "glma" , "qwen3vl_merger" ))
605+ @pytest .mark .parametrize ("invalid" , [0 , 1 , "true" ])
606+ def test_silu_consumers_require_boolean_metadata (
607+ projector_type : str ,
608+ invalid : object ,
609+ ) -> None :
610+ factory , _ , _ = _ROUTES [projector_type ]
611+ sidecar = factory ()
612+ sidecar .metadata ["clip.use_silu" ] = invalid
613+
614+ with pytest .raises (ValueError , match = "must be a boolean" ):
615+ validate_qwen_glm_projector_metadata (sidecar , projector_type )
616+
617+
618+ def test_qwen3vl_silu_metadata_changes_only_transformer_block_activation () -> None :
619+ gelu_sidecar = _qwen3vl_sidecar ()
620+ silu_sidecar = _qwen3vl_sidecar ()
621+ silu_sidecar .metadata ["clip.use_silu" ] = True
622+ _ , gelu_package = _build_package_from_sidecar ("qwen3vl_merger" , gelu_sidecar )
623+ _ , silu_package = _build_package_from_sidecar ("qwen3vl_merger" , silu_sidecar )
624+
625+ gelu_ops = [node .op_type for node in gelu_package ["vision_encoder" ].graph ]
626+ silu_ops = [node .op_type for node in silu_package ["vision_encoder" ].graph ]
627+ assert "Swish" not in gelu_ops
628+ assert silu_ops .count ("Swish" ) == 1
629+ # Final and DeepStack mergers remain tanh-GELU in both variants.
630+ assert silu_ops .count ("Gelu" ) == gelu_ops .count ("Gelu" ) - 1
631+
632+
534633@pytest .mark .parametrize ("projector_type" , tuple (_ROUTES ))
535634@pytest .mark .parametrize (
536635 "invalid" ,
@@ -895,7 +994,7 @@ def test_qwen3a_projector_matches_transformers() -> None:
895994 "audio_encoder" ,
896995 {
897996 "input_features" : features ,
898- "feature_attention_mask " : np .ones ((1 , 100 ), dtype = np .int64 ),
997+ "input_features_mask " : np .ones ((1 , 100 ), dtype = np .int32 ),
899998 },
900999 )
9011000 np .testing .assert_allclose (actual , expected , rtol = 3e-4 , atol = 3e-4 )
@@ -913,7 +1012,7 @@ def test_qwen3a_projector_matches_transformers() -> None:
9131012 padded_outputs = session .run (
9141013 {
9151014 "input_features" : padded ,
916- "feature_attention_mask " : padded_mask ,
1015+ "input_features_mask " : padded_mask . astype ( np . int32 ) ,
9171016 }
9181017 )
9191018 finally :
@@ -942,20 +1041,64 @@ def test_qwen3a_graph_io_and_processor_metadata_publish_lengths() -> None:
9421041
9431042 assert [value .name for value in graph .inputs ] == [
9441043 "input_features" ,
945- "feature_attention_mask " ,
1044+ "input_features_mask " ,
9461045 ]
9471046 assert [value .name for value in graph .outputs ] == [
9481047 "audio_features" ,
9491048 "audio_feature_lengths" ,
9501049 ]
951- assert package .gguf_processor_abi ["feature_attention_mask " ] == (
952- "int64 [1,frames], binary and right-padded"
1050+ assert package .gguf_processor_abi ["input_features_mask " ] == (
1051+ "int32 [1,frames], binary and right-padded"
9531052 )
9541053 assert "audio_feature_lengths" in package .gguf_processor_abi ["output" ]
9551054
9561055
1056+ def test_qwen3a_accepts_processor_outputs_without_adapter () -> None :
1057+ from transformers import WhisperFeatureExtractor
1058+ from transformers .models .qwen3_asr .processing_qwen3_asr import Qwen3ASRProcessor
1059+
1060+ _ , package = _build_package ("qwen3a" )
1061+ # Construct the pinned processor class with a tiny, network-free feature
1062+ # extractor. Text is omitted, so only these attributes are consulted.
1063+ processor = object .__new__ (Qwen3ASRProcessor )
1064+ processor .feature_extractor = WhisperFeatureExtractor (
1065+ feature_size = 8 ,
1066+ sampling_rate = 16_000 ,
1067+ hop_length = 160 ,
1068+ chunk_length = 1 ,
1069+ n_fft = 400 ,
1070+ padding_value = 0.0 ,
1071+ return_attention_mask = True ,
1072+ )
1073+ processor .tokenizer = SimpleNamespace (init_kwargs = {})
1074+ processor .chat_template = None
1075+ processor .timestamp_segment_time = 80
1076+ processor .audio_token = "<audio>"
1077+ processed = processor (
1078+ text = None ,
1079+ audio = [np .zeros (16_000 , dtype = np .float32 )],
1080+ sampling_rate = 16_000 ,
1081+ return_tensors = "pt" ,
1082+ )
1083+ input_names = {value .name for value in package ["audio_encoder" ].graph .inputs }
1084+ feeds = {name : processed [name ].numpy () for name in input_names }
1085+
1086+ assert set (feeds ) == {"input_features" , "input_features_mask" }
1087+ assert feeds ["input_features_mask" ].dtype == np .int32
1088+ session = OnnxModelSession (package ["audio_encoder" ])
1089+ try :
1090+ outputs = session .run (feeds )
1091+ finally :
1092+ session .close ()
1093+ assert outputs ["audio_features" ].shape == (13 , 12 )
1094+ np .testing .assert_array_equal (
1095+ outputs ["audio_feature_lengths" ],
1096+ np .array ([13 ], dtype = np .int64 ),
1097+ )
1098+
1099+
9571100@pytest .mark .parametrize (
958- "feature_attention_mask " ,
1101+ "input_features_mask " ,
9591102 [
9601103 np .zeros ((1 , 100 ), dtype = np .int64 ),
9611104 np .array ([[1 ] * 49 + [0 ] + [1 ] * 50 ], dtype = np .int64 ),
@@ -964,7 +1107,7 @@ def test_qwen3a_graph_io_and_processor_metadata_publish_lengths() -> None:
9641107 ids = ["empty" , "not-right-padded" , "non-binary" ],
9651108)
9661109def test_qwen3a_processor_mask_fails_closed (
967- feature_attention_mask : np .ndarray ,
1110+ input_features_mask : np .ndarray ,
9681111) -> None :
9691112 _ , package = _build_package ("qwen3a" )
9701113 features = np .zeros ((1 , 8 , 100 ), dtype = np .float32 )
@@ -982,7 +1125,7 @@ def test_qwen3a_processor_mask_fails_closed(
9821125 "audio_encoder" ,
9831126 {
9841127 "input_features" : features ,
985- "feature_attention_mask " : feature_attention_mask ,
1128+ "input_features_mask " : input_features_mask . astype ( np . int32 ) ,
9861129 },
9871130 )
9881131
@@ -1654,7 +1797,7 @@ def test_reduced_precision_audio_casts_float_processor_input(
16541797
16551798 feeds = {"input_features" : features }
16561799 if projector_type == "qwen3a" :
1657- feeds ["feature_attention_mask " ] = np .ones ((1 , frames ), dtype = np .int64 )
1800+ feeds ["input_features_mask " ] = np .ones ((1 , frames ), dtype = np .int32 )
16581801 actual = _run_component (package , "audio_encoder" , feeds )
16591802
16601803 assert actual .dtype == np .float16
0 commit comments