Repository navigation
Conversation
As7656431
force-pushed
the
mmap-prefetch
branch
from
October 18, 2026 19:09
3454770 to
f593375
Compare
Owner
|
Thanks for the pull request. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to review properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes:
The rules are in CONTRIBUTING.md. |
…d experts.bin (STRATA_MMAP_PREFETCH, Niko1221#3065) FileExpertSource::prefetch returns at once unless staged() (the GGUF in place, an unbuffered file tier or Linux io prefetch), so in the low-RAM mode with a pack's experts.bin read through the mapping each CPU expert of the decode faults in page by page. With STRATA_MMAP_PREFETCH the layer's CPU experts (the RAM copy's skipped) go to the OS as one batch before the pool reads them: PrefetchVirtualMemory on Windows, MADV_WILLNEED elsewhere. - =1 issues the batch on the calling (dispatch) thread - =2 hands it to a helper thread and returns at once (PrefetchVirtualMemory costs about 0.2 ms a call even when every page is resident); the newest request replaces one not yet started Opt-in; unset, nothing changes. It only asks for pages ahead of time: the bytes the pool reads are the same.
…s out the file's bytes with the batch prefetch on the calling thread and on the helper thread, and the helper stops when the source goes away (Niko1221#3065)
Author
|
/reopen |
|
Reopened, thank you. A maintainer will pick it up from here. If it conflicts with main, rebase it first; that speeds up review. |
As7656431
force-pushed
the
mmap-prefetch
branch
from
October 24, 2026 09:44
f593375 to
4eefa15
Compare
As7656431
marked this pull request as draft
October 24, 2026 09:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
In the low-RAM mode with a pack's
experts.binread through the mapping (--mmap-experts, no RAM budget),FileExpertSource::prefetchreturns at once:staged()is false (no unbuffered tier, and the io prefetch is Linux only). So each expert the decode's CPU pool computes is faulted in page by page. WithSTRATA_MMAP_PREFETCHthe layer's CPU experts go to the OS as one batch (PrefetchVirtualMemoryon Windows,madvise(MADV_WILLNEED)elsewhere) before the pool reads them;=2issues the batch on a helper thread. With the variable unset nothing changes.It does on Windows what 0.2.1 turned on by default for Linux
experts.binpacks withSTRATA_IO_PREFETCH(decode x1.21-1.38 measured on an RTX 3060 with 32 GB); that path is Linux only (set_io_prefetchis under#if defined(__linux__)).On 0.2.3.1, same PC as #3063 with its daily settings (those of #3063 plus the optional control vector that the report leaves out, and
STRATA_WATCHDOG_S=180), this branch with the variable unset againstSTRATA_MMAP_PREFETCH=2, four interleaved rounds (each setting first twice), a restart before each run: a short question, another, a 20K-token English document, a short question:STRATA_MMAP_PREFETCH=2Averages of the four rounds; decode speeds are the engine's own timings. The document hides a code word, and all 8 answers found it.
Related discussion
#3065 has the problem, the measurements and the reproduction steps. There is no maintainer reply on scope yet; the switch is opt-in and no default changes. This PR was closed in the 0.2.0-beta reset; it is now rebased on
main(7ddc17a, v0.2.3.1) and re-tested there. It is independent of #3072; the two merge cleanly together.Approach
prefetch(): when the source is not staged and the variable is set, the layer's experts go toprefetch_mapped(on the calling thread) orprefetch_async(=2). Otherwiseprefetch()is unchanged.prefetch_mapped: onePrefetchVirtualMemorycall for the layer's blobs on Windows,madvise(MADV_WILLNEED)per blob elsewhere. Experts in the RAM copy are skipped. It only asks for pages ahead of time; whatblobreturns is unchanged.prefetch_async: one helper thread; the newest request replaces one that has not started, so the decode never waits for it (PrefetchVirtualMemorycosts about 0.2 ms a call even when every page is resident). The destructor stops the thread before the mapping is closed.test_mmap_prefetchintests/core/file_expert_source_test.cpp: a syntheticexperts.binread with=1and=2, every blob compared byte for byte with the file, and a request left queued when the source goes away.Validation
Passed:
-DCMAKE_CUDA_ARCHITECTURES=120 -DSTRATA_PORTABLE=ON:cmake --build build --target strataon 1087731 (this branch before the test commit; that commit touches onlytests/), andcmake --build build --target file_expert_source_testwith-DSTRATA_BUILD_TESTS=ONon 4eefa15 (the head). No new kind of compiler warning (one more C4996getenv).file_expert_source_teston 4eefa15:file_expert_source_test: PASS, withmmap prefetch (STRATA_MMAP_PREFETCH=1): bytes PASSandmmap prefetch (STRATA_MMAP_PREFETCH=2): bytes PASS. The test also passes on main 7ddc17a, and on this branch merged with [Engine] Windows low-RAM mode: STRATA_PROMPT_DIRECT=1 for a mapped experts.bin without a RAM budget (#3065) #3072.STRATA_DUMP_FIRST_LOGITSafter an 8K document and a 300-token prompt, two runs per setting, in one round with main: on the 8K document all four runs of this branch (unset twice, set twice) were bit-identical to both of main's runs. On the 300-token prompt main's two runs gave two outputs (KL 1.9e-4 between them); every run of this branch was bit-identical to one of them. The first choice was the same in every run.serve/server.pyof 7ddc17a for each run and reads the engine's own per-request timings (STRATA_DECODE_TIMING=1). The same day,tools/strata_bench.pyof 7ddc17a against main (the run in [Benchmark] RTX 5070 12 GB + 32 GB RAM on Windows 10, Flash-Next IQ2_XS low-RAM mode (0.2.3.1) #3063), medians of 3: short-chat decode 55.8 to 75.2 tok/s (the first run right after the warm-up 14.6-21.0 to 21.9-31.0), 4K prompt 87.0 to 112.6 tok/s, 16K prompt 101.3 to 94.5 tok/s (ranges 66.7-105.3 and 90.2-128.2 overlap), agent follow-up turn first token 62.8 to 47.1 s, agent decode 5.7 to 5.1 tok/s (ranges 0.7-14.4 and 0.7-24.6).Failed: none observed.
Not run:
expert_source.cpp/hpp, which every backend compiles. I would be glad if someone with a HIP or SYCL setup could build this branch; until then I am leaving it as a draft.madvise): not built or run on Linux or macOS. On Linux the default io prefetch of 0.2.1 probably covers this case better.Limits
=1(on the calling thread) was not measured here;=2is the setting I measured.