Skip to content

Add support for Qwen3-VL-MoE models - #322

Merged
davidkoski merged 2 commits into
ml-explore:mainfrom
lucasnewman:qwen3-vl-moe
Aug 1, 2026
Merged

davidkoski merged 2 commits into
ml-explore:mainfrom
lucasnewman:qwen3-vl-moe

Conversation

@lucasnewman

Copy link
Copy Markdown
Contributor

Proposed changes

This adds support for the Qwen3-VL-MoE model family in addition to the Qwen3-VL models already supported. I also fixed the GELU approximation type for both models, which is designed to be config-driven.

I verified I get valid output in an integration test:

Prompt: what do you see?

Response:
Based on the picture the image shows a traditional Japanese painting, likely a hanging scroll or byōdō, depicting a vibrant scene of morning glory flowers (asagao) in full bloom. The key elements are:

- **Flowering Vines:** The central focus is on lush, dark green vines with clusters of deep blue, trumpet-shaped flowers. The flowers are depicted in full bloom, with some facing upwards and others hanging, creating a sense of natural movement.
- **Background:** The entire scene is set against a warm, golden-orange background, which is characteristic of traditional Japanese art. This background is divided into vertical panels, suggesting the painting is on a folding screen or a piece of paper.
- **Composition:** The composition is dynamic, with the vines and flowers flowing diagonally across the frame, creating a sense of life and vitality. The dark blue of the flowers contrasts sharply with the golden background, making them stand out.
- **Style:** The painting is done in a traditional Japanese style, likely with ink and color on paper, emphasizing the natural beauty of the flowers.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Comment on lines -576 to +588
_activation.wrappedValue = GELU(approximation: .fast)
_activation.wrappedValue = GELU(
approximation: Qwen3VLVision.geluApproximation(for: hiddenAct))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curiously it looks like this was swapped in the mlx-vlm MOE code. In the HF transformers code both types of models use exact/tanh for PatchMerger/VisionMLP. mlx-vlm MOE seems to swap them (and then this code is out of sync with that, but is actually correct per the HF reference code).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it fixes a bug in the non MOE code in that it ignored the config :-)

@davidkoski

Copy link
Copy Markdown
Member

Rebase to main to hopefully get CI to work.

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, thank you!

@davidkoski

Copy link
Copy Markdown
Member

Just waiting on CI.

@davidkoski
davidkoski merged commit cd1ab3d into ml-explore:main Aug 1, 2026
2 checks passed
div0-space pushed a commit to LibraxisAI/mlx-swift-lm that referenced this pull request Nov 29, 2026
…l-explore#322)

* Add native Recursive Flint model and strict tool protocol

* Represent automatic native protocol constraints in CBv2

* Reuse identical sliding masks within a paged prefill call

Within one paged prefill row/call, consecutive eligible query blocks with the
same query and visible-key counts have byte-identical Boolean sliding masks:
each block's first query sits (visible keys - queries) positions after its
first visible key. Retain only the last such mask locally and pass it as the
same .array SDPA mask, instead of rebuilding it per block. Span, bidirectional,
softcap and Qwen4-indexer paths, cold blocks, one-query tails, arithmetic,
128-query blocking, gather-before-write and page ownership are unchanged.

New tests compare exact BF16/FP32 outputs and retained KV against an
independent per-block rebuild oracle across cold/wrapped histories (including
a prefill gather across the physical ring seam), partial tails, decode and
reordered packed rows. Paged A/B through the provider measured about +0.8%
at 4K fixed-prompt prefill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
div0-space pushed a commit to LibraxisAI/mlx-swift-lm that referenced this pull request Nov 29, 2026
Brings ml-explore#322 (Flint), ml-explore#324, ml-explore#326-ml-explore#330 (CBv2 paged/MTP/SDPA, GPT-OSS), ml-explore#325 and the
Nemotron Super fused MTP verify window: SDK main up to the commit d-inference
master pins (889fe3c). Main's later ml-explore#331/ml-explore#332 are left out until the provider
adopts ml-explore#332's streamed tool-call type. Package.swift pins the cluster
mlx-swift 9fe34405 instead of main's 67dc7528; that was the only conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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