Skip to content

Add Gemma4 image_processor.json generation with onnxruntime-extension… - #209

Merged
apsonawane merged 5 commits into
mainfrom
asonawane/gemma4
Apr 24, 2026
Merged

Add Gemma4 image_processor.json generation with onnxruntime-extension…#209
apsonawane merged 5 commits into
mainfrom
asonawane/gemma4

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

Summary

Updates the ort-genai runtime integration to generate the correct image processor config format for Gemma4 models.

Problem

The OrtxCreateProcessor API in onnxruntime-extensions requires a JSON config with a processor.transforms array defining an ordered pipeline of image processing operations. Previously, Gemma4 models generated a HuggingFace-style processor_config.json with raw config values (image_size, patch_size, etc.), which caused a runtime crash:

RuntimeError: [json.exception.out_of_range.403] key 'transforms' not found

Changes

src/mobius/integrations/ort_genai/auto_export.py

  • _write_processor_config(): For gemma4/gemma4_text models, generates image_processor.json with the onnxruntime-extensions transforms pipeline format (DecodeImageGemma4ImageTransform) instead of the HF-style processor_config.json. Reads patch_size, max_soft_tokens, and pooling_kernel_size from the model config.
  • _write_genai_config(): Sets vision.config_filename to "image_processor.json" for Gemma4 models so the genai runtime points to the correct file.

Non-Gemma4 models are unaffected and continue generating processor_config.json.

Generated image_processor.json example

{
    "processor": {
        "name": "gemma_4_image_processing",
        "transforms": [
            {
                "operation": {
                    "name": "decode_image",
                    "type": "DecodeImage",
                    "attrs": { "color_space": "RGB" }
                }
            },
            {
                "operation": {
                    "name": "gemma4_image_transform",
                    "type": "Gemma4ImageTransform",
                    "attrs": {
                        "patch_size": 16,
                        "max_soft_tokens": 280,
                        "pooling_kernel_size": 3
                    }
                }
            }
        ]
    }
}

@github-actions

github-actions Bot commented Apr 24, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing d5624402e3eef6

Model Sub-model Changes Status

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

github-actions Bot commented Apr 24, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing d5624402e3eef6

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 60 60 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 107 107 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 53 53 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 61 61 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 58 58 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 98 98 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 59 59 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 56 56 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 61 61 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 58 58 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 408 408 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 166 166 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@codecov

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

The author of this PR, apsonawane, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at support@codecov.io with any questions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the ORT-GenAI export integration so Gemma4 models emit an onnxruntime-extensions–compatible image processor configuration and reference it from genai_config.json, preventing runtime failures in OrtxCreateProcessor.

Changes:

  • Generate image_processor.json for gemma4 / gemma4_text using a processor.transforms pipeline (DecodeImageGemma4ImageTransform).
  • Keep non-Gemma4 models on the existing HuggingFace-style processor_config.json.
  • Set vision.config_filename to image_processor.json for Gemma4 in genai_config.json.

Comment thread src/mobius/integrations/ort_genai/auto_export.py
Comment thread src/mobius/integrations/ort_genai/auto_export.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the ORT GenAI auto-export integration so Gemma4 models generate an onnxruntime-extensions compatible image processor configuration (transforms pipeline) and reference it from genai_config.json, avoiding runtime crashes caused by missing processor.transforms.

Changes:

  • Generate image_processor.json (DecodeImage → Gemma4ImageTransform) for gemma4/gemma4_text instead of HF-style processor_config.json.
  • Update Gemma4 genai_config.json to set vision.config_filename to image_processor.json.
  • Adjust the Gemma4 genai-config test expectation accordingly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/mobius/integrations/ort_genai/auto_export.py Adds Gemma4-specific processor JSON generation in ORT-Extensions format and updates genai config to reference it.
src/mobius/integrations/ort_genai/auto_export_test.py Updates Gemma4 genai-config assertion for the new processor config filename.

Comment thread src/mobius/integrations/ort_genai/auto_export.py Outdated
Comment thread src/mobius/integrations/ort_genai/auto_export.py
Comment thread src/mobius/integrations/ort_genai/auto_export_test.py
@apsonawane
apsonawane enabled auto-merge (squash) April 24, 2026 19:28
@apsonawane
apsonawane merged commit 661b235 into main Apr 24, 2026
19 of 21 checks passed
@apsonawane
apsonawane deleted the asonawane/gemma4 branch April 24, 2026 19:33
justinchuby pushed a commit that referenced this pull request Apr 25, 2026
#209)

## Summary

Updates the ort-genai runtime integration to generate the correct image
processor config format for Gemma4 models.

## Problem

The `OrtxCreateProcessor` API in onnxruntime-extensions requires a JSON
config with a `processor.transforms` array defining an ordered pipeline
of image processing operations. Previously, Gemma4 models generated a
HuggingFace-style `processor_config.json` with raw config values
(`image_size`, `patch_size`, etc.), which caused a runtime crash:

RuntimeError: [json.exception.out_of_range.403] key 'transforms' not
found


## Changes

**`src/mobius/integrations/ort_genai/auto_export.py`**

- `_write_processor_config()`: For `gemma4`/`gemma4_text` models,
generates `image_processor.json` with the onnxruntime-extensions
transforms pipeline format (`DecodeImage` → `Gemma4ImageTransform`)
instead of the HF-style `processor_config.json`. Reads `patch_size`,
`max_soft_tokens`, and `pooling_kernel_size` from the model config.
- `_write_genai_config()`: Sets `vision.config_filename` to
`"image_processor.json"` for Gemma4 models so the genai runtime points
to the correct file.

Non-Gemma4 models are unaffected and continue generating
`processor_config.json`.

## Generated `image_processor.json` example

```json
{
    "processor": {
        "name": "gemma_4_image_processing",
        "transforms": [
            {
                "operation": {
                    "name": "decode_image",
                    "type": "DecodeImage",
                    "attrs": { "color_space": "RGB" }
                }
            },
            {
                "operation": {
                    "name": "gemma4_image_transform",
                    "type": "Gemma4ImageTransform",
                    "attrs": {
                        "patch_size": 16,
                        "max_soft_tokens": 280,
                        "pooling_kernel_size": 3
                    }
                }
            }
        ]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants