[GH-ISSUE #306] Layer split: prompt-borrow sizing vs prompt-buffer reservation disagree, and the 8 GiB arena pin cap (a WDDM workaround) applies on Linux too #148

Closed
opened 2026-11-04 01:40:27 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @zipenghao on GitHub (Sep 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/306

Summary: two separate problems that only show up when a layer split is combined
with prompt borrowing on a non-Windows platform. The second one is why prefill roughly
halves on two cards.

Environment: 2x Tesla V100-SXM2-16GB (sm_70, PCIe Gen3 x16, no NVLink, same host
bridge), Xeon E5-2680 v4, 62 GiB RAM, driver 580.178.04, CUDA 12.8, v0.1.24 built from
source. Context 131072. All numbers from the same prompt and the same command.

Problem 1: prompt-borrow sizing disagrees with prompt-buffer reservation

Under a layer split, upstream sets no_prefill_borrow = true, so the prompt path owns
its own buffers and both sizing paths happen to agree. If you enable borrowing, they
stop agreeing:

  • the CUDA0 sizing at src/program/generate.cpp:2021 does not reserve the prompt
    buffer when it borrows
  • split_pf_mib at src/program/generate.cpp:1887 reserves chunk*680 per card

Measured effect of enabling borrowing as-is: CUDA1 dropped from 3461 expert-cache slots
to 1290, decode 33 -> 27.7 tok/s.

Enabling borrowing also needs a second change: :1153 hardcodes
no_prefill_borrow = true when splitting, which pulls chunk down from 8192 to 2048 at
:1174-1178. With borrowing on and chunk left at 8192 the engine cannot start at all:

device buffers for a chunk of 8192 tokens do not fit

My fix: borrow on the first pass (no reservation), and let every later pass pay for its
own prompt buffer; keep the chunk cap at 2048.

layer split auto: CUDA1 80 SMs at 1.53GHz -> 0.59 ms per layer, 6.35 GiB for experts
the prompt path borrows 2335 cache slots (4.31 GiB)
expert cache auto: 10.83 GiB free -> 8867 slots        (was 4756 on one card)

Problem 2: the 8 GiB pin cap is a WDDM workaround applied on every platform

src/program/generate.cpp:1827 caps pinned host memory at 8 GiB, and the comment says
why:

pinning all of it into two contexts leaves WDDM refusing every later allocation

That is a Windows/WDDM problem, but the cap is applied unconditionally. On Linux the
second CUDA context then pins only 7 GiB of the 45.29 GiB expert arena, and expert
reads that miss the cache go through pageable memory, page by page, instead of DMA.
That is the direct cause of the prefill regression:

1 card 2 cards, as-is 2 cards, fixed
prefill, 4053-token prompt 790 tok/s 406 tok/s 744 tok/s
prefill, 28053-token prompt 932 tok/s 378 tok/s (74.1 s) 976 tok/s (28.7 s)
decode, 99 tokens, no MTP 29.2-31.0 32.5-33.8 35.2
expert residency 4756 slots 8142 8867 (+86%)
arena pinned full, CUDA0 only 7 GiB (CUDA1 capped) 45.29 GiB, both contexts

Prerequisite if you make the cap Windows-only

On Linux, raising the cap only helps once RLIMIT_MEMLOCK allows it. Without it the
arena cannot be pinned at all and you regress to pageable copies - slower, and on a
62 GiB machine it can fail outright. So this needs to ship together with:

echo '*  -  memlock  unlimited' | sudo tee /etc/security/limits.d/99-strata.conf
# new login required; verify with: grep "Max locked memory" /proc/<engine-pid>/limits

Defaults are 7.84 GiB here (soft == hard, needs root).

Escape hatches

Both behaviours are still reachable without recompiling, which is how I A/B'd them:

  • STRATA_SPLIT_NO_BORROW=1 - restore upstream's "no borrowing under a split"
  • STRATA_ARENA_PIN_CAP=8 - restore the 8 GiB cap on all platforms

Questions

  1. Would you accept making the pin cap Windows-only? It is the single biggest win here,
    but it moves a memory requirement onto the user, so it probably wants documentation
    and a warning rather than a silent change.
  2. On problem 1, is "first pass borrows, later passes own their buffer" the intended
    semantics? If so, the two sizing sites just need to agree on it.

Patches and the full investigation: https://github.com/zipenghao/strata-v100-sm70

Related: #303 (garbled output, same setup) and #305 (sm_70 support).

Note: this report and the linked patches were drafted with AI assistance; all numbers
above were measured manually on the hardware listed.

Originally created by @zipenghao on GitHub (Sep 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/306 **Summary:** two separate problems that only show up when a layer split is combined with prompt borrowing on a non-Windows platform. The second one is why prefill roughly halves on two cards. Environment: 2x Tesla V100-SXM2-16GB (sm_70, PCIe Gen3 x16, no NVLink, same host bridge), Xeon E5-2680 v4, 62 GiB RAM, driver 580.178.04, CUDA 12.8, v0.1.24 built from source. Context 131072. All numbers from the same prompt and the same command. ## Problem 1: prompt-borrow sizing disagrees with prompt-buffer reservation Under a layer split, upstream sets `no_prefill_borrow = true`, so the prompt path owns its own buffers and both sizing paths happen to agree. If you enable borrowing, they stop agreeing: - the CUDA0 sizing at `src/program/generate.cpp:2021` does **not** reserve the prompt buffer when it borrows - `split_pf_mib` at `src/program/generate.cpp:1887` reserves `chunk*680` **per card** Measured effect of enabling borrowing as-is: CUDA1 dropped from 3461 expert-cache slots to **1290**, decode 33 -> 27.7 tok/s. Enabling borrowing also needs a second change: `:1153` hardcodes `no_prefill_borrow = true` when splitting, which pulls chunk down from 8192 to 2048 at `:1174-1178`. With borrowing on and chunk left at 8192 the engine cannot start at all: ``` device buffers for a chunk of 8192 tokens do not fit ``` My fix: borrow on the first pass (no reservation), and let every later pass pay for its own prompt buffer; keep the chunk cap at 2048. ``` layer split auto: CUDA1 80 SMs at 1.53GHz -> 0.59 ms per layer, 6.35 GiB for experts the prompt path borrows 2335 cache slots (4.31 GiB) expert cache auto: 10.83 GiB free -> 8867 slots (was 4756 on one card) ``` ## Problem 2: the 8 GiB pin cap is a WDDM workaround applied on every platform `src/program/generate.cpp:1827` caps pinned host memory at 8 GiB, and the comment says why: > pinning all of it into two contexts leaves WDDM refusing every later allocation That is a Windows/WDDM problem, but the cap is applied unconditionally. On Linux the second CUDA context then pins only 7 GiB of the 45.29 GiB expert arena, and expert reads that miss the cache go through **pageable memory, page by page**, instead of DMA. That is the direct cause of the prefill regression: | | 1 card | 2 cards, as-is | 2 cards, fixed | |---|---:|---:|---:| | prefill, 4053-token prompt | 790 tok/s | 406 tok/s | **744 tok/s** | | prefill, 28053-token prompt | 932 tok/s | 378 tok/s (74.1 s) | **976 tok/s** (28.7 s) | | decode, 99 tokens, no MTP | 29.2-31.0 | 32.5-33.8 | **35.2** | | expert residency | 4756 slots | 8142 | **8867** (+86%) | | arena pinned | full, CUDA0 only | 7 GiB (CUDA1 capped) | **45.29 GiB, both contexts** | ### Prerequisite if you make the cap Windows-only On Linux, raising the cap only helps once `RLIMIT_MEMLOCK` allows it. Without it the arena cannot be pinned at all and you regress to pageable copies - slower, and on a 62 GiB machine it can fail outright. So this needs to ship together with: ```bash echo '* - memlock unlimited' | sudo tee /etc/security/limits.d/99-strata.conf # new login required; verify with: grep "Max locked memory" /proc/<engine-pid>/limits ``` Defaults are 7.84 GiB here (soft == hard, needs root). ## Escape hatches Both behaviours are still reachable without recompiling, which is how I A/B'd them: - `STRATA_SPLIT_NO_BORROW=1` - restore upstream's "no borrowing under a split" - `STRATA_ARENA_PIN_CAP=8` - restore the 8 GiB cap on all platforms ## Questions 1. Would you accept making the pin cap Windows-only? It is the single biggest win here, but it moves a memory requirement onto the user, so it probably wants documentation and a warning rather than a silent change. 2. On problem 1, is "first pass borrows, later passes own their buffer" the intended semantics? If so, the two sizing sites just need to agree on it. Patches and the full investigation: https://github.com/zipenghao/strata-v100-sm70 Related: #303 (garbled output, same setup) and #305 (sm_70 support). *Note: this report and the linked patches were drafted with AI assistance; all numbers above were measured manually on the hardware listed.*
Author
Owner

@Niko1221 commented on GitHub (Oct 1, 2026):

Both parts are fixed: the per-stage prompt loans (0.1.30, #216) and the 8 GiB pin cap now only under WDDM (0.1.31, #253; STRATA_ARENA_PIN_GIB sets a cap). Please retest on 0.1.31 and reopen if the sizing still disagrees.

<!-- gh-comment-id:5925958994 --> @Niko1221 commented on GitHub (Oct 1, 2026): Both parts are fixed: the per-stage prompt loans (0.1.30, #216) and the 8 GiB pin cap now only under WDDM (0.1.31, #253; STRATA_ARENA_PIN_GIB sets a cap). Please retest on 0.1.31 and reopen if the sizing still disagrees.
Author
Owner

@zipenghao commented on GitHub (Oct 10, 2026):

Retested on 0.1.34 with both patches removed - both parts behave as you described, on 2x V100-SXM2-16GB (sm_70, PCIe Gen3 x16, no NVLink), Xeon E5-2680 v4, 62 GiB, memlock unlimited, IQ3_XXS pack, --kv int8, --spec 2 --spec-min-p 0.5, context 131072.

The pin cap. The arena registers in full, with no 8 GiB limit and no page-by-page fallback:

expert arena: cudaHostRegister PORTABLE ok; MAP_HUGETLB unavailable (no hugetlb pool configured?); using 4 KB pages

The prompt loans. The split proceeds without the sizing disagreement; the layer split is chosen and both stages come up with their own caches:

layer split auto: K=23 - predicted 34.1 ms per decode window; the caches hold 9105 of 24576 profiled pairs (~97.0% of the routed mass)
expert cache auto: 9.12 GiB free, 700 MiB reserved (+0 MiB for the draft head) -> 3888 slots
layer split: CUDA1 runs layers 23-47, expert cache 4211 slots (7.73 GiB)

Same machine, same prompts, 0.1.24 + local patches vs 0.1.34 stock:

0.1.24 + patches 0.1.34 stock
expert slots (both cards) 5735 8765
end-to-end, 4 prompts from cold 24.9 tok/s 29.2 tok/s
end-to-end, warm 27.6 tok/s 33.4 tok/s
decode hit rate, warm 85-87% 87-92%

Caveats worth recording for anyone else reading this: the artifact is Unsloth's UD-IQ3_XXS, so I had to pack by hand with --compat-bf16, and --native has to point at the second shard (see my comment on #305). Neither is a V100-specific issue - both are about that artifact's layout, not the card.

Closing our side. If the sizing ever disagrees again on your hardware, I have the log lines to compare.

<!-- gh-comment-id:6092033176 --> @zipenghao commented on GitHub (Oct 10, 2026): Retested on **0.1.34** with both patches removed - both parts behave as you described, on 2x V100-SXM2-16GB (sm_70, PCIe Gen3 x16, no NVLink), Xeon E5-2680 v4, 62 GiB, `memlock unlimited`, IQ3_XXS pack, `--kv int8`, `--spec 2 --spec-min-p 0.5`, context 131072. **The pin cap.** The arena registers in full, with no 8 GiB limit and no page-by-page fallback: ``` expert arena: cudaHostRegister PORTABLE ok; MAP_HUGETLB unavailable (no hugetlb pool configured?); using 4 KB pages ``` **The prompt loans.** The split proceeds without the sizing disagreement; the layer split is chosen and both stages come up with their own caches: ``` layer split auto: K=23 - predicted 34.1 ms per decode window; the caches hold 9105 of 24576 profiled pairs (~97.0% of the routed mass) expert cache auto: 9.12 GiB free, 700 MiB reserved (+0 MiB for the draft head) -> 3888 slots layer split: CUDA1 runs layers 23-47, expert cache 4211 slots (7.73 GiB) ``` Same machine, same prompts, 0.1.24 + local patches vs 0.1.34 stock: | | 0.1.24 + patches | 0.1.34 stock | |---|---:|---:| | expert slots (both cards) | 5735 | **8765** | | end-to-end, 4 prompts from cold | 24.9 tok/s | **29.2 tok/s** | | end-to-end, warm | 27.6 tok/s | **33.4 tok/s** | | decode hit rate, warm | 85-87% | **87-92%** | Caveats worth recording for anyone else reading this: the artifact is Unsloth's `UD-IQ3_XXS`, so I had to pack by hand with `--compat-bf16`, and `--native` has to point at the second shard (see my comment on #305). Neither is a V100-specific issue - both are about that artifact's layout, not the card. Closing our side. If the sizing ever disagrees again on your hardware, I have the log lines to compare.
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#148
No description provided.