Skip to content

ort_genai: native processor configs for gemma-4-12B unified - #391

Open
justinchuby wants to merge 2 commits into
mainfrom
gemma4-unified-native-processor
Open

ort_genai: native processor configs for gemma-4-12B unified#391
justinchuby wants to merge 2 commits into
mainfrom
gemma4-unified-native-processor

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Problem

For the encoder-free gemma-4-12B "unified" model, mobius deliberately did not emit image_processor.json or audio_feature_extraction.json, and its genai_config.json mapped model.type to gemma4. The unified model's inputs (48px merged pixel patches / raw 640-sample waveform frames) had no native ORT GenAI preprocessing, so the only way to run it was HuggingFace AutoProcessor + Generator.set_inputs. The emitted genai_config referenced processor files that were never written (a dangling reference; harmless for set_inputs but broken for MultiModalProcessor).

Change

With native ORT GenAI support now available (companion PRs below), emit the correct processor configs:

  • model.type: gemma4_unified → dedicated gemma4_unified ORT GenAI type (was gemma4).
  • image_processor.json: DecodeImage → Gemma4ImageTransform at patch_size=48, pooling_kernel_size=1 (patch_dim 6912). HF produces the merged patches via 16px patchify + 3×3 patches_merge, which is provably identical to a direct 48px patchify, so the existing op is reused with merged geometry.
  • audio_feature_extraction.json: AudioDecoder → Gemma4UnifiedAudioFrames (raw 640-sample framing) instead of the 128-dim log-mel op.

The text-only unified backbone (gemma4_unified_text) still resolves to gemma4_text (unchanged).

Dependencies

Testing

auto_export_test.py + genai_config_test.py: 115 passed. Updated the three unified tests to assert the emitted configs (48/1 image transform, raw-frame audio op, gemma4_unified type). ruff, ruff format, and mypy clean on the changed source.

The encoder-free gemma-4-12B "unified" model can now be preprocessed
natively by ORT GenAI (no HuggingFace processor / set_inputs needed), so
stop skipping its processor artifacts and emit the correct configs:

* model.type: gemma4_unified now maps to the dedicated "gemma4_unified"
  ORT GenAI multimodal type (was reusing "gemma4").
* image_processor.json: DecodeImage -> Gemma4ImageTransform configured
  for the 48px merged-patch contract (patch_size=48, pooling_kernel_size=1,
  patch_dim=6912). HF builds these via 16px patchify + 3x3 patches_merge,
  which is identical to a direct 48px patchify, so the existing op is
  reused with merged geometry.
* audio_feature_extraction.json: AudioDecoder -> Gemma4UnifiedAudioFrames
  (raw 640-sample waveform framing) instead of the 128-dim log-mel op.

Requires the companion onnxruntime-extensions (Gemma4UnifiedAudioFrames)
and onnxruntime-genai (gemma4_unified processor) support. Updates the
unified auto_export tests to assert the emitted configs.

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing da921704082f1c

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 Jul 9, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing da921704082f1c

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 68 68 +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 54 54 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 62 62 +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 60 60 +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 62 62 +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 413 413 +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.

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 Mobius’ ORT GenAI auto-export integration to emit native processor configs for the encoder-free Gemma-4-12B “unified” model, aligning exported artifacts with newly available ORT GenAI + ort-extensions preprocessing support.

Changes:

  • Map HF model_type="gemma4_unified" to ORT GenAI model.type="gemma4_unified" (instead of reusing gemma4).
  • Emit image_processor.json for unified models using DecodeImage → Gemma4ImageTransform with patch_size=48 and pooling_kernel_size=1.
  • Emit audio_feature_extraction.json for unified models using AudioDecoder → Gemma4UnifiedAudioFrames (raw 640-sample framing), and update tests to assert these outputs.

Reviewed changes

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

File Description
src/mobius/integrations/ort_genai/auto_export.py Updates ORT GenAI model-type mapping and writes unified-specific image/audio processor configs.
src/mobius/integrations/ort_genai/auto_export_test.py Adjusts expectations and adds assertions for unified processor config emission and attributes.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Follow the onnxruntime-extensions consolidation: both gemma4 audio configs
now use the single Gemma4Audio op with an explicit type attribute instead of
two separate op types.

* gemma4 / gemma4_text  -> Gemma4Audio type="log_mel"  (128-dim USM log-mel)
* gemma4_unified*       -> Gemma4Audio type="raw_frames" (raw 640-sample frames)

Updates the auto_export audio-config tests accordingly. 115 tests pass.

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
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.

2 participants