[PR #5255] [Engine] layer-major: say how much VRAM a super-chunk needs, and that the walk stays off #5363

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5255
Author: @Norhiro
Created: 11/4/2026
Status: 🔄 Open

Base: main ← Head: lm-off-need-side


📝 Commits (1)

  • d9e7c25 Layer-major: say how much VRAM a super-chunk needs, and that the walk stays off

📊 Changes

1 file changed (+22 additions, -2 deletions)

View changed files

📝 src/prefill/prefill.cpp (+22 -2)

📄 Description

Problem and result

When the layer-major walk cannot get VRAM for a super-chunk, the engine logs layer-major off for this prompt: no VRAM for a super-chunk (622 MiB free). That line gives the free side only. It does not say which card ran short or how much the walk would need, so a user cannot tell whether freeing 40 MiB or 4 GB would let it run. It is also printed once per distinct text, so a log read later does not show that the walk stayed off for every long prompt after the first. In #3976, @udqe (221 such lines, all free side only), @fioruccione and @cobra91 asked for the need side.

After this change, on the same run:

before: strata prefill: layer-major off for this prompt: no VRAM for a super-chunk (622 MiB free)
after:  strata prefill: layer-major off for this prompt: no VRAM for a super-chunk on CUDA0 (622 MiB free; the smallest, 12800 tokens, needs 663 MiB with the 96 MiB margin)

Every 16th long prompt in a row that the walk turns down also gets a line, whatever the reason:

strata prefill: layer-major still off, 16 long prompts in a row (now: no VRAM for a super-chunk on CUDA0 (564 MiB free; the smallest, 7680 tokens, needs 2340 MiB with the 2000 MiB margin))

Only the refusal text and the logging change. The walk's decision, the chunk path and everything else are as before.

#3976: the need-side line was offered there on 11-04 and got +1s from @udqe, @fioruccione and @cobra91. No maintainer scope agreement was asked for, since this is a log-text change with no behaviour change.

Approach

  • lm_prepare: when no super-chunk fits, the need is computed from the same quantities fit() uses.
    • The super-chunk size is the smallest one fit() tried: S - (S - min_s) / T * T.
    • The row placement is the cheaper one the mode allows: rows in VRAM only for STRATA_PREFILL_LM_R=vram.
    • The margin is lm_margin_bytes.
    • So free >= need is the condition under which the walk would run, give or take the MiB rounding: need is rounded up, free down.
    • The card is the current device, named CUDA<n> as in the engine's other lines.
  • Prefill::run: a counter of long prompts turned down in a row.
    • A short prompt is not counted, and a prompt the walk reads resets the counter.
    • Every 16th refusal prints one extra line.
    • The existing once-per-text line is unchanged.
    • The counter does not key on the text, because the free MiB and, on a layer split, the stage change from prompt to prompt. In the first version of this patch, keying on the text meant the extra line never appeared.
  • Nothing else in the repo parses these two lines. I searched the .py, .ts, .cpp and .md files.

Validation

Tests 4 and a repeat of test 1 ran on d9e7c251, this branch on ffa80d73 = v0.2.10. The repeat of test 1 gave the same lines, with CUDA0 at 626 MiB free. Tests 1-3 ran on the first version of the patch. Its lm_prepare change is identical; only the in-a-row counter differed (see Failed). Both were built with -DSTRATA_ENABLE_CUDA=ON -DSTRATA_ISA_FLOOR=avx -DCMAKE_CUDA_ARCHITECTURES="86;120", CUDA 13.3, g++ 15, Release. The "before" build is v0.2.10 with the same options.

Machine: i7-7800X, 125 GiB RAM, Fedora 44. GPUs: RTX 3060 12 GB (CUDA0, PCIe 3.0 x16) and RTX 5060 Ti 16 GB (CUDA1, 3.0 x8). Model: Qwen3.8-Flash-Next UD-Q4_K_XL native, --max-context 65536 --prefill auto --expert-cache auto --spec 4, MTP, all experts in RAM. Prompts are unique slices of one long document, temperature 0.

Passed:

  1. Two cards, layer split, STRATA_PREFILL_LAYER_MAJOR=1, no VRAM reserve, 3 prompts of 28.6K-31.4K tokens.

    • Before (v0.2.10): layers 18..48: no VRAM for a super-chunk (149 MiB free) and no VRAM for a super-chunk (622 MiB free).
    • After: the same free values, now with the card and the need. CUDA1 needs 663 MiB with 149 MiB free; CUDA0 needs 663 MiB with 622 MiB free.
    • TTFT was the same in both builds: 39.6-40.1 s.
  2. Two cards, nothing set (0.2.10's default, chunk-major), 2 prompts. No layer-major line of any kind, as in v0.2.10.

  3. The need matches the decision in every case. I used the RTX 3060 alone, where the small-card rule turns the walk on by default, and moved the margin with STRATA_PREFILL_LM_MARGIN_MIB:

    margin need printed / implied free at the prompt walk
    2000 MiB 2363 MiB 530-660 MiB off, 17 of 17 prompts
    117 MiB (= 2363 − 2000 + 117) 480 MiB 660, 546 MiB ran, 2 of 2 (... MiB VRAM free before in the run line)
    245 MiB 585 MiB (printed) 660 MiB ran
    245 MiB 585 MiB (printed) 544 MiB off

    In the 245 MiB start the cache came out smaller, the default chunk was 3840, and the line said "the smallest, 7680 tokens". So the printed size follows the run's own chunk.

  4. The in-a-row line. The RTX 3060 alone with a 2000 MiB margin and 17 long prompts. All 17 were turned down. Seven different texts were printed, because the free MiB moved between 530 and 658. layer-major still off, 16 long prompts in a row appeared once, at the 16th.

  5. Build: the build passed (ninja, 170/170). No new warnings in prefill.cpp. The two that remain, ssq and multi, are in lines this patch does not touch.

Failed:

  • The first version, which keyed the in-a-row count on the text, never printed the in-a-row line in test 4. That version is not in this PR; the version here is the one that passed test 4.

Not run:

  • HIP and SYCL builds. prefill.cpp is part of strata_prefill for HIP too. The patch only adds calls the file already makes (cudaGetDevice, cudaGetLastError), but I have no AMD card and did not build it. I am keeping this a draft until someone can build HIP, or a maintainer says the CUDA build is enough for a log-text change.
  • Windows.
  • The Terminal and app tests. No Python or TypeScript changed, and nothing there reads these lines.
  • A machine where the walk is on by default on a layer split (pre-0.2.10 behaviour). The two-card text was checked with STRATA_PREFILL_LAYER_MAJOR=1, so the margin shown there is 96 MiB, not the 512 MiB a by-default run would use.

Limits

  • "Smallest" is the smallest size this prompt would accept, not the smallest the walk could ever use. It depends on the prompt and the stage's chunk, so two prompts can show different needs.
  • On a layer split, the counter counts prompts, not stages. The reason in the in-a-row line is the latest one, from whichever stage refused.
  • The counter is per process, like the existing once-per-text memory.

AI-assisted: Claude Code wrote the patch with me and ran the tests on my machine. I read every changed line, and the logs quoted above are from those runs.

🤖 Generated with Claude Code


🔄 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/5255 **Author:** [@Norhiro](https://github.com/Norhiro) **Created:** 11/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `lm-off-need-side` --- ### 📝 Commits (1) - [`d9e7c25`](https://github.com/Niko1221/Strata/commit/d9e7c251c17d9931d627095e9ada5d2280e0a7a5) Layer-major: say how much VRAM a super-chunk needs, and that the walk stays off ### 📊 Changes **1 file changed** (+22 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/prefill/prefill.cpp` (+22 -2) </details> ### 📄 Description ## Problem and result When the layer-major walk cannot get VRAM for a super-chunk, the engine logs `layer-major off for this prompt: no VRAM for a super-chunk (622 MiB free)`. That line gives the free side only. It does not say which card ran short or how much the walk would need, so a user cannot tell whether freeing 40 MiB or 4 GB would let it run. It is also printed once per distinct text, so a log read later does not show that the walk stayed off for every long prompt after the first. In #3976, @udqe (221 such lines, all free side only), @fioruccione and @cobra91 asked for the need side. After this change, on the same run: ``` before: strata prefill: layer-major off for this prompt: no VRAM for a super-chunk (622 MiB free) after: strata prefill: layer-major off for this prompt: no VRAM for a super-chunk on CUDA0 (622 MiB free; the smallest, 12800 tokens, needs 663 MiB with the 96 MiB margin) ``` Every 16th long prompt in a row that the walk turns down also gets a line, whatever the reason: ``` strata prefill: layer-major still off, 16 long prompts in a row (now: no VRAM for a super-chunk on CUDA0 (564 MiB free; the smallest, 7680 tokens, needs 2340 MiB with the 2000 MiB margin)) ``` Only the refusal text and the logging change. The walk's decision, the chunk path and everything else are as before. ## Related discussion #3976: the need-side line was offered there on 11-04 and got +1s from @udqe, @fioruccione and @cobra91. No maintainer scope agreement was asked for, since this is a log-text change with no behaviour change. ## Approach - **`lm_prepare`:** when no super-chunk fits, the need is computed from the same quantities `fit()` uses. - The super-chunk size is the smallest one `fit()` tried: `S - (S - min_s) / T * T`. - The row placement is the cheaper one the mode allows: rows in VRAM only for `STRATA_PREFILL_LM_R=vram`. - The margin is `lm_margin_bytes`. - So `free >= need` is the condition under which the walk would run, give or take the MiB rounding: need is rounded up, free down. - The card is the current device, named `CUDA<n>` as in the engine's other lines. - **`Prefill::run`:** a counter of long prompts turned down in a row. - A short prompt is not counted, and a prompt the walk reads resets the counter. - Every 16th refusal prints one extra line. - The existing once-per-text line is unchanged. - The counter does not key on the text, because the free MiB and, on a layer split, the stage change from prompt to prompt. In the first version of this patch, keying on the text meant the extra line never appeared. - **Nothing else in the repo parses these two lines.** I searched the .py, .ts, .cpp and .md files. ## Validation Tests 4 and a repeat of test 1 ran on `d9e7c251`, this branch on `ffa80d73` = v0.2.10. The repeat of test 1 gave the same lines, with CUDA0 at 626 MiB free. Tests 1-3 ran on the first version of the patch. Its `lm_prepare` change is identical; only the in-a-row counter differed (see Failed). Both were built with `-DSTRATA_ENABLE_CUDA=ON -DSTRATA_ISA_FLOOR=avx -DCMAKE_CUDA_ARCHITECTURES="86;120"`, CUDA 13.3, g++ 15, Release. The "before" build is v0.2.10 with the same options. Machine: i7-7800X, 125 GiB RAM, Fedora 44. GPUs: RTX 3060 12 GB (CUDA0, PCIe 3.0 x16) and RTX 5060 Ti 16 GB (CUDA1, 3.0 x8). Model: Qwen3.8-Flash-Next UD-Q4_K_XL native, `--max-context 65536 --prefill auto --expert-cache auto --spec 4`, MTP, all experts in RAM. Prompts are unique slices of one long document, temperature 0. **Passed:** 1. **Two cards, layer split, `STRATA_PREFILL_LAYER_MAJOR=1`, no VRAM reserve, 3 prompts of 28.6K-31.4K tokens.** - Before (v0.2.10): `layers 18..48: no VRAM for a super-chunk (149 MiB free)` and `no VRAM for a super-chunk (622 MiB free)`. - After: the same free values, now with the card and the need. CUDA1 needs 663 MiB with 149 MiB free; CUDA0 needs 663 MiB with 622 MiB free. - TTFT was the same in both builds: 39.6-40.1 s. 2. **Two cards, nothing set (0.2.10's default, chunk-major), 2 prompts.** No layer-major line of any kind, as in v0.2.10. 3. **The need matches the decision in every case.** I used the RTX 3060 alone, where the small-card rule turns the walk on by default, and moved the margin with `STRATA_PREFILL_LM_MARGIN_MIB`: | margin | need printed / implied | free at the prompt | walk | |---|---|---|---| | 2000 MiB | 2363 MiB | 530-660 MiB | off, 17 of 17 prompts | | 117 MiB (= 2363 − 2000 + 117) | 480 MiB | 660, 546 MiB | ran, 2 of 2 (`... MiB VRAM free before` in the run line) | | 245 MiB | 585 MiB (printed) | 660 MiB | ran | | 245 MiB | 585 MiB (printed) | 544 MiB | off | In the 245 MiB start the cache came out smaller, the default chunk was 3840, and the line said "the smallest, 7680 tokens". So the printed size follows the run's own chunk. 4. **The in-a-row line.** The RTX 3060 alone with a 2000 MiB margin and 17 long prompts. All 17 were turned down. Seven different texts were printed, because the free MiB moved between 530 and 658. `layer-major still off, 16 long prompts in a row` appeared once, at the 16th. 5. **Build:** the build passed (ninja, 170/170). No new warnings in `prefill.cpp`. The two that remain, `ssq` and `multi`, are in lines this patch does not touch. **Failed:** - The first version, which keyed the in-a-row count on the text, never printed the in-a-row line in test 4. That version is not in this PR; the version here is the one that passed test 4. **Not run:** - **HIP and SYCL builds.** `prefill.cpp` is part of `strata_prefill` for HIP too. The patch only adds calls the file already makes (`cudaGetDevice`, `cudaGetLastError`), but I have no AMD card and did not build it. **I am keeping this a draft until someone can build HIP**, or a maintainer says the CUDA build is enough for a log-text change. - Windows. - The Terminal and app tests. No Python or TypeScript changed, and nothing there reads these lines. - A machine where the walk is on by default on a layer split (pre-0.2.10 behaviour). The two-card text was checked with `STRATA_PREFILL_LAYER_MAJOR=1`, so the margin shown there is 96 MiB, not the 512 MiB a by-default run would use. ## Limits - **"Smallest" is the smallest size this prompt would accept, not the smallest the walk could ever use.** It depends on the prompt and the stage's chunk, so two prompts can show different needs. - **On a layer split, the counter counts prompts, not stages.** The reason in the in-a-row line is the latest one, from whichever stage refused. - **The counter is per process, like the existing once-per-text memory.** AI-assisted: Claude Code wrote the patch with me and ran the tests on my machine. I read every changed line, and the logs quoted above are from those runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#5363
No description provided.