[PR #1323] [CLOSED] prefill: batched unbuffered stager reads; close the experts.bin view once reads are unbuffered (port of #833) #3382

Closed
opened 2026-11-07 14:41:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1323
Author: @malloc32
Created: 10/7/2026
Status: ❌ Closed

Base: main ← Head: pr/833-stager-reads


📝 Commits (1)

  • d3659bc prefill: batched unbuffered expert reads in the stager; close the experts.bin view once reads are unbuffered

📊 Changes

4 files changed (+124 additions, -19 deletions)

View changed files

📝 include/strata/core/expert_source.hpp (+12 -0)
📝 src/core/expert_source.cpp (+61 -1)
📝 src/prefill/prefill.cpp (+43 -18)
📝 src/program/generate.cpp (+8 -0)

📄 Description

AI-written. This PR was prepared by an AI (Claude Opus 5.5, via Claude Code) at the submitter's request; the code, the port and the measurements were done by the AI on the submitter's machine, and the submitter reviewed it before opening.

Update 2026-10-07: rebased onto 0.1.40.2 (e8ca9af). The one conflict was the Stager's wait in src/prefill/prefill.cpp: the release's sleeping wait (stager_sleep(), Linux by default) now applies to each job of a claimed run, beside the batched reads.

What

A port of @adonizm's #833 onto the current main (it was closed by the history rewrite, not rejected). Two changes:

  1. The prompt path's stager claims runs of consecutive jobs and reads them with one read_direct batch (ExpertSource::copy_blobs), merging neighbouring blobs into requests of up to 32 MiB. STRATA_STAGER_BATCH (default 8 for file-backed blobs, 1 otherwise).
  2. Once the file tier reads unbuffered, the mapped view of experts.bin is closed (FileExpertSource::drop_mapping, Windows): while it is mapped, NTFS serves the unbuffered reads one at a time. STRATA_KEEP_MAPPING=1 keeps it.

Two fixes on the way: unmapped_ is declared on every platform (mapped_blob reads it outside the Windows block, so Linux did not compile), and copy_blobs asks resident_blob, which follows the exchange rotation (STRATA_EXCHANGE_ROTATE).

Measured

i7-12700K, 64 GB, 2x RTX 5060 Ti (layer split), IQ3_S, experts.bin on a Samsung 990 PRO, --resident-budget-gib 8, unbuffered reads: prompt 513 -> 623 tok/s at 8K, 962 -> 1,198 at 32K. Batching gives most of it; closing the view adds 4-5%. The original author's numbers: 1,261 -> 1,669 tok/s at 47.6K.

Not tested

Linux and HIP builds (the Linux fix was checked with a syntax-only compile).

🤖 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/1323 **Author:** [@malloc32](https://github.com/malloc32) **Created:** 10/7/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/833-stager-reads` --- ### 📝 Commits (1) - [`d3659bc`](https://github.com/Niko1221/Strata/commit/d3659bc752b101d422090fed7d6c24f19e0ebc11) prefill: batched unbuffered expert reads in the stager; close the experts.bin view once reads are unbuffered ### 📊 Changes **4 files changed** (+124 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/expert_source.hpp` (+12 -0) 📝 `src/core/expert_source.cpp` (+61 -1) 📝 `src/prefill/prefill.cpp` (+43 -18) 📝 `src/program/generate.cpp` (+8 -0) </details> ### 📄 Description **AI-written.** This PR was prepared by an AI (Claude Opus 5.5, via Claude Code) at the submitter's request; the code, the port and the measurements were done by the AI on the submitter's machine, and the submitter reviewed it before opening. **Update 2026-10-07:** rebased onto 0.1.40.2 (`e8ca9af`). The one conflict was the Stager's wait in `src/prefill/prefill.cpp`: the release's sleeping wait (`stager_sleep()`, Linux by default) now applies to each job of a claimed run, beside the batched reads. ## What A port of @adonizm's #833 onto the current `main` (it was closed by the history rewrite, not rejected). Two changes: 1. The prompt path's stager claims runs of consecutive jobs and reads them with one `read_direct` batch (`ExpertSource::copy_blobs`), merging neighbouring blobs into requests of up to 32 MiB. `STRATA_STAGER_BATCH` (default 8 for file-backed blobs, 1 otherwise). 2. Once the file tier reads unbuffered, the mapped view of `experts.bin` is closed (`FileExpertSource::drop_mapping`, Windows): while it is mapped, NTFS serves the unbuffered reads one at a time. `STRATA_KEEP_MAPPING=1` keeps it. Two fixes on the way: `unmapped_` is declared on every platform (`mapped_blob` reads it outside the Windows block, so Linux did not compile), and `copy_blobs` asks `resident_blob`, which follows the exchange rotation (`STRATA_EXCHANGE_ROTATE`). ## Measured i7-12700K, 64 GB, 2x RTX 5060 Ti (layer split), IQ3_S, `experts.bin` on a Samsung 990 PRO, `--resident-budget-gib 8`, unbuffered reads: prompt **513 -> 623 tok/s at 8K, 962 -> 1,198 at 32K**. Batching gives most of it; closing the view adds 4-5%. The original author's numbers: 1,261 -> 1,669 tok/s at 47.6K. ## Not tested Linux and HIP builds (the Linux fix was checked with a syntax-only compile). 🤖 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-07 14:41:05 +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#3382
No description provided.