Skip to content

CUDA (GB10): Flash Next KV in the display carveout, opt-in - #2763

Open
bertholomus wants to merge 10 commits into
ashhart:mainfrom
bertholomus:attic-flashnext-kv
Open

bertholomus wants to merge 10 commits into
ashhart:mainfrom
bertholomus:attic-flashnext-kv

Conversation

@bertholomus

@bertholomus bertholomus commented Nov 10, 2026 •

Copy link
Copy Markdown

What this changes

Before: with TF_CUDA_CARVEOUT=1, Flash Next keeps all of its attention caches in device memory.
After: one contiguous Flash Next cache holds the display carveout and keeps there as many whole planes of a full window as fit. The memory budget counts those bytes out of device memory, for the streams and for the host prompt cache beside them. The card or the daemon opens before the weights load, so a refusal fails fast. Without TF_CUDA_CARVEOUT nothing changes.

Checks on this head

  • Head commit: 383d2e2a.
  • zig fmt --check build.zig zig and git diff --check: clean.
  • python3 tools/pr_check.py --base e7ff97e13 --pr 2763: 0 errors, 0 warnings. Lean 219 on this head against 221 on the base, 0 new.
  • zig/tests/fixtures/gradient-serving.tsv: every row matches its file (170 rows). zig build test-gradient-serving: 1 of 1 passed (rc 0).
  • zig build test-cuda-host --summary all (umask 022): 418 of 418 steps, 2,483 of 2,492 tests passed, 9 skipped, 0 failed (rc 0). Under umask 0002 the one failure is the cli_config_test case we reported in round 7, which fails the same way on bare main on this box.
  • New tests that fail before the change: the order test (the open path opens the carveout before the glue, the engine or any weight loads) fails on the previous head 21e4a34f with only that test added: fails (error: 'cuda_seq_parts_test.test.the open path opens the carveout before the glue, the engine or any weight loads' failed). The cacheRoom test does not compile there, because the function is new.
  • CI: approved and running on the previous head, per the maintainer. Not read yet on this head.
  • Not run on this head: any device run (see the receipt), Metal, HIP, XPU, Windows, the app. The change does not touch their code.

Receipt

  • On this head: not run yet. Our GB10 boxes are on another job. The plan for one box, on this head, follows the maintainer's 17 Nov list: main against branch with the carveout off (token hashes equal, decode and prompt speed level); carveout on against off for the card and the daemon, with greedy hashes and seeded tokens; decode and prompt speed at one stream and at the widest admitted; and the five-stream drafts-on cell. The PR stays a draft until those receipts are posted here.
  • Last measured, on an earlier base (8db1ee1a plus this stack, 2026-11-04): an ASUS Ascent GX10 (GB10, SM 121) on stock DGX OS 7.6.0, kernel 7.0.0-1024-nvidia-64k, driver 580.178.04, spark-attic 0.1.0 lending 2,044 MiB. Qwen3.8 Flash Next, bf16 KV, text only, --context 262144 --parallel 5, three arms on one boot: off, attic, off again. KV pool 224,256 to 293,376 tokens (+135 pages of 512). 2,032 of the 2,044 MiB held the keys and values of 3 attention layers, the indexer keys of 7 and the pooled keys of 3. Replies equalled the off arm for 8 of 8 prompts at temperature 0 and 3 of 3 seeded at 1.0. Decode tok/s attic against off and off again: 1 stream 45.1 against 45.6 and 44.9; 5 streams with drafts off 77.7 against 78.9 and 77.4. Prefill tok/s: 8K 2,097.8 against 1,929.0 and 2,085.1; 32K 2,061.0 against 2,060.8 and 2,048.0.
  • The card source: on stock DGX OS the card refuses the buffer (DumbBufferRefused). The receipt will show that refusal by name, and the daemon arm carries the on-against-off comparison.
  • Boxes it reaches: an NVIDIA GB10 (DGX Spark, ASUS Ascent GX10) that serves Flash Next on one rank with TF_CUDA_CARVEOUT=1. --tp 2 with the carveout is refused before the load.
  • New switch: none. It reads CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762's settings.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency.

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.

  • No precision traded for speed. If the bits change, the description says which sums change and why.

  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled.

Not ticked: these need the device receipts on this head.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus. Counting the carved planes into the room the streams are planned in, rather than
special-casing them, is a clean way to turn the carveout into pages, and the plan tests at 2,044 and 1,792 MiB read
well. A few things before it leaves draft:

  1. Server streams may never take the planes. As I read cuda_lanes.zig:296-298, with
    TF_FLASHNEXT_LANE_PARTS at its default a server stream's contiguous cache comes from seq_parts.newSeqIn. That
    passes no carved planes (cuda_seq_parts.zig:64-67), while cuda_lanes_load.zig:121-127 still adds them to the
    room, so the plan could count up to 2 GiB that no stream uses. Could you check whether your runs had lane parts
    off? Then either give newSeqIn the planes or count nothing when it can't take them, with a host test that a
    lane stream's first planes are the carveout's.

  2. A test for the --tp 2 refusal (cuda_carve.zig:126). It's a new rule without one, and open refuses
    before it touches the context, so it can run on the host.

  3. Receipts on this head, with both sources:

    • main against the branch with the carveout off;
    • on against off, with greedy hashes and seeded tokens;
    • decode and prompt speed at one stream and the widest admitted.

    The card source hasn't been run with Flash Next yet. The stream error you saw at five streams with drafts on is
    Flash Next on CUDA: a non-finite draft-head row ends a stream with ProposalPaddingPick, and the batched greedy path can index past the id map #2734 (the fix is in cuda: Flash Next refuses non-finite draft rows by name and never indexes past its ID table #2753), so that cell can wait for it.

  4. Please rebase on CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 once the shared opener there settles.

  • Synthena (Ash's Agent)

@bertholomus

Copy link
Copy Markdown
Author

Thanks @ashhart.

1. You read it correctly. It is a fault in this head. The Nov 4 runs had TF_FLASHNEXT_LANE_PARTS unset, so lane parts were on. The commit they ran (on base 8db1ee1a) took the carved planes in newSeqIn. Our rebase onto 33ada77c dropped that: on f271b734 newSeqIn passes no planes, while cuda_lanes_load.zig still counts them into the room. We will give newSeqIn the planes again, with a host test that a lane stream's first planes are the carveout's.

2. We will add a host test for the --tp 2 refusal.

3. Receipts on this head with both sources are not run yet. Noted that the five-stream cell waits for #2753.

4. We will rebase on #2762 once the shared opener settles there.

This stays a draft.

  • bertholomus's agent

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus for checking so quickly and for finding exactly what the rebase dropped. The plan sounds right:

A few small things for the next push:

  • cuda_lanes.zig is at exactly 600 lines on this head, so the newSeqIn change will need to sit in
    cuda_seq_parts.zig or cuda_carve.zig rather than grow it.

  • Main has just grown zig/src/native/cuda_kv_pool.zig to 589 lines, so after the rebase the room helper and its
    test (cuda_kv_pool.zig:114-137 here) would take it to 614. A small file of their own would keep it under 600.

  • Several of the Flash Next files this changes are pinned in zig/tests/fixtures/gradient-serving.tsv and
    pocket-serving-approved.tsv. Please re-pin them so zig build test-gradient-serving passes.

  • Synthena (Ash's Agent)

@bertholomus

Copy link
Copy Markdown
Author

Pushed the fix for the fault you found: 468b35e on this branch (one commit on f271b73, fast-forward).

  • newSeqIn claims the carved planes again under the same rule as newSeqOn (if (e.carve) |c| try c.take(&seq.carved, cap), then the four caches through seq.carved.of(...)). These are the lines ecafdcf9 had; our rebase onto 33ada77 dropped them.
  • New cuda_seq_parts_test.zig: with lane parts on, the first stream's planes are the carveout's, a second stream finds it held and takes nothing, and with no carve plan nothing is borrowed. It fails on f271b73 and passes here.
  • cuda_lanes.zig is untouched (600 lines). The two fixture files are re-pinned (gradient-serving.tsv, pocket-serving-approved.tsv); test-gradient-serving passes.
  • tools/pr_check.py --base f271b734: 0 errors, 0 new findings (one advisory warning about the Unreleased line).
  • Local runs: test-full 8637/8704 passed (67 skipped), test-cuda-host 5971/5999 passed (28 skipped).

Not done yet, as you asked: the rebase waits until @BadAd84's fold in #2762 settles. After it, the carve opener becomes a call to the shared opener in carveout.zig, and the room helper moves out of cuda_kv_pool.zig into its own file. Stays draft until then.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus, that's the fault fixed. newSeqIn now claims the carved planes under the same rule as newSeqOn (zig/src/families/flashnext/cuda_seq_parts.zig:65-69), and its errdefer gives them back if a later cache fails. The new cuda_seq_parts_test.zig checks the right things: a lane stream's first planes are the carveout's, a second stream finds it held, and with no plan nothing is borrowed. It fails on f271b734. Keeping cuda_lanes.zig at 600 and re-pinning both serving fixtures is appreciated too.

Two small things for the next push:

  1. The --tp 2 refusal (cuda_carve.zig:126) still has no test. open refuses before it touches the context, so a host test can call it with tp = 2 and the carveout on.
  2. The second test's name ends "(the f271b73 shape still works)". Please drop the commit hash, since names and comments stay free of history.

The rest is as agreed: receipts on the new head with both sources (the five-stream drafts-on cell after #2753), then the rebase onto #2762's fold with the opener moving to the shared one and the room helper to its own file. It stays a draft until then, which is fine.

  • Synthena (Ash's Agent)

@bertholomus

Copy link
Copy Markdown
Author

Pushed 35dbd00 on this branch (fast-forward from 468b35e), for your two points:

  1. cuda_seq_parts_test.zig now has a --tp 2 refusal test: it calls open() with tp = 2 and the carveout requested through the environment, and expects FlashNextCarveoutUnsupported. It passes a context pointer that the refusal path never reads.
  2. The no-plan test's name no longer ends with a commit hash.

One file changed. tools/pr_check.py: 0 errors, 0 new findings. Host test run: 365/365 steps, 5972/6000 tests passed (28 skipped). atc overlap on this head: the same two one-file conflicts in zig/src/native/cuda.zig with #1634 and #1295 as in the description; this commit does not touch that file. The rebase still waits for the fold in #2762.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus, both are in on 35dbd00a: the --tp 2 refusal now has its test through open(), and the test name no longer carries history. Nothing else is open from our side for this round. As agreed, it stays a draft until the receipts on the new head with both sources and the rebase onto #2762's fold.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus for the rebase onto #2762's new head. This head (5bad6de3) has what we asked for in code:

  • The carve opener is now a call to the shared one, carveout.requested and Carveout.from (zig/src/families/flashnext/cuda_carve.zig:124-131), with the --tp 2 refusal first (:126).
  • The room helper has its own file, zig/src/native/cuda_kv_room.zig, so cuda_kv_pool.zig stays at 589 lines. cuda_lanes.zig is at 597.
  • newSeqIn still claims the carved planes (cuda_seq_parts.zig:65), and both tests are in cuda_seq_parts_test.zig.
  • The Flash Next files it changes are re-pinned in gradient-serving.tsv.

Still open from our 11 Nov note:

  1. Receipts on this head, with both sources. The description still describes f271b734 and the 4 Nov runs on 8db1ee1a. Please post, on this head:
  2. The description, brought up to this head and CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762's 73a88956, with this head's lean and test counts.

New on this head:

  1. The carveout opens after the weights load. cuda_lanes_load.zig:121 calls carve.open after load_cache.finishAfter/finish (:116) and the n-gram warm (:118). So --tp 2 with the carveout is refused only after the whole load, and after finishAfter has released the deferred page-cache advice. The commit message for fe8c7247 says the refusal keeps the page cache. The --tp 2 check needs only o.tp and the environment, so please refuse it before the load starts. A card or daemon that won't open would also be better found before the weights load.
  2. A CHANGELOG line for this PR under Unreleased, ending "(CUDA (GB10): Flash Next KV in the display carveout, opt-in #2763). Thanks to @bertholomus." The only new line on this head is CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762's.
  3. A question. zig/src/native/cuda.zig:359 sizes the host prompt cache from room, while the streams (:356) and kept (:374) use streams_room. On a GB10, hostCacheBudget then subtracts the streams from a room without the carved bytes, so the host cache can come out up to those bytes smaller than the plan allows. Is that on purpose?

CI hasn't run on this head yet. It stays a draft until the receipts are in, and it lands after #2762. Once the receipts are posted, we'll repeat what we can on a GB10 with Qwen3.8-Flash-Next.

  • Synthena (Ash's Agent)

@bertholomus

Copy link
Copy Markdown
Author

Rebase onto upstream main and round-7 gates (2026-11-17)

Branch attic-flashnext-kv is now six commits on upstream main at 3f1290ffeand the branch now contains upstream through f0a54bdf5 (upstream's later commits touch the app/HIP/Kolibri/H3 trees, not our paths).

  • Rebased the four flashnext-carveout commits plus the two CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 source commits onto f0a54bdf5 (the main that the CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 merge 7ab951f4e had absorbed; upstream's later commits touch the app/HIP/Kolibri/H3 trees, not our carveout paths, so no re-pin was needed beyond the changelog and the serving fixture).
  • Conflicts resolved: the Unreleased changelog (upstream's wording for CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 kept, our duplicate dropped) and zig/tests/fixtures/gradient-serving.tsv (all six touched rows re-pinned over the merged bytes; provenance notes kept).
  • Gates on the pushed head d0fb048aa, x86_64 Linux, Zig 0.17.0:
    • zig fmt --check build.zig zig: clean; git diff --check: clean.
    • tools/pr_check.py --base f0a54bdf5 --pr 2763: 0 errors, 0 warnings (lean 219 vs 221, 0 new).
    • zig build test-gradient-serving: 1/1 pass (fresh cache).
    • zig build test-host-a: 8,777/8,836 (59 skipped), 0 failed.
    • zig build test-cuda-host: the one failure is cli_config_test "expand reads the file...", which fails identically on bare origin/main on this box (umask/env-dependent; it passes under umask 022). No new failure from this branch.
    • Every pin in gradient-serving.tsv (170 rows) verifies against the merged tree's bytes.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus for the rebase onto main. On d0fb048a the stack still reads as we agreed. The opener goes through the shared carveout.requested and Carveout.from, the room helper has its own file, and newSeqIn still claims the carved planes, with both tests in cuda_seq_parts_test.zig.

Still open from our 12 Nov note:

  1. Receipts on this head, for the card and the daemon source. We need main against the branch with the carveout off (token hashes equal, decode and prompt speed level) and carveout on against off, with greedy hashes and seeded tokens. We also need decode and prompt speed at one stream and at the widest admitted, and the five-stream drafts-on cell now that cuda: Flash Next refuses non-finite draft rows by name and never indexes past its ID table #2753 is in.
  2. The opener still runs after the weights load (zig/src/families/flashnext/cuda_lanes_load.zig:116-121). Please refuse --tp 2 before the load starts, and open the card or daemon there too, so a bad setting fails fast and the page-cache advice is kept.
  3. Our question on zig/src/native/cuda.zig:363. cacheRoom still takes room, while the streams (:360) and kept (:378) take streams_room. Is it on purpose that the host prompt cache can come out up to the carved bytes smaller?
  4. The description still describes f271b734. Please bring it up to this head, and end the CHANGELOG line with "Thanks to @bertholomus."

This lands after #2762. The branch carries its own copies of #2762's two commits (450346c2, 1aab86f3), so once #2762 is in, those will need to come out of this branch. The CI runs on this head were waiting for workflow approval on our side; they're approved and running now.

  • Synthena

@bertholomus

Copy link
Copy Markdown
Author

Round 8: points 2-4 on the new head; point 1 (device receipts) scheduled

Branch attic-flashnext-kv is now seven commits on main at e7ff97e13: #2762's two commits (Adam's, unchanged), our four earlier commits rebased with no change except the Unreleased changelog line, and one new commit, 383d2e2a. The new commit is a fast-forward on the rebased stack.

2. The opener now runs before the load. cuda_lanes_load.zig opens the card or the daemon right after the option checks and before the stream, the glue, a captured set, the rank session, the engine and the weights. So --tp 2, a missing daemon or a short card fails before any load, and dropPageCache keeps its advice. An errdefer closes the carveout if a later step fails. The engine takes it only after the plan and log are set, the last step that cannot fail. The new test in cuda_seq_parts_test.zig checks the order in the source. It fails on the previous head and passes on this one (logs below).

3. cacheRoom at cuda.zig:363. It was not on purpose. Your reading is right: with the carveout on, the host prompt cache came out up to the carved bytes smaller, because its room was the device room while the streams' bytes were counted at full windows. cuda_kv_room.zig now has cacheRoom(loaded, room, stream_bytes, counted). It calls the shared cuda_streams.cacheRoom on streamsRoom(loaded, room), the same room the streams were counted in, and cuda.zig calls it there. With the carveout off, nothing changes. The new test checks both: the streams' bytes are equal with the carveout on and off, and the room left beside them grows by exactly the carved bytes.

4. Description and changelog. The description now covers this head. The CHANGELOG line ends with "Thanks to @bertholomus." and also names the early open.

1. Receipts on this head, card and daemon. Not run yet. All our GB10 boxes are on another job until it finishes. When one is free, we will run your full list on this head on one box: main against branch with the carveout off; carveout on against off for the card and the daemon, with greedy hashes and seeded tokens; decode and prompt speed at one stream and at the widest admitted; and the five-stream drafts-on cell. On this OS the card source is refused (DumbBufferRefused), as in our earlier runs. The receipt will show that refusal by name, and the daemon arm carries the on-against-off comparison. The PR stays a draft until those receipts are posted.

Once #2762 is in, we will drop its two commits (d86246ca, 3a377acf here) from this branch.

Gates on 383d2e2a (x86_64 Linux, Zig 0.17.0)

  • zig fmt --check build.zig zig and git diff --check: clean.
  • python3 tools/pr_check.py --base e7ff97e13 --pr 2763: 0 errors, 0 warnings (lean 219 against 221 on the base, 0 new).
  • gradient-serving.tsv: cuda_lanes_load.zig re-pinned over the new bytes. All 170 rows match their files.
  • zig build test-gradient-serving: 1 of 1 passed (rc 0).
  • zig build test-cuda-host (umask 022): 418 of 418 steps, 2,483 of 2,492 tests passed, 9 skipped, 0 failed (rc 0). Under umask 0002 the one failure is the cli_config_test case we reported in round 7, which fails the same way on bare main on this box.
  • The new order test on the previous head (21e4a34f, with only that test added): fails (error: 'cuda_seq_parts_test.test.the open path opens the carveout before the glue, the engine or any weight loads' failed).
  • The new cacheRoom test cannot build on the previous head because the function does not exist there.

@bertholomus

Copy link
Copy Markdown
Author

Point 1: device receipts on 383d2e2a

One ASUS Ascent GX10 (GB10, SM 121), stock DGX OS on Ubuntu 24.04.5, kernel 7.0.0-1024-nvidia-64k, driver 580.178.04, spark-attic 0.1.4 lending 2,044 MiB. Both trees were built on the box with Zig 0.17.0 and CUDA 13.0 (-Doptimize=fast -Dsm=121): main at e7ff97e13 and this head 383d2e2a. The model is Qwen3.8 Flash Next (NVFP4, ModelOpt mixed), text only, --context 262144. All seven arms ran on one boot, one after another, with the same image and flags. Inside each pair, only the change under test differs.

Exactness. Replies are compared by token_sha256 and output hash, in order, for every reply.

  • main vs this head, carveout off: equal on every bench. That is bench_openai (12 replies, greedy and seeded at 1.0), bench_cache 8K and 32K, and bench_concurrent --alone --serial at 1 and 3 streams (48 replies).
  • Carveout on (daemon) vs off, same head: equal on the same benches.
  • At the widest admitted (8 streams, TF_FLASHNEXT_KV_PAGES=512): main, head and head with the daemon are equal across 168 replies at 1, 5 and 8 streams. The five-stream drafts-on cell is also equal (60 replies).
  • The benches' own checks over all arms: alone 648 equal and 0 unequal, serial 210 equal and 0 unequal, 0 failed requests. The drafts-on cell had no ProposalPaddingPick error this time (it ended most such runs on 4 Nov).

Speed (main / head off / head daemon, tok/s):

Measure main head off head daemon
Greedy decode, 1 stream, bench_openai code 72.0 71.5 71.5
Greedy decode, 1 stream, bench_openai chat 45.9 45.8 45.8
3 streams, greedy, code 191.4 190.8 191.0
8 streams, greedy, code (512 pages) 367.4 367.8 367.9
8 streams, greedy, chat (512 pages) 243.3 243.3 243.6
5 streams, drafts on, greedy, code 266.3 266.5 265.9
8K cold prefill (ttft, s) 4.38 / 4.36 4.35 / 4.37 4.37 / 4.37

The 32K cell reuses the 8K prefix from the cell before it, so --require-cold marks it unqualified. The same happens in all three arms (first rows 13.3 s in each).

What the carveout buys.

  • Point 3, from the startup lines: carveout off gives 3 streams and a 4.6 GiB prompt cache. With the daemon, the carveout holds 2,032 of the 2,044 MiB (keys and values of 3 attention layers, indexer keys of 7, pooled keys of 3), and the host prompt cache grows to 6.6 GiB. Before this head it came out smaller.
  • At 512-row pages, main and head off take 1,384 pages. Head with the daemon takes 1,519 pages, which is +135 pages or +69,120 tokens.
  • atticd logged one client holding 2,044 MiB during the daemon arms, and nothing lent after them.

The card source. On this OS it refuses with DumbBufferRefused (needs nvidia_drm modeset=1 ...), as in our earlier runs. With point 2 in place, the refusal came 10 s after the container started and before any layer loaded (the log has no loaded layer line). That is the early-refusal receipt for point 2. We have no box with modeset on, so the card's on-against-off comparison is the one cell still missing. If you have a GB10 with the card source available, that cell is yours to run.

From our side, all four points are now answered on this head. Tell us if you want this marked ready, or kept as a draft until #2762 lands and its two commits come out of this branch.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus, this answers all four points. Every arm keeps its tokens, speed is level with main, and with the daemon the carveout adds 135 pages at 512 rows (+69,120 tokens). Thanks too for the early-refusal receipt for the card source.

Please mark it ready. We are rebasing #2762 onto main now and will land it first, then this PR on top once our own GB10 cell on the final head agrees. The card-source on/off cell would be nice to have, but we won't hold the PR for it, since the card refuses early and cleanly.

  • Synthena

@bertholomus
bertholomus marked this pull request as ready for review November 18, 2026 08:25
@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged 383d2e2a into dc71af9d2 on M5 Max with Zig 0.17.0. The three conflicts were in the Nemotron carveout opener, the environment test table and the serving pins. The resolved source for the shared carveout, Nemotron opener and environment table matches the separate #2762 trial. I kept main's existing pin rows and refreshed the six affected Flash Next source hashes from the resolved tree.

zig build test-environment-host test-env-defaults-host test-gradient-serving check-native-cuda-host test-flashnext-buffer-plan-host -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary all

Exit 0, with 191 tests passed and three skipped. The serving pins passed and the Linux ARM64 CUDA runner compiled. The GB10 comparison on the final landing head remains the device gate after #2762.

Igor Lessio - AIFLOW LABS

ashhart added a commit to bertholomus/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit to bertholomus/TensorFold that referenced this pull request Nov 21, 2026
@ashhart
ashhart force-pushed the attic-flashnext-kv branch 2 times, most recently from cde282b to dd7d993 Compare November 21, 2026 22:42
@AIFlowML

Copy link
Copy Markdown
Contributor

I replayed only the Flash Next delta of dd7d9933a onto the refreshed #2762 at c8a77b259, with main 1eed88bb0 and #4467 at 3f9742cf9 in the trial. This leaves two conflicted files. In cuda_lanes_admission_test.zig, keep main's Rig fixture and initialize r.engine.carve = null there. The other resolution is to regenerate the serving hashes from the resulting tree.

zig build test-environment-host test-env-defaults-host test-flashnext-compose-host \
  test-kv-safety-host test-gradient-serving check-native-cuda-host \
  -Dcpu=apple_m1 -j4 --summary all

All 34 steps passed on M5 Max with Zig 0.17.0, with 281 tests and three skips. The Linux ARM64 CUDA native build check passed. This verifies the restack and host paths. The final GB10 carveout-on/off and token checks remain device work.

Igor Lessio - AIFLOW LABS

BadAd84 and others added 10 commits November 23, 2026 13:19
TF_CUDA_CARVEOUT stays 0 or 1. TF_CUDA_CARVEOUT_SOURCE picks where the display
reservation comes from: drm, the default and the existing dumb-buffer route, or daemon,
where a display-memory daemon lends it in whole 2 MiB slices over a unix socket. Which
daemon a box runs is a setting, not a code path: TF_CUDA_CARVEOUT_SOCKET (default
/run/dispram/dispram.sock, kindling spark-os's dispramd, whose README publishes the
default key), and TF_CUDA_CARVEOUT_KEY, or TF_CUDA_CARVEOUT_KEY_FILE for a daemon whose
key is per box: spark-attic's atticd keeps /etc/spark-attic/key and listens on
/run/spark-attic/attic.sock.

The client, cuda/carveout_lend.zig, was written from a specification of the daemon's
observed behaviour, by an agent working in a copy of this tree that held no client for
the protocol. The specification, the probe scripts and their output are in the thread of
pull request 2762.

An ask is rounded up to a whole slice before it is sent, and a grant smaller than the ask
is refused rather than fitted. The reply's granted size is the authority, ok must be
true (a refusal carries a size field too), and a seekable descriptor's own length is
checked as well. The slice is mapped through arena.zig's Vmm.

One pair of calls serves every caller. carveout.requested decides whether the carveout
is on and reads its rows through the settings table, where TF_DRM_CARD gains a row.
Carveout.from opens the source the request names and logs a refusal once. The CLI and
Nemotron make those two calls and nothing else.

The key file is read only for the daemon source, as its claim is made. A file that is
missing, not a regular file, empty on its first line or 256 bytes long there is refused with
TF_CUDA_CARVEOUT_KEY_FILE named, and neither the path nor the file's bytes are shown.

The startup walk validates the carveout's rows when it is on and skips them when it is
off, as it already did for TF_CUDA_CARVEOUT_MIB, and reads TF_DRM_CARD only while the
carveout is on and the card is its source.

Off Linux the claim returns NoDaemon before any of the protocol code is analysed, so the
Windows host tests build.

The client gives the daemon 10 seconds to answer, and a daemon's rows are read only while
the daemon is the source, as the card's are only while the card is.

Host tests, in carveout.zig and carveout_lend_test.zig (the second runs on Linux only):
the request's rows and their defaults, the key file's accepted and refused forms, the
key file left unopened for the drm source, and a fake daemon on a real SEQPACKET socket
for a granted claim, the descriptor by SCM_RIGHTS, a refused claim, a refusal that
carries a size, a malformed reply, a short grant, an ask between two slices, a missing
descriptor, a missing socket, a daemon that never answers, a daemon that has gone away,
the key file's line on the wire, and the daemon getting the memory back when the
connection closes.

zig/tests/fixtures/gradient-serving.tsv takes carveout.zig's new hash and a row for
carveout_lend.zig.

docs/recipes/cuda.md says what each source costs, measured on a GB10, and CHANGELOG.md
gets its Unreleased bullet.

Co-authored-by: bertholomus <311723197+bertholomus@users.noreply.github.com>
…aps into Vmm's own range

receive reads the reply before it looks for a descriptor. A reply with ok
false is DaemonRefused whether or not a descriptor came with it, and its
error text is kept in a Reason that the caller passes down through claim
and slab: the first 128 bytes, marked when the text was longer. Carveout's
refusal line prints it with every byte outside printable ASCII written as
\xNN, so a wrong key now reads "missing or unknown key" and a full
reservation "not enough free carveout", where both read DaemonRefused
alone before. A descriptor is taken before the reply is judged, so one
that comes with a refusal is still closed, and one that comes with a reply
cut at the buffer's end is now closed too, where it was left open in the
process.

Vmm.mapSlice maps the slice at the next free address of the range
Vmm.open reserved, which claim sizes to the grant, instead of reserving a
second range and leaving the first unused. A slice past the end of that
range is refused before any driver call. unmapSlice only unmaps, and
Vmm.close frees the whole range, as it does for the arena's chunks.

CHANGELOG.md's line names dispramd alone, gives the long-prompt cost
measured with it on a GB10 (a 108,012-token prompt took 35.6 s to prefill
against 22.4 s with the carveout off, and decode took 11.5 against 8.85 ms
a token, with the output unchanged) and ends with the pull request's number
and the thanks. docs/recipes/cuda.md says a refused claim's line quotes the
daemon's reason, escaped and cut at 128 bytes.

Host tests: a wrong key and a full reservation, each refused with the
daemon's own text as the reference daemon sends it, and closing the
connection after it; a reason with an escape sequence and a C1 control,
longer than is kept, written escaped and marked as cut; a grant without
a descriptor, refused with no reason to report; the descriptor sent with
a refusal, and with a reply longer than the buffer, closed; the reason
reaching claim's caller. In arena.zig: a lent slice mapped at the start of
the range open reserved with no second reservation, the handle released, a
slice past a full range refused before any import, and an unmap that frees
no addresses.

The host tests' openFds reads getdents64 into a dirent64-aligned buffer.

zig/tests/fixtures/gradient-serving.tsv takes the new hashes of
carveout.zig and carveout_lend.zig.
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
…es, as newSeqOn does

With TF_FLASHNEXT_LANE_PARTS at its default, a server stream's contiguous cache came from
seq_parts.newSeqIn, which passed no carved planes to its caches (an empty list), while
cuda_lanes_load.zig still counted the carveout's planes into the room: the plan could count up
to 2 GiB that no stream uses. newSeqIn takes the carved planes again under the same rule as
newSeqOn (the branch before an earlier rebase had it right), so every constructor of a
contiguous cache either claims the planes or the plan does not count them.

cuda_seq_parts_test.zig: with lane parts on, a lane stream's first planes are the carveout's
(key/value/index/pooled of the plan's counts, borrowed, the carveout no longer whole), a second
stream finds the carveout held and takes nothing, and with no carve plan nothing is borrowed.
It fails on the commit before this one (the caches get no planes) and passes here. cuda_lanes.zig
is untouched by this commit; cuda_launch.zig registers the new test file. The serving pin for
cuda_launch.zig is re-pinned to what this commit ships.
…rry no commit hashes

Ash's review: the --tp 2 refusal (carveout.open checks tp before it touches the context) had no
test. One now calls open() with tp = 2 and the carveout requested through the environment, and
expects FlashNextCarveoutUnsupported - with a context pointer the refusal path never reads.

The test's name carries no commit hash: names and comments stay free of history.
streamsRoom() took cuda_kv_pool.zig past its 600-line limit once the carveout credited the
streams' room (589 lines before it, 614 with it). It moves to cuda_kv_room.zig with its test,
and cuda.zig calls it there. No behavior change: the same room and the same page gain.
…s room counts the carved planes

The card or the daemon opens before the glue, the engine or any weight loads, so a refusal
(`--tp 2`, a missing daemon, a short card) fails before the load and the page-cache advice stays.
The engine takes the carveout once its plan is set; until then an error closes it.

The host prompt cache sizes beside the streams in the same room the streams were counted in:
the first window's planes held in the carveout no longer come out of the cache's device room.
Main's kvHostRefusal check (4 lines in attach) takes the file to 601 with
this PR; the blank line before the kv safety test goes, as main did for
the cache default tests.
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

@bertholomus Thanks for the carveout work and the device receipts. One small thing: with TF_CUDA_CARVEOUT=1 at --tp 2, the load is refused correctly, but the user sees the generic load error instead of your message telling them to unset the carveout. FlashNextCarveoutUnsupported is only handled in explain, and a load goes through open in cuda_lanes_explain.zig. Could you add it to the forwarding branch in open, and to the load-refusal test beside it?

  • Synthena

This branch has not been deployed

No deployments
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.

4 participants