Repository navigation
Fix Qwen3.5/3.6-MoE VL decoder QMoE quantization support - #511
Merged
Merged
Conversation
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]>
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
Performance Comparison
|
Contributor
There was a problem hiding this comment.
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_embeddingswhen routinglm_headweights. - 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.
justinchuby
reviewed
Aug 18, 2026
…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
justinchuby
approved these changes
Aug 18, 2026
Co-authored-by: Copilot <[email protected]>
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
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 siblingQwen35MoECausalLMModel. 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) viaMobiusBuilder, alongside microsoft/Olive#2628 and microsoft/Olive#2457.Changes
use_qmoedetection (via_supported_qmoe_quantization), mirroring the text-only sibling.A guard that raises a clear
ValueErrorwhen 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_weightscalls 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'sQwen35MoEBlockplacement).Explicit
NotImplementedErrorguards for:quant_methodin{"gptq", "awq"}— not yet supported by this VL wrapper (only Olive-quantized checkpoints are handled today).quantize_embeddings/quantize_lm_head— no quantizedEmbedding/Linearmodule 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 justconfig.tie_word_embeddings) when deciding whether to duplicatelm_headfromembed_tokens, for internal consistency with the recovered "effective tie" value.Tests
New
TestQwen35MoEVL3ModelQMoEExportclass covering:Full model suite:
python -m pytest src/mobius/models/ -q→ 401 passed, 3 pre-existing unrelated failures (confirmed present on cleanmain: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.