[PR #3060] [CLOSED] [Engine] STRATA_RAM_ADAPT: move experts out of their stage buffer, up to 4 pairs a layer #4428

Closed
opened 2026-11-07 15:35:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3060
Author: @SanghunYun
Created: 10/18/2026
Status: ❌ Closed

Base: main ← Head: ram-adapt-stage


📝 Commits (1)

  • c06903c STRATA_RAM_ADAPT: move incoming experts out of their stage buffer, up to 4 pairs a layer

📊 Changes

5 files changed (+97 additions, -27 deletions)

View changed files

📝 docs/DETAILS.md (+17 -17)
📝 include/strata/core/expert_source.hpp (+6 -1)
📝 src/core/expert_source.cpp (+27 -0)
📝 src/program/generate.cpp (+25 -9)
📝 tests/core/file_expert_source_test.cpp (+22 -0)

📄 Description

Problem and result

STRATA_RAM_ADAPT moves experts the conversation keeps routing to into the RAM copy, but each move re-reads the incoming expert from the file, and only one pair per layer moves per window. The incoming expert was usually just read for the window before, and its blob is still in that read's stage buffer.

With this change, a move copies the blob out of the stage buffer instead (no file read), and because that is cheap, a layer may move up to 4 pairs instead of 1. n now caps only the moves that still need a file read; STRATA_RAM_ADAPT=1 is enough.

RTX 3060 12 GB, 32 GB RAM, NVMe, 20.5 GiB RAM tier, v0.2.1, two models read in place: IQ2_XS and IQ3_XXS (only --pack/--native differ). Each run is a fresh engine with the stock profile and the model's page cache dropped. 3 interleaved runs per setting; ± is the 95% CI of the difference. IQ3_XXS's expert cache holds 2791 VRAM slots instead of 3769, so more experts come from the file and the gain is larger.

ShareGPT, 120 requests (30 conversations × 4 turns) model off RAM_ADAPT=8 (main) RAM_ADAPT2 (main) this PR, =1
decode tok/s IQ2_XS 37.70 48.71 47.65 51.40
IQ3_XXS 23.24 33.07 31.20 38.71
prompt tok/s IQ2_XS 117.8 137.4 134.5 141.5
IQ3_XXS 79.9 97.8 95.4 104.2
session time s IQ2_XS 931 743 761 701
IQ3_XXS 1527 1104 1161 977
storage read GB IQ2_XS 956 408 506 308
IQ3_XXS 2215 1105 1311 717

Against main's =8: IQ2_XS decode +5.5% (±1.0), prompt +2.9% (±1.9), storage reads −24.5%; IQ3_XXS decode +17.1% (±2.0), prompt +6.5% (±2.8), storage reads −35%. With both models the PR is ahead in every request block (1–10, 11–30, 31–60, 61–120).

ShareGPT 120 requests, IQ2_XS and IQ3_XXS: decode tok/s, prompt tok/s and expert reads from the file per token, by setting

Each point is a 10-request window over the 3 runs per setting (window sums: tokens / time, reads / tokens). A column shares its y axis.

standard-v1 (22 requests, no concurrency stage) model off =8 RAM_ADAPT2 this PR
decode tok/s IQ2_XS 42.04 47.58 45.37 48.34
IQ3_XXS 28.59 36.33 33.27 37.73
prompt tok/s IQ2_XS 572.1 578.3 577.2 578.2
IQ3_XXS 503.6 514.4 513.7 514.0
storage read GB IQ2_XS 318 262 283 256
IQ3_XXS 584 454 494 426

Against =8 on standard-v1, decode is +1.6% (±2.6) with IQ2_XS and +3.9% (±4.1) with IQ3_XXS, both within noise; prompt is unchanged. No case is worse beyond noise. Short requests (performance-short, IQ2_XS) go from 44.0 (off) to 49.0 tok/s (+11%).

These runs are on v0.2.1. The branch is rebased on v0.2.2 (011c9e60), which does not touch this path; a spot check there (IQ2_XS ShareGPT, one PR run between two =8 runs within 0.7%) gives decode +6.5%, prompt +2.4%, storage reads −24.9%.

Engine arguments, identical in every run (only the binary and the STRATA_RAM_ADAPT* variables differ, and --pack/--native between the models):

strata --serve --prefill auto:16384 --spec 3 --mtp-max-t 3 --spec-min-p 0.5 --suffix-draft 0 --max-context 131072
  --kv k8v4 --pool-workers 7 --ple-io direct --greedy --stop-eos --stats --mmap-experts --mtp <mtp dir>
  --prompt-cache-root 1024 --prompt-cache-every 0 --vision --conversation-cache-min-free-mib 768
  --conversation-cache-min-free-mib 1280 --tail-role-token 8678
  --conversation-cache-min-tokens 3072 --pack <IQ2_XS or IQ3_XXS pack> --native <IQ2_XS or IQ3_XXS gguf> --expert-profile <stock profile>
  --resident-budget-gib 20.5 --expert-cache 4200 --vram-reserve-mib 768 --adapt-async 1
  --conversation-cache-mib 1536 --conversation-cache-slots 3 --prompt-cache 2

STRATA_UNBUFFERED_LOAD=1 STRATA_STAGER_THREADS=8 STRATA_STAGER_RING=32 STRATA_LOOKAHEAD=1 STRATA_PREFILL_CPU_SHARE=auto
STRATA_RESIDENT_HEADROOM_GIB=0 STRATA_GGUF_PTE_BUDGET_MB=23500 STRATA_KV_RECLAIM_EXPERTS=1 STRATA_RETAIN_TURN_BOUNDARIES=0
STRATA_ADAPT_OVERLAP=0 STRATA_ROUTE_TAIL_SKIP=7 STRATA_PREFILL_TIMING=1 STRATA_DECODE_TIMING=1 CUDA_MODULE_LOADING=LAZY

#1838 (ported to main), the maintainer's comment there on the short-request cost, and this PR's earlier version.

Approach

replace_resident_staged copies in out of its finished stage buffer under stage_mu_, so claim_stage cannot hand that buffer to another blob during the copy. It uses the same Foresight hold and between-window checks as replace_resident. In the selection loop, each layer pairs its most-routed experts outside the copy with its least-routed unused ones inside it, up to 4 pairs. The pair thresholds (routed count 2 or more, unused below 0.5) are unchanged.

The default path is unchanged when STRATA_RAM_ADAPT is unset (checked byte for byte, see Validation). RAM_ADAPT2 is untouched. The stats line also reports how many moves came out of a stage buffer.

Validation

Passed:

  • CUDA sm_86 Release build, v0.2.2 + this commit (before: v0.2.1). file_expert_source_test and --rotation-gpu pass, including a new staged-move case with exact bytes on pinned and pageable buffers.
  • HIP gfx1100 Release build (ROCm 7.10 SDK), v0.2.2 + this commit: compiles and links; file_expert_source_test host-side passes with GPUs hidden.
  • Default path byte-identical to v0.2.2: stock, this branch with STRATA_RAM_ADAPT unset, stock again (IQ2_XS, standard-v1, 22 requests, fresh engines): 22/22 equal outputs (server tool-call ids left out). Fixed so that stock equals stock, adaptive VRAM tier on: --adapt-async 0 --pcie-frac 0.10, STRATA_ADAPT_NOWAIT=0 STRATA_PREFILL_CPU_SHARE=0 STRATA_IQ_MT_MIN=1.
  • With the option on, some answers differ from off, as they do with main's =8. The moves change no computation, only which experts are in pinned RAM, and only those can go to the GPU in the PCIe share of a window's misses (expert_source.cpp); the GPU rounds slightly differently from the CPU. With --pcie-frac 0, stock, this PR (=1) and main's =8 give 22/22 equal outputs.
  • The measurements above: 48 runs (24 per model), all requests completed, identical prompt token hashes across runs. The stock profile was unchanged after every run.

Failed: none observed.

Not run:

  • SYCL build. SYCL compiles its own copies of expert_source.cpp, generate.cpp and expert_source.hpp (sycl/CMakeLists.txt), so it is not affected.
  • AMD GPU inference.
  • standard-v1 through strata bench run: the request files and body were replayed through serve/server.py with --greedy, so this is not a submittable standard result.

Limits

  • One machine, two quantizations (IQ2_XS, IQ3_XXS), English prompts.
  • Sessions of 120 requests from a cold page cache; longer serving was not measured.
  • Other RAM budgets and SATA drives were not measured.
  • Replay: https://github.com/SanghunYun/Strata/tree/ram-adapt-replay has the ShareGPT builder (dataset revision, sha256 and seed fixed), replay.py (also replays standard-v1 from your checkout and records the engine's timings and storage reads), summarize.py (settings × runs, Welch intervals) and our per-run numbers for both models.

🔄 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/3060 **Author:** [@SanghunYun](https://github.com/SanghunYun) **Created:** 10/18/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `ram-adapt-stage` --- ### 📝 Commits (1) - [`c06903c`](https://github.com/Niko1221/Strata/commit/c06903c01b3de05ed821a6e3bb7353c8d8d21c07) STRATA_RAM_ADAPT: move incoming experts out of their stage buffer, up to 4 pairs a layer ### 📊 Changes **5 files changed** (+97 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+17 -17) 📝 `include/strata/core/expert_source.hpp` (+6 -1) 📝 `src/core/expert_source.cpp` (+27 -0) 📝 `src/program/generate.cpp` (+25 -9) 📝 `tests/core/file_expert_source_test.cpp` (+22 -0) </details> ### 📄 Description ## Problem and result `STRATA_RAM_ADAPT` moves experts the conversation keeps routing to into the RAM copy, but each move re-reads the incoming expert from the file, and only one pair per layer moves per window. The incoming expert was usually just read for the window before, and its blob is still in that read's stage buffer. With this change, a move copies the blob out of the stage buffer instead (no file read), and because that is cheap, a layer may move up to 4 pairs instead of 1. `n` now caps only the moves that still need a file read; `STRATA_RAM_ADAPT=1` is enough. RTX 3060 12 GB, 32 GB RAM, NVMe, 20.5 GiB RAM tier, v0.2.1, two models read in place: IQ2_XS and IQ3_XXS (only `--pack`/`--native` differ). Each run is a fresh engine with the stock profile and the model's page cache dropped. 3 interleaved runs per setting; ± is the 95% CI of the difference. IQ3_XXS's expert cache holds 2791 VRAM slots instead of 3769, so more experts come from the file and the gain is larger. | ShareGPT, 120 requests (30 conversations × 4 turns) | model | off | `RAM_ADAPT=8` (main) | `RAM_ADAPT2` (main) | this PR, `=1` | | --- | --- | ---: | ---: | ---: | ---: | | decode tok/s | IQ2_XS | 37.70 | 48.71 | 47.65 | **51.40** | | | IQ3_XXS | 23.24 | 33.07 | 31.20 | **38.71** | | prompt tok/s | IQ2_XS | 117.8 | 137.4 | 134.5 | **141.5** | | | IQ3_XXS | 79.9 | 97.8 | 95.4 | **104.2** | | session time s | IQ2_XS | 931 | 743 | 761 | **701** | | | IQ3_XXS | 1527 | 1104 | 1161 | **977** | | storage read GB | IQ2_XS | 956 | 408 | 506 | **308** | | | IQ3_XXS | 2215 | 1105 | 1311 | **717** | Against main's `=8`: IQ2_XS decode +5.5% (±1.0), prompt +2.9% (±1.9), storage reads −24.5%; IQ3_XXS decode +17.1% (±2.0), prompt +6.5% (±2.8), storage reads −35%. With both models the PR is ahead in every request block (1–10, 11–30, 31–60, 61–120). ![ShareGPT 120 requests, IQ2_XS and IQ3_XXS: decode tok/s, prompt tok/s and expert reads from the file per token, by setting](https://raw.githubusercontent.com/SanghunYun/Strata/ram-adapt-replay/charts/sharegpt120-v021-iq2-iq3.png) Each point is a 10-request window over the 3 runs per setting (window sums: tokens / time, reads / tokens). A column shares its y axis. | `standard-v1` (22 requests, no concurrency stage) | model | off | `=8` | `RAM_ADAPT2` | this PR | | --- | --- | ---: | ---: | ---: | ---: | | decode tok/s | IQ2_XS | 42.04 | 47.58 | 45.37 | **48.34** | | | IQ3_XXS | 28.59 | 36.33 | 33.27 | **37.73** | | prompt tok/s | IQ2_XS | 572.1 | 578.3 | 577.2 | 578.2 | | | IQ3_XXS | 503.6 | 514.4 | 513.7 | 514.0 | | storage read GB | IQ2_XS | 318 | 262 | 283 | **256** | | | IQ3_XXS | 584 | 454 | 494 | **426** | Against `=8` on `standard-v1`, decode is +1.6% (±2.6) with IQ2_XS and +3.9% (±4.1) with IQ3_XXS, both within noise; prompt is unchanged. No case is worse beyond noise. Short requests (`performance-short`, IQ2_XS) go from 44.0 (off) to 49.0 tok/s (+11%). These runs are on v0.2.1. The branch is rebased on v0.2.2 (`011c9e60`), which does not touch this path; a spot check there (IQ2_XS ShareGPT, one PR run between two `=8` runs within 0.7%) gives decode +6.5%, prompt +2.4%, storage reads −24.9%. Engine arguments, identical in every run (only the binary and the `STRATA_RAM_ADAPT*` variables differ, and `--pack`/`--native` between the models): ``` strata --serve --prefill auto:16384 --spec 3 --mtp-max-t 3 --spec-min-p 0.5 --suffix-draft 0 --max-context 131072 --kv k8v4 --pool-workers 7 --ple-io direct --greedy --stop-eos --stats --mmap-experts --mtp <mtp dir> --prompt-cache-root 1024 --prompt-cache-every 0 --vision --conversation-cache-min-free-mib 768 --conversation-cache-min-free-mib 1280 --tail-role-token 8678 --conversation-cache-min-tokens 3072 --pack <IQ2_XS or IQ3_XXS pack> --native <IQ2_XS or IQ3_XXS gguf> --expert-profile <stock profile> --resident-budget-gib 20.5 --expert-cache 4200 --vram-reserve-mib 768 --adapt-async 1 --conversation-cache-mib 1536 --conversation-cache-slots 3 --prompt-cache 2 STRATA_UNBUFFERED_LOAD=1 STRATA_STAGER_THREADS=8 STRATA_STAGER_RING=32 STRATA_LOOKAHEAD=1 STRATA_PREFILL_CPU_SHARE=auto STRATA_RESIDENT_HEADROOM_GIB=0 STRATA_GGUF_PTE_BUDGET_MB=23500 STRATA_KV_RECLAIM_EXPERTS=1 STRATA_RETAIN_TURN_BOUNDARIES=0 STRATA_ADAPT_OVERLAP=0 STRATA_ROUTE_TAIL_SKIP=7 STRATA_PREFILL_TIMING=1 STRATA_DECODE_TIMING=1 CUDA_MODULE_LOADING=LAZY ``` ## Related discussion #1838 (ported to main), the maintainer's comment there on the short-request cost, and this PR's earlier version. ## Approach `replace_resident_staged` copies `in` out of its finished stage buffer under `stage_mu_`, so `claim_stage` cannot hand that buffer to another blob during the copy. It uses the same Foresight hold and between-window checks as `replace_resident`. In the selection loop, each layer pairs its most-routed experts outside the copy with its least-routed unused ones inside it, up to 4 pairs. The pair thresholds (routed count 2 or more, unused below 0.5) are unchanged. The default path is unchanged when `STRATA_RAM_ADAPT` is unset (checked byte for byte, see Validation). `RAM_ADAPT2` is untouched. The stats line also reports how many moves came out of a stage buffer. ## Validation **Passed:** - CUDA sm_86 Release build, v0.2.2 + this commit (before: v0.2.1). `file_expert_source_test` and `--rotation-gpu` pass, including a new staged-move case with exact bytes on pinned and pageable buffers. - HIP gfx1100 Release build (ROCm 7.10 SDK), v0.2.2 + this commit: compiles and links; `file_expert_source_test` host-side passes with GPUs hidden. - Default path byte-identical to v0.2.2: stock, this branch with `STRATA_RAM_ADAPT` unset, stock again (IQ2_XS, `standard-v1`, 22 requests, fresh engines): 22/22 equal outputs (server tool-call ids left out). Fixed so that stock equals stock, adaptive VRAM tier on: `--adapt-async 0 --pcie-frac 0.10`, `STRATA_ADAPT_NOWAIT=0 STRATA_PREFILL_CPU_SHARE=0 STRATA_IQ_MT_MIN=1`. - With the option on, some answers differ from off, as they do with main's `=8`. The moves change no computation, only which experts are in pinned RAM, and only those can go to the GPU in the PCIe share of a window's misses (`expert_source.cpp`); the GPU rounds slightly differently from the CPU. With `--pcie-frac 0`, stock, this PR (`=1`) and main's `=8` give 22/22 equal outputs. - The measurements above: 48 runs (24 per model), all requests completed, identical prompt token hashes across runs. The stock profile was unchanged after every run. **Failed:** none observed. **Not run:** - SYCL build. SYCL compiles its own copies of `expert_source.cpp`, `generate.cpp` and `expert_source.hpp` (`sycl/CMakeLists.txt`), so it is not affected. - AMD GPU inference. - `standard-v1` through `strata bench run`: the request files and body were replayed through `serve/server.py` with `--greedy`, so this is not a submittable standard result. ## Limits - One machine, two quantizations (IQ2_XS, IQ3_XXS), English prompts. - Sessions of 120 requests from a cold page cache; longer serving was not measured. - Other RAM budgets and SATA drives were not measured. - Replay: https://github.com/SanghunYun/Strata/tree/ram-adapt-replay has the ShareGPT builder (dataset revision, sha256 and seed fixed), `replay.py` (also replays `standard-v1` from your checkout and records the engine's timings and storage reads), `summarize.py` (settings × runs, Welch intervals) and our per-run numbers for both models. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:35:39 +07:00
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#4428
No description provided.