Skip to content

Add fixed-capacity Gemma4 vision exports - #803

Draft
ananyaa-ms wants to merge 2 commits into
mainfrom
aamancherla/gemma4-fixed-capacity-vision
Draft

ananyaa-ms wants to merge 2 commits into
mainfrom
aamancherla/gemma4-fixed-capacity-vision

Conversation

@ananyaa-ms

@ananyaa-ms ananyaa-ms commented Oct 29, 2026 •

Copy link
Copy Markdown

Motivation: Compiling google/gemma-4-E2B-it for OpenVINO NPU requires static vision shapes. Expose fixed-capacity vision export through extra_options so the full vision model can compile without splitting it into smaller models.

• Add opt-in fixed patch and output capacities while preserving dynamic export defaults.
• Support fixed or dynamic image batches with image-major output blocks.
• Preserve spatial pooling and valid-feature ordering, with unused capacity at each image’s tail.
• Validate export settings and document shapes and downstream trimming requirements.
• Add shape, pooling, FP32/FP16 parity, and package compatibility coverage.

@ananyaa-ms
ananyaa-ms requested review from a team and a balanced review from Copilot October 29, 2026 17:04
@CLAassistant

CLAassistant commented Oct 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing c0d6a208 → 3616bef1

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 68 68 +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 105 105 +0.0% ⚪
gpt2 model_size_bytes 324 KB 324 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +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 269 269 +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 131 131 +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 461 461 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 176 176 +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.

🟢 Approval recommended

No active review issues are identified for the opt-in fixed-capacity Gemma4 vision export changes.

No open issues 🎉

What changed in this PR

Adds opt-in fixed-capacity Gemma4 vision exports while preserving the default dynamic-output, single-image behavior.

Changes:

  • Supports fixed patch/output capacities with fixed or symbolic image batches.
  • Preserves spatial pooling and image-major feature ordering, with padding at each image’s tail.
  • Adds configuration validation, shape and numerical parity tests, and documentation for trimming outputs before embedding.
File Description
src/​mobius/​tasks/​_gemma4.py Defines fixed-capacity vision input shapes and batch contracts.
src/​mobius/​models/​gemma4.py Adds a fixed-capacity spatial pooler and selects it when configured.
src/​mobius/​models/​gemma4_test.py Tests shapes, pooling, FP32/FP16 parity, embedding compatibility, and invalid settings.
src/​mobius/​_configs/​_base.py Adds and validates vision capacity and batch settings.
docs/​api/​build_from_module.md Documents configuration, tensor shapes, and downstream trimming requirements.

Review effort: Balanced

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing c0d6a208 → 3616bef1

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)

@ananyaa-ms
ananyaa-ms force-pushed the aamancherla/gemma4-fixed-capacity-vision branch from 21c050e to 3616bef Compare November 3, 2026 01:26
@justinchuby justinchuby self-assigned this Nov 3, 2026
``GatherBlockQuantized`` or requantize weights. PersonaPlex and RE-USE
bespoke builders do not support this option.

``extra_options`` supplies model-specific settings. Currently supported

@justinchuby justinchuby Nov 3, 2026 •

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.

It would be good to have a way to avoid bloat in this option. That said I don't have a better idea yet.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We're able to modify the model for a fixed capacity output using Olive surgeries (microsoft/Olive#2791). Then this mobius PR won't be needed.

@justinchuby

Copy link
Copy Markdown
Member

Could you include motivation in the PR description? Thanks!

@titaiwangms

Copy link
Copy Markdown
Contributor

Is #746 related?

@ananyaa-ms

ananyaa-ms commented Nov 4, 2026 •

Copy link
Copy Markdown
Author

Is #746 related?

No, I think #746 is for attention ops. The current PR is to export a fully static-shaped vision model

@ananyaa-ms
ananyaa-ms marked this pull request as draft November 4, 2026 22:39
@justinchuby

Copy link
Copy Markdown
Member

@ananyaa-ms if this logic is for fixing some shapes to a static value, I wonder if it would make sense to pair this with the symbolic engine https://github.com/onnx/onnx-shape-inference. So that this becomes generally applicable to models.

@ananyaa-ms

ananyaa-ms commented Nov 9, 2026 •

Copy link
Copy Markdown
Author

@ananyaa-ms if this logic is for fixing some shapes to a static value, I wonder if it would make sense to pair this with the symbolic engine https://github.com/onnx/onnx-shape-inference. So that this becomes generally applicable to models.

This PR was opened to export a fully-static shaped version of the vision model to support NPU compilation. Based on our conversation @justinchuby , I'm replacing this with an Olive surgery (microsoft/Olive#2791) as it's probably only required for few NPU EPs

This branch has not been deployed

No deployments
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.

5 participants