[PR #4117] [Engine] Automatically use --resident-experts to prevent startup failure #4908

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

📋 Pull Request Information

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

Base: main ← Head: auto-low-ram-mode


📝 Commits (3)

  • d07a3f4 engine: when the expert arena cannot fit the RAM available at start, take the resident low-RAM mode instead of failing (STRATA_ARENA_FIT=0 keeps the arena)
  • 8f72492 engine: the arena-fit switch's line in plain words ("Enabling --resident-experts mode to compensate.")
  • ba38f17 engine: the arena-fit margin is 1 GiB (platform::kArenaFitFloor), not 2.5, so fewer starts that fit by paging other programs out change; docs say which case changes

📊 Changes

4 files changed (+80 additions, -11 deletions)

View changed files

📝 docs/DETAILS.md (+10 -0)
📝 include/strata/platform/memory.hpp (+11 -0)
📝 src/platform/memory_test.cpp (+24 -1)
📝 src/program/generate.cpp (+35 -10)

📄 Description

Problem and result

The README says Strata "switches to its low-RAM mode by itself" but on many systems it will just fail to start
because it inappropriately decides to copy every expert into RAM unless --resident-experts is added by hand.
This is because setup decides whether to use --resident-experts based on the PC's total RAM, but drivers and
other programs may well make it impossible to load without it (leading to error 1453).

With this change, when the arena cannot fit the RAM available at start with 1 GiB to spare,
the engine enables --resident-experts and prints one line:

strata generate: the experts (46.8 GiB) do not fit in RAM available now (33.1 GiB, 1.0 GiB kept free). Enabling `--resident-experts` mode to compensate.

In the nonstandard case that --expert-profile is disabled it uses --mmap-experts instead.

https://github.com/Niko1221/Strata/issues/4116

Approach by Opus5.5

I prompted it with possible solutions in my order of preference, saying "Choose the clear winner or my preference if there isn't one":

  1. alter full-RAM mode so it graciously stops requiring a full copy, much like low-RAM mode
  2. transition to low-RAM mode gracefully upon first allocation failure
  3. transition to low-RAM mode immediately at startup on noticing there isn't enough RAM for full-RAM copy

It chose the third:

  • The check runs right after the expert layout is read (the arena's size is known then) and before anything that
    depends on the mode: --kv-grow, the prompt chunk and the arena itself.
  • platform::arena_fits_ram holds the rule. The margin is 1 GiB (platform::kArenaFitFloor, not measured), kept
    small so that as few starts as possible change (see Compatibility).
  • --resident-experts now goes through one helper, take_resident_experts, shared by the flag and the switch, so
    both set the same options (including STRATA_RESIDENT_PIN and STRATA_RESIDENT_HEADROOM_GIB).
  • It does nothing when the config already has --mmap-experts, --resident-experts, --resident-budget-gib or
    --shared-expert-arena, nor on Metal (always mapped). STRATA_ARENA_FIT=0 keeps the old behavior.
  • docs/DETAILS.md gets a paragraph under the low-RAM mode.

Compatibility: a start whose arena fits gets the same flags and the same output. One case changes: a start that
works today only because Windows pushes other programs into the page file to make room for the arena now takes the
low-RAM mode instead, because memory that could be paged out is not counted as available. That is likely common on
64 GB PCs (a 16 GB card with 64 GB of RAM gets the arena from setup, and needs 47.8 GiB available at start to keep
it), and the low-RAM mode avoids the minutes of a sluggish PC that the paging causes. How its speed compares there
is not measured. The margin is small (1 GiB) for this reason: a start that fits with a little to spare keeps the
arena.

Validation

All on one PC: Ryzen AI Max+ 395 / Radeon 8060S (gfx1151), 128 GB with a 64 GB BIOS carve-out (Windows sees
63.6 GiB), Windows 11 Pro 10.0.26200. Qwen3.8-Flash-Next IQ3_S with setup's config (--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --max-context 204800 --kv int8 --vision --vram-reserve-mib 700, speed projection on).
Engines built with tools\hip\build_windows.bat, STRATA_HIP_ARCHS=gfx1151, STRATA_NO_VISION=1, Visual Studio
2026 Build Tools, ROCm 10.2.0a20260930.

Passed:

  • Rebased onto main at 4b9e05a2 (engine 0.1.51) and checked again there: the HIP build, platform_memory_test: OK,
    and one start with setup's config: "the experts (46.8 GiB) do not fit in RAM available now (31.2 GiB, 1.0 GiB kept
    free). Enabling --resident-experts mode to compensate.", all 24,576 experts in the GPU cache, ready after about
    6 minutes, a 400-token answer at 17.8 tok/s. The runs below were made before the rebase, on engine 0.1.49.2.
  • HIP build on Windows (gfx1151) of this branch: strata.exe, strata-device.exe and the package. No new warnings
    besides the getenv deprecation the file already has everywhere.
  • platform_memory_test (HIP build, Windows): the seven new arena_fits_ram cases and the existing ones,
    platform_memory_test: OK.
  • Hardware, with this branch and setup's config (no low-RAM flag): the engine printed the line above (33.1 GiB
    available), the GPU cache took all 24,576 experts (46.84 GiB), only 3.41 GiB was copied into RAM, the server was
    ready after about 6.5 minutes, and a 400-token answer to a 67-token prompt (temperature 0) decoded at 20.4 tok/s.
    Two earlier runs of the branch, before the message and the margin changed (31.9 and 30.4 GiB available), switched
    the same way and decoded at 18.8, 21.1 and 18.3 tok/s.

Failed:

  • The same engine built from main at 7dd5cf18 without this change, setup's config: 33.3 GiB available, "the expert
    load was refused: short unbuffered read of layer 0 ... (error 1453)", exit code 1. Engine 0.1.48 failed the same way
    on four starts (23.0-37.9 GiB available, at layers 0, 4, 21 and 14). This is the failure the PR fixes.

Not run:

  • CUDA build and any NVIDIA card: no CUDA toolkit here. generate.cpp is compiled there.
  • Metal build: no Mac. The check is skipped on Metal, which always maps the experts, but the file is compiled there.
  • SYCL build: no oneAPI. SYCL includes memory.hpp (one new inline function) and has its own generate.cpp, which
    this PR does not change.
  • Linux, and any PC whose arena fits: I checked by reading the code that the switch is skipped there, not by running it.
  • A layer split, helper GPUs, --kv-grow and --vram-elastic together with the switch.
  • Long prompts and long conversations in the switched mode.

Reference run: the unchanged build from main with --resident-experts added by hand started (about 7.5 minutes)
and decoded the same two answers at 19.3 and 20.3 tok/s. So the switch gives the same speed as the flag. One run of
each; not enough to claim more than that.

Limits

  • The check uses the RAM available at the moment of start. If other programs take RAM later, the engine does not
    react.
  • --kv-grow needs every expert in RAM: after the switch it stays off and says so, as with --resident-experts.
    docs/DETAILS.md says --vram-elastic does not work with the resident mode either; I did not check how it
    behaves after the switch.
  • Setup's own rule (total RAM, low_ram_needed) is unchanged, so the config and setup's messages still describe the
    arena.
  • I need help with the CUDA and SYCL builds, and with a run on an NVIDIA card whose arena fits, to confirm it is
    unchanged there.

🔄 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/4117 **Author:** [@qwertie](https://github.com/qwertie) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `auto-low-ram-mode` --- ### 📝 Commits (3) - [`d07a3f4`](https://github.com/Niko1221/Strata/commit/d07a3f47ec8dd2a8b863abfbcd45f3aaf3a2a6c4) engine: when the expert arena cannot fit the RAM available at start, take the resident low-RAM mode instead of failing (STRATA_ARENA_FIT=0 keeps the arena) - [`8f72492`](https://github.com/Niko1221/Strata/commit/8f72492db0e8c584137d325ddc766f22cc8409dd) engine: the arena-fit switch's line in plain words ("Enabling `--resident-experts` mode to compensate.") - [`ba38f17`](https://github.com/Niko1221/Strata/commit/ba38f174ae7629a3f00c17735203c07485a88c92) engine: the arena-fit margin is 1 GiB (platform::kArenaFitFloor), not 2.5, so fewer starts that fit by paging other programs out change; docs say which case changes ### 📊 Changes **4 files changed** (+80 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+10 -0) 📝 `include/strata/platform/memory.hpp` (+11 -0) 📝 `src/platform/memory_test.cpp` (+24 -1) 📝 `src/program/generate.cpp` (+35 -10) </details> ### 📄 Description ## Problem and result The README says Strata "switches to its low-RAM mode by itself" but on many systems it will just fail to start because it inappropriately decides to copy every expert into RAM unless `--resident-experts` is added by hand. This is because setup decides whether to use `--resident-experts` based on the PC's total RAM, but drivers and other programs may well make it impossible to load without it (leading to error 1453). With this change, when the arena cannot fit the RAM available at start with 1 GiB to spare, the engine enables `--resident-experts` and prints one line: ``` strata generate: the experts (46.8 GiB) do not fit in RAM available now (33.1 GiB, 1.0 GiB kept free). Enabling `--resident-experts` mode to compensate. ``` In the nonstandard case that `--expert-profile` is disabled it uses `--mmap-experts` instead. ## Related discussion https://github.com/Niko1221/Strata/issues/4116 ## Approach by Opus5.5 I prompted it with possible solutions in my order of preference, saying "Choose the clear winner or my preference if there isn't one": > 1. alter full-RAM mode so it graciously stops requiring a full copy, much like low-RAM mode > 2. transition to low-RAM mode gracefully upon first allocation failure > 3. transition to low-RAM mode immediately at startup on noticing there isn't enough RAM for full-RAM copy It chose the third: - The check runs right after the expert layout is read (the arena's size is known then) and before anything that depends on the mode: `--kv-grow`, the prompt chunk and the arena itself. - `platform::arena_fits_ram` holds the rule. The margin is 1 GiB (`platform::kArenaFitFloor`, not measured), kept small so that as few starts as possible change (see Compatibility). - `--resident-experts` now goes through one helper, `take_resident_experts`, shared by the flag and the switch, so both set the same options (including `STRATA_RESIDENT_PIN` and `STRATA_RESIDENT_HEADROOM_GIB`). - It does nothing when the config already has `--mmap-experts`, `--resident-experts`, `--resident-budget-gib` or `--shared-expert-arena`, nor on Metal (always mapped). `STRATA_ARENA_FIT=0` keeps the old behavior. - `docs/DETAILS.md` gets a paragraph under the low-RAM mode. Compatibility: a start whose arena fits gets the same flags and the same output. One case changes: a start that works today only because Windows pushes other programs into the page file to make room for the arena now takes the low-RAM mode instead, because memory that could be paged out is not counted as available. That is likely common on 64 GB PCs (a 16 GB card with 64 GB of RAM gets the arena from setup, and needs 47.8 GiB available at start to keep it), and the low-RAM mode avoids the minutes of a sluggish PC that the paging causes. How its speed compares there is not measured. The margin is small (1 GiB) for this reason: a start that fits with a little to spare keeps the arena. ## Validation All on one PC: Ryzen AI Max+ 395 / Radeon 8060S (gfx1151), 128 GB with a 64 GB BIOS carve-out (Windows sees 63.6 GiB), Windows 11 Pro 10.0.26200. Qwen3.8-Flash-Next IQ3_S with setup's config (`--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --max-context 204800 --kv int8 --vision --vram-reserve-mib 700`, speed projection on). Engines built with `tools\hip\build_windows.bat`, `STRATA_HIP_ARCHS=gfx1151`, `STRATA_NO_VISION=1`, Visual Studio 2026 Build Tools, ROCm 10.2.0a20260930. **Passed:** - Rebased onto `main` at 4b9e05a2 (engine 0.1.51) and checked again there: the HIP build, `platform_memory_test: OK`, and one start with setup's config: "the experts (46.8 GiB) do not fit in RAM available now (31.2 GiB, 1.0 GiB kept free). Enabling `--resident-experts` mode to compensate.", all 24,576 experts in the GPU cache, ready after about 6 minutes, a 400-token answer at 17.8 tok/s. The runs below were made before the rebase, on engine 0.1.49.2. - HIP build on Windows (gfx1151) of this branch: `strata.exe`, `strata-device.exe` and the package. No new warnings besides the `getenv` deprecation the file already has everywhere. - `platform_memory_test` (HIP build, Windows): the seven new `arena_fits_ram` cases and the existing ones, `platform_memory_test: OK`. - Hardware, with this branch and setup's config (no low-RAM flag): the engine printed the line above (33.1 GiB available), the GPU cache took all 24,576 experts (46.84 GiB), only 3.41 GiB was copied into RAM, the server was ready after about 6.5 minutes, and a 400-token answer to a 67-token prompt (temperature 0) decoded at 20.4 tok/s. Two earlier runs of the branch, before the message and the margin changed (31.9 and 30.4 GiB available), switched the same way and decoded at 18.8, 21.1 and 18.3 tok/s. **Failed:** - The same engine built from `main` at 7dd5cf18 without this change, setup's config: 33.3 GiB available, "the expert load was refused: short unbuffered read of layer 0 ... (error 1453)", exit code 1. Engine 0.1.48 failed the same way on four starts (23.0-37.9 GiB available, at layers 0, 4, 21 and 14). This is the failure the PR fixes. **Not run:** - CUDA build and any NVIDIA card: no CUDA toolkit here. `generate.cpp` is compiled there. - Metal build: no Mac. The check is skipped on Metal, which always maps the experts, but the file is compiled there. - SYCL build: no oneAPI. SYCL includes `memory.hpp` (one new inline function) and has its own `generate.cpp`, which this PR does not change. - Linux, and any PC whose arena fits: I checked by reading the code that the switch is skipped there, not by running it. - A layer split, helper GPUs, `--kv-grow` and `--vram-elastic` together with the switch. - Long prompts and long conversations in the switched mode. Reference run: the unchanged build from `main` with `--resident-experts` added by hand started (about 7.5 minutes) and decoded the same two answers at 19.3 and 20.3 tok/s. So the switch gives the same speed as the flag. One run of each; not enough to claim more than that. ## Limits - The check uses the RAM available at the moment of start. If other programs take RAM later, the engine does not react. - `--kv-grow` needs every expert in RAM: after the switch it stays off and says so, as with `--resident-experts`. `docs/DETAILS.md` says `--vram-elastic` does not work with the resident mode either; I did not check how it behaves after the switch. - Setup's own rule (total RAM, `low_ram_needed`) is unchanged, so the config and setup's messages still describe the arena. - I need help with the CUDA and SYCL builds, and with a run on an NVIDIA card whose arena fits, to confirm it is unchanged there. --- <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#4908
No description provided.