perf(qwen36): Q4_K shared-expert FFN kernels + Q8_0/Q5_K→Q4_K requant of the MoE FFN stage (+3.1–3.8%)#360
Conversation
- Introduced new shared expert kernels for Q4_K requantization in Qwen3.6. - 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 to handle Q4_K shared expert conditions.
🐈 Copycat warning (real-time guard)1% containment + structural similarity (Levenshtein + bigram cosine both above threshold vs this PR's code shape) by a different author.
|
|
log tail |
❌ sparkinfer auto-eval —
|
| metric | value |
|---|---|
| label | eval:REJECT |
| Qwen3.5 score | eval-qwen35:REJECT (fail) |
| Qwen3.6 score | eval-qwen36:REJECT (fail) |
| Qwen3.5 vs same-box main | 240.81 tok/s → +0.4% (+1.0) |
| Qwen3.5 scored decode (32768 ctx · 32k-context) | 241.84 tok/s |
| Qwen3.5 correctness | top-1 90.0% · KL 0.0445 |
| Qwen3.5 128-token no-regression gate | 299.24 tok/s vs main 298.35 tok/s · pass |
| Qwen3.5 4k-context no-regression gate | 283.09 tok/s vs main 282.9 tok/s · pass |
| Qwen3.5 32k-context no-regression gate | 241.84 tok/s vs main 240.81 tok/s · pass |
| Qwen3.6 vs same-box main | 426.9 tok/s → -6.5% (-27.7) |
| Qwen3.6 scored decode (32768 ctx · 32k-context) | 399.17 tok/s |
| Qwen3.6 correctness | top-1 93.0% · KL 0.0313 |
| Qwen3.6 128-token no-regression gate | 435.59 tok/s vs main 472.74 tok/s · fail |
| Qwen3.6 512-context no-regression gate | 441.66 tok/s vs main 479.5 tok/s · fail |
| Qwen3.6 4k-context no-regression gate | 424.67 tok/s vs main 457.59 tok/s · fail |
| Qwen3.6 16k-context no-regression gate | 416.43 tok/s vs main 450.59 tok/s · fail |
| Qwen3.6 32k-context no-regression gate | 399.17 tok/s vs main 426.9 tok/s · fail |
| Qwen3.5 optimize | eval:REJECT · 241.84 tok/s · fail |
| Qwen3.5 optimize — Qwen3.6-35B-A3B guard accuracy | top-1 93.0% · KL 0.0313 · pass |
| Qwen3.5 optimize — Qwen3.6-35B-A3B 128 | 435.3 tok/s · fail |
| Qwen3.5 optimize — Qwen3.6-35B-A3B 512 | 441.59 tok/s · fail |
| Qwen3.5 optimize — Qwen3.6-35B-A3B 4k | 424.58 tok/s · fail |
| Qwen3.5 optimize — Qwen3.6-35B-A3B 16k | 417.15 tok/s · fail |
| Qwen3.5 optimize — Qwen3.6-35B-A3B 32k | 399.69 tok/s · fail |
| Qwen3.6 optimize | eval:REJECT · 399.17 tok/s · fail |
| Qwen3.6 optimize — Qwythos-9B (Q4_K_M) guard accuracy | top-1 90.0% · KL 0.0445 · pass |
| Qwen3.6 optimize — Qwythos-9B (Q4_K_M) 128 | 298.32 tok/s · pass |
| Qwen3.6 optimize — Qwythos-9B (Q4_K_M) 4k | 282.3 tok/s · pass |
| Qwen3.6 optimize — Qwythos-9B (Q4_K_M) 32k | 241.83 tok/s · pass |
| regressions | regression-qwen36-128, regression-qwen36-512, regression-qwen36-4k, regression-qwen36-16k, regression-qwen36-32k |
No context cleared the 2% significance gate while at least one context regressed. Auto-closing this PR.
RTX 5090 (sm_120) · 128/512/4k/16k/32k guarded · scored vs same-box main · strongest context scores · built from source · correctness vs llama.cpp. Automated — not merged; merge manually after review.
Closed: no activity for 2+ daysThis PR has had no updates (commits, comments, reviews, or label changes) for 2 days (threshold: 2 days). Reopen this PR or open a fresh one when you're ready to continue. |
Summary
The Qwen3.6-35B-A3B MoE FFN stage still reads its shared-expert projections at Q8_0 and its routed-expert down projection at Q5_K. Decode is memory-bandwidth bound, so these wide reads sit on the critical path every token. This PR:
shared_gate_up_q4k_mmvq+shared_down_q4k_mmvq) inkernels/csrc/cuda/moe/expert_ffn_q4k.cu, mirroring the existing Q8 MMVQ path but usingsi_vec_dot_q4_KDP4A + shared-memory reduction, exposed vialaunch_shared_expert_q4k_mmvq.dev_quant_requant_q4k(extended to accept Q5_K as a source).Net effect: less bytes/token moved in the FFN stage → higher decode tok/s. The path is gated to the Qwen3.6 UD fingerprint and toggleable (
SPARKINFER_SHEXP_REQUANT_Q4K,SPARKINFER_ROUTED_DOWN_REQUANT_Q4K); other models (e.g. Qwythos-9B) are untouched.Proof of speedup
Tested on RTX 5090 (sm_120)
Decode tok/s (end-to-end, from
bench/scripts/bench.sh— required for evaluation):Gain is consistent (+3.1–3.8%) across every context on Qwen3.6, clears the 2% significance gate, and the Qwythos guard is flat (within run-to-run noise), confirming the gate is correctly scoped.
Correctness
Q4_K requantization is lossy, so I verified top-1 agreement of the next-token argmax between the baseline (Q8_0/Q5_K) and this PR (Q4_K) over a fixed prompt set: ~95–96% top-1 agreement, above the 90% gate. The shared-expert and routed-down projections are the least sensitive FFN tensors to 4-bit requant, and the measured agreement confirms no meaningful quality regression.
Scope
Changes are confined to the contribution scope (
kernels/,runtime/,moe/):Test plan
bench/scripts/bench.shA/B, before=main/ after=this PR, Qwen3.6-35B: +3.1–3.8% across ctx 4096–32768