Repository navigation
deepseek-v41-zig: two fixes from main (template append in place, JSON writer bound) - #24
Merged
bertholomus merged 3 commits intoOct 19, 2026
Conversation
Owner
|
Thank you @hashd1ve for bringing these two upstream fixes over with their authors kept, and for the memory measurements. Merged. |
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)
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.
What this changes
Brings two fixes from TensorFold
mainthatdeepseek-v41-zigpredates, cherry-picked with their authors:8c725d2fand7cea0043. A namespace string that accumulates is appended in place. Only the context of the test hunk intests.zigneeded resolving.Without the first fix, DeepSeek-V4.1's chat template (
{% set ns.out = ns.out + ... %}, 22 times per pass, rendered twice per request) took rank 0 ~10.9 KB of host memory per prompt token in long agent sessions. That was ~3 GiB per request at 288K tokens, enough to take a GB10 head to its memory floor. Details and measurements are in bertholomus/deepseek-v4.1-tensorfold-tp2-2xgb10#29.Receipt
deepseek-v41-zigat9f82099plus this change. Two DGX Sparks (GB10, 128 GB each), TP=2 over RoCE with both rails,nvcr.io/nvidia/pytorch:26.07-py3. Checkpoint easthambuilds/DeepSeek-V4.1-Flash-1017-EXL3-2.9bpw at2913ea75. Served with--context 1048576 --parallel 4, drafts and CUDA graphs on.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: not run. Instead, 12 greedy chat prompts (temperature 0, 128 tokens, drafts on) give byte-identical text to the unpatched9f82099image, with this change and the two companion PRs built together.tools/bench_openai.py: not run. The recipe'skit_bench.py decode --set agives prose 57.0 → 56.9 and structured 104.9 → 104.3 tok/s, with the three PRs together.tools/prefill_cold.py: not run. No prompt-pass code changes.zig build test(CUDA host tests, aarch64 Linux) 219 pass, 0 fail, 0 skip, with the three PRs together./tokenizeids for 1,500 random conversations are identical before and after. Upstream's new template test fails on9f82099(OutOfMemorywithin its 24 MiB budget) and passes with the change.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (not run as such; greedy replies equal the unpatched engine's)