Skip to content

flashnext cuda: the mixed PLE shard and the nested shards leave the page cache after load - #3467

Merged
ashhart merged 3 commits into
ashhart:mainfrom
jschmied:fn-pagecache-drop
Nov 19, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
jschmied:fn-pagecache-drop

Conversation

@jschmied

@jschmied jschmied commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Head: fe9b4fc (two commits on origin/main 41a72fd: the change dbb5625 and its gradient-serving pin rows).

After a Flash Next CUDA load (NVIDIA's NVFP4 export, shards under tensors/), about 3 GiB of checkpoint pages stay in the page cache for as long as the server runs. They are only freed under pressure. The cause is shard 15, which holds the n-gram table (1.26 GiB) beside 3.27 GiB of load-only tensors (embedding 1.18 GiB, HC, MTP layer, vision). runtimePages skipped the release of the whole shard. The final sweep (cache.directory) listed only top-level *.safetensors, so for this checkpoint it advised nothing.

Change

  • Family (flashnext/cuda_prompt_wt.zig, cuda_lanes_load.zig):
    • A shard now drops all its pages except the n-gram tensors' ranges (Shard.drop, which calls core's releaseExcept), in all three places that released before: close, release, use.
    • The final sweep now takes its file list from the index (core.checkpoint.shardFiles), so nested shards are reached. Files the n-gram table holds open are still skipped by inode.
  • Core (core/checkpoint_cache.zig): directory(io, dir, keep) becomes shards(io, paths, keep), which walks the paths it is given. Flash Next is its only caller. files, drop and visit, which the other families use, are unchanged. releaseExcept and shardFiles are existing core code, not new.
  • Host scan test (zig/cuda_checkpoint_cache_host.zig): it now pins the new call text.
  • Other families are not touched. CUDA on GB10: the memory budget is at most CUDA's free memory, after the checkpoint's cached pages are dropped #3192 (open) drops the shards before admission. This change drops them after the load, which CUDA on GB10: the memory budget is at most CUDA's free memory, after the checkpoint's cached pages are dropped #3192 leaves to the loaders, so the two are complementary. Both use the same index list.

Replies keep their tokens. Only page-cache advice changes: the mapping is read-only, a dropped page refaults from the file, and no bytes change.

Planted control

  • The new test is zig/src/core/checkpoint_cache.zig:88. Its fixture has nested tensors/ shards, a held PLE file and a symlink alias. It expects 2 files advised, and the held file and the alias are never advised.
  • The same fixture, run against main's walk, is red: expected 2, found 0.
  • Green on this head: 3/3, and test-cuda-load-cache-host 22/22.

Served, GB10, A-B-B-A (TENSORFOLD_MEMORY_RESERVE_GIB=16, default flags; page cache dropped before every start)

  • The load line is identical on both: model 72.76 GiB; 3 streams at once, 7.86 GiB each at a 262144-token window ... loaded in 44.8s.
  • Memory 10 s after load (main 1 / main 2 vs fix 1 / fix 2):
main fix
Cached 3.65 / 5.09 GiB 0.69 / 0.69 GiB
shard 15 resident (mincore) 2.97 GiB 0.01 GiB
MemFree 39.29 / 38.04 GiB 42.24 / 42.65 GiB
MemAvailable 42.01 / 42.24 GiB 42.00 / 42.41 GiB (page cache counts as available)
nvidia-smi per pid 73.46 GiB 73.46 GiB
load (ready) 47.1 / 45.0 s 45.0 / 46.0 s
  • After serving requests, shard 15 stays at 0.02 GiB on the fix, so nothing refaults the dropped part. The n-gram shards 16-21 hold the same pages on both.
  • The index-driven sweep drops nothing extra on this checkpoint: shards 1-14 were already out on main, because their shards release at close. It makes the sweep reach a nested layout at all.
  • Replies are byte-identical to main in all four arms: greedy x4, seeded (temperature 0.8, seed 7) x2, concurrency 4 x4, and the three long-prompt cells' text.
  • Cold turns: 35,401-token prompts, 256 tokens out, three cells per arm, paired main 1 with fix 1 and main 2 with fix 2.
    • TTFT fix/main paired median 1.000, 3 of 6 slower, each by at most 0.6 %. Medians 17.903 s (main) vs 17.868 s (fix).
    • Decode fix/main paired median 1.003, 2 of 6 slower, each by at most 0.5 %. Medians 48.40 vs 48.56 tok/s.
    • The slower cells fall in the first pair and the faster ones in the second, and the serving path doesn't change. I read this as run-to-run noise, but it is stated here plainly.
  • Resume and multi-turn: not run separately. The prompt cache and serving code are untouched, and this changes only load-time page advice.
  • Refusal test: not applicable, because the change adds no new refusal.

CI (x86, -Dfixed-cpu test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths, check-native-cuda-host compile-cuda-tests, tools/pr_check.py, zig fmt --check):

  • Everything is green except cli_config_test "serve --config: expand reads the file...". That test fails the same way on origin/main 41a72fd on the same runner.
  • Lean: 341 vs 341.

Proposed CHANGELOG line (for you to place):
- Flash Next on CUDA: after load, the checkpoint's mixed n-gram shard keeps only the n-gram table in the page cache, and the final sweep reaches shards nested under tensors/ (about 3 GiB of page cache freed on the NVFP4 export).

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The mixed shard keeps its n-gram ranges, and the index sweep reaches nested shards while excluding live aliases. The receipt correctly separates reclaimed file cache from unchanged GPU allocation.

We will run the device check on our side for Flash Next's NVIDIA checkpoint, checking retained n-gram pages, exact replies and load/decode timing. The required zig, zig-windows, pytest and fmt jobs must also be green at the final head before landing.

  • Synthena (Ash's Agent)

jschmied added a commit to jschmied/TensorFold that referenced this pull request Nov 16, 2026
@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart Thanks. On the required jobs: zig failed in test-gradient-serving on "serving source changed". This PR changes flashnext/cuda_lanes_load.zig and flashnext/cuda_prompt_wt.zig, and their rows in zig/tests/fixtures/gradient-serving.tsv still pinned main's hashes.

fe9b4fc908 updates those two rows only, with a note naming #3467. zig build -Dfixed-cpu test-gradient-serving passes locally. The change itself is as before.

Could you approve the workflows at this head?

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@jschmied, the device checks are done on a GB10 with Flash Next NVFP4, at fe9b4fc's tree (your last push only re-pinned the two load files). Replies are exact (0 of 20 prompt rows differ across runs) and cold-prompt speed is level from 2k to 64k.

One cell looked slower in the balanced run: 8 streams, greedy, the same chat prompt on every stream (median 153.7 to 142.5 tok/s). That shape runs identical replies in lockstep and swings with how they line up, so we reran just that cell with a different prompt on each stream, four runs an arm: greedy goes from 73.0 to 73.0 tok/s and sampled from 72.9 to 71.7, with the runs overlapping. The other 8-stream cells were level or faster, so there's no slowdown to fix. CI is green and it's queued; if #3456 lands first, cuda_lanes_load.zig's pin needs the one-row update you mentioned.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. We re-checked this head against current main. The four source files it touches are unchanged on main since your base. The two rows you re-pinned in gradient-serving.tsv still match, and the fixture merges cleanly beside main's newer rows. Main hasn't touched cuda_lanes_load.zig, so no extra pin update is needed.

The final sweep now walks the index's shard list, the index Store.open loads from, so nested shards are reached, and the held n-gram files stay excluded by inode. Nothing to change.

  • Synthena

jschmied and others added 3 commits November 19, 2026 03:26
…age cache after load

Shard 15 of the NVFP4 checkpoint holds the n-gram table beside 3.27 GiB of load-only tensors (embedding, HC,
MTP, vision); the runtimePages guard skipped its release whole, and the final sweep listed only top-level
*.safetensors while this checkpoint keeps its shards under tensors/. Now a shard drops everything but the
n-gram tensors' pages (releaseExcept), and the sweep walks the index's shards (core.checkpoint.shardFiles).
@ashhart
ashhart merged commit 1827532 into ashhart:main Nov 19, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants