[PR #4039] [Engine] opt-in smaller prompt scratch (STRATA_PF_GROUP_SCRATCH, STRATA_PF_HC_REGION): bigger --prefill auto chunks, bitwise, 8 GB cards +18-24% prompt #4885

Open
opened 2026-11-07 16:31:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4039
Author: @merbanan
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: pr/prefill-group-scratch


📝 Commits (3)

  • b824998 prefill: STRATA_PF_GROUP_SCRATCH=1, the MMQ path's GU / H / Hq hold one expert group's rows (opt-in, bitwise)
  • 37a7feb prefill: STRATA_PF_HC_REGION=1, the hyper-connection read's scratch in the shared region (opt-in, bitwise)
  • c4dd0af docs: STRATA_PF_GROUP_SCRATCH and STRATA_PF_HC_REGION in DETAILS.md

📊 Changes

2 files changed (+164 additions, -13 deletions)

View changed files

📝 docs/DETAILS.md (+6 -0)
📝 src/prefill/prefill.cpp (+158 -13)

📄 Description

Problem and result

A streamed prompt chunk sends every non-resident expert over PCIe once, so on a card where the experts don't fit, the chunk size sets how often an expert crosses the link per prompt token. --prefill auto caps the chunk by the prompt path's buffers, which live in the cache slots it borrows. On an 8 GB card that cap is what limits prefill.

Two of those buffers are larger than they need to be:

  • the MMQ path's gate/up output, its SwiGLU output and its q8_1 copy are sized for the whole chunk (T*K rows, ~84 KB a token), although a group's products read them and are done before the next group starts;
  • the hyper-connection read's scratch (xn16, lo, lo16, gated, the BF16x2 low halves) sits outside the region the attention and MoE halves already share.

With both switches on, --prefill auto picks a bigger chunk and prompts read faster; the answers are the same bytes.

Approach

Both are opt-in and off by default:

  • STRATA_PF_GROUP_SCRATCH=1: GU / H / Hq hold one expert group's rows. The cap is T (one expert's most) plus three times a group's average; a group past it runs as sub-ranges of its experts, each with its own relative bounds appended to the bounds table. Only taken when every layer runs MMQ (no fused experts, no FP16 fallback); a layer that would take another path stops the prompt with a message instead of overrunning the smaller buffers. STRATA_PF_GROUP_CAP=<rows> forces a smaller cap (test knob).
  • STRATA_PF_HC_REGION=1: the hyper-connection scratch is a fourth set of the shared region. A half's read is done with it before that half's set is written, and the fused write at a half's end runs after the half's last region reader on the same stream. Same kernels on the same values. Off with the unfused hyper-connection path.

bytes_needed counts the same carve, including GROUP_SCRATCH's larger bounds table. Documented in docs/DETAILS.md.

Validation

Environment: RTX 2060 SUPER 8 GB (sm_75), Ryzen 9 3900X, 92 GB RAM, Linux 7.0, CUDA build with gcc-13 (-DCMAKE_CUDA_ARCHITECTURES=75 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_BUILD_TESTS=ON), Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS native pack, --kv k8v4 --spec 3 --mtp ... --expert-cache auto --prefill auto --max-context 131072. Baseline: main 7dd5cf18, built and run the same way.

Passed:

  • Default path byte-identical: with the switches off, six greedy probes (two file edits, a 142-line rename, needle recalls at 10K / 30K / 60K) give the same output bytes as main.
  • Switches on: the same six outputs, byte-identical to main (2 loads).
  • Speed (benchmark at 4K / 16K / 32K, tokens/s), 2 loads each, main vs both switches on:
    • --prefill auto chunk: 3840 -> 5888 tokens
    • prompt: main 336 / 370 / 380 and 336 / 371 / 380; this 395 / 461 / 460 and 395 / 460 / 460 -> +18% / +24% / +21%
    • decode: main 25.9 / 26.5 / 27.9 and 25.0 / 29.1 / 27.0; this 25.6 / 28.0 / 27.0 and 25.5 / 27.9 / 26.7 (unchanged within noise)
    • probes: big-rename prompt 333 -> 440, needle 10K prompt 377 -> 460
  • Built and ran on this branch: draft_policy_test, verify_parity, spec_verify_parity (0 mismatches), verify_batch_parity, prefill_plan_test, prefill_mmq_scatter_test (0 failures); the same as main.

Failed: none observed.

Not run:

  • HIP and SYCL builds (no such toolchain here). The change is in src/prefill/prefill.cpp, which they compile.
  • Other GPUs. A Tesla T4 run was not usable as evidence: that box had a host-RAM fault at the time.

Limits

GROUP_SCRATCH only applies when every layer takes MMQ, so it is a no-op with the fused prompt experts. The gain is largest where the prompt chunk is VRAM-bound (8 GB cards streaming experts); on a card where the chunk is already large, expect little.


🔄 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/4039 **Author:** [@merbanan](https://github.com/merbanan) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/prefill-group-scratch` --- ### 📝 Commits (3) - [`b824998`](https://github.com/Niko1221/Strata/commit/b824998c7e0b76267b3ebc8e2dad4501db446a21) prefill: STRATA_PF_GROUP_SCRATCH=1, the MMQ path's GU / H / Hq hold one expert group's rows (opt-in, bitwise) - [`37a7feb`](https://github.com/Niko1221/Strata/commit/37a7feb83a7584f41e70f1073a2965d8b750db25) prefill: STRATA_PF_HC_REGION=1, the hyper-connection read's scratch in the shared region (opt-in, bitwise) - [`c4dd0af`](https://github.com/Niko1221/Strata/commit/c4dd0af3cb78cf8bc4c33df5ed279de5578168d6) docs: STRATA_PF_GROUP_SCRATCH and STRATA_PF_HC_REGION in DETAILS.md ### 📊 Changes **2 files changed** (+164 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+6 -0) 📝 `src/prefill/prefill.cpp` (+158 -13) </details> ### 📄 Description ## Problem and result A streamed prompt chunk sends every non-resident expert over PCIe once, so on a card where the experts don't fit, the chunk size sets how often an expert crosses the link per prompt token. `--prefill auto` caps the chunk by the prompt path's buffers, which live in the cache slots it borrows. On an 8 GB card that cap is what limits prefill. Two of those buffers are larger than they need to be: - the MMQ path's gate/up output, its SwiGLU output and its q8_1 copy are sized for the whole chunk (T*K rows, ~84 KB a token), although a group's products read them and are done before the next group starts; - the hyper-connection read's scratch (xn16, lo, lo16, gated, the BF16x2 low halves) sits outside the region the attention and MoE halves already share. With both switches on, `--prefill auto` picks a bigger chunk and prompts read faster; the answers are the same bytes. ## Approach Both are opt-in and off by default: - `STRATA_PF_GROUP_SCRATCH=1`: GU / H / Hq hold one expert group's rows. The cap is T (one expert's most) plus three times a group's average; a group past it runs as sub-ranges of its experts, each with its own relative bounds appended to the bounds table. Only taken when every layer runs MMQ (no fused experts, no FP16 fallback); a layer that would take another path stops the prompt with a message instead of overrunning the smaller buffers. `STRATA_PF_GROUP_CAP=<rows>` forces a smaller cap (test knob). - `STRATA_PF_HC_REGION=1`: the hyper-connection scratch is a fourth set of the shared region. A half's read is done with it before that half's set is written, and the fused write at a half's end runs after the half's last region reader on the same stream. Same kernels on the same values. Off with the unfused hyper-connection path. `bytes_needed` counts the same carve, including GROUP_SCRATCH's larger bounds table. Documented in docs/DETAILS.md. ## Validation Environment: RTX 2060 SUPER 8 GB (sm_75), Ryzen 9 3900X, 92 GB RAM, Linux 7.0, CUDA build with gcc-13 (`-DCMAKE_CUDA_ARCHITECTURES=75 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_BUILD_TESTS=ON`), Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS native pack, `--kv k8v4 --spec 3 --mtp ... --expert-cache auto --prefill auto --max-context 131072`. Baseline: main 7dd5cf18, built and run the same way. Passed: - Default path byte-identical: with the switches off, six greedy probes (two file edits, a 142-line rename, needle recalls at 10K / 30K / 60K) give the same output bytes as main. - Switches on: the same six outputs, byte-identical to main (2 loads). - Speed (benchmark at 4K / 16K / 32K, tokens/s), 2 loads each, main vs both switches on: - `--prefill auto` chunk: 3840 -> 5888 tokens - prompt: main 336 / 370 / 380 and 336 / 371 / 380; this 395 / 461 / 460 and 395 / 460 / 460 -> +18% / +24% / +21% - decode: main 25.9 / 26.5 / 27.9 and 25.0 / 29.1 / 27.0; this 25.6 / 28.0 / 27.0 and 25.5 / 27.9 / 26.7 (unchanged within noise) - probes: big-rename prompt 333 -> 440, needle 10K prompt 377 -> 460 - Built and ran on this branch: draft_policy_test, verify_parity, spec_verify_parity (0 mismatches), verify_batch_parity, prefill_plan_test, prefill_mmq_scatter_test (0 failures); the same as main. Failed: none observed. Not run: - HIP and SYCL builds (no such toolchain here). The change is in src/prefill/prefill.cpp, which they compile. - Other GPUs. A Tesla T4 run was not usable as evidence: that box had a host-RAM fault at the time. ## Limits GROUP_SCRATCH only applies when every layer takes MMQ, so it is a no-op with the fused prompt experts. The gain is largest where the prompt chunk is VRAM-bound (8 GB cards streaming experts); on a card where the chunk is already large, expect little. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4885
No description provided.