Skip to content

Update gemma4 genai audio config logic - #223

Merged
apsonawane merged 4 commits into
mainfrom
asonawane/gemma
Apr 28, 2026
Merged

apsonawane merged 4 commits into
mainfrom
asonawane/gemma

Conversation

@apsonawane

@apsonawane apsonawane commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Gemma4 Audio Encoder Support for ORT-GenAI Export

Summary

Adds audio encoder export support for Gemma4 multimodal models in the ORT-GenAI integration pipeline. This enables Gemma4 any-to-any (vision+audio+text) models to be exported with the correct audio processor configuration and genai_config.json speech section.

Changes

auto_export.py

  • _write_audio_processor_config() — New function that writes audio_feature_extraction.json for Gemma4 models using the feature_extraction.sequence schema required by OrtxCreateSpeechFeatureExtractor. The pipeline consists of AudioDecoder → Gemma4LogMel with USM-style 128-dim log-mel spectrogram parameters.
  • _write_genai_config() — Gemma4 speech section overrides:
    • filename: audio_encoder/model.onnx
    • config_filename: audio_feature_extraction.json (instead of default audio_processor.json)
    • input_names mapping: audio_embeds → input_features, attention_mask → input_features_mask
  • _write_vision_processor_config() — Renamed from _write_processor_config for clarity. Gemma4 vision path now writes image_processor.json with DecodeImage → Gemma4ImageTransform transforms pipeline, checked before has_speech to ensure vision config is always written for VLM+audio models.
  • write_ort_genai_config() — Calls _write_audio_processor_config() and includes result in the output dict under "audio_processor".

auto_export_test.py

Added 6 new tests covering audio export:

Test What it verifies
test_audio_no_audio_returns_none _write_audio_processor_config returns None when config has no audio attribute
test_audio_non_gemma4_returns_none Returns None for non-Gemma4 model types
test_audio_gemma4_writes_feature_extraction_json Writes audio_feature_extraction.json with correct feature_extraction.sequence schema, AudioDecoder + Gemma4LogMel ops, and expected attrs
test_gemma4_audio_processor_json_written End-to-end: write_ort_genai_config produces audio_feature_extraction.json
test_gemma4_audio_processor_not_written_without_audio No audio config written when config lacks audio
test_gemma4_genai_config_speech_section genai_config.json speech section has correct config_filename, filename, and input mapping (input_features / input_features_mask)

Notes

  • The feature_extraction.sequence format (not processor.transforms) is required by the onnxruntime-extensions OrtxCreateSpeechFeatureExtractor API.
  • The _write_vision_processor_config rename updates the existing test reference (test_gemma4_image_processor_json_written).

@apsonawane
apsonawane requested review from a team and Copilot April 27, 2026 21:48
@github-actions

github-actions Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing db0ae40 → 28c0252

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.

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 export path for Gemma4 models, especially for speech-capable variants, by switching Gemma4 audio processor config generation to the feature_extraction.sequence schema and adjusting how genai_config selects/writes processor config filenames and audio input mappings.

Changes:

  • Emit Gemma4 audio feature extraction config in feature_extraction.sequence format and write it as audio_feature_extraction.json.
  • Prioritize Gemma4 model types when populating vision config parameters in genai_config.json.
  • Override Gemma4 speech section settings in genai_config.json (config filename + input mapping).

@codecov

codecov Bot commented Apr 27, 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 [email protected] with any questions.

@github-actions

github-actions Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing db0ae40 → 28c0252

Model Sub-model Changes Status

No architecture changes detected. ✅


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

@justinchuby justinchuby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Could you provide context in the PR description?

@justinchuby justinchuby changed the title Update gemma4 export Update gemma4 export audio config logic Apr 27, 2026
@justinchuby justinchuby changed the title Update gemma4 export audio config logic Update gemma4 genai audio config logic Apr 27, 2026
@justinchuby

Copy link
Copy Markdown
Member

Could you include tests? Thanks

@apsonawane

Copy link
Copy Markdown
Contributor Author

Added tests and updated the description

@apsonawane
apsonawane merged commit 612abc3 into main Apr 28, 2026
21 of 23 checks passed
@apsonawane
apsonawane deleted the asonawane/gemma branch April 28, 2026 07:08
@apsonawane
apsonawane restored the asonawane/gemma branch April 28, 2026 07:09
apsonawane added a commit that referenced this pull request Apr 28, 2026
follow up from this PR: #223

---------

Co-authored-by: Justin Chu <[email protected]>
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.

4 participants