mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4446
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3086
Author: @As7656431
Created: 10/18/2026
Status: 🔄 Open
Base:
main← Head:mmap-prefetch📝 Commits (2)
1087731expert source: batch-prefetch a layer's CPU experts for a plain mapped experts.bin (STRATA_MMAP_PREFETCH, #3065)4eefa15tests: STRATA_MMAP_PREFETCH on a plain mapped experts.bin - blob hands 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 (#3065)📊 Changes
3 files changed (+146 additions, -1 deletions)
View changed files
📝
include/strata/core/expert_source.hpp(+16 -0)📝
src/core/expert_source.cpp(+79 -1)📝
tests/core/file_expert_source_test.cpp(+51 -0)📄 Description
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(7ddc17a3, 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 strataon10877310(this branch before the test commit; that commit touches onlytests/), andcmake --build build --target file_expert_source_testwith-DSTRATA_BUILD_TESTS=ONon4eefa15b(the head). No new kind of compiler warning (one more C4996getenv).file_expert_source_teston4eefa15b: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 main7ddc17a3, and on this branch merged with #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.pyof7ddc17a3for each run and reads the engine's own per-request timings (STRATA_DECODE_TIMING=1). The same day,tools/strata_bench.pyof7ddc17a3against main (the run in #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.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.