mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1368] [CLOSED] prefill: quantize each token's MoE input once and scatter it to its k rows (the same bytes) #3411
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3411
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1368
Author: @sergqwer
Created: 10/7/2026
Status: ❌ Closed
Base:
main← Head:pr/mmq-scatter📝 Commits (1)
d270599prefill: quantize each token's MoE input once and scatter it to its k rows (the same bytes)📊 Changes
5 files changed (+179 additions, -2 deletions)
View changed files
📝
CMakeLists.txt(+6 -0)📝
include/strata/prefill/moe_mmq.hpp(+6 -0)📝
src/prefill/moe_mmq.cu(+13 -0)📝
src/prefill/prefill.cpp(+4 -2)➕
tests/cuda/prefill_mmq_scatter_test.cpp(+150 -0)📄 Description
The prompt path quantizes a layer's MoE input to q8_1 in expert order:
mmq::quantize(m.mixed, m.src_dev, ...)runs over T x K rows (K = 10), so every token's row ofmixedis read and quantized ten times, once per expert. llama.cpp'squantize_scatter_mmq_q8_1_cuda(in the pinnedquantize.cu, which strata_mmq already compiles) quantizes each token once and writes the block to all of the token's rows through the inverse map. Prefill already builds that map asslot_dev: token t's k-th row isslot[t * K + k], the inverse ofsrc_dev.This adds
mmq::quantize_scatter(x, slot, src, ...)and uses it at that call site. The q8_1 bytes are the same, so it is the default.STRATA_QUANT_GATHER=1keeps the per-row gather. The peer and down-projection quantizations are unchanged. It adds no device code, so the CUDA and HIP builds compile the same kernels as before; the SYCL port has its ownprefill.cppand is untouched.Identity
prefill_mmq_scatter_test(new ctest). It compares scatter against the gather on the whole output buffer, for every q8_1 layout MMQ uses: D4 (Q2_0, Q8_0, IQ2_XS), DS4 (Q4_1) and D2S6 (Q2_K). T = 1, 2, 7, 600 and 2099, routing built as Prefill builds it (10 of 512 experts), one all-zero token. All 25 cases: 0 differing bytes.e8ca9afd. Tested with IQ2_XS at 600 tokens, 2K and 32K, and Q2_0 at 2K, all with a fixed cache. The first-token logits are identical bytes and the 32 greedy tokens are the same.prefill_fused_moe_test,prefill_fused_iq_testandquantize_act_paritypass.Measured
RTX 5090 (96 MB L2) + Ryzen 9 9950X3D.
The quantizer alone (
prefill_mmq_scatter_test --bench, median of 20):Both versions write the same T x K q8_1 rows. The gather also reads each input row K times. When the chunk's input fits in L2, as with an 8K chunk (84 MB) on this card, those re-reads are cheap and the two are even. When it does not, the gather goes back to DRAM for them.
In the engine (IQ2_XS, a 32K prompt, nsys, the quantizer kernels' total):
--prefill auto:32768That is ~0.4% of a 4.6 s prompt. The whole-prompt times (3 interleaved pairs at 600, 2K and 32K) were within the run-to-run noise.
On this card the gain only shows with large chunks. On cards with less L2 even an 8K chunk's input does not fit: a 5070 has 48 MB, a 3090 6 MB. I could not measure those cards here.
🤖 Generated with Claude Code
https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.