diff --git a/examples/gemma4/ort_genai/vlm/genai_config.json b/examples/gemma4/ort_genai/vlm/genai_config.json index c47657bf..c53e3a5f 100644 --- a/examples/gemma4/ort_genai/vlm/genai_config.json +++ b/examples/gemma4/ort_genai/vlm/genai_config.json @@ -4,7 +4,10 @@ "vocab_size": 262144, "context_length": 131072, "bos_token_id": 2, - "eos_token_id": [1, 106], + "eos_token_id": [ + 1, + 106 + ], "pad_token_id": 0, "image_token_id": 255999, "decoder": { @@ -12,7 +15,7 @@ "log_id": "onnxruntime-genai", "provider_options": [] }, - "filename": "model.onnx", + "filename": "decoder/model.onnx", "hidden_size": 1536, "head_size": 256, "num_attention_heads": 8, @@ -37,12 +40,26 @@ "alignment": "right", "slide_key_value_cache": true, "slide_inputs": true, - "layers": [0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13] + "layers": [ + 0, + 1, + 2, + 3, + 5, + 6, + 7, + 8, + 10, + 11, + 12, + 13 + ] } }, "vision": { "filename": "vision.onnx", "config_filename": "processor_config.json", + "spatial_merge_size": 2, "session_options": { "log_id": "onnxruntime-genai", "provider_options": [] diff --git a/src/mobius/integrations/ort_genai/auto_export.py b/src/mobius/integrations/ort_genai/auto_export.py index fe2afe28..37a9ff74 100644 --- a/src/mobius/integrations/ort_genai/auto_export.py +++ b/src/mobius/integrations/ort_genai/auto_export.py @@ -196,7 +196,9 @@ def _write_processor_config( "patch_size": getattr(vision, "patch_size", None) or 14, } - path = os.path.join(output_dir, "processor_config.json") + proc_filename = "processor_config.json" + + path = os.path.join(output_dir, proc_filename) with open(path, "w", encoding="utf-8") as f: json.dump(processor, f, indent=4) return path @@ -275,8 +277,9 @@ def _write_genai_config( vision_kwargs["spatial_merge_size"] = None vision_kwargs["config_filename"] = "vision_processor.json" elif model_type in ("gemma4", "gemma4_text"): - vision_kwargs["spatial_merge_size"] = None - vision_kwargs["config_filename"] = "processor_config.json" + vision_cfg = getattr(config, "vision", None) + sms = getattr(vision_cfg, "spatial_merge_size", 2) + vision_kwargs["spatial_merge_size"] = sms if vision_input_mapping is not None: vision_kwargs["input_names"] = vision_input_mapping diff --git a/src/mobius/integrations/ort_genai/auto_export_test.py b/src/mobius/integrations/ort_genai/auto_export_test.py index 0ab5ada7..60b8c21c 100644 --- a/src/mobius/integrations/ort_genai/auto_export_test.py +++ b/src/mobius/integrations/ort_genai/auto_export_test.py @@ -586,7 +586,7 @@ def test_gemma4_vision_inputs(self, tmp_path): assert "pixel_values" in vision_inputs assert "pixel_position_ids" in vision_inputs assert "image_grid_thw" not in vision_inputs - assert "spatial_merge_size" not in data["model"]["vision"] + assert data["model"]["vision"]["spatial_merge_size"] == 2 def test_gemma4_decoder_has_input_ids_and_inputs_embeds(self, tmp_path): """Gemma4 decoder has both inputs_embeds and input_ids.""" @@ -779,7 +779,7 @@ def test_gemma4_genai_config_from_real_model(self, tmp_path): # Config-level properties are still present assert data["model"]["image_token_id"] == 255999 - assert "spatial_merge_size" not in data["model"]["vision"] + assert data["model"]["vision"]["spatial_merge_size"] == 2 assert data["model"]["vision"]["config_filename"] == "processor_config.json" def test_auto_export_produces_genai_config(self, tmp_path): diff --git a/src/mobius/integrations/ort_genai/genai_config.py b/src/mobius/integrations/ort_genai/genai_config.py index e35b15db..9d83e6cc 100644 --- a/src/mobius/integrations/ort_genai/genai_config.py +++ b/src/mobius/integrations/ort_genai/genai_config.py @@ -353,9 +353,10 @@ def generate(self) -> dict[str, Any]: decoder_inputs = dict(self._decoder_inputs) else: decoder_inputs = _default_decoder_inputs(is_vlm=is_multimodal) + decoder_filename = "decoder/model.onnx" if is_multimodal else "model.onnx" decoder: dict[str, Any] = { "session_options": _make_session_options(self.ep), - "filename": "model.onnx", + "filename": decoder_filename, "head_size": self.head_dim, "hidden_size": self.hidden_size, "inputs": decoder_inputs,