perf(qwen36): Q4_K shared-expert FFN kernels + Q8_0/Q5_K→Q4_K requant of the MoE FFN stage (+2.8–3.2%)#358
Closed
carlh7777 wants to merge 1 commit into
Closed
Conversation
- Introduced new shared expert kernels for Qwen3.6 with Q4_K requantization. - Updated model loading logic to support Q4_K weights for shared gate, up, and down projections. - Enhanced .gitignore to exclude new model directories and files. - Adjusted forward_token method in Qwen35Model to handle Q4_K configurations.
Member
🚩 Flagged: eval-gamingThis PR involves an account blocked for gaming the SN74 emission mechanism (sybil / coordinated duplicate farming): Per the project's no-gaming policy these accounts are blocked: the PR is not evaluated, scored, or merged. See |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two load-time weight requantizations targeting the MoE FFN stage of the Qwen3.6-35B-A3B decode path, gated to the Qwen3.6 fingerprint (
is_qwen35_or_qwen36_hybrid_moe) and off by default on every other model. The FFN stage runs on every token across all 40 layers, so shrinking its per-token weight reads is a broad, context-flat decode win.ffn_{gate,up,down}_shexp) as Q8_0 — 34 bytes/block on a read that fires every layer, every token. This requantizes it to Q4_K once at model load (~47% fewer weight bytes) and decodes it through two new Q4_K shared-expert MMVQ kernels (shared_gate_up_q4k_mmvq_kernel,shared_down_q4k_mmvq_kernel+ launcherlaunch_shared_expert_q4k_mmvq). They mirror the existing Q8 shared-expert control flow (FNQ Q8_1 → gate/up·silu → quant_h Q8_1 → down), only the weight dot swaps to the int8 dp4a Q4_K path. Gated to the exact shared-expert shape the kernels specialize (<2048, 512>).ffn_down_expsQ5_K→Q4_K at load stacks a further byte reduction on the same stage and routes automatically through the pre-existing Q4_K routed-down MMVQ dispatch (down_type == 12).Strict no-op on Qwythos-9B and any non-matching model.
A/B toggles (same binary):
SPARKINFER_SHEXP_REQUANT_Q4K=0restores native Q8_0 shared-expert reads;SPARKINFER_ROUTED_DOWN_REQUANT_Q4K=0restores native Q5_K routed-down. Both set = the "before" column below.Proof of speedup
Decode tok/s (end-to-end,
qwen3_gguf_bench,Qwen3.6-35B-A3B-UD-Q4_K_M.gguf, 128 decode tokens), default vsSPARKINFER_SHEXP_REQUANT_Q4K=off+SPARKINFER_ROUTED_DOWN_REQUANT_Q4K=off, same binary:All contexts clear the 2% gate. The FFN weight read fires every token regardless of KV depth, so the win is flat across context — a byte-reducing requant cannot slow decode. VRAM 23.7 → 22.0 GB. Qwythos-9B unchanged (fingerprint-gated no-op).
Cross-checked against a built-from-source
origin/main @ a502a59baseline (before = main, after = this branch, back-to-back same box): 438.5 → 448.7 @128 and 375.7 → 387.4 @32k — theoffcolumn above reproduces main within ~0.3% at every context.Accuracy
The requant is lossy but confined to the accuracy-tolerant FFN projections. Teacher-forced top-1 agreement of the default (Q4_K) build vs the native (off) build on a held-out 299-token window:
Subject to the harness KL/top-1 gate (
bench/scripts/accuracy.sh, top-1 ≥ 0.90, KL ≤ 0.20).Relation to open/merged PRs
Original — no open or merged PR requantizes the Qwen3.6 shared-expert FFN or adds Q4_K shared-expert kernels, and none requantizes the routed-expert down (Q5_K→Q4_K).
kernels/csrc/cuda/moe/expert_ffn_q4k.cu/moe.h— the shared-expert Q4_K path is new code touched by no other PR.runtime/src/models/qwen35.cpp(+43/−9); the reused lines are the genericdev_quant_requant_q4khelper (extended to accept a Q5_K source) and the load-loop call sites — standard requant boilerplate, not another PR's contribution.Test plan
qwen3_gguf_bench/qwen3_gguf_scoreon RTX 5090 (sm_120)origin/mainbaseline vs branch, back-to-back