Repository navigation
fix(dsv41): the loader reads each layer's expert run from the rank cache whole - #18
Merged
bertholomus merged 1 commit intoOct 17, 2026
Conversation
…che whole Loader.experts() visits a layer's expert entries pass by pass (every gate trellis, then every up, then every down, then each suh/svh stack), but the rank cache stores them expert by expert, so a load made nine strided sweeps over each layer's ~2.4 GiB and defeated kernel readahead (recipe issue bertholomus#24). experts() now takes the byte extent of the layer's expert entries from the index, reads it whole with O_DIRECT (core/direct_io, 64 MiB pieces) into one aligned buffer and serves the entries inside it as views; visiting order, uploads and layouts are unchanged, and a failed direct read logs a warning and falls back to per-entry reads. rank_cache.writeFake is pub for the new test. 2x GB10, 2.9 bpw pack, cold page cache: tf-dsv41-load --cache 66.3 / 67.4 s -> 15.7 / 15.7 s per rank, served rank 0 loaded in 70.8 s -> 19.3 s; 2123 of 2252 tensors byte-identical across builds (the other 129 are the *.ffn.experts.ptr0/1/2 device-address tables) and greedy replies on three prompts unchanged. zig build test green (19/19 steps, 184/184 tests) on Zig 0.17.0 aarch64; lean_check at the branch's 1420. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
Thank you @lepetitprince716-prog, this is a clean fix. We ran the tests (184 of 184 pass, your new one included), built the node binaries, and read the span and fallback paths: the loaded bytes stay the same, and the span buffer is freed before the pools are sized. Merged into Thanks also to @dylandoesai for the careful measurements in bertholomus/deepseek-v4.1-tensorfold-tp2-2xgb10#24. |
bertholomus
pushed a commit
that referenced
this pull request
Oct 20, 2026
…che whole (#18) Loader.experts() visits a layer's expert entries pass by pass (every gate trellis, then every up, then every down, then each suh/svh stack), but the rank cache stores them expert by expert, so a load made nine strided sweeps over each layer's ~2.4 GiB and defeated kernel readahead (recipe issue #24). experts() now takes the byte extent of the layer's expert entries from the index, reads it whole with O_DIRECT (core/direct_io, 64 MiB pieces) into one aligned buffer and serves the entries inside it as views; visiting order, uploads and layouts are unchanged, and a failed direct read logs a warning and falls back to per-entry reads. rank_cache.writeFake is pub for the new test. 2x GB10, 2.9 bpw pack, cold page cache: tf-dsv41-load --cache 66.3 / 67.4 s -> 15.7 / 15.7 s per rank, served rank 0 loaded in 70.8 s -> 19.3 s; 2123 of 2252 tensors byte-identical across builds (the other 129 are the *.ffn.experts.ptr0/1/2 device-address tables) and greedy replies on three prompts unchanged. zig build test green (19/19 steps, 184/184 tests) on Zig 0.17.0 aarch64; lean_check at the branch's 1420. Co-authored-by: lepetitprince716-prog <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 9a0c014)
bertholomus
added a commit
that referenced
this pull request
Oct 20, 2026
…ything new (tp2 #18) --loop-guard watched only for an exact cycle of at most eight tokens. A templated reasoning loop, each line fresh while its token 8-grams recycle, has no such cycle: @Capicua25x saw the guard fire 0 times on 6 such runaways in production traffic (tp2 #18). The guard now also counts, in windows of 1,024 reply tokens while the think block is open, the share of the window's token 8-grams (with the 7 tokens before it) that no earlier window had; that many windows in a row under 2% close the think block the way a cycle does. This is our Python engine's call_gate.ThinkLoop (the novelty signal of tp2 #9, on token ids), next to cycleAt, which stays the first check. - TENSORFOLD_LOOP_WINDOWS: the dry windows in a row (default 10; 0: exact cycles only). Python's 3 cut a legitimate long deliberation in @Capicua25x's traffic; 10 still caught every runaway they captured. - runtime.loop.novelty: the closing window's share of new grams; the server log says loop=novelty:0.0000. - Without --loop-guard nothing changes. With it, a reply with an exact cycle closes as before and reports runtime.loop.period; only a reply the cycle check misses can close earlier. - loopCut finds the window end in a round's tokens, so drafted rounds close where single tokens do. As in ThinkLoop.cut, only a batch's first window end may fire (rounds are far shorter than a window). Tests: each window's share equals the Python reference's (a loop of 13, and a three-letter LCG text over 60 windows); the fire points equal the reference's on four sequences at 3 and 10 windows, a token at a time and in rounds of 7 and 48; a loop of 13 closes thinking through the lane engine, drafted equal to plain. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 94725fbbf0cb834343e6e6f5f23307a7f4f37bfb)
bertholomus
added a commit
that referenced
this pull request
Oct 20, 2026
The four-node line that serves DeepSeek-V4.1-Flash-1017 on four GB10 nodes comes in as its own commits: the two-node port's fixes since v0.1.1, the four-node commits rebased onto them, TensorFold 1.0.12 merged under the family, and the fixes since. This merge keeps the branch a fast-forward of v0.1.1 (5940208). Against v0.1.1: - TensorFold 1.0.12 under the family (047441d). - The two-node port's fixes: a launch with no captured Triton variant runs the closest more general one; Pillow's child is started again if it dies; a request the pool cannot hold yet waits for a stream to end; TF_DS_RING_ZERO and TF_DS_REPLAY_FLOOR (both off by default). - Every rank checks its settings against rank 0's at the start; TENSORFOLD_SSE_KEEPALIVE (off by default); the loop guard's novelty signal (two-node recipe issue #18). - Pull request #4 (Lucas Peters): the prompt indexer passes each row block's vis 16-byte aligned. Pull request #18 (lepetitprince716-prog): the loader reads each layer's expert run from the rank cache whole. - TF_DS_IDX_SPLIT (off by default): the keyed indexer layers' long rows split by columns over the nodes. v0.1.1's four-node commits appear again in the merged line, rebased there (28dbfe1, the L2 prefetch settings, to 2591b86, the node inputs and kit tools). The merged tree is that line's, with v0.1.1's README fork note, NOTICE, ATTRIBUTION.md and the four-node paragraph of THIRD_PARTY_NOTICES.md carried over; the next commit brings them up to v0.2.0. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
bertholomus
added a commit
that referenced
this pull request
Oct 20, 2026
… TensorFold 1.0.12, two contributors The README's fork note names first the weights the branch serves since v0.2.0, bertholomus/DeepSeek-V4.1-Flash-1017-EXL3-4.0bpw (MIT), our EXL3 quant of deepseek-ai/DeepSeek-V4.1-Flash-1017, then the 2.9 bpw weights v0.1.x served. NOTICE lists every upstream file the branch changes against 1.0.12, the kept 1.0.2 kit packer and the two contributions (pull requests #4 and #18). ATTRIBUTION.md adds the 1017 checkpoint and our quant, TensorFold 1.0.12, Lucas Peters and lepetitprince716-prog, and @Capicua25x's report behind the loop guard's novelty signal. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.
Fixes the slow rank cache load reported in bertholomus/deepseek-v4.1-tensorfold-tp2-2xgb10#24.
Cause
The rank cache stores each layer's routed and shared experts expert by expert (w1 tr/suh/svh, w3 ..., w2 ...).
Loader.experts()inzig/src/families/dsv41/weights.zigvisits them pass by pass: every gate trellis, then every up, then every down, then each of the six suh/svh stacks. That is nine strided sweeps over each layer's ~2.4 GiB of expert entries, about 6.7 MB apart, which defeats kernel readahead. Each layer's expert entries form one contiguous run of the file (43 runs, 95.1 GiB of the 98.8 GiB cache).Change
experts(), the byte extent of the layer's expert entries comes from the index and is read whole with O_DIRECT (core/direct_io.zig, 64 MiB pieces) into one page-aligned buffer.entry()returns views into that buffer for keys inside it.rank_cache.writeFakebecomespubfor the new test.Receipts
Same machines before and after: 2x DGX Spark (GB10), Ubuntu 24.04.5, kernel 7.0.0-1019-nvidia, driver 580.178.04 (CUDA 13.0), build container NGC PyTorch 26.07, Zig 0.17.0,
-Doptimize=safe -Dsm=121, basedfc8fe5, the recipe's 2.9 bpw pack (rank caches 98.8 GiB), NVMeread_ahead_kb4096, cold page cache before each run.tf-dsv41-load --cache, rank 0 / rank 1loaded inloaded_sThe page cache stays under ~5 GiB during the load and kswapd does not reclaim; before, MemFree reached zero around 37 s and kswapd scanned ~600k pages/s.
An independent run on another pair of Sparks (same base, same pack) is in the issue: rank 0 57.4 s -> 25.7 s, rank 1 63.9 s -> 30.0 s, with byte-identical greedy replies.
Checks
zig build test: 19/19 steps, 184/184 tests on Zig 0.17.0 aarch64 (dsv41 step 108/108), including the newrank cache spantest (entries in the span byte for byte, entries outside it read one by one, piecewise direct reads equal a buffered read, a span past the end of the file falls back). Its fallback case logs one expected warning.tf-dsv41-load --digests, old vs new build, on both ranks: 2123 of 2252 tensors byte-identical. The other 129 are exactly the*.ffn.experts.ptr0/1/2tables, which hold absolute device addresses (zrec_cmp.pyexcludes them too).python3 tools/zig/lean_check.py: 1420 problems before and after (the branch's baseline), no new findings in the touched files.Not run: Metal/macOS and
test-golden, which exists only in the macOS build (the change is in the CUDA-only dsv41 family), and the shard (.shards) source path, which this change does not touch.Not done: reading layer i+1's span while layer i allocates and uploads should save several more seconds (estimate, not measured).
🤖 Generated with Claude Code