mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #89] [MERGED] loader: bulk-read the expert arena and the MTP drafter (MSVC splits ifstream reads into 4095-byte calls) #2450
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#2450
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/89
Author: @dannychirkov
Created: 9/28/2026
Status: ✅ Merged
Merged: 9/29/2026
Merged by: @Niko1221
Base:
main← Head:fix/msvc-expert-loader-bulk-read📝 Commits (2)
5edb9d6loader: read the expert arena in bulk instead of std::ifstreamcc1d8e8mtp: bulk-read the drafter shards as well📊 Changes
6 files changed (+140 additions, -20 deletions)
View changed files
📝
include/strata/core/expert_source.hpp(+9 -0)📝
include/strata/core/pinned.hpp(+25 -0)📝
src/core/expert_source.cpp(+10 -0)📝
src/core/load_main.cpp(+4 -1)📝
src/core/mtp.cpp(+40 -10)📝
src/core/pinned.cu(+52 -9)📄 Description
loader: bulk-read the expert arena and the MTP drafter
What this fixes
On a Windows/MSVC build,
std::ifstream::readis not one read.basic_filebuf::xsgetn(__msvc_filebuf.hpp) loops over
so every streaming read is chopped into 4095-byte
freadcalls. For the IQ3_XXS pack(one 42.9 GB
experts.bin, arena ~40 GiB) that is ~11.4 million reads, and the load isdominated by per-call overhead, not by the disk. Measured on this machine: 4095.8 bytes
per operation over ~11.4M operations, 0.03 GiB/s effective read rate, 1222 s for the
expert phase. The same defect was present in the drafter path (
src/core/mtp.cpp:read_fileofdense.binand the 512 x 64 MiB expert loop).src/core/expert_source.cpphas the samestd::ifstreamread in its GGUF branch(
load_experts_gguf); it is not touched here because the pack path is the one thisreport measures, but it is the same pattern and probably wants the same fix.
What changed
src/core/pinned.cu,include/strata/core/pinned.hpp,src/core/expert_source.cpp,include/strata/core/load_main.cpp- read the arena withfopen/freadand an explicit64-bit seek (
_fseeki64), with a short-read check that fails the load (LoadStats.ok,LoadStats.error) instead of silently continuing with partial data.src/core/mtp.cpp- the same for the drafter: the whole-filedense.binread and the512-expert loop (
_fseeki64/_ftelli64).The bytes read, the call sites and the behaviour on Linux/glibc are unchanged; only the
read path is.
Measurements
One machine, one config (64K context,
--expert-cache 2500,--kv int8, MTP on), coldstart, only the binary differs between the three arms. Boundaries are the same for
every arm and every number below:
READY at N s, from process start (the harness reads thesame instant as
ready_s_engine_clock).expert load phases:line (the original has no suchtimer; its number is derived from its own
loaded 39.97 GiB at 0.03 GiB/s, i.e.39.97 / 0.0327).
(The expert phase reads 39.97 GiB; the rate in the engine's own line is 39.97 GiB / phase
wall, while the harness also reports the summed per-thread read time, 217.86 s over 6
threads = 78% of the phase wall, i.e. 1.10 GiB/s while actually reading.)
This says nothing about generation speed. Decode was not measured in these arms and
this change does not touch it; the only generation run here is a short prompt to prove the
engine serves requests.
Verification
side, with the bodies taken verbatim out of the source: 8/8 offsets reproduce the
original bytes, including offsets above 4 GiB (layer 0 @ 0, layer 6 @ 4 928 307 200,
layer 47 @ 41 798 860 800, a 3 MiB + 615 B block), 48/48 layers match, and the
reassembled files are byte-identical to the originals (external
sha256sumof thereassembled files matches the files themselves).
ok = 0withshort read in layer 0: got 6815744 of 6819840 B at offset 42906157056.1.43 s -> 0.47 s, a truncated file (700 000 000 of 707 788 800 B) and a missing file are
both refused, and the reassembled bytes match the files'
sha256sum.main(v0.1.20) and compile clean there with the sametoolchain (MSVC 14.44.35207 / CUDA 13.0 / Ninja, Release), so the patch is not tied to the
0.1.15 tree the numbers above come from. The numbers themselves were taken on 0.1.15+these
two patches; only the binary differed between arms.
Caveats
consistent with a limited file cache but does not by itself prove that the read was
fully cold. The fix was not derived from that observation; it was found in the STL
source and then confirmed by the differential stand above.
were local instrumentation, and
src/program/generate.cpphas changed upstream since),nor a version-stamp change in
CMakeLists.txt.Environment
Windows 11, MSVC 14.44.35207 / cl 19.44.35229 (Ninja generator), CUDA 13.0 V13.0.48,
CMake 4.3.1, Ryzen 9 3900X, 64 GB DDR4-3200, PCIe 3.0 x8/x8, RTX 5060 Ti 16 GB
(sm_120) + GTX 1050 Ti, pack: ISTA-DASLab GSQ-RCO IQ3_XXS (2 shards + PLE, 3.06 bit/w,
48 layers, 512 experts).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.