Skip to content

feat(qwen4): add opt-in low-RAM Host-MoE (Q3_A32/Q2_A32) with NPUxCPU overlap - #1269

Open
This-Is-NPC wants to merge 2 commits into
ROCm:mainfrom
This-Is-NPC:feat/qwen4-mtp-imatrix-opt
Open

This-Is-NPC wants to merge 2 commits into
ROCm:mainfrom
This-Is-NPC:feat/qwen4-mtp-imatrix-opt

Conversation

@This-Is-NPC

Copy link
Copy Markdown

Summary

This PR builds directly on top of the merged Qwen4-35B-A3B engine (#1266) to add two complementary optimizations — 100% backward-compatible with the official FastFlowLM/Qwen4-35B-A3B-NPU2 checkpoint, vision tower, prefix cache, flm_state_api, and causal_lm vtable ABI (144 B unchanged):

1. 16 GB / 24 GB Mixed-Precision imatrix Host-MoE (Q3_A64 / Q2_A32_256) + Async NPU×CPU Overlap

  • Problem: The official Qwen4 engine pins 21.35 GB of NPU BOs (~450 MiB/layer of Q4_K routed experts across 40 layers). On 16 GB / 24 GB machines (or 32–48 GB developer laptops with <23 GiB free RAM), this pushes the memory-mapped 21 GB engram table and page cache into swap, collapsing decode throughput to ~0.5 tok/s.
  • Solution:
    • Introduces AVX-512BW+VNNI (_mm512_dpbusd_epi32) mixed-precision host-MoE kernels in qwen4_moe_vnni.hpp:
      • Q3_A64 (asymmetric 3-bit, group-64, 28 B / 64 weights = 3.50 bpw)
      • Q2_A32_256 (asymmetric 2-bit, group-32 super-blocks, 84 B / 256 weights = 2.625 bpw, with optional imatrix-weighted MSE-ALS calibration)
    • Skips allocating P.gu[il] / P.dn[il] NPU BOs for host-MoE layers, reducing pinned NPU memory from 21.35 GB → 2.73 GB (-87.2%) and NPU weight packing time from 41.3 s → 3.0–7.0 s.
    • Overlaps persistent NPU shared-expert execution (sh_task(il) on the existing decode.xclbin, zero new xclbins) with CPU router + top-8 + AVX-512 VNNI routed experts.
    • Adds automatic RAM detection (MemAvailable < 16.5 GiB → q2_hq, 16.5–23 GiB → q3, >= 23 GiB → unchanged lossless Q4_K on NPU), manual override via FLM_QWEN4_MOE_QUANT=none|q3|q3_all|q2_hq|q2|q2_ultra, madvise(MADV_DONTNEED) eviction of dead on-the-fly Q4_K mmap pages, and zero-copy mmap loading of pre-quantized .q3_a64/.q2_a32 tensors.
    • Includes an offline imatrix collector (FLM_QWEN4_DUMP_IMATRIX) and streaming offline quantizer (tools/qwen4_q4nx_quantizer.cpp, make quantizer).

2. Native MTP (blk.40) Speculative Decoding (Greedy + Exact Stochastic Rejection Sampling)

  • Adds qwen4_moe_mtp.{hpp,cpp} and Qwen4::_speculative_generate(...) in modeling_qwen4.cpp following the Qwen3_8MTP contract (causal_lm::supports_speculation / speculate / last_speculation_prime_us, plus FLM_DISABLE_SPECULATION=1 and chooser fallback for grammar/penalties/ignore_eos).
  • Zero extra NPU BOs, zero extra xclbins: loads an optional sibling mtp.q4nx (blk.40 with Q3_A64 routed experts + multilingual top-64K Q4_K draft LM head, ~16–20 ms/draft). Silently inactive with zero overhead when mtp.q4nx is absent.
  • Adds O(1) recurrent-state rollback (model::rewind_speculate) across all 30 GDN layers + layer-1 PLE conv history, plus step_snaps capture during model::forward.
  • Supports exact Leviathan et al. (2023) speculative rejection sampling (min(1, p(d)/q(d))) for temperature > 0 (top_k/top_p/min_p), achieving 60.4% draft acceptance (2.21 tok/cycle) at Qwen4's official default sampling (temperature=1.0, top_p=0.95, top_k=20).

3. Minor Linux GCC 14+/16 Build Fixes

  • Added #include <climits> for UCHAR_MAX in npu_cmd.hpp.
  • Made CXX ?= g++-13 overridable and auto-detected -mavx512vnni in detail/qwen4_moe_npu/Makefile.

Live NPU Benchmarks (/dev/accel/accel0, Official FastFlowLM/Qwen4-35B-A3B-NPU2)

Measured on a Ryzen AI NPU2 Linux laptop with 18 GiB available RAM (real-world developer desktop workload), identical prompt (--ctx-len 4096, /set r-eff none, /set gen-lim 160):

Configuration Pinned NPU BOs Peak Host RSS NPU Pack TTFT Prefill (tok/s) Decode (tok/s) Total Wall MTP Telemetry
Official main baseline (Q4_K NPU) 21.35 GB 7.73 GiB 41.3 s 23.02 s 2.16 0.53 417.8 s —
+ Q2_HQ Host-MoE + NPU×CPU Overlap 2.73 GB (-87.2%) 14.01 GiB 7.0 s 2.22 s 22.05 6.86 (12.9×) 71.6 s —
+ Q2_SWEET (16 GB) Host-MoE + Overlap 2.73 GB (-87.2%) 13.90 GiB 3.0–4.9 s 1.28 s 38.36 (17.8×) 7.25 (13.7×) 71.4 s —
+ Q2_SWEET + Native MTP (greedy temp=0) 2.73 GB (-87.2%) 13.90 GiB 3.0 s 0.93 s (24.8×) 46.50 (21.5×) 6.01 (11.3×) 64.9 s 57.9% acc, 2.12 tok/cyc, draft 16.6 ms, verify 329.7 ms
+ Q2_HQ + Native MTP (default temp=1.0, top_p=0.95, top_k=20) 2.73 GB (-87.2%) 14.89 GiB 5.2 s 1.48 s 30.14 4.75 (9.0×) 84.9 s 60.4% acc, 2.21 tok/cyc, draft 20.0 ms, verify 436.0 ms

Note on MTP verify latency: The blk.40 draft head achieves 57.9%–66.7% acceptance (2.12–2.32 tok/cycle) in only 16–20 ms/cycle. Currently, multi-token verification runs via prefill_overlay.xclbin (which pads K=3..4 to dq_rows=64 and reconfigures overlays across 40 layers), so in Host-MoE mode persistent decode.xclbin (7.25 tok/s) still slightly edges out batched verify (6.01 tok/s). With a future small-batch verify path in decode.xclbin (or on 32+ GB systems with full NPU routed experts), the same MTP front-end immediately unlocks ~1.8–2.1× pure decode speedup.

Verification

  • Built libqwen4_moe_npu.so, qwen4_q4nx_quantizer, and src/build/flm cleanly with zero errors.
  • Verified readelf -sW vtable size _ZTV13qwen4_moe_npu == 144 bytes (exact ABI match with libqwen3_8mtp_npu.so).
  • Verified Q3_A64 and Q2_A32_256 AVX-512 VNNI kernels + imatrix MSE-ALS gain (+0.0144 cosine similarity / -26% MSE on outlier channels).
  • Verified end-to-end live NPU inference on official FastFlowLM/Qwen4-35B-A3B-NPU2 across baseline, Q2_HQ, Q2_SWEET, greedy MTP, and stochastic MTP (temp=1.0, top_p=0.95, top_k=20).

(Follow-up optimization PR superseding #1267, rebased cleanly onto #1266.)

@tawei-amd tawei-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. Running Qwen4-35B-A3B on 16-24 GB machines is a real gap: with ~18 GiB free, the 21 GB pinned expert set pushes main into swap, and decode is unusable there. We'd like to take the low-RAM path, but in a different shape. Requesting changes. Summary first, details below.

Proposed direction: a separate model tag, opt-in only

The Q3/Q2 expert modes change output quality a lot (numbers below), so they should never be picked automatically from MemAvailable. That makes output depend on whatever else is running at load time. Please:

  1. Ship the low-RAM mode as its own model tag, e.g. qwen4-lowmem:35b-a3b, with its own HF repo holding the pre-quantized routed experts (imatrix-calibrated, produced offline by your quantizer). qwen4:35b-a3b stays exactly as it is today.
    • Remove the MemAvailable auto-selection and the load-time Q4_K -> Q3/Q2 requantization from the default path.

    • The engine selects host-MoE because the package contains .q3_a64 / .q2_a32 tensors (you already detect has_prequant), not because of free RAM.

    • If we want both a ~24 GB and a ~16 GB option, that's two tags (or one; let's decide from the KLD numbers).

    • Hosting: the weights for the new tag need to live in our official repos: Hugging Face FastFlowLM/Qwen4-35B-A3B-lowmem-NPU2 and ModelScope amd/Qwen4-35B-A3B-lowmem-NPU2 (final names TBD), like every other FLM model, so flm pull works from both. Would that be possible on your side? Concretely, we'd need:

      • the pre-quantized package (or a link we can fetch it from);
      • the exact recipe to reproduce it: quantizer command and profile, the imatrix file and how it was collected (calibration data), and the source checkpoint revision;
      • your OK for us to redistribute it under the base model's license.

      We'll rebuild it from the recipe, check that it matches, and do the HF/ModelScope upload ourselves. The model card will credit you.

  2. Report quality next to the speed table. We gate on top-100 KLD against BF16. The model card should state the trade-off plainly.
  3. Split MTP into a follow-up PR. By your own table it currently lowers decode (7.25 -> 6.01 tok/s), and the accept test isn't exact (see below). Happy to review it once a small-batch verify path makes it faster than plain decode.
  4. Source only: please drop src/lib/xrt/libqwen4_moe_npu.so. CI builds the engine libraries.

Quality: what the Q3/Q2 modes cost

We measured llama.cpp stand-ins for your modes: q3_k for Q3_A64 and q2_k for Q2_A32_256, using your exact per-layer layout (mid layers 4..35, edges 0..3 / 36..39). Everything else uses the shipped recipe with an imatrix, quantized from BF16. Scores are teacher-forced against BF16 on 21 x 2048-token chunks of held-out text:

mode mean KLD same top-1 PPL ratio
shipped qwen4:35b-a3b (Q4_K experts) 0.033 92.8% 1.004
q3 (your 24 GB auto mode) 0.070 89.8% 1.008
q2_hq (your 16 GB auto mode) 0.131 85.9% 1.037
q2 / q2_sweet 0.161 84.6% 1.043

These numbers are a lower bound. The current auto path requantizes from Q4_K at load time without an imatrix, which will score worse. Please run the same kind of KLD check on your actual kernels/packages. That's also how we'd choose between q3 and q2_hq for the tag.

Bugs to fix (in the low-RAM PR)

  • qwen4_moe_decode.cpp:929: a_sh_only / runs[il].sh_only are only created when !P.pst, but P.pst defaults to true. After a persistent-decode stall or timeout, P.pst flips to false and moe() executes the never-created run (lines ~1206/1213). That's a crash or hang. Always create sh_only for host layers.
  • qwen4_moe_forward.cpp:1809: posted is now true for any T<=8. ple_products then runs par_for on the side thread concurrently with layer 0's par_for on the main thread, for every small prefill tail. Before, this only happened for T==1, where par_for is serial. Keep the old condition unless the pool is shown to be reentrant.
  • Makefile:36: CXX ?= g++-13 is a no-op because make predefines CXX. Use ifeq ($(origin CXX),default).
  • qwen4_moe_vnni.hpp:2701: h_f32[M_TOK][512] has no bounds check on inter. Add a static_assert or runtime check. Also add the missing <cstdlib> (vnni.hpp) and <array> (mtp.cpp) includes; MSVC CI will need them.
  • qwen4_moe_host.cpp:500: duplicate evict_mmap_pages (an exported copy of the static one at line 262). Delete it.
  • qwen4_moe_decode.cpp:1096: experts_gate_up/down(il) dereference null for host-MoE layers. Throw a clear error instead.
  • qwen4_moe_npu.cpp:61: please drop the hardcoded Qwen4-35B-A3B-NPU2 xclbin fallback. The new tag's package should carry, or reference, its xclbins through the normal model metadata.

Performance

  • Host-MoE prefill (eval_host_moe_batch) walks tokens in blocks of 8 and re-reads each active expert's weights per block. That's ~64x per layer on a 512-token chunk. Grouping the chunk by expert (per-expert token lists, tiles of 8) streams each expert once and should lift the 22-46 tok/s prefill a lot.
  • For the speed table, please include a machine with enough RAM as the reference. Main does ~15 tok/s decode there, so the comparison is 7.25 tok/s at 16-24 GB against 15 tok/s at 32 GB+, rather than "13.7x".

For the MTP follow-up (not this PR)

  • qwen4_moe_mtp.cpp:193: build_sparse_dist builds its own truncated distribution (top 256 when top_k<=0, own temperature/min_p/top_p order). The accept test must use the same distribution as the regular sampler, or speculative output is biased.
  • qwen4_moe_npu.cpp:290: MTP state isn't reset on checkpoint restore, rows-only restore, or prefix-cache load.
  • qwen4_moe_mtp.cpp:607: record_trunk advances pos_base only by the trimmed part of each chunk. A 1000-token prompt advances it by ~360, not ~870, so RoPE positions drift.
  • qwen4_moe_mtp.cpp:570: the full-max_len K/V allocation at load and the ~60 MB-per-step snapshots work against the 16 GB target. Allocate lazily.
  • modeling_qwen4.cpp:3267: sampler->temperature is dereferenced when sampler is null (the line above guards it, this one doesn't).

Thanks again. The overlap of the NPU shared expert with host routed experts is a nice idea, and we'd be glad to see it land as the low-RAM tag.

@This-Is-NPC This-Is-NPC changed the title feat(qwen4): add 16GB/24GB imatrix Host-MoE with NPUxCPU overlap and native MTP speculative decoding feat(qwen4): add opt-in low-RAM Host-MoE (Q3_A32/Q2_A32) with NPUxCPU overlap Dec 6, 2026
@This-Is-NPC

Copy link
Copy Markdown
Author

Thanks for the thorough review and the KLD stand-in numbers — super helpful!

I have updated PR #1269 to follow your proposed direction (opt-in pre-quantized low-RAM tag only, source-only, MTP split out) and addressed every bug and performance item you flagged:

Scope & bug fixes

  • Opt-in pre-quantized only: Removed MemAvailable auto-selection and load-time Q4_K→Q3/Q2 requantization from qwen4_moe_host.cpp. qwen4:35b-a3b is completely untouched; Host-MoE activates strictly when .q3_a32 / .q2_a32 tensors are present in model.q4nx.
  • MTP split out: Moved all MTP code to a separate follow-up branch (to be opened later once small-batch verify + the 5 MTP fixes are in place).
  • Source-only: Dropped src/lib/xrt/libqwen4_moe_npu.so from the PR.
  • All 7 review bugs fixed:
    1. qwen4_moe_decode.cpp: Always create a_sh_only / runs[il].sh_only for host-MoE layers (survives persistent-decode fallback).
    2. qwen4_moe_forward.cpp: Restored posted = be && PLE_LAYER > 0 && !side_off.
    3. Makefile: Replaced CXX ?= with ifeq ($(origin CXX),default).
    4. qwen4_moe_vnni.hpp: Added validate_host_moe_dims() bounds checks before OpenMP (inter <= 512, D <= 4096, alignment), added <cstdlib> / <array>, and enabled VNNI under _MSC_VER with /arch:AVX512.
    5. qwen4_moe_host.cpp: Deleted the duplicate evict_mmap_pages (and removed unused mmap eviction code).
    6. qwen4_moe_decode.cpp: experts_gate_up() / experts_down() now throw a clear std::runtime_error on host-MoE layers instead of dereferencing null.
    7. qwen4_moe_npu.cpp: Reverted to main (dropped hardcoded Qwen4-35B-A3B-NPU2 xclbin fallback; the new tag will use xclbin_folder in model_list.json once the final repo name is decided).

Prefill optimization & quantization upgrade

  • Expert-grouped Host-MoE prefill (eval_host_moe_batch): Quantizes all T tokens once, groups all T * 8 assignments across the chunk by expert (heaviest first), and streams each active expert's weights once across tiles of up to 32 tokens (in 8-token VNNI sub-tiles). Microbenchmark speedup at T=512: 2.60x–2.69x, lifting real NPU prefill from 22–46 tok/s to 75–81 tok/s (close to official Q4_K's 84 tok/s).
  • Upgraded Q3_A64 → Q3_A32_256 (group-32, 3.625 bpw) + per-expert IMT2 imatrix: Testing real KLD showed group-64 + layer-averaged down_sq gave 0.129 KLD on q3. Switching to group-32 (116 B / 256 w, same VNNI loop as Q2_A32_256 + 1 mask-add) and per-expert down_sq[il][e] dropped q3 KLD by ~25% and cut the PPL delta in half.

Real KLD + speed table (measured on actual kernels/packages)

Evaluated with the same top-100 KLD + tail-bucket metric as qwen35_dflash2_e2e.cpp on 8 × 2048 = 16,384 held-out WikiText-2 test tokens against the shipped FastFlowLM/Qwen4-35B-A3B-NPU2 (rev 45a1a83f30fada934fb3b9f664d566af8d41c636) as reference (Q4_K vs BF16 is 0.033 KLD / 1.004 PPL ratio per your measurement):

Profile model.q4nx Pinned NPU BOs NPU Prefill 512 Eval+lm_head (warm) Decode (NPU+CPU) Mean KLD (vs Q4_K) Same top-1 (vs Q4_K) PPL ratio (vs Q4_K)
shipped qwen4:35b-a3b (Q4_K) 20.65 GiB 21.35 GB 84.0 tok/s 128.5 tok/s ~15 tok/s (32 GB+) / ~8.9 tok/s (26 GiB free) 0 (ref) 100% 1.0000
q3 (32 host Q3_A32 + 8 NPU Q4_K) 17.65 GiB 6.45 GB 80.7 tok/s 93.9 tok/s ~8.8 tok/s 0.0967 88.44% 1.0171
q3_all (40 host Q3_A32) 16.90 GiB 2.73 GB 75.3 tok/s 86.3 tok/s ~9.5 tok/s 0.1082 87.32% 1.0226
q2_hq (8 Q3_A32 + 32 Q2_HQ) 14.90 GiB 2.73 GB 63.1 tok/s 93.5 tok/s ~9.9 tok/s 0.2624 81.35% 1.0944

Based on these numbers, q3_all (only 2.73 GB pinned NPU BOs, 16.90 GiB model.q4nx, 1.0226 PPL ratio) or q3 (1.0171 PPL ratio, 6.45 GB pinned BOs) look far stronger than q2_hq (which doubles KLD to save only 2 GiB). Note also that these packages were quantized from shipped Q4_K — quantizing directly from BF16 in your pipeline should lower KLD further by avoiding double quantization.

Hosting & reproducible recipe

You have my full OK to redistribute the pre-quantized package(s) on Hugging Face (FastFlowLM/...) and ModelScope (amd/...) under the base model's Apache-2.0 license.

Exact recipe to reproduce:

  • Source package: FastFlowLM/Qwen4-35B-A3B-NPU2 @ revision 45a1a83f30fada934fb3b9f664d566af8d41c636 (from Qwen/Qwen4-35B-A3B)
  • Calibration data (imatrix): Salesforce/wikitext (wikitext-2-raw-v1, train split), first 32 × 512 = 16,384 tokens (tokenized with tokenizer.json, add_special_tokens=False), collected via FLM_QWEN4_DUMP_IMATRIX=imatrix_wikitext2_16k_v2.bin (IMT2 per-expert format, 21 MiB, SHA-256 3c8983562dbaba413f5d35b436c826f43f53e15a42901d5280c55756d55129c6).
  • Quantizer command:
    make -C flm-dev-kit/FLM_DLL/detail/qwen4_moe_npu quantizer
    ./flm-dev-kit/FLM_DLL/build/qwen4_moe_npu/bin/qwen4_q4nx_quantizer \
      --in model.q4nx --out model_lowmem.q4nx --profile q3_all --imatrix imatrix_wikitext2_16k_v2.bin
    (or --profile q3 if you prefer the 8 edge layers kept at Q4_K on NPU)

Let me know which profile (q3_all vs q3, or both) and final tag/repo name(s) you'd like — I can upload the imatrix + pre-quantized model.q4nx to a staging HF repo right away for you to fetch and verify, and add the model_list.json entry with "xclbin_folder": "Qwen4-35B-A3B-NPU2" once the names are finalized.

@tawei-amd

Copy link
Copy Markdown
Collaborator

Wow, thank you! That was a fast and really thorough turnaround. You covered every point from the first round within a day, and a few things stood out:

  • The expert-grouped prefill (2.6x on eval_host_moe_batch) is a great improvement.
  • Measuring real KLD on the actual kernels and packages is exactly the data we needed to make a call.
  • The redistribution OK and the full reproducible recipe make hosting easy on our side. Thank you for both.

We'd love to ship this as a new model, qwen4-lowmem:35b-a3b, probably in v1.0.16. Here's how we'd suggest getting there together.

The plan

1. Quantize from BF16 with unsloth's imatrix. This is where we think the remaining quality is.

  • Your packages are quantized from the shipped Q4_K, so the weights get rounded twice.
  • In our stand-in test, building the same layout straight from BF16 came out noticeably better.
  • Unsloth's Qwen4-35B-A3B imatrix (a standard llama.cpp GGUF) has per-expert, per-column importance for gate/up (2048 x 256 experts) and down (512 x 256). It's calibrated on a broad chat/code/multilingual mix, which should help more than 16K tokens of wikitext.
  • We'd use the same imatrix as the shipped model: unsloth's merged with our own calibration run, which scored ~8% lower KLD than unsloth's alone. The model card will credit unsloth.

Could you extend qwen4_q4nx_quantizer to:

  • read the routed experts from the BF16 GGUF (or safetensors), and
  • accept a llama.cpp GGUF imatrix (*.in_sum2 / *.counts)?

2. We can run the quantization here, if that works for you. We already have the BF16 checkpoint, the imatrix files and our KLD setup, so you wouldn't need a staging repo. We'd build the packages with your tool, share the numbers in this PR, and upload to FastFlowLM/Qwen4-35B-A3B-lowmem-NPU2 (HF) and amd/Qwen4-35B-A3B-lowmem-NPU2 (ModelScope).

3. Then pick 3-bit or 2-bit together, from data. Your numbers point to q3_all: 2.73 GB locked NPU memory, only +0.011 KLD over q3. But q2_hq might close some of the gap once it's built from BF16. We'll build both and compare:

  • KLD vs BF16;
  • decode/prefill speed;
  • peak RAM on a 16 GB and a 24 GB machine.

Then we'll post the results here and decide with you. Our guess today is q3_all, but we're happy to be surprised.

4. The model_list.json entry for qwen4-lowmem:35b-a3b with "xclbin_folder": "Qwen4-35B-A3B-NPU2". We'll fill in size/hash after the build.

A few fixes before merge

These came out of a second pass over the new code. They're mostly about failing loudly instead of silently:

  • Quantizer input checks (tools/qwen4_q4nx_quantizer.cpp):
    • compare the imatrix header (D, inter, num_experts) against the model, since a mismatched or truncated file reads out of bounds;
    • check the input tensor dtype/shape, byte count and read errors;
    • reject an unknown --profile (a typo like q3all currently writes an unquantized copy).
  • validate_host_moe_dims inside OpenMP: it can throw from an omp parallel region, which ends in std::terminate. Validating once at load time avoids that and takes the check out of the hot path.
  • VNNI build and runtime:
    • CMake non-MSVC flags need -mavx512vnni (otherwise CMake builds quietly use the scalar loops);
    • clang-cl needs the target feature for the _MSC_VER branch;
    • a runtime CPU check would give a clean "unsupported CPU" message instead of SIGILL.
  • imatrix collector (qwen4_moe_forward.cpp):
    • the host-MoE branch returns before the down-projection collection, so down_sq stays zero on host layers;
    • generated tokens are counted along with the prompts;
    • the destructor's write isn't error-checked, so it can print "Saved" on a full disk.

One number to double-check

Your table shows the shipped qwen4:35b-a3b prefill at 84 tok/s @512. On our machines, flm bench gives 625-735 tok/s at 1K-2K prompts, so we suspect that run hit memory pressure or took a different path. Could you rerun the baseline with plenty of free RAM, and report the low-RAM prefill with flm bench too? Then the two rows compare directly.

Performance ideas for later (not blocking)
  • eval_host_moe_batch allocates and zeroes a per-thread n_threads*T*D accumulator per layer (~64 MB at T=512, 16 threads). Per-(token, k) slots or row partitioning would avoid it.
  • Each expert's token group runs on one thread (dynamic,1 over experts). A hot expert can serialize the chunk; splitting large groups across threads would help.
  • Decode: eval_host_moe_single_range spreads 4 experts over ~16 threads and opens a parallel region plus allocations twice per layer. Splitting rows across all threads should speed up decode.
  • Decode: the CPU router runs before pst_issue(sh_t[0]). Issuing the shared expert first would let it overlap the routing.
  • Prefill: the shared expert runs before eval_host_moe_batch, so prefill doesn't overlap NPU and CPU yet.
  • The persistent-decode fallback sets P.pst=false without exec_task's stderr notice and duplicates its retry logic. Reusing exec_task would keep them in sync.
  • A few comments still say Q3_A64; the format is now Q3_A32_256.

On our side

  • Build q3_all and q2_hq from BF16 and share KLD, speed and peak RAM here.
  • Measure how much free RAM the shipped tag needs for full speed, so the model cards can tell people which tag to pick.
  • Pressure-test on Linux and Windows CI, then upload and publish.

Thanks again for driving this. Making a 35B model usable on 16-24 GB laptops is a real win for a lot of people, and the NPU-shared-expert + CPU-routed-expert overlap is a neat design. Let us know what you think of the plan!

This branch has not been deployed

No deployments
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