Repository navigation
Emit Gemma4 optional audio modality contract - #419
Merged
Merged
Conversation
Co-authored-by: Copilot <[email protected]>
Performance Comparison
|
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
Contributor
There was a problem hiding this comment.
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.pyhelpers to declare/read component presence and optional-input zero-fallback contracts. - Update Gemma4 tasks to (a) strip audio padding via
Compressto produce rank-2audio_features, (b) declarewhen_present=audioon audio components, and (c) declare embeddingaudio_featuresas optional with a zeros fallback. - Extend native VLM metadata emission to include
io.optional_inputsandphases.<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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Contract
Validation
WP-B4 optional-modality exporter contract.