mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3378] [CLOSED] [Other] tools: read the FP4-Local checkpoint with cached sequential reads, not a process-lifetime np.memmap #4601
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#4601
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/3378
Author: @jerry78424
Created: 10/20/2026
Status: ❌ Closed
Base:
main← Head:fix-ckpt-bufread📝 Commits (1)
97289eatools: read the FP4-Local checkpoint with cached sequential reads, not a process-lifetime np.memmap📊 Changes
2 files changed (+63 additions, -5 deletions)
View changed files
📝
tools/nvfp4_local_pack.py(+22 -5)📝
tools/test_nvfp4_local_pack.py(+41 -0)📄 Description
Fixes #3377. Related: #3227 / #3228 (a different failure of the same step; no hunk overlap — that PR touches the overlay gens around
:191-211, this one theCheckpointclass at:48-91).The problem and the result
preparefails mid-pack on Windows: the pack python dies at 50–67 % of the experts write, exit 1, no traceback, while its own committed memory is ~3.5 GB.Checkpoint.raw()maps every shard withnp.memmap(..., mode="r")for the process's life; the pack pass reads 64.36 GB of distinct expert bytes, and on Windows every faulted page is charged to the process working set, whichullAvailPhys(= psutilavailable=os.freemem= our ownram_used,serve/telemetry.py:624-625) counts as used until the OS trims — the step presents a ~64 GB RAM demand for a few-GB real one (issue: +41 GB in five minutes, run dead at ~11 GB free).With this change the same reads return hash-identical bytes, run ~1.2x faster warm, and the working set stays flat — a full 68 GB pack run to a scratch dir with the serving model loaded (the scenario that failed): exit 0, byte-identical
experts.bin, working set 3.3–5.3 GB bounded (externally sampled), free RAM never below ~53 GB.The approach
Checkpoint.raw()reads the tensor's byte range through a cached file handle withseek+readintointo a fresh buffer; the kernel's pages then live in the system file cache (standby: counted as available) instead of the process working set.array()'s.view().reshape()contract (buffers >=8-byte aligned; U8/U16/U32/F32 all used); it is writable wheremode="r"was read-only — no consumer writes (all produce fresh outputs; a mutator would previously have raised through numpy or faulted through a torch view) — andraw()shares one handle per shard, so it is not thread-safe, unlike the memmap it replaces; all call sites are single-threaded.readintobounds it to ~0. Within a shard the order walks three ascending streams (exceptions, weights, CSF-fixed) expert-ascending. np.memmap has no Windows lever (noFILE_FLAG_SEQUENTIAL_SCAN/madvise equivalent).iq_pack.py:161,218,324(~6 GB dense.gguf) andLocalTensor.mmap_bytesin convert (~4 GB).Validation
python -m pytest tools/test_nvfp4_local_pack.py: 13 — the 11 existing (they never constructCheckpoint) plus 2 added here: a synthetic two-shard checkpoint (byte-exact reads at a tensor's range,array()dtype/shape views, repeat reads, truncated shard ->EOFErrorinstead of a silent short view).--outwith the serving model loaded: exit 0,experts.binsize identical (67,948,118,016 bytes), SHA-256 match1e124ee94b7c921a7c895d2898bfa4ddc2d8111f3fd3e8b94207759c363291a5; externally sampled working set 3.3–5.3 GB bounded, free 53.3–60.0 GB throughout (in-run 15 s sampler; pre-patch signature: +41 GB in 5 min).ple/mtp/verifyindividually (same class, different call sites, covered by the new class tests); Linux/AMD (OS-neutral file I/O; the inflation mechanism is Windows-specific).Limits
readintoreturns short only at EOF (the buffering layer absorbs partial raw reads); the addedEOFErrornames a truncated shard instead of the old silent short memmap view — a behavior change only for corrupt checkpoints.Environment: tested at
e88ee39d(v0.2.0-beta-12), Windows 11 26200, Ryzen 7 9800X3D, 187 GB RAM, RTX 5090 (driver 617.42), NVMe, modelnvidia/Qwen3.8-Flash-Next-FP4-Local.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.