[PR #4065] [CLOSED] [Engine] Fill the startup expert profile with several threads (STRATA_FILL_THREADS) #4893

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4065
Author: @chenyb999-zhcn
Created: 10/25/2026
Status: ❌ Closed

Base: main ← Head: engine-fill-parallel


📝 Commits (2)

  • 0ee8937 engine: fill the startup expert profile with several threads (STRATA_FILL_THREADS, default 8): admit every pair serially first, then run blob_stable and fill_slot_blocking over disjoint slots on workers (the decode-time refill already does this concurrently); the layer-split stages' fills get the advise-free-parallelism they never had, plus the timing line; the unbuffered tier and STRATA_FILL_THREADS=0/1 keep the sequential loop unchanged (#4064)
  • 0b2e1cd engine: the parallel profile fill also takes the unbuffered tier: the 64-pair batch loop is a serial reader (82 MB/s on the box of #4064, 503 s startup, against 1372 MB/s from the same parallel workers on the same O_DIRECT tier; startup 503 s -> 62 s, the stage fill 146.8 s -> 16.4 s), and RouterLookahead::warm stops hinting the mapping with MADV_WILLNEED when the reads bypass the page cache (one fill measured 728k hints, 3.7 GB of readahead for nobody, competing with the reads that matter); STRATA_FILL_THREADS<=1 still keeps the sequential batch loop unchanged (#4064)

📊 Changes

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

View changed files

📝 docs/DETAILS.md (+3 -0)
📝 include/strata/core/expert_cache.hpp (+4 -1)
📝 src/core/expert_source.cpp (+2 -0)
📝 src/program/generate.cpp (+141 -10)

📄 Description

Closes #4064

Problem and result

A cold --serve start of a 48-layer MoE (Qwen3.8-Flash-Next UD-Q4_K_XL, 108 GB of GGUF in four shards) on a
2x Tesla V100 32 GB / 96 GB RAM box reads ~115 GiB: the PLE n-gram table (26.8 GiB), the dense weights (5.7 GiB),
the startup expert profile (48.6 GiB into the two GPU caches) and the 8-30 GiB page-locked RAM complement. Only
the expert fills read with a deep queue; everything else read as a single stream through the page cache, one
128 KiB window or one 4 KiB fault at a time.

A cold start before this PR (298 s wall clock, drop_caches in the launch script, --resident-budget-gib 32):

phase bytes time rate
token embedding 644 MiB 11.0 s 58 MB/s
pack dense weights 1416 MiB 23.6 s 60 MB/s
495 native projection matrices 3619 MiB 60.4 s 60 MB/s
PLE table --ple-io ram 26.8 GiB 120.1 s 240 MB/s
profile fill CUDA0 25.09 GiB 19.6 s 1378 MB/s
profile fill CUDA1 23.55 GiB 17.1 s 1476 MB/s
RAM complement 30.28 GiB 33 s ~985 MB/s

72% of that start sat in the first four rows: 34.5 GiB read through the page cache against a drive that does
813 MB/s for random 1 MiB reads at queue depth 1 and 1.4-1.9 GB/s with 8-63 requests in flight.

The same start after this series (same box, same config, no drop_caches in the script, --resident-budget-gib 8):

phase before after
pack dense 1416 MiB 23.6 s 0.3 s (resident) / 2.7 s (cold)
495 projection matrices 3619 MiB 60.4 s 18.0 s
PLE table (see #4104 / #4105) 120.1 s 24.2 s @1188 MB/s
MTP draft layer 835 MiB 13.6 s 1.1 s
profile fill CUDA0 19.6 s 20.3 s (unchanged, already at the drive's rate)
profile fill CUDA1 17.1 s 16.6 s (unchanged)
whole start 298 s 110 s

What changed

Four independent fixes, each one turning a serialized read into the machine's real parallelism:

  1. The startup profile fill runs on several threads (STRATA_FILL_THREADS, default 8) - parallel_profile_fill
    over disjoint slots, blob_stable + fill_slot_blocking per worker, the shape the decode-time refill already
    used. STRATA_FILL_THREADS<=1 keeps the old sequential loop. It also walks the pairs in (layer, expert)
    order instead of profile order: the profile is ranked by routing frequency, which turned the fill into a random
    walk over the two 49 GiB shards (see the limits below).
  2. The unbuffered tier takes the parallel fill too, and RouterLookahead::warm stops hinting the mapping with
    MADV_WILLNEED when the file tier reads O_DIRECT - the hint was feeding a page cache that the reads
    deliberately bypass (728,160 hints / 3.7 GB in a 422 s strace window).
  3. platform::advise_willneed asks for read-ahead in 4 MiB steps, not 128 KiB. Every step is one read-ahead
    window and the caller waits for it, so a 3.6 GiB projection load queued ~29k windows one after another. The
    128 KiB walk is what turned a 1.4 GB/s drive into 60 MB/s (23.6 s -> 10.3 s on the pack's 1416 MiB alone).
  4. platform::read_range_direct + populate_read: the dense weights, the token embedding, the
    hyper-connection Q8 matrices and the drafter's files are staged through 4 MiB O_DIRECT requests (one cached
    descriptor per file - the projection loop used to open and close one 495 times) instead of being copied out of
    the mapping one page fault at a time; and a tensor whose pages are already resident is copied straight from the
    mapping (resident_fraction, measured with mincore), so a warm start does no drive I/O for it at all.

Validation

Same box, engine 0.1.50 built from this branch:

  • fill A/B with everything else equal, STRATA_UNBUFFERED_LOAD=1, cold: CUDA0 profile fill 329.0 s @82 MB/s ->
    19.6 s @1372 MB/s; CUDA1 stage fill 146.8 s -> 16.4 s @1544 MB/s; startup 503 s -> 62 s.
  • MADV_WILLNEED hints during a fill: 728,160 (3.7 GB) -> 0.
  • dense: pack 23.6 s -> 2.7 s cold / 0.3 s resident; projections 60.4 s -> 18.0 s cold.
  • MTP draft: 13.6 s -> 1.1 s.
  • whole cold start: 298 s -> 110 s (00:52:40 -> 00:54:30 in the log of the reporting box).

Limits

  • The drive, not the engine, is the remaining variable. On this box (ZhiTai Ti600 1TB, DRAM-less QLC, 40 MiB
    host memory buffer, firmware ZTA23001) the controller periodically drops its command service rate by ~25x for one
    to seven minutes while reporting itself 100% busy. Measured with a per-second /proc/diskstats monitor plus
    contrast probes taken during an episode: read 59-61 MB/s, 480-490 completions/s (against ~12,500/s when
    healthy), io_ticks 97-99%, average queue depth 78-241, and - the point - sequential and scattered reads are
    equally dead
    (1.9-10 MB/s sequential against 4-8 MB/s for 256 scattered 1 MiB reads), so it is the device, not
    the access pattern. Controls: no host writes in the window (Data Units Written flat), no other reader, no swap,
    APST disabled and the power state pinned to PS0 (the episode still happened), thermal management transition
    counts at 0 with the drive at 48-49 C against a 90 C warning threshold, and SMART/media errors unchanged. The
    same start pattern immediately before and after runs at 1120-1300 MB/s mean and finishes in 138 s. In the same
    start one phase can stall and the next run normally (one run: PLE 432 s @67 MB/s, then every later phase at full
    speed). Also relevant: max_hw_sectors_kb is 128 on this drive, so every 4 MiB read is 32 NVMe commands - a
    healthy drive here answers ~12,500/s, an episode ~500/s. What remains is inside the drive; walking the fill in
    file order (commit 1) removes the scatter that makes it worse, but it cannot remove a stall.
  • This does not remove the ~115 GiB of reads, it makes them use the drive. On a 96 GB box the page cache cannot
    hold the model (26.8 GiB locked PLE + 8-30 GiB resident complement + 8 GiB conversation cache leave ~45 GiB for
    108 GB of shards), so a start that drops the caches always re-reads everything. Keeping the caches (no
    drop_caches) plus a small --resident-budget-gib is what makes the dense/embedding stage free; the expert
    fills stay unbuffered by design.
  • --resident-budget-gib trades startup against decode, measured on the same box with one 7,878-token prompt
    (identical runs otherwise): 8 GiB -> 9 s of complement, decode 26.2 tok/s, 84.9 GB of experts read from the file
    for that prompt; 24 GiB -> 27 s of complement (+18 s of startup), decode 56.6 tok/s, 65.3 GB read (23% less).
    Prefill went the other way in the one clean pair (274 vs 104 tok/s), because at 8 GiB the file tier keeps a
    15.1 GiB page cache that the prompt path streams from. So: 24 GiB for decode-heavy use, 8 GiB when restarts must
    be as short as possible - the fills are at the drive's rate either way.
  • The PLE table's own populate is #4104 / #4105; the chunked/probe variants of it live in that PR's series.
  • Windows gets nothing from read_range_direct/populate_read (its copies go on faulting the mapping as before);
    the advising step applies to every platform.

🔄 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/4065 **Author:** [@chenyb999-zhcn](https://github.com/chenyb999-zhcn) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `engine-fill-parallel` --- ### 📝 Commits (2) - [`0ee8937`](https://github.com/Niko1221/Strata/commit/0ee8937289d1ef4ce5f108add2e732af707b9fd9) engine: fill the startup expert profile with several threads (STRATA_FILL_THREADS, default 8): admit every pair serially first, then run blob_stable and fill_slot_blocking over disjoint slots on workers (the decode-time refill already does this concurrently); the layer-split stages' fills get the advise-free-parallelism they never had, plus the timing line; the unbuffered tier and STRATA_FILL_THREADS=0/1 keep the sequential loop unchanged (#4064) - [`0b2e1cd`](https://github.com/Niko1221/Strata/commit/0b2e1cdd7b7a7ed88cf1ddd89f2a626fa36d95b7) engine: the parallel profile fill also takes the unbuffered tier: the 64-pair batch loop is a serial reader (82 MB/s on the box of #4064, 503 s startup, against 1372 MB/s from the same parallel workers on the same O_DIRECT tier; startup 503 s -> 62 s, the stage fill 146.8 s -> 16.4 s), and RouterLookahead::warm stops hinting the mapping with MADV_WILLNEED when the reads bypass the page cache (one fill measured 728k hints, 3.7 GB of readahead for nobody, competing with the reads that matter); STRATA_FILL_THREADS<=1 still keeps the sequential batch loop unchanged (#4064) ### 📊 Changes **4 files changed** (+150 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+3 -0) 📝 `include/strata/core/expert_cache.hpp` (+4 -1) 📝 `src/core/expert_source.cpp` (+2 -0) 📝 `src/program/generate.cpp` (+141 -10) </details> ### 📄 Description Closes #4064 ## Problem and result A cold `--serve` start of a 48-layer MoE (Qwen3.8-Flash-Next UD-Q4_K_XL, 108 GB of GGUF in four shards) on a 2x Tesla V100 32 GB / 96 GB RAM box reads ~115 GiB: the PLE n-gram table (26.8 GiB), the dense weights (5.7 GiB), the startup expert profile (48.6 GiB into the two GPU caches) and the 8-30 GiB page-locked RAM complement. Only the expert fills read with a deep queue; everything else read as a single stream through the page cache, one 128 KiB window or one 4 KiB fault at a time. A cold start before this PR (298 s wall clock, `drop_caches` in the launch script, `--resident-budget-gib 32`): | phase | bytes | time | rate | |---|---|---|---| | token embedding | 644 MiB | 11.0 s | 58 MB/s | | pack dense weights | 1416 MiB | 23.6 s | 60 MB/s | | 495 native projection matrices | 3619 MiB | 60.4 s | 60 MB/s | | PLE table `--ple-io ram` | 26.8 GiB | 120.1 s | 240 MB/s | | profile fill CUDA0 | 25.09 GiB | 19.6 s | 1378 MB/s | | profile fill CUDA1 | 23.55 GiB | 17.1 s | 1476 MB/s | | RAM complement | 30.28 GiB | 33 s | ~985 MB/s | 72% of that start sat in the first four rows: 34.5 GiB read through the page cache against a drive that does 813 MB/s for random 1 MiB reads at queue depth 1 and 1.4-1.9 GB/s with 8-63 requests in flight. The same start after this series (same box, same config, no `drop_caches` in the script, `--resident-budget-gib 8`): | phase | before | after | |---|---|---| | pack dense 1416 MiB | 23.6 s | **0.3 s** (resident) / 2.7 s (cold) | | 495 projection matrices 3619 MiB | 60.4 s | **18.0 s** | | PLE table (see #4104 / #4105) | 120.1 s | 24.2 s @1188 MB/s | | MTP draft layer 835 MiB | 13.6 s | **1.1 s** | | profile fill CUDA0 | 19.6 s | 20.3 s (unchanged, already at the drive's rate) | | profile fill CUDA1 | 17.1 s | 16.6 s (unchanged) | | **whole start** | **298 s** | **110 s** | ## What changed Four independent fixes, each one turning a serialized read into the machine's real parallelism: 1. **The startup profile fill runs on several threads** (`STRATA_FILL_THREADS`, default 8) - `parallel_profile_fill` over disjoint slots, `blob_stable` + `fill_slot_blocking` per worker, the shape the decode-time refill already used. `STRATA_FILL_THREADS<=1` keeps the old sequential loop. It also walks the pairs in **(layer, expert)** order instead of profile order: the profile is ranked by routing frequency, which turned the fill into a random walk over the two 49 GiB shards (see the limits below). 2. **The unbuffered tier takes the parallel fill too**, and `RouterLookahead::warm` stops hinting the mapping with `MADV_WILLNEED` when the file tier reads `O_DIRECT` - the hint was feeding a page cache that the reads deliberately bypass (728,160 hints / 3.7 GB in a 422 s strace window). 3. **`platform::advise_willneed` asks for read-ahead in 4 MiB steps, not 128 KiB.** Every step is one read-ahead window and the caller waits for it, so a 3.6 GiB projection load queued ~29k windows one after another. The 128 KiB walk is what turned a 1.4 GB/s drive into 60 MB/s (23.6 s -> 10.3 s on the pack's 1416 MiB alone). 4. **`platform::read_range_direct` + `populate_read`**: the dense weights, the token embedding, the hyper-connection Q8 matrices and the drafter's files are staged through 4 MiB O_DIRECT requests (one cached descriptor per file - the projection loop used to open and close one 495 times) instead of being copied out of the mapping one page fault at a time; and a tensor whose pages are already resident is copied straight from the mapping (`resident_fraction`, measured with `mincore`), so a warm start does no drive I/O for it at all. ## Validation Same box, engine 0.1.50 built from this branch: - fill A/B with everything else equal, `STRATA_UNBUFFERED_LOAD=1`, cold: CUDA0 profile fill 329.0 s @82 MB/s -> **19.6 s @1372 MB/s**; CUDA1 stage fill 146.8 s -> **16.4 s @1544 MB/s**; startup 503 s -> 62 s. - `MADV_WILLNEED` hints during a fill: 728,160 (3.7 GB) -> **0**. - dense: pack 23.6 s -> 2.7 s cold / 0.3 s resident; projections 60.4 s -> 18.0 s cold. - MTP draft: 13.6 s -> 1.1 s. - whole cold start: 298 s -> **110 s** (00:52:40 -> 00:54:30 in the log of the reporting box). ## Limits - **The drive, not the engine, is the remaining variable.** On this box (ZhiTai Ti600 1TB, DRAM-less QLC, 40 MiB host memory buffer, firmware ZTA23001) the controller periodically drops its command service rate by ~25x for one to seven minutes while reporting itself 100% busy. Measured with a per-second `/proc/diskstats` monitor plus contrast probes taken *during* an episode: read 59-61 MB/s, 480-490 completions/s (against ~12,500/s when healthy), `io_ticks` 97-99%, average queue depth 78-241, and - the point - **sequential and scattered reads are equally dead** (1.9-10 MB/s sequential against 4-8 MB/s for 256 scattered 1 MiB reads), so it is the device, not the access pattern. Controls: no host writes in the window (`Data Units Written` flat), no other reader, no swap, `APST` disabled and the power state pinned to PS0 (the episode still happened), thermal management transition counts at **0** with the drive at 48-49 C against a 90 C warning threshold, and SMART/media errors unchanged. The same start pattern immediately before and after runs at 1120-1300 MB/s mean and finishes in 138 s. In the same start one phase can stall and the next run normally (one run: PLE 432 s @67 MB/s, then every later phase at full speed). Also relevant: `max_hw_sectors_kb` is 128 on this drive, so every 4 MiB read is 32 NVMe commands - a healthy drive here answers ~12,500/s, an episode ~500/s. What remains is inside the drive; walking the fill in file order (commit 1) removes the scatter that makes it worse, but it cannot remove a stall. - This does not remove the ~115 GiB of reads, it makes them use the drive. On a 96 GB box the page cache cannot hold the model (26.8 GiB locked PLE + 8-30 GiB resident complement + 8 GiB conversation cache leave ~45 GiB for 108 GB of shards), so a start that drops the caches always re-reads everything. Keeping the caches (no `drop_caches`) plus a small `--resident-budget-gib` is what makes the dense/embedding stage free; the expert fills stay unbuffered by design. - `--resident-budget-gib` trades startup against decode, measured on the same box with one 7,878-token prompt (identical runs otherwise): 8 GiB -> 9 s of complement, decode 26.2 tok/s, 84.9 GB of experts read from the file for that prompt; 24 GiB -> 27 s of complement (+18 s of startup), decode 56.6 tok/s, 65.3 GB read (23% less). Prefill went the other way in the one clean pair (274 vs 104 tok/s), because at 8 GiB the file tier keeps a 15.1 GiB page cache that the prompt path streams from. So: 24 GiB for decode-heavy use, 8 GiB when restarts must be as short as possible - the fills are at the drive's rate either way. - The PLE table's own populate is #4104 / #4105; the chunked/probe variants of it live in that PR's series. - Windows gets nothing from `read_range_direct`/`populate_read` (its copies go on faulting the mapping as before); the advising step applies to every platform. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:09 +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#4893
No description provided.