Skip to content

Commit 12b96ae

Browse files
justinchubyCopilot
andauthored
fix: genai config gaps - decoder path, image_processor.json, spatial_merge_size (#204)
Fix 4 gaps vs the reference working Gemma4 genai config: 1. **decoder.filename**: `"decoder/model.onnx"` for multi-model VLM packages (was `"model.onnx"`) 2. **vision.config_filename**: `"image_processor.json"` for Gemma4 (matches ort-extensions convention) 3. **vision.spatial_merge_size**: Added from config (was missing) 4. **audio_features**: Kept in embedding inputs (accurate to graph) Also renames `examples/gemma4/ort_genai/vlm/processor_config.json` → `image_processor.json`. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 95099bf commit 12b96ae

4 files changed

Lines changed: 30 additions & 9 deletions

File tree

‎examples/gemma4/ort_genai/vlm/genai_config.json‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
"vocab_size": 262144,
55
"context_length": 131072,
66
"bos_token_id": 2,
7-
"eos_token_id": [1, 106],
7+
"eos_token_id": [
8+
1,
9+
106
10+
],
811
"pad_token_id": 0,
912
"image_token_id": 255999,
1013
"decoder": {
1114
"session_options": {
1215
"log_id": "onnxruntime-genai",
1316
"provider_options": []
1417
},
15-
"filename": "model.onnx",
18+
"filename": "decoder/model.onnx",
1619
"hidden_size": 1536,
1720
"head_size": 256,
1821
"num_attention_heads": 8,
@@ -37,12 +40,26 @@
3740
"alignment": "right",
3841
"slide_key_value_cache": true,
3942
"slide_inputs": true,
40-
"layers": [0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13]
43+
"layers": [
44+
0,
45+
1,
46+
2,
47+
3,
48+
5,
49+
6,
50+
7,
51+
8,
52+
10,
53+
11,
54+
12,
55+
13
56+
]
4157
}
4258
},
4359
"vision": {
4460
"filename": "vision.onnx",
4561
"config_filename": "processor_config.json",
62+
"spatial_merge_size": 2,
4663
"session_options": {
4764
"log_id": "onnxruntime-genai",
4865
"provider_options": []

‎src/mobius/integrations/ort_genai/auto_export.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ def _write_processor_config(
196196
"patch_size": getattr(vision, "patch_size", None) or 14,
197197
}
198198

199-
path = os.path.join(output_dir, "processor_config.json")
199+
proc_filename = "processor_config.json"
200+
201+
path = os.path.join(output_dir, proc_filename)
200202
with open(path, "w", encoding="utf-8") as f:
201203
json.dump(processor, f, indent=4)
202204
return path
@@ -275,8 +277,9 @@ def _write_genai_config(
275277
vision_kwargs["spatial_merge_size"] = None
276278
vision_kwargs["config_filename"] = "vision_processor.json"
277279
elif model_type in ("gemma4", "gemma4_text"):
278-
vision_kwargs["spatial_merge_size"] = None
279-
vision_kwargs["config_filename"] = "processor_config.json"
280+
vision_cfg = getattr(config, "vision", None)
281+
sms = getattr(vision_cfg, "spatial_merge_size", 2)
282+
vision_kwargs["spatial_merge_size"] = sms
280283

281284
if vision_input_mapping is not None:
282285
vision_kwargs["input_names"] = vision_input_mapping

‎src/mobius/integrations/ort_genai/auto_export_test.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def test_gemma4_vision_inputs(self, tmp_path):
586586
assert "pixel_values" in vision_inputs
587587
assert "pixel_position_ids" in vision_inputs
588588
assert "image_grid_thw" not in vision_inputs
589-
assert "spatial_merge_size" not in data["model"]["vision"]
589+
assert data["model"]["vision"]["spatial_merge_size"] == 2
590590

591591
def test_gemma4_decoder_has_input_ids_and_inputs_embeds(self, tmp_path):
592592
"""Gemma4 decoder has both inputs_embeds and input_ids."""
@@ -779,7 +779,7 @@ def test_gemma4_genai_config_from_real_model(self, tmp_path):
779779

780780
# Config-level properties are still present
781781
assert data["model"]["image_token_id"] == 255999
782-
assert "spatial_merge_size" not in data["model"]["vision"]
782+
assert data["model"]["vision"]["spatial_merge_size"] == 2
783783
assert data["model"]["vision"]["config_filename"] == "processor_config.json"
784784

785785
def test_auto_export_produces_genai_config(self, tmp_path):

‎src/mobius/integrations/ort_genai/genai_config.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,10 @@ def generate(self) -> dict[str, Any]:
353353
decoder_inputs = dict(self._decoder_inputs)
354354
else:
355355
decoder_inputs = _default_decoder_inputs(is_vlm=is_multimodal)
356+
decoder_filename = "decoder/model.onnx" if is_multimodal else "model.onnx"
356357
decoder: dict[str, Any] = {
357358
"session_options": _make_session_options(self.ep),
358-
"filename": "model.onnx",
359+
"filename": decoder_filename,
359360
"head_size": self.head_dim,
360361
"hidden_size": self.hidden_size,
361362
"inputs": decoder_inputs,

0 commit comments

Comments
 (0)