mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3809] [CLOSED] [Engine] opt-in fused int8 prefill for the native Q2_0 pack on sm_80+ (STRATA_PF_FUSED_Q2N=1) #4790
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#4790
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/3809
Author: @chaog992
Created: 10/23/2026
Status: ❌ Closed
Base:
main← Head:pf-fused-q2n📝 Commits (1)
b213423prefill: STRATA_PF_FUSED_Q2N=1 (opt-in): the native Q2_0 pack's Q2_0 / Q2_0 layers on the fused int8 kernels on sm_80+📊 Changes
4 files changed (+36 additions, -8 deletions)
View changed files
📝
CMakeLists.txt(+4 -0)📝
docs/DETAILS.md(+3 -1)📝
src/prefill/moe_fused_iq.cu(+11 -2)📝
tests/cuda/prefill_fused_iq_test.cpp(+18 -5)📄 Description
Problem and result
On a PC whose CPU lacks the AVX-512 set that setup checks for, setup makes the native Q2_0 pack. On a CUDA card of sm_80 or newer its Q2_0 / Q2_0 prompt experts run through MMQ, although the fused int8 kernel for that format is in the binary.
STRATA_PF_FUSED_Q2N=1sets that kernel up and takes it for the Q2_0 / Q2_0 layers on sm_80+ where the fused path's existing conditions hold. Unset, dispatch and output are as before. Set, the prompt arithmetic changes and the generated text can change.On the tested RTX 5080 configuration (2,100 experts in VRAM), prompts of 4K, 16K and 23K tokens read 2-3.5% faster at the same chunk. The fused path's smaller buffers also let
--prefill autopick a 5,632-token chunk instead of 4,864: with that, a 16K prompt reads 32-33% faster, a 23K prompt 14%, a 4K prompt 0-2%. These are whole-engine numbers, including the ring and buffer changes.Related discussion
This reuses the Q2_0 gate/up implementation added in #2145. The maintainer's port note records that with
STRATA_PF_FUSED=1an RTX A4000 stopped matching the old output and read 4K prompts 4.5% slower, so that coverage was limited to the Turing opt-in. This PR proposes a separate opt-in and keeps the default andSTRATA_PF_FUSED=1paths as they are, which is the condition the port note set; it does not explain or re-measure the A4000 result. If you would rather gate it to the card class measured here (sm_120), that is a one-line change.Approach
With the new switch on sm_80+, the Q2_0 gate/up kernel is set up alongside the IQ formats' and the Q2_0 / Q2_0 pair takes the fused path when the engine's existing conditions permit;
STRATA_PF_FUSED=0andSTRATA_PF_FUSED_NATIVE=0still turn it off. A failed setup keeps the previous occupancy and the MMQ path (from reading the code; the failure was not induced). Engine dispatch for HIP, Turing and the canonical (AVX-512) Q2_0 pack is unchanged.A second ctest entry runs the kernel test's Q2_0 / Q2_0 pair with the switch alone, through a new test flag,
--unset-pf-fused; it skips below sm_80. DETAILS.md documents the switch.Validation
Tested:
a76ab44bon011c9e60(v0.2.2); rebased asb2134238on main4b9e05a2(docs/DETAILS.md only;src/and the test are identical to a76ab44b). Linux, RTX 5080 16 GB (sm_120), i9-14900K, 125 GiB, driver 595.84; builds nvidia/cuda:13.0.0-devel, nvcc 13.0.48, sm_120; Docker, 16 threads, 96 GiB. Qwen3.8-Flash-Next GSQ-RCO native Q2_0, 32K context, int8 KV,--expert-cache 2100 --adapt-every 100000 --pool-workers 15 --vram-reserve-mib 4096,STRATA_PREFILL_CPU_SHARE=0in every arm.The A/B and KL runs used an earlier build of this change,
24c86452; a build with the submittedsrc/gives the same first-token logits byte for byte, set and unset (40/40 files). The validation bundle has the exact commands and config, the raw rows, the logs and the revision provenance; its README maps each step script to its numbers. The branch merges onto today's main (after 0.2.3) without conflict; the open #3779 touches the same file and is independent of this change.Passed:
STRATA_PF_FUSED_Q2N=1 prefill_fused_iq_test "--only=Q2_0 / Q2_0" --unset-pf-fused --chunks=2048,4864,8192. Parity passed; one layer (512 experts, top 10) at 2,048 / 4,864 / 8,192 tokens: 1.92x / 1.37x / 1.30x the MMQ path, with the same relative RMS against the FP32 reference on the test's 96 sampled token/expert pairs per chunk (1.717e-2 / 1.533e-2 / 2.711e-2).timings.prompt_per_second. Auto chunk, five rounds: 16K and 23K faster in 5/5 rounds per probe, 4K in 3/5 and 5/5. Fixed--prefill 4864in both arms, four rounds: faster in 4/4 at every size. Random prefixes vary the lengths by a few tokens; tok/s is per actual token. Unset,--prefill 5632is cut to 2,816 to fit the expert cache.STRATA_PREFILL_MMQ=0), cache off, 30 prompts of 1.5-4.6K tokens assembled from the quant-quality set's segments (not independent documents). Fused / MMQ: mean 0.0110 / 0.0112, median 0.0058 / 0.0038, worst 0.061 / 0.090, top-1 agreement with FP16 28/30 / 29/30. The 1K prompts (no fused run) and the 5K ones (different chunking) are left out; over all 38 distinct prompts the means are 0.0100 / 0.0099. Generations were not compared.ctest -R prefill_fused_iq_testpasses both entries (57.8 s / 9.2 s). The new entry runs with the switch alone; without it the test refuses the pair. UnderSTRATA_EMULATE_CC=75 STRATA_PF_FUSED_SM75=1the new entry skips (77). The engine logs the fused path with the switch alone and not withSTRATA_PF_FUSED=0added.-DSTRATA_PREFILL_MMQ=ON(engine,hip_prefill_fused_iq). Both ctest entries skip (77) on a box without a card; no HIP card was run.Median prompt tok/s per arm (two probes per size)
Failed: one extra run of the kernel test under
STRATA_EMULATE_CC=86on this sm_120-only build stopped with an illegal memory access in its MMQ reference part, before the fused kernel ran. Code inspection suggests a build/emulation mismatch (the emulation hands MMQ an 8.6 card's configuration while the kernels are sm_120-only); that explanation is unconfirmed static analysis. The log is in the bundle.Not run: other CUDA cards; multi-GPU and layer-split configurations; a Turing card (the skip was checked by emulation only); a card that holds every expert; Windows; the CPU prompt share at its default; teacher-forced KL and task-level quality tests. SYCL and Metal do not compile this file (their own stubs).
Limits
STRATA_PREFILL_HELP=1, a layer the switch covers makes the prompt helper not bind (bind_stage_helper; unconfirmed static analysis, not run).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.