Skip to content

ggml-openvino: Enable MOE models on NPU for Qwen3.6-35B-A3B - #444

Open
yzhou51 wants to merge 3 commits into
ravi9:dev_backend_openvinofrom
yzhou51:qwen3.6_moe_npu
Open

yzhou51 wants to merge 3 commits into
ravi9:dev_backend_openvinofrom
yzhou51:qwen3.6_moe_npu

Conversation

@yzhou51

@yzhou51 yzhou51 commented Nov 20, 2026 •

Copy link
Copy Markdown

Overview

MoE models did not run on the NPU. On CPU and GPU, the backend translates MUL_MAT_ID to OpenVINO's GatherMatmul, which the NPU plugin does not support.

NPUW, the partitioning layer of the NPU plugin, has its own MoE support. It isolates the experts into functions and runs only the routed experts for each token, with the router on the host (the HOST_ROUTED mode). This PR translates the MoE block of a model into the form NPUW recognises, and sets the NPUW properties for that mode.

It covers the block that build_moe_ffn emits with:

  • a softmax router
  • top-k selection, with optional weight normalization
  • SwiGLU experts

That is the case for qwen35moe (Qwen3.6-35B-A3B, tested) and qwen3moe, which builds the same block (not tested). CPU and GPU keep GatherMatmul.

Additional information

How to run

export GGML_OPENVINO_DEVICE=NPU
export GGML_OPENVINO_PREFILL_CHUNK_SIZE=128
export GGML_OPENVINO_NPU_CONFIG="NPUW_WEIGHTS_BANK_ALLOC=CPU,NPUW_FUNCALL_ASYNC=NO,COMPILATION_NUM_THREADS=1"
./llama-cli -m Qwen_Qwen3.6-35B-A3B-Q4_0.gguf -c 256
REM Windows
set GGML_OPENVINO_DEVICE=NPU
set GGML_OPENVINO_PREFILL_CHUNK_SIZE=128
set GGML_OPENVINO_NPU_CONFIG=NPUW_WEIGHTS_BANK_ALLOC=CPU,NPUW_FUNCALL_ASYNC=NO,COMPILATION_NUM_THREADS=1
llama-cli.exe -m Qwen_Qwen3.6-35B-A3B-Q4_0.gguf -c 256

NPUW_WEIGHTS_BANK_ALLOC=CPU keeps NPUW's copy of the weights in host memory instead of the memory the NPU can address. It costs some speed, so it is documented rather than set by default.

Performance

Testing

Qwen3.6-35B-A3B Q4_0, greedy, prompt The capital of France is, -c 256, with the settings above:

System Output Prefill Decode
ggml-CPU (reference) Paris, a city renowned for its iconic …
PTL (NPU 5010), 32 GB, Windows Paris, a city renowned for its rich history, vibrant culture, and iconic landmarks … 0.84–0.98 t/s 1.5–1.8 t/s
LNL (NPU 4000), 32 GB, Windows The capital of France is Paris, a city renowned for its rich history, vibrant culture, and iconic landmarks. Situated in the north-central part of the country, Paris is not only 0.39 t/s 0.83 t/s
LNL (NPU 4000), 32 GB, Ubuntu same as LNL Windows 0.54 t/s 1.12 t/s
  • Backend defaults alone: on PTL, the settings above and the same settings with an explicit NPUW_MOE_POOL_SIZE=0,NPUW_MOE_TOKEN_CHUNK_SIZE=16 give identical output, so the backend's MoE defaults work on their own.

Accuracy

(PTL NPU): KLD against the ggml-CPU build, wikitext-2, -c 256, 40 chunks:

PPL(base) PPL(Q) PPL(Q)/PPL(base) Mean KLD Same top-1
8.024 8.436 ± 0.317 1.051 0.081 ± 0.002 86.6 %

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure:
    YES, AI help analysis and enable this feature.

Comment thread ggml/src/ggml-openvino/utils.cpp Resolved
@ravi9
ravi9 force-pushed the dev_backend_openvino branch from 80ea1c8 to ac3b8f5 Compare November 20, 2026 23:21
@ravi9
ravi9 force-pushed the dev_backend_openvino branch from bdb5789 to 9a8fecb Compare November 21, 2026 06:31
@ravi9
ravi9 force-pushed the qwen3.6_moe_npu branch 2 times, most recently from 3d3cb96 to 87aaa15 Compare November 22, 2026 08:22
@ravi9
ravi9 force-pushed the dev_backend_openvino branch from ba196ad to 2f46244 Compare November 23, 2026 00:47
@ravi9
ravi9 force-pushed the dev_backend_openvino branch from ba80126 to 45e6c13 Compare November 23, 2026 05:36
@ravi9
ravi9 force-pushed the dev_backend_openvino branch from 45e6c13 to 51fc2f9 Compare November 23, 2026 19:20
@ravi9
ravi9 force-pushed the qwen3.6_moe_npu branch 2 times, most recently from db4f2b7 to ba520f8 Compare November 24, 2026 20:32
@ravi9
ravi9 force-pushed the dev_backend_openvino branch from e3c85f8 to 1e5d24b Compare November 24, 2026 21:04
@ravi9

ravi9 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@yzhou51 On Linux, the accuracy needs to be fixed.
Perplexity check of #444 at ba520f8 on Panther Lake (64 GB, Ubuntu 26.04, OpenVINO 2026.4.1, NPU driver 1.38.0.20260910). KLD against the ggml-CPU logits, wikitext-2, -c 256 -b 256, 8 chunks, NPU with the settings (GGML_OPENVINO_PREFILL_CHUNK_SIZE=128, GGML_OPENVINO_NPU_CONFIG=NPUW_WEIGHTS_BANK_ALLOC=CPU,NPUW_FUNCALL_ASYNC=NO,COMPILATION_NUM_THREADS=1):

Run PPL(Q) PPL(base) Ratio Mean KLD Same top p
Qwen3.6-35B-A3B Q4_0, NPU 36.30 7.89 4.60 1.704 45.9 %
Same, GGML_OPENVINO_NPU_COMPILER_TYPE=PLUGIN 36.30 7.89 4.60 1.704 45.9 %
Qwen3.6-35B-A3B Q4_0, OpenVINO CPU 8.00 7.89 1.014 0.012 96.4 %
Qwen3.5-0.8B Q4_K_M, NPU (dense GDN, control) 29.89 25.41 1.177 0.172 78.3 %
  • The NPU result is far from the Accuracy table in the PR description (ratio 1.051, KLD 0.081, 86.6 % top-1 on PTL Windows). Every chunk is affected: chunk PPL 28–44.
  • The OpenVINO CPU path is close to the reference, and a dense GDN model on the NPU shows the usual NPU deviation. The gap is specific to the NPU MoE path added here.
  • The earlier head 87aaa15 gave the same picture: 40.1 vs 8.76 at -c 256, 33.9 vs 8.03 at -c 128.

@ravi9
ravi9 force-pushed the dev_backend_openvino branch from fcf6088 to 2371fe4 Compare November 26, 2026 03:53
@yzhou51 yzhou51 closed this Nov 26, 2026
@yzhou51 yzhou51 reopened this Nov 26, 2026
@ravi9
ravi9 force-pushed the dev_backend_openvino branch 2 times, most recently from 7d8ccda to e0b9fd7 Compare November 27, 2026 02:29
@yzhou51

yzhou51 commented Nov 27, 2026

Copy link
Copy Markdown
Author

Reproduce it in the LNL ubuntu 32G.

Reproduce

I ran on Lunar Lake, Ubuntu, NPU driver 1.38.0.20260910 (the same driver as yours), Qwen3.6-35B-A3B Q4_0. KLD is against the ggml-CPU logits, wikitext-2, -c 256 -b 256, with your NPU settings. Only the OpenVINO package changes between the two Lunar Lake runs:

Run Chunks PPL(Q) PPL(base) Ratio Mean KLD Same top p
Lunar Lake, OpenVINO 2026.4.1 (official release) 8 36.22 7.89 4.589 1.692 46.6 %
your run: Panther Lake, OpenVINO 2026.4.1 8 36.30 7.89 4.60 1.704 45.9 %
Lunar Lake, OpenVINO built from master (2026.5.1) 8 8.66 7.89 1.096 0.0946 87.6 %

With 2026.4.1, Lunar Lake reproduces your numbers almost exactly. With the master build, on the same machine with the same driver and settings, the result is as expected. On Panther Lake under Windows with a master build, I measured a mean KLD of 0.081, 86.6% same top p and a PPL ratio of 1.051. I don't have a Panther Lake Ubuntu machine, so the comparison on Ubuntu is on Lunar Lake only.

Cause

2026.4.1 was tagged on 2026-09-23. It doesn't have these NPUW changes, which the NPU MoE path of this PR depends on:

openvinotoolkit/openvino#38123, "[NPUW] Preserve MoE mixing scores and drain failed expert requests" (merged 2026-09-26). It corrects how the MoE executor applies the expert mixing scores, including zero and underfilled selections.
openvinotoolkit/openvino#38124, "[NPUW] Share batched MoE matching and sparse lowering" (merged 2026-10-19). It adds BatchedMoEPattern, the batched MoE form that this PR emits for the NPU.
With 2026.4.1, NPUW still isolates the experts through its older matchers, so the model runs, but the expert outputs are mixed incorrectly. Your OpenVINO CPU result and the dense GDN control on the NPU (Qwen3.5-0.8B) are as expected, which also points to the NPUW MoE path rather than to the translation in this PR.

Next

I'll add this minimum version to the NPU MoE section of docs/backend/OPENVINO.md in this PR.

yzhou51 and others added 3 commits November 27, 2026 13:55
NPUW, the partitioning layer of the NPU plugin, has its own MoE support.
It isolates the experts into functions and runs only the routed experts for
each token, with the router on the host (the `HOST_ROUTED` mode).
This PR translates the MoE block of a model into the form NPUW recognises,
and sets the NPUW properties for that mode.
ov_graph_compute_static scanned every node of the graph for a MoE block on
each call, cache hits included, to choose the NPUW MoE properties.
set_input_output already matches each MoE block when the decoder is built,
so it now records the result in GgmlOvDecoder::has_moe_block(), and the
properties are added from that flag when a graph compiles. The properties
are the same as before.
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