[PR #833] [CLOSED] Prefill: batched unbuffered expert reads, close the experts.bin view; opt-in RAM budget with helper caches #2860

Closed
opened 2026-11-04 02:03:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/833
Author: @adonizm
Created: 10/4/2026
Status: ❌ Closed

Base: main ← Head: pp-opt


📝 Commits (10+)

  • 749d957 setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)
  • 5a30024 calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)
  • 9f60d13 serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)
  • eb8da1d /metrics: each request's speculative draft counts, and their sums in the totals (#457)
  • 6a09387 setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)
  • d6a91e2 docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)
  • d8d4ad3 Merge branch 'f-135-eng' into rel-0.1.35
  • 7b600d5 Merge branch 'f-135-small' into rel-0.1.35
  • d9ab843 Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it
  • 57bd713 sycl: pipeline the expert cache's profile fill (model load 3-4x faster)

📊 Changes

1 file changed (+8 additions, -1 deletions)

View changed files

📝 src/program/generate.cpp (+8 -1)

📄 Description

What

Two engine changes, plus one opt-in switch, that speed up prompt reading (prefill) on a PC whose RAM cannot hold all the experts. That is the 32 GB case, where the file tier reads unbuffered.

  1. Batched stager reads (src/prefill/prefill.cpp, src/core/expert_source.cpp). Each prompt-path stager thread now claims a run of consecutive jobs. The source reads them with a single read_direct batch through the new ExpertSource::copy_blobs, which merges neighbouring blobs into requests of up to 32 MiB. Before this, every job was its own ~2 MB request. Set with STRATA_STAGER_BATCH: the default is 8 for file-backed blobs and 1 otherwise. STRATA_STAGER_BATCH=1 restores the old behaviour.
  2. Close the experts.bin view once reads are unbuffered (FileExpertSource::drop_mapping, called from generate.cpp after the RAM copy is built). While the file is mapped, NTFS serves its unbuffered reads one at a time. After startup the view is only used as a fallback, so it is closed: mapped_blob returns nullptr and every file read goes through read_direct. STRATA_KEEP_MAPPING=1 keeps the view open (A/B).
  3. STRATA_RESIDENT_REMOTE=1 (experimental, opt-in). Allows --resident-budget-gib alongside the CUDA1-3 helper caches (--expert-cache-device1). The prompt path runs on CUDA0 and streams from the source, so the RAM budget is what speeds up long prompts, while the helpers serve decode. Without the variable, the existing refusal is unchanged.

Why

On a 32 GB PC, IQ3_XXS read a 47.6K prompt at 227 tok/s. STRATA_PREFILL_TIMING=1 showed 86% of the GPU timeline waiting on expert blobs, and drive counters showed ~660 MB/s of mmap page faults. With a RAM budget and unbuffered reads it was still bound by the SSD, at queue depth 1 and ~2.3 GB/s.

A standalone test on the same drive (WD SN580, 2 MiB unbuffered reads at QD32): 2.35 GB/s with experts.bin mapped, 3.57 GB/s without. With the view closed, the drive runs at an average queue depth of 12 during prefill.

Measurements

RTX 5070 Ti 16 GB + RTX 3060 12 GB, Ryzen 7 7800X3D, 32 GB RAM, Windows (WDDM), IQ3_XXS (Swift), 47.6K-token prompt, --prefill auto:32768. One run per arm unless noted.

Configuration Prompt tok/s
Original config (8192 chunks, mmap) 226.7
--resident-budget-gib 18, release 0.1.39 1,261
same, this build, STRATA_STAGER_BATCH=1 1,260
batch 4 / 8 / 16 1,344 / 1,370 / 1,381
batch 8 + view closed 1,669
batch 8, view kept (STRATA_KEEP_MAPPING=1) 1,330
STRATA_RESIDENT_REMOTE=1, budget 16 GiB, --pool-workers 7 (two runs) 1,665 / 1,787

Decode, measured on three 600-token answers: the original config gives 33.6 tok/s. A single GPU with the RAM budget gives 35.6 tok/s. The RAM budget with the CUDA1 helper (STRATA_RESIDENT_REMOTE=1) gives 43.3 tok/s.

Notes for review

  • drop_mapping acts only when direct_ is non-empty and the source is experts.bin. It does nothing for the GGUF-in-place mode, which keeps maps_ for the token embedding and PLE. base_ stays non-null only as the "opened" mark. mapped_blob checks unmapped_, and close() skips the unmap when the view is already closed.
  • The stager batch is capped at kRing, so the earliest unfinished run never waits on a ring buffer it holds itself. A run that mixes in non-transient jobs copies those individually.
  • Outputs are not bit-identical to before. A different read order does not change any bytes, but STRATA_RESIDENT_REMOTE changes where experts are computed (GPU helper versus CPU), exactly as the helper cache already does. Generated text was checked for coherence, not with a KL comparison.
  • Not tested: Linux (drop_mapping is Windows-only by design, and copy_blobs falls back to the default loop), HIP, and layer splits.

🤖 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/833 **Author:** [@adonizm](https://github.com/adonizm) **Created:** 10/4/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pp-opt` --- ### 📝 Commits (10+) - [`749d957`](https://github.com/Niko1221/Strata/commit/749d957a1790b1a171dd4a01ab3e31b3882c9892) setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446) - [`5a30024`](https://github.com/Niko1221/Strata/commit/5a3002446dbb9dfcabb7d0bd9f113da90cc2f3c0) calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447) - [`9f60d13`](https://github.com/Niko1221/Strata/commit/9f60d13246e46b02b1dd0841980b4d18b0faaea7) serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448) - [`eb8da1d`](https://github.com/Niko1221/Strata/commit/eb8da1d8c26ec41e6ffb084fdf579dba7cad10bd) /metrics: each request's speculative draft counts, and their sums in the totals (#457) - [`6a09387`](https://github.com/Niko1221/Strata/commit/6a093874fe037020f49bd5cf053879ff6a133c21) setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444) - [`d6a91e2`](https://github.com/Niko1221/Strata/commit/d6a91e2d1770d0f469d6ec15890acc7ee93e764c) docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438) - [`d8d4ad3`](https://github.com/Niko1221/Strata/commit/d8d4ad337d3c98ba21d3bd0af1a16e9177e112b6) Merge branch 'f-135-eng' into rel-0.1.35 - [`7b600d5`](https://github.com/Niko1221/Strata/commit/7b600d55ff801caaaa11542af1523050992e049b) Merge branch 'f-135-small' into rel-0.1.35 - [`d9ab843`](https://github.com/Niko1221/Strata/commit/d9ab8435f654c368c586340d490915f6addf56a3) Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it - [`57bd713`](https://github.com/Niko1221/Strata/commit/57bd713454ddb4b965f994e95d95cacd68c93fb1) sycl: pipeline the expert cache's profile fill (model load 3-4x faster) ### 📊 Changes **1 file changed** (+8 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/program/generate.cpp` (+8 -1) </details> ### 📄 Description ## What Two engine changes, plus one opt-in switch, that speed up prompt reading (prefill) on a PC whose RAM cannot hold all the experts. That is the 32 GB case, where the file tier reads unbuffered. 1. **Batched stager reads** (`src/prefill/prefill.cpp`, `src/core/expert_source.cpp`). Each prompt-path stager thread now claims a run of consecutive jobs. The source reads them with a single `read_direct` batch through the new `ExpertSource::copy_blobs`, which merges neighbouring blobs into requests of up to 32 MiB. Before this, every job was its own ~2 MB request. Set with `STRATA_STAGER_BATCH`: the default is 8 for file-backed blobs and 1 otherwise. `STRATA_STAGER_BATCH=1` restores the old behaviour. 2. **Close the `experts.bin` view once reads are unbuffered** (`FileExpertSource::drop_mapping`, called from `generate.cpp` after the RAM copy is built). While the file is mapped, NTFS serves its unbuffered reads one at a time. After startup the view is only used as a fallback, so it is closed: `mapped_blob` returns nullptr and every file read goes through `read_direct`. `STRATA_KEEP_MAPPING=1` keeps the view open (A/B). 3. **`STRATA_RESIDENT_REMOTE=1`** (experimental, opt-in). Allows `--resident-budget-gib` alongside the CUDA1-3 helper caches (`--expert-cache-device1`). The prompt path runs on CUDA0 and streams from the source, so the RAM budget is what speeds up long prompts, while the helpers serve decode. Without the variable, the existing refusal is unchanged. ## Why On a 32 GB PC, IQ3_XXS read a 47.6K prompt at 227 tok/s. `STRATA_PREFILL_TIMING=1` showed 86% of the GPU timeline waiting on expert blobs, and drive counters showed ~660 MB/s of mmap page faults. With a RAM budget and unbuffered reads it was still bound by the SSD, at queue depth 1 and ~2.3 GB/s. A standalone test on the same drive (WD SN580, 2 MiB unbuffered reads at QD32): **2.35 GB/s with experts.bin mapped, 3.57 GB/s without.** With the view closed, the drive runs at an average queue depth of 12 during prefill. ## Measurements RTX 5070 Ti 16 GB + RTX 3060 12 GB, Ryzen 7 7800X3D, 32 GB RAM, Windows (WDDM), IQ3_XXS (Swift), 47.6K-token prompt, `--prefill auto:32768`. One run per arm unless noted. | Configuration | Prompt tok/s | |---|---:| | Original config (8192 chunks, mmap) | 226.7 | | `--resident-budget-gib 18`, release 0.1.39 | 1,261 | | same, this build, `STRATA_STAGER_BATCH=1` | 1,260 | | batch 4 / 8 / 16 | 1,344 / 1,370 / 1,381 | | batch 8 + view closed | **1,669** | | batch 8, view kept (`STRATA_KEEP_MAPPING=1`) | 1,330 | | `STRATA_RESIDENT_REMOTE=1`, budget 16 GiB, `--pool-workers 7` (two runs) | 1,665 / 1,787 | Decode, measured on three 600-token answers: the original config gives 33.6 tok/s. A single GPU with the RAM budget gives 35.6 tok/s. The RAM budget with the CUDA1 helper (`STRATA_RESIDENT_REMOTE=1`) gives 43.3 tok/s. ## Notes for review - `drop_mapping` acts only when `direct_` is non-empty and the source is `experts.bin`. It does nothing for the GGUF-in-place mode, which keeps `maps_` for the token embedding and PLE. `base_` stays non-null only as the "opened" mark. `mapped_blob` checks `unmapped_`, and `close()` skips the unmap when the view is already closed. - The stager batch is capped at `kRing`, so the earliest unfinished run never waits on a ring buffer it holds itself. A run that mixes in non-transient jobs copies those individually. - Outputs are not bit-identical to before. A different read order does not change any bytes, but `STRATA_RESIDENT_REMOTE` changes where experts are computed (GPU helper versus CPU), exactly as the helper cache already does. Generated text was checked for coherence, not with a KL comparison. - Not tested: Linux (`drop_mapping` is Windows-only by design, and `copy_blobs` falls back to the default loop), HIP, and layer splits. 🤖 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>
bsakaguchi 2026-11-04 02:03: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#2860
No description provided.