[PR #4380] [Engine] Prefill: cache the fused ring's layer check per CUDA device (layer split over unlike cards, refs #3577) #5030

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4380
Author: @moses-sun
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: fix/fused-ring-per-cuda-device


📝 Commits (1)

  • 5d5e380 Prefill: the fused ring's layer check is cached per CUDA device, so a layer split over unlike cards keeps MMQ's buffers where it must

📊 Changes

1 file changed (+17 additions, -5 deletions)

View changed files

📝 src/prefill/prefill.cpp (+17 -5)

📄 Description

Problem and result

On a --layer-split across cards that do not agree on the fused int8 prompt experts, every prefill chunk >=
stream_all_min() failed while short prompts still worked. Four-card rig (2x RTX 5080, 84 SMs; 2x RTX 5070 Ti, 70 SMs;
all sm_120), Qwen3.8-Flash-Next GSQ-RCO IQ3_S native pack, --layer-split 12,25,37, --max-context 524288, engine 0.1.51:

strata: prompt experts on the fused int8 kernels (STRATA_PF_FUSED=1, #136)
strata serve: prefill: the fused layout's MoE buffers are too small for layer 25's expert path at a chunk of 8192 tokens

The request is refused (HTTP 400) and prompts above about 2K tokens are unusable on that rig. With this commit, same pack,
same split, same flags on engine 0.1.52:

strata serve: prompt 29486 tokens = 0 reused + 29486 read in 8673 ms (3399.8 tok/s), 40 generated in 234 ms ...

and the string too small does not occur anywhere in the 24 hours of log around it.

#3577 reports the same error at chunk 8192 with IQ3_S on an RTX 5080 + RTX 3060 split. I do not have that rig and did not
reproduce it there; reading the path, the 3060 is sm_86, so its stage is the one without native_supported() and it would
hit the same cached decision. It is not marked as fixed here.

The rule this keeps is the one #546 / #958 / #583 established: the MoE buffers may only be shrunk when every layer that
will run in them can take the fused path. That rule is about the card, and the old check answered "which card is current
right now" only once.

Approach

fused_ring() decides whether fused_layout() shrinks the MoE buffers to the fused path's needs. It asked
fused::native_supported() for every layer's format and cached the answer in one function-local static const bool.
native_supported() is a per-device answer: on CUDA with STRATA_PF_FUSED unset it returns
d.ok && d.s120 && d.sms >= 80 && d_covered_on(...) from moe_fused_iq.cu's dev_info(), i.e. the card that is
current at that moment. On this rig the 5080s (84 SMs) take the fused kernels and the 5070 Tis (70 SMs) do not, so the
first call — on the 5080 stage — shrank the buffers for the whole split, and the 5070 Ti stages then ran MMQ at a full
chunk inside them. Layer 25 is the first layer of the first 5070 Ti stage, which is why that is the layer named in the
error.

The cache is now one entry per device (0 unknown, 1 every layer covered, 2 not), keyed on the caller's current
device, and read/written as std::atomic<int8_t> with relaxed ordering: the batch-slot threads read fused_ring() too,
and a lost race only recomputes the same per-device answer. A card that can take the fused path still gets the shrink and
its speed-up; a card that cannot keeps MMQ's full-size buffers. No new env var, no change to a homogeneous rig: every
device there answers what the single global used to.

Alternatives considered: the conservative "do not shrink unless every card in the split can take it" is simpler but
throws away the fused path on the 5080 stages of exactly the rigs that have the problem; a per-stage sizing pass would
have to reach the buffer ownership outside this file. If you prefer the conservative form, it is a smaller diff than this
one.

Validation

Passed:

  • Build of this branch on the four-card box, sm_120 only, CUDA 13.1, GCC 13.3:
    cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=120 -DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.1/bin/nvcc -DSTRATA_GGML_DIR=<llama.cpp checkout> -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON -DSTRATA_MMQ_TQ_OVERLAY=ON then cmake --build build --target strata -j48:
    the engine links, no warnings from src/prefill/prefill.cpp.
  • The change under load: the same logic with a plain int8_t cache (this branch minus the atomic, which is a relaxed
    load and store of the same two values) has served that rig since 2026-10-28 00:20 —
    2x 5080 + 2x 5070 Ti, IQ3_S native pack, --layer-split 12,25,37, 512K context, --batch 4 --batch-groups auto --batch-mtp --trim-stage-weights, STRATA_PIPED_MTP=1. Fresh reads of the path that used to fail: 29,486 tokens at
    3,399.8 tok/s, 29,484 at 3,246.1, 17,441 at 3,134.6 (chunk 8192); decode 170.9 tok/s on a single stream.
    grep -c "too small" over the log: 0. Before the change the same rig refused those prompts at chunk 8192, layer 25.

Failed:

none observed.

Not run:

  • The std::atomic form under load: the rig's four cards are serving that deployment and I do not restart it for a PR.
    Say so if you want it run first; the change is the cache type only.
  • HIP and SYCL builds. src/prefill/prefill.cpp reaches cudaGetDevice through
    include/strata/hip_compat/cuda_runtime.h on HIP, and the file already calls cudaGetDevice/cudaSetDevice this way
    (lines 620, 863, 1503), so I expect it to hipify as before, but I did not build it.
  • No correctness suite was run: this changes buffer sizing, not arithmetic. The pack, kernels and chunk scan are
    untouched.

Limits

  • The cache assumes the caller has the stage's device current when fused_ring() is read, which is how this file's
    other device queries work (cudaGetDevice at line 620 and 1503) and what the rig shows: the fix took effect exactly
    where the error came from. A caller that sizes a stage's buffers without selecting it would still read the wrong
    answer.
  • 32 devices, the same ceiling CUDA uses here; anything beyond it falls back to device 0's answer.

🔄 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/4380 **Author:** [@moses-sun](https://github.com/moses-sun) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/fused-ring-per-cuda-device` --- ### 📝 Commits (1) - [`5d5e380`](https://github.com/Niko1221/Strata/commit/5d5e380c498655f57be26aaed90854b84cd86045) Prefill: the fused ring's layer check is cached per CUDA device, so a layer split over unlike cards keeps MMQ's buffers where it must ### 📊 Changes **1 file changed** (+17 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `src/prefill/prefill.cpp` (+17 -5) </details> ### 📄 Description ## Problem and result On a `--layer-split` across cards that do not agree on the fused int8 prompt experts, every prefill chunk >= `stream_all_min()` failed while short prompts still worked. Four-card rig (2x RTX 5080, 84 SMs; 2x RTX 5070 Ti, 70 SMs; all sm_120), Qwen3.8-Flash-Next GSQ-RCO IQ3_S native pack, `--layer-split 12,25,37`, `--max-context 524288`, engine 0.1.51: ```text strata: prompt experts on the fused int8 kernels (STRATA_PF_FUSED=1, #136) strata serve: prefill: the fused layout's MoE buffers are too small for layer 25's expert path at a chunk of 8192 tokens ``` The request is refused (HTTP 400) and prompts above about 2K tokens are unusable on that rig. With this commit, same pack, same split, same flags on engine 0.1.52: ```text strata serve: prompt 29486 tokens = 0 reused + 29486 read in 8673 ms (3399.8 tok/s), 40 generated in 234 ms ... ``` and the string `too small` does not occur anywhere in the 24 hours of log around it. ## Related discussion #3577 reports the same error at chunk 8192 with IQ3_S on an RTX 5080 + RTX 3060 split. I do not have that rig and did not reproduce it there; reading the path, the 3060 is sm_86, so its stage is the one without `native_supported()` and it would hit the same cached decision. It is not marked as fixed here. The rule this keeps is the one #546 / #958 / #583 established: the MoE buffers may only be shrunk when every layer that will run in them can take the fused path. That rule is about the card, and the old check answered "which card is current right now" only once. ## Approach `fused_ring()` decides whether `fused_layout()` shrinks the MoE buffers to the fused path's needs. It asked `fused::native_supported()` for every layer's format and cached the answer in one function-local `static const bool`. `native_supported()` is a per-device answer: on CUDA with `STRATA_PF_FUSED` unset it returns `d.ok && d.s120 && d.sms >= 80 && d_covered_on(...)` from `moe_fused_iq.cu`'s `dev_info()`, i.e. the card that is current at that moment. On this rig the 5080s (84 SMs) take the fused kernels and the 5070 Tis (70 SMs) do not, so the first call — on the 5080 stage — shrank the buffers for the whole split, and the 5070 Ti stages then ran MMQ at a full chunk inside them. Layer 25 is the first layer of the first 5070 Ti stage, which is why that is the layer named in the error. The cache is now one entry per device (`0` unknown, `1` every layer covered, `2` not), keyed on the caller's current device, and read/written as `std::atomic<int8_t>` with relaxed ordering: the batch-slot threads read `fused_ring()` too, and a lost race only recomputes the same per-device answer. A card that can take the fused path still gets the shrink and its speed-up; a card that cannot keeps MMQ's full-size buffers. No new env var, no change to a homogeneous rig: every device there answers what the single global used to. Alternatives considered: the conservative "do not shrink unless every card in the split can take it" is simpler but throws away the fused path on the 5080 stages of exactly the rigs that have the problem; a per-stage sizing pass would have to reach the buffer ownership outside this file. If you prefer the conservative form, it is a smaller diff than this one. ## Validation **Passed:** - Build of this branch on the four-card box, sm_120 only, CUDA 13.1, GCC 13.3: `cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=120 -DCMAKE_CUDA_COMPILER=/usr/local/cuda-13.1/bin/nvcc -DSTRATA_GGML_DIR=<llama.cpp checkout> -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON -DSTRATA_MMQ_TQ_OVERLAY=ON` then `cmake --build build --target strata -j48`: the engine links, no warnings from `src/prefill/prefill.cpp`. - The change under load: the same logic with a plain `int8_t` cache (this branch minus the atomic, which is a relaxed load and store of the same two values) has served that rig since 2026-10-28 00:20 — 2x 5080 + 2x 5070 Ti, IQ3_S native pack, `--layer-split 12,25,37`, 512K context, `--batch 4 --batch-groups auto --batch-mtp --trim-stage-weights`, `STRATA_PIPED_MTP=1`. Fresh reads of the path that used to fail: 29,486 tokens at 3,399.8 tok/s, 29,484 at 3,246.1, 17,441 at 3,134.6 (chunk 8192); decode 170.9 tok/s on a single stream. `grep -c "too small"` over the log: 0. Before the change the same rig refused those prompts at chunk 8192, layer 25. **Failed:** none observed. **Not run:** - The `std::atomic` form under load: the rig's four cards are serving that deployment and I do not restart it for a PR. Say so if you want it run first; the change is the cache type only. - HIP and SYCL builds. `src/prefill/prefill.cpp` reaches `cudaGetDevice` through `include/strata/hip_compat/cuda_runtime.h` on HIP, and the file already calls `cudaGetDevice`/`cudaSetDevice` this way (lines 620, 863, 1503), so I expect it to hipify as before, but I did not build it. - No correctness suite was run: this changes buffer sizing, not arithmetic. The pack, kernels and chunk scan are untouched. ## Limits - The cache assumes the caller has the stage's device current when `fused_ring()` is read, which is how this file's other device queries work (`cudaGetDevice` at line 620 and 1503) and what the rig shows: the fix took effect exactly where the error came from. A caller that sizes a stage's buffers without selecting it would still read the wrong answer. - 32 devices, the same ceiling CUDA uses here; anything beyond it falls back to device 0's answer. --- <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#5030
No description provided.