[PR #3809] [CLOSED] [Engine] opt-in fused int8 prefill for the native Q2_0 pack on sm_80+ (STRATA_PF_FUSED_Q2N=1) #4790

Closed
opened 2026-11-07 15:39:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • b213423 prefill: 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=1 sets 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 auto pick 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.

This reuses the Q2_0 gate/up implementation added in #2145. The maintainer's port note records that with STRATA_PF_FUSED=1 an 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 and STRATA_PF_FUSED=1 paths 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=0 and STRATA_PF_FUSED_NATIVE=0 still 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: a76ab44b on 011c9e60 (v0.2.2); rebased as b2134238 on main 4b9e05a2 (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=0 in every arm.

The A/B and KL runs used an earlier build of this change, 24c86452; a build with the submitted src/ 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:

  • Kernel: 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).
  • Unset: against v0.2.2, first-token logits byte-identical on 40 fresh prompts (38 distinct, 1-5K tokens, prompt cache off); prompt tok/s within 1% at 4K / 16K / 23K over five interleaved rounds.
  • Speed: two fresh prompts per size per start, the server's 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 4864 in 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 5632 is cut to 2,816 to fit the expert cache.
  • Quality: first-token KL against the FP16 prompt path (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.
  • Switches: ctest -R prefill_fused_iq_test passes both entries (57.8 s / 9.2 s). The new entry runs with the switch alone; without it the test refuses the pair. Under STRATA_EMULATE_CC=75 STRATA_PF_FUSED_SM75=1 the new entry skips (77). The engine logs the fused path with the switch alone and not with STRATA_PF_FUSED=0 added.
  • Builds: CUDA sm_120 (engine, test); HIP gfx1201 with -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)
prompt tokens unset, auto 4,864 set, auto 5,632 unset, fixed 4,864 set, fixed 4,864 set, fixed 5,632
4K ~4,270 2,444 / 2,595 2,479 / 2,655 2,454 / 2,603 2,502 / 2,668 2,494 / 2,666
16K ~15,870 2,592 / 2,602 3,438 / 3,438 2,593 / 2,591 2,674 / 2,673 3,438 / 3,444
23K ~22,910 2,972 / 2,973 3,382 / 3,388 2,970 / 2,969 3,072 / 3,070 3,384 / 3,380

Failed: one extra run of the kernel test under STRATA_EMULATE_CC=86 on 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

  • One card and one pack, with the experts streamed from RAM. Other GPUs or configurations may be slower; the switch does not benchmark fused against MMQ before enabling it. No default change is proposed.
  • With the default streaming threshold, chunks below 1,024 tokens do not take the fused path. The short-prompt probes were variable (x1.03 / x0.78 / x0.99 medians over five rounds); no short-prompt gain is claimed.
  • Decode was too variable for a conclusion. Decode kernels and dispatch are unchanged.
  • On a layer split with 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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3809 **Author:** [@chaog992](https://github.com/chaog992) **Created:** 10/23/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pf-fused-q2n` --- ### 📝 Commits (1) - [`b213423`](https://github.com/Niko1221/Strata/commit/b2134238d62432eaeda27df6d2104d4f35a4cbfa) prefill: 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) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 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=1` sets 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 auto` pick 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](https://github.com/Niko1221/Strata/pull/2145#issuecomment-6231112457) records that with `STRATA_PF_FUSED=1` an 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 and `STRATA_PF_FUSED=1` paths 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=0` and `STRATA_PF_FUSED_NATIVE=0` still 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: `a76ab44b` on `011c9e60` (v0.2.2); rebased as `b2134238` on main `4b9e05a2` (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=0` in every arm. The A/B and KL runs used an earlier build of this change, `24c86452`; a build with the submitted `src/` gives the same first-token logits byte for byte, set and unset (40/40 files). The [validation bundle](https://github.com/chaog992/Strata/tree/cf6930e087c935aba678817661e47fba1de01f7e) 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:** - Kernel: `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). - Unset: against v0.2.2, first-token logits byte-identical on 40 fresh prompts (38 distinct, 1-5K tokens, prompt cache off); prompt tok/s within 1% at 4K / 16K / 23K over five interleaved rounds. - Speed: two fresh prompts per size per start, the server's `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 4864` in 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 5632` is cut to 2,816 to fit the expert cache. - Quality: first-token KL against the FP16 prompt path (`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. - Switches: `ctest -R prefill_fused_iq_test` passes both entries (57.8 s / 9.2 s). The new entry runs with the switch alone; without it the test refuses the pair. Under `STRATA_EMULATE_CC=75 STRATA_PF_FUSED_SM75=1` the new entry skips (77). The engine logs the fused path with the switch alone and not with `STRATA_PF_FUSED=0` added. - Builds: CUDA sm_120 (engine, test); HIP gfx1201 with `-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. <details> <summary>Median prompt tok/s per arm (two probes per size)</summary> | prompt | tokens | unset, auto 4,864 | set, auto 5,632 | unset, fixed 4,864 | set, fixed 4,864 | set, fixed 5,632 | |---|---:|---:|---:|---:|---:|---:| | 4K | ~4,270 | 2,444 / 2,595 | 2,479 / 2,655 | 2,454 / 2,603 | 2,502 / 2,668 | 2,494 / 2,666 | | 16K | ~15,870 | 2,592 / 2,602 | 3,438 / 3,438 | 2,593 / 2,591 | 2,674 / 2,673 | 3,438 / 3,444 | | 23K | ~22,910 | 2,972 / 2,973 | 3,382 / 3,388 | 2,970 / 2,969 | 3,072 / 3,070 | 3,384 / 3,380 | </details> **Failed:** one extra run of the kernel test under `STRATA_EMULATE_CC=86` on 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 - One card and one pack, with the experts streamed from RAM. Other GPUs or configurations may be slower; the switch does not benchmark fused against MMQ before enabling it. No default change is proposed. - With the default streaming threshold, chunks below 1,024 tokens do not take the fused path. The short-prompt probes were variable (x1.03 / x0.78 / x0.99 medians over five rounds); no short-prompt gain is claimed. - Decode was too variable for a conclusion. Decode kernels and dispatch are unchanged. - On a layer split with `STRATA_PREFILL_HELP=1`, a layer the switch covers makes the prompt helper not bind (`bind_stage_helper`; unconfirmed static analysis, not run). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:39:05 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4790
No description provided.