Skip to content

fix: GPT-OSS MXFP4 dequant + Gemma3 VL auto-routing - #194

Merged
justinchuby merged 3 commits into
mainfrom
justinchu/gpt-oss
Apr 23, 2026
Merged

fix: GPT-OSS MXFP4 dequant + Gemma3 VL auto-routing#194
justinchuby merged 3 commits into
mainfrom
justinchu/gpt-oss

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

Two fixes on this branch:

1. GPT-OSS MXFP4 dequantization

The openai/gpt-oss-20b checkpoint stores expert weights in MXFP4 format (_blocks + _scales uint8 tensors) instead of full weight tensors. This caused 2304 missing expert weights during build.

Fix: Added a dequantization phase in preprocess_weights using HF's _convert_moe_packed_tensors (4-bit nibble-packed with shared exponent). The dequantized tensors are then handled by the existing split/transpose logic.

Also made gate_up_proj and down_proj matching more precise with endswith() to avoid matching _blocks/_scales suffixes.

2. Gemma3 VL auto-routing

google/gemma-3-4b-it has model_type="gemma3" but is actually multimodal (Gemma3ForConditionalGeneration with vision_config). The registry maps gemma3 → text-only task, producing only 1 model instead of 3.

Fix: Added multimodal auto-detection in _builder.py. When a HF config has vision_config or audio_config and a {model_type}_multimodal registry key exists, model_type is promoted to the multimodal variant. This routes gemma3 → gemma3_multimodal → 3-model VL output.

Tests

All 2555 tests pass.

The openai/gpt-oss-20b checkpoint stores expert weights in MXFP4
format (_blocks + _scales tensors) instead of full weight tensors.
Add a dequantization phase using HF's _convert_moe_packed_tensors
before the existing split/transpose logic.

Also make gate_up_proj and down_proj matching more precise with
endswith() to avoid matching _blocks/_scales suffixes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing f409743b515d56

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 Apr 23, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing f409743b515d56

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.

@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mobius/models/gptoss.py 80.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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 addresses two build-time correctness issues: (1) loading GPT-OSS checkpoints that store MoE expert weights in MXFP4 packed form, and (2) automatically routing Gemma3 configs with vision/audio sub-configs to the multimodal registry entry so the correct multi-model package is produced.

Changes:

  • Add an MXFP4 dequantization phase in GPTOSSCausalLMModel.preprocess_weights() that converts _blocks/_scales tensors into full expert weight tensors before existing split/transpose logic runs.
  • Tighten GPT-OSS expert weight key matching using endswith() to avoid accidentally matching MXFP4 suffix keys.
  • Add multimodal auto-detection in build() to promote {model_type}{model_type}_multimodal when the HF config indicates vision/audio encoders and a corresponding registry key exists.

Reviewed changes

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

File Description
src/mobius/models/gptoss.py Dequantizes MXFP4-packed MoE expert tensors and refines key matching to prevent suffix collisions.
src/mobius/_builder.py Promotes HF model_type to a registered multimodal variant based on vision_config/audio_config presence.

Comment thread src/mobius/models/gptoss.py
Comment thread src/mobius/models/gptoss.py
Comment thread src/mobius/_builder.py Outdated
Comment thread src/mobius/_builder.py Outdated
Comment thread src/mobius/_builder.py Outdated
@justinchuby
justinchuby force-pushed the justinchu/gpt-oss branch 2 times, most recently from 2191d22 to 086710b Compare April 23, 2026 17:57
All model_type=gemma3 HF models (4B/12B/27B) are multimodal with
vision_config. Only gemma3_text (1B) is text-only. Update the
registry to map gemma3 → Gemma3MultiModalModel with vision-language
task, matching HF's type assignment.

Remove the gemma3_multimodal alias — gemma3 now IS the multimodal
entry. Update test configs and references accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@justinchuby
justinchuby merged commit f27118b into main Apr 23, 2026
20 of 23 checks passed
@justinchuby
justinchuby deleted the justinchu/gpt-oss branch April 23, 2026 18:36
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