Repository navigation
Add Qwen3.6-35B-A3B (Qwen3.5-MoE-VL) support with Olive INT4 example - #313
Conversation
Qwen3.6-35B-A3B is the vision-language variant of Qwen3.5-MoE. The HF
config reports model_type=qwen3_5_moe with text_config + vision_config;
mobius dispatches it to a new qwen3_5_moe_vl entry that composes the
existing Qwen35MoETextModel backbone with the Qwen3-VL ViT + InputMixer
(same pipeline as the dense Qwen3.5-VL).
Changes:
- New Qwen35MoEVLDecoderModel and Qwen35MoEVL3ModelCausalLMModel in
src/mobius/models/qwen35.py, mirroring Qwen35VL3ModelCausalLMModel but
swapping the text backbone for the MoE variant. Extended
Qwen35MoETextModel.forward to accept inputs_embeds for VL decoding.
preprocess_weights unpacks HF's fused experts.{gate_up,down}_proj
[E, ...] tensors into per-expert names.
- Registry entry qwen3_5_moe_vl -> Qwen35MoEVL3ModelCausalLMModel; the
builder overrides model_type to qwen3_5_moe_vl when the composite
config has a vision_config.
- L1 tiny config + checker skip entry.
- L4/L5 golden case + reference outputs (HF-generated).
- examples/qwen3_6_35b_a3b_ort_genai.py: ORT GenAI inference example
with --quantize {Q4_K_M,NF4} flag that runs Olive on the decoder.
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Performance Comparison
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
🏗️ Architecture Diff
qwen3_5_moe (hybrid-text-generation) / model — 238 change(s)Op summary: 275 → 275 nodes --- base
+++ head
@@ -91,54 +91,54 @@
MatMul
Constant
Equal
-Cast
-Mul
-ReduceSum
-Mul
-Transpose
-MatMul
-Sigmoid
-Mul
-Transpose
-MatMul
-Mul
-Transpose
-MatMul
-Constant
-Equal
-Cast
-Mul
-ReduceSum
-Mul
-Add
-Transpose
-MatMul
-Sigmoid
-Mul
-Transpose
-MatMul
-Mul
-Transpose
-MatMul
-Constant
-Equal
-Cast
-Mul
-ReduceSum
-Mul
-Add
-Transpose
-MatMul
-Sigmoid
-Mul
-Transpose
-MatMul
-Mul
-Transpose
-MatMul
-Constant
-Equal
-Cast
+CastLike
+Mul
+ReduceSum
+Mul
+Transpose
+MatMul
+Sigmoid
+Mul
+Transpose
+MatMul
+Mul
+Transpose
+MatMul
+Constant
+Equal
+CastLike
+Mul
+ReduceSum
+Mul
+Add
+Transpose
+MatMul
+Sigmoid
+Mul
+Transpose
+MatMul
+Mul
+Transpose
+MatMul
+Constant
+Equal
+CastLike
+Mul
+ReduceSum
+Mul
+Add
+Transpose
+MatMul
+Sigmoid
+Mul
+Transpose
+MatMul
+Mul
+Transpose
+MatMul
+Constant
+Equal
+CastLike
Mul
ReduceSum
Mul
@@ -202,74 +202,74 @@
MatMul
Constant
Equal
-Cast
-Mul
-ReduceSum
-Mul
-Transpose
-MatMul
-Sigmoid
-Mul
-Transpose
-MatMul
-Mul
-Transpose
-MatMul
-Constant
-Equal
-Cast
-Mul
-ReduceSum
-Mul
-Add
-Transpose
-MatMul
-Sigmoid
-Mul
-Transpose
-MatMul
-Mul
-Transpose
-MatMul
-Constant
-Equal
-Cast
-Mul
-ReduceSum
-Mul
-Add
-Transpose
-MatMul
-Sigmoid
-Mul
-Transpose
-MatMul
-Mul
-Transpose
-MatMul
-Constant
-Equal
-Cast
-Mul
-ReduceSum
-Mul
-Add
-Transpose
-MatMul
-Sigmoid
-Mul
-Transpose
-MatMul
-Mul
-Transpose
-MatMul
-Transpose
-MatMul
-Sigmoid
-Mul
-Add
-Add
-Add
-RMSNormalization
-Transpose
-MatMul
+CastLike
+Mul
+ReduceSum
+Mul
+Transpose
+MatMul
+Sigmoid
+Mul
+Transpose
+MatMul
+Mul
+Transpose
+MatMul
+Constant
+Equal
+CastLike
+Mul
+ReduceSum
+Mul
+Add
+Transpose
+MatMul
+Sigmoid
+Mul
+Transpose
+MatMul
+Mul
+Transpose
+MatMul
+Constant
+Equal
+CastLike
+Mul
+ReduceSum
+Mul
+Add
+Transpose
+MatMul
+Sigmoid
+Mul
+Transpose
+MatMul
+Mul
+Transpose
+MatMul
+Constant
+Equal
+CastLike
+Mul
+ReduceSum
+Mul
+Add
+Transpose
+MatMul
+Sigmoid
+Mul
+Transpose
+MatMul
+Mul
+Transpose
+MatMul
+Transpose
+MatMul
+Sigmoid
+Mul
+Add
+Add
+Add
+RMSNormalization
+Transpose
+MatMulAdded nodes:
Removed nodes:
Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
There was a problem hiding this comment.
Pull request overview
Adds support for the Qwen3.6-35B-A3B (Qwen3.5-MoE-VL) vision-language family to mobius by introducing a dedicated registry entry that builds a 3-model split (decoder/vision_encoder/embedding) and by adding golden test artifacts plus an ORT GenAI + Olive INT4 example script.
Changes:
- Added
qwen3_5_moe_vlregistry dispatch (via_builder.pymodel_type override for composite configs withvision_config) and wired it to a new MoE-VL 3-model module implementation. - Extended the Qwen3.5-MoE text backbone to support
inputs_embedsfor VL decoding and implemented MoE-VL weight routing/unpacking for the 3-model split. - Added L1 tiny config coverage and L4/L5 golden case + generation outputs, plus a standalone example for ORT GenAI inference and optional Olive INT4 quantization.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/build_graph_test.py | Adds qwen3_5_moe_vl to the build-graph test model set. |
| tests/_test_configs.py | Introduces a tiny qwen3_5_moe_vl config for fast graph construction tests. |
| testdata/golden/vision-language/qwen3_6-35b-a3b.json | Adds golden top-k logits + input_ids for Qwen3.6-35B-A3B. |
| testdata/golden/vision-language/qwen3_6-35b-a3b_generation.json | Adds golden generation tokens/text for Qwen3.6-35B-A3B. |
| testdata/cases/vision-language/qwen3_6-35b-a3b.yaml | Adds an L4+L5 test case definition (CI-skipped due to size). |
| src/mobius/models/qwen35.py | Adds MoE-VL decoder + 3-model split module; extends MoE text model to accept inputs_embeds; adds MoE fused-expert unpacking for the 3-model path. |
| src/mobius/models/init.py | Exports the new Qwen35MoEVL3ModelCausalLMModel. |
| src/mobius/_registry.py | Registers qwen3_5_moe_vl and maps it to the hybrid VL task and a default model id. |
| src/mobius/_builder.py | Overrides model_type to qwen3_5_moe_vl when model_type=qwen3_5_moe and vision_config is present on the composite config. |
| examples/qwen3_6_35b_a3b_ort_genai.py | Adds ORT GenAI/ORT-session inference example with optional Olive INT4 quantization workflow. |
| if "lm_head.weight" not in renamed and "model.embed_tokens.weight" in renamed: | ||
| renamed["lm_head.weight"] = renamed["model.embed_tokens.weight"] |
There was a problem hiding this comment.
Good catch — confirmed unreachable. Qwen35MoEVLDecoderModel is constructed only as a sub-module of Qwen35MoEVL3ModelCausalLMModel (line ~667) and never registered standalone, so this preprocess_weights was dead code, hiding both bugs you flagged (the un-stripped key check, and the missing fused MoE expert unpack). Dropped the whole method in 5baaa24 with a comment explaining the routing lives on the wrapper.
| Requirements:: | ||
|
|
||
| pip install mobius-ai[ort-genai] | ||
| # For INT4 quantization (Olive from source recommended): | ||
| pip install -e /path/to/Olive cupy-cuda12x | ||
|
|
||
| Usage:: |
There was a problem hiding this comment.
Right, ort-genai extras didn't include Pillow but the example scripts import PIL.Image for --image. Fixed in 5baaa24 by adding Pillow to the ort-genai extras (matches what testing extras already do).
| def preprocess_weights( | ||
| self, state_dict: dict[str, torch.Tensor] | ||
| ) -> dict[str, torch.Tensor]: | ||
| """Route language_model weights for standalone decoder build.""" | ||
| renamed: dict[str, torch.Tensor] = {} | ||
| for key, value in state_dict.items(): | ||
| if key.startswith(("mtp_", "mtp.")): | ||
| continue | ||
| stripped = key | ||
| if stripped.startswith("model."): | ||
| stripped = stripped[len("model.") :] | ||
| if stripped.startswith("visual."): | ||
| continue | ||
| if stripped.startswith("language_model."): | ||
| stripped = stripped[len("language_model.") :] | ||
| renamed[stripped] = value | ||
| if self.config.tie_word_embeddings: |
There was a problem hiding this comment.
Good catch — confirmed unreachable. Qwen35MoEVLDecoderModel is constructed only as a sub-module of Qwen35MoEVL3ModelCausalLMModel (line ~667) and never registered standalone, so this preprocess_weights was dead code, hiding both bugs you flagged (the un-stripped key check, and the missing fused MoE expert unpack). Dropped the whole method in 5baaa24 with a comment explaining the routing lives on the wrapper.
OnnxKQuantQuantization renames the decoder's logits output to logits_Q4. Aliasing it back in _run_session keeps the generation loop unchanged across quantized and unquantized models. Verified end-to-end on Qwen3.6-35B-A3B Q4_K_M (21GB decoder): output matches the HF bf16 golden token-for-token for the first 12 tokens. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Verification update✅ Olive Q4_K_M quantization — decoder shrank from 128 GB (f32) to 21 GB; quantization ran in 17 minutes (CPU, k-quant block_size=32). ✅ L5 smoke test — assembled Identical token-for-token to the first 12 tokens of the HF bf16 golden reference ( 🔧 Fix included: Olive's Still TODO (out of this PR's scope)
|
Qwen35MoEBlock.forward used op.Cast(match, to=1) (FLOAT) for the expert-selection mask, which causes a type mismatch when the model is built in bf16 or f16: routing_weights is bf16/f16 but match_float becomes f32, breaking the subsequent Mul. Switch to op.CastLike(match, routing_weights) so the mask dtype follows the routing-weight dtype, matching the pattern used in the shared MoELayer component. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Switch the qwen3_6-35b-a3b test case to dtype=float16 (the dtype that the CUDA EP can actually run for LinearAttention/CausalConvWithState), regenerate the HF golden in fp16 to match, and propagate the decoder's declared input dtype through the e2e VL prefill+generation harness so inputs_embeds and image_features are always cast to whatever the model expects. - testdata/cases/.../qwen3_6-35b-a3b.yaml: bfloat16 -> float16 - scripts/generate_golden.py: pass case.dtype through to HF loader - src/mobius/_testing/ort_inference.py: handle bf16 / ml_dtypes both for feeds (via ortvalue_from_numpy_with_onnx_type) and outputs (via dlpack + torch + ml_dtypes view). Add get_input_dtype(). - tests/e2e_golden_test.py: cast inputs_embeds, image_features and empty KV cache to the decoder/embedding session's declared dtypes. L4 + L5 pass on CUDA with the fp16 build of Qwen3.6-35B-A3B. Signed-off-by: justinchuby <[email protected]>
…eights 1) Add Pillow to the ort-genai optional-dependencies extra. The examples/qwen3_6_35b_a3b_ort_genai.py and other multimodal example scripts import PIL.Image, but the doc says 'pip install mobius-ai[ort-genai]' which previously installed only onnxruntime-genai. Without this users hit ModuleNotFoundError when running --image. 2) Remove Qwen35MoEVLDecoderModel.preprocess_weights. The method was unreachable: this class is only ever constructed as a sub-module of Qwen35MoEVL3ModelCausalLMModel and is not registered standalone, so the wrapper's preprocess_weights does all weight routing (prefix-strip + MoE expert unpack + tied lm_head). The removed method also had two latent bugs (tie_word_embeddings checked for the un-stripped key 'model.embed_tokens.weight' that never exists post-strip; fused MoE expert tensors were not unpacked into per-expert ONNX initializers). Rather than fix dead code, drop it and document why the class has no preprocess_weights. Signed-off-by: justinchuby <[email protected]>
Qwen3.6-35B-A3B is the vision-language variant of Qwen3.5-MoE. The HF
config reports
model_type=qwen3_5_moewith bothtext_configandvision_config; mobius dispatches it to a newqwen3_5_moe_vlregistry entry that composes the existing
Qwen35MoETextModelbackbone with the Qwen3-VL ViT +
InputMixer(same pipeline as thedense Qwen3.5-VL
Qwen35VL3ModelCausalLMModel).Changes
Qwen35MoEVLDecoderModel+Qwen35MoEVL3ModelCausalLMModelin
src/mobius/models/qwen35.py. ExtendedQwen35MoETextModel.forwardto accept
inputs_embedsfor VL decoding.preprocess_weightsunpacks HF's fused
experts.{gate_up,down}_projtensors intoper-expert names (HF stores
[E, 2*inter, H]/[E, H, inter])._builder.pyoverridesmodel_typetoqwen3_5_moe_vlwhen the composite config has avision_config;text-only Qwen3.5-MoE still resolves to
qwen3_5_moe.qwen3_5_moe_vlentry with taskhybrid-qwen-vl.build_graph_test.pypasses.Qwen/Qwen3.6-35B-A3B(top-1 token=760 ""The"", 24-token generationcaptured).
examples/qwen3_6_35b_a3b_ort_genai.pyruns ORT GenAIinference and supports
--quantize {Q4_K_M,NF4}via Olive.Test status
build_graph_testforqwen3_5_moe_vlarch_validation/tmp/qwen3_6-onnx)Follow-ups