mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3752] [CLOSED] [Engine] GP100 prompt path: a fully resident layer's experts weight-stationary, one launch per product (STRATA_MMQ_WS=1, opt-in) #4767
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#4767
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/3752
Author: @ruibeikaa
Created: 10/22/2026
Status: ❌ Closed
Base:
main← Head:prefill-ws-gp100📝 Commits (4)
d6c39c8prefill: mmq::swiglu_quant, swiglu and the down product's q8_1 rows in one kernel (SM60 build, no caller yet)8ee1189prefill: weight-stationary expert kernels for GP100 (moe_ws: one launch per layer and product; not used yet)cd198d0prefill: a resident layer's experts weight-stationary, one launch per product (STRATA_MMQ_WS=1, GP100)477b5f8moe_ws: STRATA_WS_FAST=1 - the IQ4_NL down's 32-token tier with fewer instructions per pass (opt-in, same bits)📊 Changes
12 files changed (+2597 additions, -2 deletions)
View changed files
📝
CMakeLists.txt(+20 -0)📝
include/strata/prefill/moe_mmq.hpp(+5 -0)➕
include/strata/prefill/moe_ws.hpp(+70 -0)📝
src/prefill/moe_mmq.cu(+70 -0)➕
src/prefill/moe_ws.cu(+157 -0)➕
src/prefill/moe_ws.cuh(+49 -0)➕
src/prefill/moe_ws_down.cu(+645 -0)➕
src/prefill/moe_ws_down_bench.cu(+270 -0)➕
src/prefill/moe_ws_gu_iq2.cu(+736 -0)➕
src/prefill/moe_ws_gu_iq3.cu(+370 -0)📝
src/prefill/prefill.cpp(+111 -2)➕
tests/cuda/prefill_swiglu_quant_test.cpp(+94 -0)📄 Description
Problem and result
On a GP100 die (compute capability 6.0: 732 GB/s HBM2, no
__dp4a, no tensor cores) the prompt pass's routed experts run as MMQ launches per 16-expert group: a gate/up, a swiglu, a quantize and a down launch per group, each group's experts gathered and padded to the group's largest row count, and every MMQ tile decoding its weight blocks again. With every expert resident in VRAM, that per-group overhead rather than the weight bytes is a large share of a prompt read on this card: avoiding it removes about a third of the read time below.With
STRATA_MMQ_WS=1, a layer whose routed experts are all resident on this GPU runsquantize_scatter-> gate/up as one weight-stationary launch over all its experts, read where they lie in the expert cache -> oneswiglu_quantover all its rows -> down as one launch, instead of the per-group launches. On four GP100 dies with every expert resident, prompt reading drops by 31-37% (240 tokens 2,156 -> 1,364 ms, 1.15K 4,210 -> 2,760 ms, a fresh 26K read 41,231 -> 28,555 ms, a 1.1K append to a 26K conversation 4,873 -> 3,257 ms; one run per arm, details below); decode is unchanged. The products keep MMQ's int8 values, scales and epilogue order, so GU, H and the down rows are MMQ's bits: every reply and every engine state hash stays the same. Unset (the default), nothing is allocated and every launch is the one before.Related discussion
This is the prompt-path counterpart of the GP100 decode work in #3455 (scope issue #3454): that PR keeps the prompt path's MMQ gather unchanged; this one replaces the gather and per-group launches for fully resident layers. The two are independent: this branch is main plus three commits and does not need #3455. If #3455 is merged first, its 4-bit gate/up layers must be excluded from this path (one condition, since their slots no longer hold GGUF blocks) or served by a 4-bit variant of the weight-stationary gate/up, which I have measured and will send as a follow-up once both are in. The scope is the same as #3454's (opt-in, GP100 only, default path byte-identical); I am happy to open a separate scope issue if you prefer.
Approach
mmq::swiglu_quant): swiglu and the down product's q8_1 rows in one kernel, byte for byteswiglu+quantize's output, with a test (prefill_swiglu_quant_test, underSTRATA_BUILD_TESTS). It is a partial port of another contributor's prompt-path fusion change (kept under their name): only this kernel, no caller of its own. Built only in theSTRATA_EXPERIMENTAL_SM60CUDA build.moe_ws, kernels only): newsrc/prefill/moe_ws.{hpp,cu,cuh},moe_ws_down.cu,moe_ws_gu_iq2.cu,moe_ws_gu_iq3.cu. A CTA is 128 (or 256) weight rows of one expert against up to 64 of that expert's activation rows, a thread per weight row: each weight block is decoded once per pass instead of once per MMQ tile, and each expert runs its own row count. Gate/up for IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S; down for Q2_0 and IQ4_NL. Every product keeps MMQ's int8 values, scales and per-32-value epilogue in its K order (a 32-value block's integer sum is exact, so only the float epilogue's order matters).ws::fastercarries the measured ws / per-group MMQ time ratios per format (one GP100 die) and picks a layer only where both products are faster at its rows per routed expert. They need only ggml'scommon.cuh/mmq.cuhat the pinned commit.prefill.cpp): the per-layer decision afterquantize_scatter: all routed experts resident, this GPU alone (no peer or CPU share, no streamed entries of the layer), not the fused layout, not aSTRATA_MMQ_DIRECTlayer, no Hadamard, no NVFP4 tail, no FP4 activations, aligned. The layer's expert offsets from the cache's base and the CTAs' chunk table go up with the group bounds (in the mapped table, or through the pinned upload ring). Every other layer keeps its path.ws::mode()is 1 only withSTRATA_MMQ_WS=1and every visible GPU at compute capability 6.0.STRATA_PREFILL_WSis defined only in theSTRATA_EXPERIMENTAL_SM60CUDA build (not under HIP); elsewhere a stub says mode 0. The offset and chunk buffers (under 1 MiB per die) are allocated only when the mode is not 0, so unset, the arena layout and the mapped table are the ones before.Validation
Environment note: everything below was measured with every expert resident in VRAM on four GP100 dies (two PH402 SKU 200 boards, 32 GB HBM2 per die; the Swift 1.5 IQ3_S pack fits whole: no CPU share, no PCIe share, no adaptive tier). The path declines a layer that is not fully resident, so a single 16 GB P100 that keeps experts in RAM takes the per-group MMQ as before; that setup was not measured. HIP, SYCL and Metal were not built.
Rig: four GP100 dies (application clocks 715 MHz memory / 1050 MHz graphics, 140 W cap), Windows 11, driver 581.80 (TCC), CUDA 12.9, VS 2022. Build:
-DSTRATA_EXPERIMENTAL_SM60=ON -DCMAKE_CUDA_ARCHITECTURES=60, ggml at the pinned 3cf03257f, unpatched. Model: Swift 1.5 IQ3_S (abliterated GSQ-RCO GGUF, dense matrices in Q8_0). Engine arguments, the same on every arm:--serve --expert-cache auto --prefill auto --spec 4 --spec-min-p 0.85 --mtp <drafter> --max-context 1048576 --kv int8 --layer-split 12,24,36 --mtp-window 8192 --pipeline-windows 2 --conversation-cache-mib 32768 --conversation-cache-slots 8 --rope-scaling yarn --rope-scale 4. Environment, the same on every arm:STRATA_Q8_SM60=1 STRATA_STAGE_TRIM=1 STRATA_PREFILL_PIPE=70 STRATA_MMQ_RESIDENT_SORT_NE=1 STRATA_DF_BRANCH=1 STRATA_FUSE_DECODE=1 STRATA_FUSE_WAIT=2 STRATA_SIDE_MIXER=2 STRATA_GR_UP75=1 STRATA_B6_MMVQ_ROWS=1 STRATA_ADAPT_LAG=2 STRATA_ADAPT_NOWAIT=1 STRATA_DECODE_TIMING=1 STRATA_STATE_HASH=1.STRATA_MMQ_WSwas the only difference between the two branch arms.Passed:
011c9e60(engine 0.1.47) unchanged, X0 = this branch with the switch unset, X1 = this branch withSTRATA_MMQ_WS=1. Ten requests per arm: five short prompts (400-512 tokens out), a fresh 26K-token read + 400 out, prompt reads of 240 and 1.15K tokens (16 out), a 26K-token conversation and a 1.1K append to it (16 out). Prompt chunks were the same in every arm (512 below 1.2K tokens, 768 above).STRATA_STATE_HASHitem (GDN, PLE, tail, pooled, KV, MTP) equal on all ten requests. X1's log hasa resident layer's experts weight-stationary, one launch per product (STRATA_MMQ_WS=1); X0's does not.e88ee39d(engine 0.1.45.3), as one arm of a stack of other opt-in GP100 changes that were already on in the arm before it (#3455 with 47 of 48 layers in 4-bit slots, served by a 4-bit variant of the weight-stationary gate/up that is not in this PR;--pipeline-windows 3; a 256-token prompt chunk floor; fused prompt-path swiglu + quantize and combine + write; changes of mine not posted yet), turning the weight-stationary path on took prompt reads 240 tokens 2,847 -> 2,084 ms, 1.15K 3,857 -> 2,163, 7.7K 15,283 -> 9,587, 33K 49,687 -> 34,139, a fresh 26K 41,932 -> 27,810, an 88K append 125,258 -> 91,682 ms, with every reply hash and state item equal to the arm before on 15 requests including a 250K-token read. Those numbers depend on that configuration and are not this PR's claim.STRATA_EXPERIMENTAL_SM60=ON(strata) and sm_86 without it (strata), both on this branch, both clean. In the sm_86 build none of the new kernels is compiled.Failed: none observed.
Not run: HIP, SYCL and Metal builds (no such machine here; the new code is under the
STRATA_EXPERIMENTAL_SM60CUDA-only guards). The PR is a draft for that reason: a HIP, SYCL or Metal build by someone who has one would close it.prefill_swiglu_quant_teston this branch (my builds hadSTRATA_BUILD_TESTS=OFF; the kernel is covered by the end-to-end hashes, since every weight-stationary layer goes through it). A layer-level parity tool for the weight-stationary kernels on this revision (it was done on an older 0.1.41-based tree, all 10 gate/up and down format pairs of the Swift pack at T = 128 / 512 / 1792 / 8192; here the evidence is the end-to-end reply and state hashes). Partial residency, peer or CPU shares (declined by condition). Packs other than Swift 1.5 IQ3_S. Cards other than GP100.Limits
STRATA_EXPERIMENTAL_SM60builds only.Addendum (2026-10-23): fewer instructions per pass in the IQ4_NL down's 32-token tier,
STRATA_WS_FAST=1(opt-in, default off)One more commit.
nl4::dn_kernel_fastinmoe_ws_down.cuis picked only withSTRATA_WS_FAST=1, for the IQ4_NL down's 256 x 32 tier (u >= 20 rows per routed expert, i.e. prompt chunks of about 1024 tokens and up). The weight-stationary kernels issue close to all of GP100's instruction slots, so their time follows the instruction count; two changes cut the per-pass overhead without touching any token's arithmetic: aswitchon the number of token pairs falls through the 16 unrolled pairs instead of a guard per pair and block, and dy is stored [block][token] so a pair's two dy are one 8-byte shared load (122 -> 102 registers, still two CTAs per SM). Every token's XMAD chains and epilogue are the default kernel's, so Dm is the same bytes. Below u 20, for the Q2_0 down and for every gate/up nothing changes. The commit also addsmoe_ws_down_bench(EXCLUDE_FROM_ALL, sm_60 build): a layer's 512 real down experts from the GGUF, lognormal and flat-32 routings,ws::downwith and without the switch compared byte for byte and timed.The gate/up variants I measured with the same ideas are written for #3455's 4-bit slots; this branch's GGUF-layout gate/up kernels have no measured counterpart, so none is included.
Environment note: PH402 SKU 200 boards, four GP100 dies of 32 GB HBM2 each (128 GB in all), every expert resident in VRAM, no CPU share, no PCIe share. The single-die numbers below use one of those dies (715 / 1050 MHz).
Bitwise, one GP100 die, this branch:
moe_ws_down_bench <IQ3_S shard> --layers 0,2,1 --t 768,1024,1536,2048,4096 --models ln0.5,ln1.0,flat32 --reps 15withSTRATA_MMQ_WS=1: 45 checks, 0 failures (every Dm row memcmp-equal; layer 1 is a Q2_0 down, the default kernel either way, as a control).Timing, same run (IQ4_NL layer 0; layer 2 within 0.6% of it; median of 15 interleaved; ms per layer, default ->
STRATA_WS_FAST=1):(flat at T >= 2048 is capped at 512 experts x 32 rows.) The Q2_0 control is x0.998-1.001 everywhere.
Default off:
cuobjdumpofmoe_ws_down.cu,moe_ws_gu_iq2.cuandmoe_ws_gu_iq3.cu, sm_60 build: the 20 kernels this branch had before the commit have identical SASS after it;dn_kernel_fast<256, 32, 2, 2>is the only addition, and its SASS is identical to the build used in the end-to-end run below. The sm_86 build compiles none of the WS kernels and builds clean.End to end, four GP100 dies, not this branch's revision: engine 0.1.47 (main
011c9e60) plus 26 opt-in GP100 commits of mine (#3455's 4-bit slots, this PR with a 4-bit variant of its gate/up,--pipeline-windows 3and others),STRATA_MMQ_WS=1andSTRATA_SM60_TABLE=0in both arms, one fresh engine per arm:STRATA_WS_FAST=1took a fresh 26K read 27,555 -> 27,235 ms (-1.16%), a fresh 33K read 34,426 -> 34,028 ms (-1.16%) and an 88K-context 1.5K append 84,897 -> 84,113 ms (-0.92%); decode unchanged (-0.11%); every reply hash identical on 9 requests. That arm also ran faster 4-bit gate/up kernels for #3455's slots, which are not in this PR, so the down's own share of those numbers is smaller (on one die the two parts were of similar size). One run per arm.Not run: HIP, SYCL and Metal builds (no such machine here; the new code is inside the
STRATA_EXPERIMENTAL_SM60CUDA-only WS sources). An end-to-end run on this branch's own revision.CI note: the red
metal-linkcheck is not caused by this PR. The job fails while compiling upstream'smetal/src/mtl_rt.mm(lines 69 and 92:MTLGPUFamilyMetal4,MTLCompileOptions.mathMode,MTLMathModeFast/MTLMathModeSafe), which themacos-14runner's SDK does not provide. The workflow runs on any pull request that touchessrc/orinclude/; this PR changes no file undermetal/.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.