Skip to content

[qwen] Add Qwen3_5MoeForCausalLM (flat text-only MoE) support - #384

Merged
xadupre merged 2 commits into
mainfrom
copilot/fix-issue-374
Jun 17, 2026
Merged

[qwen] Add Qwen3_5MoeForCausalLM (flat text-only MoE) support#384
xadupre merged 2 commits into
mainfrom
copilot/fix-issue-374

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Propagates onnxruntime-genai#2146 (Qwen3.5‑MoE). The MoE *ForConditionalGeneration builder from #2146 was already present and faithful to upstream; the gap was the flat text-only Qwen3_5MoeForCausalLM variant, which mbext provides for the dense model (Qwen35CausalLMModel/Qwen3_5ForCausalLM) but not for MoE.

Changes

  • builders/qwen.py
    • Generalized Qwen35MoeTextModel.__init__ so the MoE config mapping (num_experts → num_local_experts, moe_intermediate_size → intermediate_size) applies to both the nested (text_config) and the flat Qwen3_5MoeTextConfig:
      tc = config.text_config if hasattr(config, "text_config") else config
    • Added Qwen35MoeCausalLMModel(Qwen35MoeTextModel), mirroring the dense Qwen35CausalLMModel: defaults exclude_embeds=False (keeps the embedding layer so the graph takes input_ids) and loads weights via Qwen3_5MoeForCausalLM.
  • builder.py — dispatch Qwen3_5MoeForCausalLM → Qwen35MoeCausalLMModel.
  • tests/fast/test_random_qwen3_5_moe.py — flat-config helper + test_qwen3_5_moe_causallm_fp32_cpu_full_attention_build asserting input_ids input, an MoE/QMoE op, and model_type == "qwen3_5_moe_text".

Notes for reviewers

Qwen3_5MoeForCausalLM is an mbext-side extension (not in #2146 upstream), added for parity with the existing dense ForCausalLM path. The text-only model_type (qwen3_5_moe_text) aligns with the model_type.h entry from onnxruntime-genai#2186.

Copilot AI changed the title [WIP] Fix issue related to PR 2146 for xadupre/mbext Add Qwen3_5MoeForCausalLM (flat text-only MoE) support Jun 17, 2026
Copilot AI requested a review from xadupre June 17, 2026 09:54
@xadupre
xadupre marked this pull request as ready for review June 17, 2026 10:09
@github-actions

Copy link
Copy Markdown

📂 Impacted Files

3 file(s) changed in this pull request:

🔵 modelbuilder/builder.py (+4 / -0)
🔵 modelbuilder/builders/qwen.py (+42 / -8)
🔵 tests/fast/test_random_qwen3_5_moe.py (+116 / -0)

@github-actions github-actions Bot changed the title Add Qwen3_5MoeForCausalLM (flat text-only MoE) support [qwen] Add Qwen3_5MoeForCausalLM (flat text-only MoE) support Jun 17, 2026
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.91%. Comparing base (65b1a42) to head (20673a5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #384      +/-   ##
==========================================
+ Coverage   78.88%   78.91%   +0.02%     
==========================================
  Files          27       27              
  Lines        8113     8123      +10     
==========================================
+ Hits         6400     6410      +10     
  Misses       1713     1713              
Flag Coverage Δ
fast-tests 78.91% <100.00%> (+0.02%) ⬆️
fast-tests-ort-nightly 78.86% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xadupre
xadupre merged commit 7fe68a5 into main Jun 17, 2026
11 checks passed
@xadupre
xadupre deleted the copilot/fix-issue-374 branch June 17, 2026 10:56
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