Skip to content

Emit Gemma4 optional audio modality contract - #419

Merged
justinchuby merged 2 commits into
mainfrom
squad/joshi-wp-b4
Jul 22, 2026
Merged

justinchuby merged 2 commits into
mainfrom
squad/joshi-wp-b4

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

  • declare Gemma4 audio optionality on exported ONNX graph structure and emit io.optional_inputs.audio_features with the frozen audio presence key and zero fallback
  • emit phases.audio_encoder.when_present: audio while keeping the strategy stage run_on: prompt_only
  • adapt E2B audio features inside the exported audio encoder graph by flattening batch/time and applying the downsampled validity mask with ONNX Compress
  • route the resulting rank-2 audio output directly to the rank-2 embedding input; keep gemma4_unified declarations consistent

Contract

optional_inputs:
  audio_features:
    presence: audio
    absent:
      kind: zeros
      shape: [0, 1536]
phases:
  audio_encoder:
    run_on: prompt_only
    when_present: audio

Validation

  • ruff check on changed files
  • ruff format --check on changed files
  • python3 -m pytest src/mobius/integrations/onnx_genai/inference_metadata_test.py -q (40 passed)
  • targeted Gemma4 graph/adapter tests (4 passed)
  • verified an E2B-width export emits a rank-2, dtype-compatible audio_encoder.audio_features to embedding.audio_features edge

WP-B4 optional-modality exporter contract.

Copilot AI review requested due to automatic review settings July 22, 2026 13:33
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 640c1cb → 2f6fee8

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.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 640c1cb → 2f6fee8

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


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

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

This PR introduces a small “pipeline contract” layer (presence keys + optional-input fallbacks) carried alongside exported IR graphs and uses it to emit richer genai_config metadata for Gemma4’s optional audio path (including phases.<component>.when_present and io.optional_inputs), while also changing the Gemma4 audio encoder export to strip padded rows inside the ONNX graph and output rank-2 audio_features.

Changes:

  • Add _pipeline_contract.py helpers to declare/read component presence and optional-input zero-fallback contracts.
  • Update Gemma4 tasks to (a) strip audio padding via Compress to produce rank-2 audio_features, (b) declare when_present=audio on audio components, and (c) declare embedding audio_features as optional with a zeros fallback.
  • Extend native VLM metadata emission to include io.optional_inputs and phases.<model>.when_present, and add/adjust tests to validate these contracts and the new audio feature shape.

Reviewed changes

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

Show a summary per file
File Description
tests/build_graph_test.py Updates Gemma4/Gemma4Unified graph assertions and adds a runtime test ensuring audio padding rows are stripped in the exported graph.
src/mobius/tasks/_gemma4.py Implements rank-2 audio_features via Compress, always emits audio_features_mask for Gemma4, and declares audio presence + optional embedding input contract.
src/mobius/integrations/onnx_genai/inference_metadata.py Emits io.optional_inputs from graph input declarations and emits phases.*.when_present from component presence declarations.
src/mobius/integrations/onnx_genai/inference_metadata_test.py Adjusts Gemma4 routing expectations to rank-2 audio flow and asserts emitted YAML contains optional_inputs and when_present.
src/mobius/_pipeline_contract.py New utility module for presence/optional-input declarations consumed during metadata emission.

Comment on lines +38 to +46
"""Declare a zero fallback for an optional ONNX graph input."""
if not presence:
raise ValueError("Optional-input presence key must be non-empty")
shape = list(absent_shape)
if not shape or any(isinstance(dim, int) and dim < 0 for dim in shape):
raise ValueError("Optional-input absent shape must contain non-negative dimensions")
value.metadata_props[_OPTIONAL_INPUT_PRESENCE] = presence
value.metadata_props[_OPTIONAL_INPUT_ABSENT_SHAPE] = json.dumps(shape)

Comment on lines +59 to +75
try:
shape = json.loads(absent_shape)
except (TypeError, json.JSONDecodeError) as error:
raise ValueError(
f"ONNX input {value.name!r} has an invalid optional-input absent shape"
) from error
if not isinstance(shape, list) or not shape:
raise ValueError(
f"ONNX input {value.name!r} optional-input absent shape must be a non-empty list"
)
return {
"presence": presence,
"absent": {
"kind": "zeros",
"shape": shape,
},
}
Address the reviewer note by exercising Gemma 4 audio padding removal with BFLOAT16 inputs and verifying dtype restoration.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings July 22, 2026 13:56

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

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

@justinchuby
justinchuby marked this pull request as ready for review July 22, 2026 14:04
@justinchuby
justinchuby requested a review from a team July 22, 2026 14:04
@justinchuby
justinchuby merged commit 54be48a into main Jul 22, 2026
22 of 23 checks passed
@justinchuby
justinchuby deleted the squad/joshi-wp-b4 branch July 22, 2026 14:14
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