Skip to content

Fix Qwen3.5/3.6-MoE VL decoder QMoE quantization support - #511

Merged
titaiwangms merged 6 commits into
mainfrom
fix/qwen35-vl-qmoe-preprocess-weights
Aug 18, 2026
Merged

titaiwangms merged 6 commits into
mainfrom
fix/qwen35-vl-qmoe-preprocess-weights

Conversation

@titaiwangms

Copy link
Copy Markdown
Contributor

Summary

Qwen35MoEVL3ModelCausalLMModel.preprocess_weights (the 3-model-split vision-language wrapper for Qwen3.5/3.6-MoE) previously had zero quantization awareness, unlike its text-only sibling Qwen35MoECausalLMModel. An Olive-quantized VL checkpoint would be silently mishandled: quantized MoE expert weights would be routed as if float, producing a broken/incomplete ONNX export with no error raised.

This is one of the pieces needed to support end-to-end quantized export of Qwen/Qwen3.6-35B-A3B (256-expert MoE VL model) via MobiusBuilder, alongside microsoft/Olive#2628 and microsoft/Olive#2457.

Changes

  • use_qmoe detection (via _supported_qmoe_quantization), mirroring the text-only sibling.

  • A guard that raises a clear ValueError when packed-but-unsupported quantized expert weights are found, instead of silently falling back to the (incompatible) dense per-expert path.

  • preprocess_olive_weights + pack_qmoe_expert_weights calls to rename and pack Olive-quantized decoder MoE expert weights into the native QMoE ONNX parameter layout (target_moe_path=".mlp", matching the text-only sibling's Qwen35MoEBlock placement).

  • Explicit NotImplementedError guards for:

    • quant_method in {"gptq", "awq"} — not yet supported by this VL wrapper (only Olive-quantized checkpoints are handled today).
    • quantize_embeddings / quantize_lm_head — no quantized Embedding/Linear module variants are wired up anywhere in this 3-model split, so these flags previously produced orphaned initializers with no error.

    Both guards fail loudly instead of silently producing a broken export.

  • Honors quantization.tie_word_embeddings (not just config.tie_word_embeddings) when deciding whether to duplicate lm_head from embed_tokens, for internal consistency with the recovered "effective tie" value.

Tests

New TestQwen35MoEVL3ModelQMoEExport class covering:

  • QMoE packing/binding (Olive-quantized)
  • Dense fallback (unquantized)
  • Unsupported-ABI guard (packed-but-non-QMoE quantization)
  • Vision/embedding/MTP-routing preservation (unaffected by decoder quantization)
  • GPTQ/AWQ rejection (clear error)
  • Quantized-embeddings/lm_head rejection (clear error)
python -m pytest src/mobius/models/qwen35_test.py -v
10 passed

Full model suite: python -m pytest src/mobius/models/ -q → 401 passed, 3 pre-existing unrelated failures (confirmed present on clean main: deepseek_v4_flash_test.py::test_ort_genai_sidecar_metadata, qwen_image_test.py::test_cuda_matches_cpu, world_model_test.py::test_mlp_world_model_matches_pytorch).

ruff check / ruff format --check: clean.

Review

This change went through a full internal review pass (readability, correctness, adversarial/critical, spec-adherence, and cross-module integration review, plus independent test execution) before being opened. Findings from that review (GPTQ/AWQ gap, quantized-embedding binding gap) are addressed via the explicit guards above rather than full implementations, since neither is needed by the current Olive→Mobius pipeline for Qwen3.6-35B-A3B.

Qwen35MoEVL3ModelCausalLMModel.preprocess_weights previously had zero
quantization awareness, unlike its text-only sibling
Qwen35MoECausalLMModel. This meant an Olive-quantized VL checkpoint
would be silently mishandled: quantized MoE expert weights would be
routed as if float, producing a broken/incomplete export with no
error raised.

This adds:
- use_qmoe detection (via _supported_qmoe_quantization) mirroring the
  text-only sibling
- a guard that raises a clear ValueError when packed-but-unsupported
  quantized expert weights are found (instead of silently falling
  back to the dense per-expert path)
- preprocess_olive_weights + pack_qmoe_expert_weights calls to rename
  and pack Olive-quantized decoder MoE expert weights into the native
  QMoE ONNX parameter layout (target_moe_path=".mlp", matching the
  text-only sibling's Qwen35MoEBlock placement)
- explicit NotImplementedError guards for GPTQ/AWQ quant_method and
  for quantize_embeddings/quantize_lm_head, both of which are not yet
  supported by this VL wrapper (no quantized Embedding/Linear module
  variants are wired up in the 3-model split), so these configs now
  fail loudly instead of producing orphaned initializers
- honors quantization.tie_word_embeddings (not just
  config.tie_word_embeddings) when deciding whether to duplicate
  lm_head from embed_tokens

Adds TestQwen35MoEVL3ModelQMoEExport with coverage for: QMoE
packing/binding, dense fallback, unsupported-ABI guard,
vision/embedding/MTP-routing preservation, GPTQ/AWQ rejection, and
quantized-embeddings/lm_head rejection.

Co-authored-by: Copilot <[email protected]>
@titaiwangms
titaiwangms requested review from a team and a lite review from Copilot August 17, 2026 22:04
@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 5589243 → 8e75ba4

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)

@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 5589243 → 8e75ba4

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 105 105 +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 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 264 264 +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 126 126 +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 428 428 +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

This PR updates the Qwen3.5/3.6 MoE vision-language (3-model split) wrapper so its decoder preprocess_weights becomes quantization-aware, aligning it with the text-only MoE path and enabling correct Olive→QMoE packing for quantized exports.

Changes:

  • Add Olive-specific preprocessing + QMoE packing for VL decoder MoE expert weights, and reject unsupported/unsafe quantization configurations instead of silently producing broken exports.
  • Update weight-tying logic to consider quantization.tie_word_embeddings when routing lm_head weights.
  • Add a dedicated unit-test suite covering QMoE packing, dense fallback, and explicit error paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/mobius/models/qwen35.py Adds quantization-aware VL decoder weight routing, Olive preprocessing, QMoE packing, and explicit guards.
src/mobius/models/qwen35_test.py Adds VL-specific tests validating QMoE packing/binding, fallback behavior, and clear rejection of unsupported quantization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/mobius/models/qwen35.py Resolved
Comment thread src/mobius/models/qwen35.py Resolved
titaiwangms and others added 2 commits August 18, 2026 08:16
…5 models

Addresses maintainer review feedback on PR #511 asking whether
quantization dispatch logic could be shared instead of duplicated
across model classes.

- Add preprocess_quantized_weights() in _weight_utils.py: a single
  orchestration point for GPTQ/AWQ/Olive dispatch, embed/lm_head
  tying, and QMoE expert packing.
- Move supported_qmoe_quantization() (formerly a private helper in
  components/_moe.py) to _weight_utils.py as a public function;
  components/_moe.py keeps a compatibility alias.
- Add embed_key/head_key parameters to preprocess_olive_weights() so
  non-default key prefixes (e.g. VL models' decoder.-prefixed keys)
  can reuse the same tying logic without special-casing.
- Wire CausalLMModel (base.py), Qwen35MoECausalLMModel,
  Qwen35VL3ModelCausalLMModel, and Qwen35MoEVL3ModelCausalLMModel to
  the shared helper. Qwen35VL3ModelCausalLMModel (dense VL) gains
  quantization support for the first time as a result.
- Reject packed GPTQ/AWQ/Olive embedding or LM-head keys directly by
  inspecting checkpoint keys, not just config flags, so a
  misconfigured quantization config can't silently produce
  unsupported 3-D initializers for modules that require float
  weights.
- Backfill all three embed-table initializer keys
  (decoder.model.embed_tokens.weight, decoder.lm_head.weight,
  embedding.embed_tokens.weight) when tying is active, so the
  separate embedding sub-model never ends up with an unassigned
  initializer.
- Preserve prior no-op behavior when tying is requested but neither
  embed nor head key is present in a partial state dict.

Verified: full src/mobius/models/ suite (408 passed, 3 pre-existing
unrelated failures), ruff check/format clean.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: e10674c1-6909-4b09-9f5a-d41b28c89d2d

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 6 out of 6 changed files in this pull request and generated no new comments.

Comment thread src/mobius/components/_moe.py Resolved
Comment thread src/mobius/_weight_utils.py Resolved
@titaiwangms
titaiwangms merged commit 2481e3c into main Aug 18, 2026
20 of 23 checks passed
@titaiwangms
titaiwangms deleted the fix/qwen35-vl-qmoe-preprocess-weights branch August 18, 2026 19:54
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.

3 participants