Skip to content

dsv41 cuda: the KV pool's family tensors come from the display carveout first - #3592

Draft
BadAd84 wants to merge 4 commits into
ashhart:mainfrom
BadAd84:dsv41-pool-carveout
Draft

BadAd84 wants to merge 4 commits into
ashhart:mainfrom
BadAd84:dsv41-pool-carveout

Conversation

@BadAd84

@BadAd84 BadAd84 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Stacked on #2762: this branch contains #2762's commits and the merge with main; the diff against main shows them until #2762 lands. Review the last commit only; it must land after #2762.

What this changes

With the display carveout on (TF_CUDA_CARVEOUT=1, the client from #2762), each of the DeepSeek-V4.1 KV pool's family tensors is taken from the carveout when it fits there, first fit in family order, and from device memory otherwise. The load-time memory check then charges the pool only for the part in device memory. With the carveout off nothing changes: every tensor comes from DeviceBuffer.alloc, as on main.

Checks on this head

  • Head commit: f272c709f (tree e697f7ef7d7a), on the merge 7d67a0d41 (tree 8339fe4aa0e1).
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: each tree's own checker, the base (the CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 merge) 6,552 files and 219 problems, this head 6,553 files and 219 problems, 0 new (lean_new.py). The 219 are inherited: main alone has 221. python3 tools/pr_check.py --base origin/main: 18 changed files, 0 errors, and the one advisory warning that the Unreleased line names no pull request number yet.
  • Tests run, with the command and pass, fail and skip counts: on x86_64 Linux (Zig 0.17.0, host steps only, no device work), each as zig build -j4 -Dfixed-cpu <step> --summary all on this tree: test-dsv41-device-host 225 of 225 tests, test-dsv41-forward 172 of 173 (1 skipped), test-dsv41-draft 137 of 137, test-dsv41-shared 102 of 103 (1 skipped), test-dsv41-cuda-host 69 of 69, test-cuda-host 6,772 of 6,805 (33 skipped), test-environment-host 27 of 27, test-env-defaults-host 117 of 117, test-environment-report-host 39 of 39 and test-gradient-serving 1 of 1. test-dsv41-kv, test-dsv41-env-host and test-dsv41-state pass, with Zig reusing the runs of identical test binaries. compile-dsv41-server, compile-dsv41-device-host, compile-dsv41-kv, compile-dsv41-tool and check-native-cuda-host build. test-host, the CI job's Linux step: 11,841 of 11,938 tests passed, 96 skipped, 1 failed. The failure is bringup_test's "a peer that stops after agreeing is found dead by name within the membership's dead time", a timing bound in main's own zig/src/cluster, which this change does not touch; it failed while the host was under heavy load and passed when its step ran alone (37 of 38, 1 skipped). Before the change the three new tests do not compile (the base has no openCarveout, Measured.carved or DevicePool.carvedBytes), and 7 mutants, each reverting one decision of this change, are each killed by the test written for it.
  • CI: no run when this was opened.
  • Not run, and why: the Windows host job (no Windows host here). An aarch64 build of this head (the device receipts below were taken on aarch64 images of the older base). zig build test as a whole; test-host, the CI job's Linux step, is listed above.

Receipt

The receipts below were measured on 2026-11-14 on an image of upstream v1.2.7 (93a2e93ec) with #2762's round-6 client and this change re-seated on it. That image also carried six more changes of ours that this branch does not contain and does not need, among them the float-projection setting our checkpoint needs to load. Receipts on this head's base are to follow.

  • Main against branch: not run. Every comparison below is the carveout on against off on one image: the 262,144-token cells ran A B B A with a fresh boot a cell, the 1,048,576-token cells one boot each way.
  • Boxes it reaches: GB10 with a display carveout, from the DRM dumb buffer or from a lending daemon (CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762).
  • New switch? Default, accepted values, profile row: no. CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762's rows decide it (TF_CUDA_CARVEOUT, TF_CUDA_CARVEOUT_SOURCE, TF_CUDA_CARVEOUT_MIB); unset, nothing changes. No profile row.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: two GB10s at --tp 2 on one ConnectX-7 cable (NCCL), kindling spark-os with dispramd lending 2,046 MiB a box, TF_CUDA_CARVEOUT_SOURCE=daemon. Checkpoint Mia-AiLab/DeepSeek-V4.1-Flash-1017-EXL3-EAQ-v1.1-2.9-bpw at aee640e2. The image's Zig, driver and CUDA toolkit versions were not recorded with these receipts; they will be with the receipts to follow.
  • Paths and platforms the change reaches, which I ran and which I could not: ran the daemon source at TP=2 with a split pool, at 262,144 and 1,048,576 tokens of context. Not run: the DRM source (it refuses on this OS, as CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 says), a single GB10 with an unsplit pool, and the carveout off on main itself. The carveout-off path is the same code as main by construction: a null carveout takes DeviceBuffer.alloc and the check charges the whole pool.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: from our own harness, not upstream's tools (those runs come with the receipts to follow). It compares token-id sha256 digests of fixed prompts.
    • At 262,144 tokens, the carveout on against off: 598 digests equal (4 salted resumed-turn digests are not comparable), and 826 of 838 replies equal as a multiset; the other 12 are those salted prompts. Drafted equals serial, burst and staggered equal solo, and resumed equals fresh, with the carveout on and off. 8 solo and 8 concurrent forks with the carveout on equal the solo forks with it off.
    • At 1,048,576 tokens, the carveout on: needles at 242,014, 498,776, 648,662 and 999,309 tokens came back exact, and the 8 solo and 8 concurrent forks equal the 262,144-token forks.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): not yet. It comes with the receipts on this head's base.
  • Decode speed before and after, from tools/bench_openai.py: from our own harness (carveout on against off, A B B A).
    • At 262,144 tokens, with the whole pool in the carveout: short decode 0.980x and 0.971x at 1 stream, 0.995x at 8; deep in a conversation 0.972x at 1 stream and at 8.
    • At 1,048,576 tokens, 8 streams, about half of the pool in the carveout (1,837 of 3,975 MiB a rank), one boot each way: short decode 262.8 and 267.6 tok/s against 265.8 and 269.7; deep 74.0 against 75.4 tok/s.
  • Prompt speed before and after: cold prompts from our own harness, not tools/bench_cache.py.
    • At 262,144 tokens, whole pool in the carveout, 1 stream: 31,372 tokens 25.90 and 25.91 s against 24.98 and 24.75 s (1.042x); 185,405 tokens 185.87 and 185.39 s against 167.09 and 166.06 s (1.114x); a resumed turn 3.37 and 3.34 s against 2.93 and 2.94 s (1.143x).
    • At 1,048,576 tokens, 8 streams, the same placement, one boot each way: 185,405 tokens 174.80 s against 166.74 s; a resumed turn 3.16 s against 2.94 s.
    • A 626,293-token prompt at 1,048,576 tokens of context with a 1,572,864-token pool, whole pool in the carveout: 948.5 s against 767.6 s (1.236x); 256 tokens decoded at that depth 48.94 against 50.35 tok/s; replies identical.
  • Licence of any new weights or drafter, or "n/a": n/a, no weights or drafter.

What the carveout buys, from the same receipts:

carveout off carveout on
262,144 tokens: pool in the carveout, a rank none 1,590 of 1,590 MiB, 8 of 8 tensors
262,144 tokens: MemAvailable after the load, rank 0 / rank 1 5,023 to 6,287 / 6,179 to 7,696 MiB 7,390 to 7,702 / 8,494 to 9,243 MiB
1,048,576 tokens, 3,932,160-token split pool: pool in the carveout, a rank none 1,837 of 3,975 MiB, 5 of 8 tensors
1,048,576 tokens: rank 0's worst point, predicted by the check 2.28 GiB (the 8-stream boot) 3.40 to 3.65 GiB (the 1 to 8-stream boots)
1,048,576 tokens: rank 0's lowest sampled free memory 2.36 GiB (one boot) 3.11 GiB (lowest over every boot)

The hard floor in those boots was 2 GiB (TF_DSV41_FLOOR_HARD_GIB=2.0). Without the carveout the 1,048,576-token boot runs within 0.28 GiB of it by the check's prediction; with the carveout, rank 0 never sampled below 3.11 GiB.

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. Measured on the older image above; to be repeated on this head.

  • No precision traded for speed. If the bits change, the description says which sums change and why. No sum changes: only the memory the pool's tensors live in.

  • 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. With the carveout off this is main's code path. With it on, prompts are slower, as measured above; that trade is why it is opt-in.

BadAd84 and others added 4 commits November 12, 2026 17:05
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.
Brings upstream main at 93de4c7 into the branch at
902b0a3, so the pull request is judged against current
main and no pushed commit is rewritten.

One conflict, CHANGELOG.md: both sides insert at the top of Unreleased. This branch's ashhart#2762
bullet stays first and every line of main's Unreleased block is kept as main has it, so the
merged changelog is main's plus that one bullet.

Four files both sides changed merged on their own and keep both sides' changes:
docs/environment.md and zig/src/platform/environment.zig (this branch's carveout rows
beside main's new settings and its blank-default rule), zig/src/platform/environment_test.zig
(their tests), and docs/recipes/cuda.md (main's API-reference line and this branch's daemon
section). zig/tests/fixtures/gradient-serving.tsv keeps both sides' rows, and this branch's
carveout.zig and carveout_lend.zig pins still match the merged files.
…ut first

With the display carveout on (TF_CUDA_CARVEOUT=1, the lending client from pull
request 2762), each of the DeepSeek-V4.1 KV pool's family tensors is taken from the
carveout when it fits there and from ordinary device memory otherwise, first fit in
family order, and each span goes back to the carveout when the pool is torn down.
With the carveout off every tensor comes from cuda.DeviceBuffer.alloc as before. No
setting is added: the carveout's own rows, already in the settings table, decide it.

A span the carveout lends is zeroed by Carveout.take on the legacy stream, which the
compute stream does not wait for, so the pool syncs the device once when it took one;
an ordinary allocation's fill runs on the compute stream and orders there already.

The load-time check (kv/budget.zig) charges the pool only for the part that stays in
device memory. The carved part is not assumed: DevicePool.carvedBytes runs the same
first-fit placement the allocator makes over a copy of the carveout's spans, so the
check uses the placement's own figure. The largest pool the terms still admit is
priced with those bytes as room, and the figures kept for the end-of-boot check hold
the device part, so its measured growth stays a measurement of memory the kernel can
see.

A carveout asked for without TF_DSV41_POOL_TOKENS stops the load with
CarveoutWithoutPool: the carveout exists to hold the pool, and without one it would
take memory nothing uses. A daemon or card that is not there, or a refused claim,
stops the load at the client's own line, and a refused claim's line carries the
daemon's reason. A malformed carveout row is refused by its name and accepted forms,
because the family's startup walk covers only its own rows.

Why: at a 1,048,576-token context a two-GB10 pair's 3,932,160-token split pool
leaves rank 0 less than half a GiB above the 2 GiB hard floor at its worst point;
with part of the pool in the carveout's slice the margin is more than a GiB. The
slice costs prompt speed, not decode, which is why it is opt-in. The receipts, and
the image they were measured on, are in the pull request.

Host tests: kv/budget.zig's check with a carved part (the worst point lifted by the
carved bytes, those bytes counted as room for the largest pool that fits, a carveout
larger than the pool charging nothing, and a refusal whose line names the carved
part); kv/device.zig's placement (family order, a family that does not fit left to
device memory while a later one still fits, and the spans untouched by the dry run);
and carveout_kv_test.zig in the device host steps (off unless asked for, with or
without a pool; refused without a pool; refused by name for a malformed row and for
a slice under the source's unit; and a load stopped by a daemon that is not there,
with nothing left allocated).

CHANGELOG.md gets its Unreleased bullet above the carveout client's.
@BadAd84

BadAd84 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Receipts for this draft on the stack it sits on: head f272c709f against its base 7d67a0d41 (#2762's head at that merge), two images built for this run, two GB10 at TP=2.

Two deviations, the same on both arms:

Token ids, base against head, carveout unset

Both arms ran the same environment file byte for byte. Two prompts (code and chat) at one stream, temperature 0: 2 compared, 2 equal, 0 different, 0 missing.
Inside each arm the bench_concurrent --alone --serial checks agree: 6 of 6 alone and 2 of 2 serial, 0 unequal, 0 failed.

Resume equals fresh

Raw token ids, so the first request's end is a strict prefix of the second. Rank 0 logs sessions: slot 0 resumed 8240 of 8256 prompt tokens from RAM in both phases, and the resumed reply equals the fresh one token for token, serial dd5ced43 and drafted ec75f9ae.
This engine reports cached_tokens: 0 in every response, so the evidence is the engine's line and the digest equality, not that field. Our first in-cell check keyed on that field and failed vacuously; it is kept on record as a tool defect.

The carveout at boot

With the carveout on, the whole pool is placed in the display carveout on both ranks: 8 of 8 family tensors, 0 MiB of it charged to device memory, at pool sizes 1,127,429 tokens (1,141 of 1,141 MiB) and 846,032 tokens (856 of 856 MiB).

What we do not have on this stack

No timing number: the second GB10 was held by another session's builds through every timing window, so every decode, prompt and capacity cell was discarded as confounded instead of quoted. The refusal cells at 1,048,576 context were also not taken, for the same reason.
A timing receipt for this change on this stack remains to be taken on an idle pair, and we will post it when we have it. The earlier timing numbers in the description were taken on the previous stack and are not repeated here.

@1jsamuel

Copy link
Copy Markdown

Additional GB10 placement evidence for this PR: our local DeepSeek backport uses the space remaining after compressed caches for RoPE tables and five index workspaces, reaching 2,042.026642 MiB of a 2,044 MiB claim on each TP2 rank.

This is a field report from an older serving tree, not a test of PR #3592's head or a patch ready for current main. The allocation categories may be useful when extending the new KV-family implementation.

Environment and source

  • Two headless Acer Veriton GN100 / NVIDIA GB10 nodes, 128 GB unified-memory class, TP=2.
  • Ubuntu 24.04.5; kernel 7.0.0-1019-nvidia; 4 KiB OS pages; NVIDIA driver 580.178.04.
  • spark-attic v0.1.6, validated heap mode, installed from the checksum-verified release artifact.
  • DeepSeek-V4.1-Flash-1017-BLACKFOLD EXL3 2.9bpw; TensorFold 629c524a0ea57512a5342abb498d1b7c25353343 plus existing local serving patches and this allocator backport. The daemon/VMM implementation derives from PR CUDA (GB10): a lending-daemon source for the display carveout, opt-in #2762 at 15970cfcb924b12f0158b8855e7c6722dd1f7325.
  • The 1,048,576-token shared pool, client limits and 2,000 MHz GPU ceiling were unchanged. This report does not qualify full-pool or maximum-concurrency operation.

Useful placement, per rank

Allocation category Bytes MiB
Existing 16 compressed attention/index-cache arrays 933,235,488 890.002716
Four RoPE tables in one allocation 536,896,000 512.023926
Five index workspaces 671,088,640 640.000000
Useful total, 22 allocations 2,141,220,128 2,042.026642

The workspaces are prompt keys/score/pool (128/64/256 MiB) and round keys/score (128/64 MiB). RoPE is arena-owned and allocated first; the caches and selected workspaces follow. All selected buffers remain valid until model teardown, and streams/graphs finish before release. Each allocation falls back to ordinary CUDA memory if it cannot fit.

Both ranks logged the exact category totals. Alignment takes 2,272 bytes and 2,066,944 bytes remain unused. Relative to the cache-only integration, this moves an additional 1,207,984,640 bytes / 1,152.023926 MiB per node. Rank 0's cold native allocation counter fell from 112,043,696,164 to 110,835,711,524 bytes, exactly that difference. These are useful-placement and allocation-counter measurements, not a claim of added physical RAM or an equivalent instantaneous Linux MemAvailable increase.

Checks and bounded timings

  • 250/250 host tests passed, including placement/alignment/refusal accounting; both aarch64 release binaries built successfully.
  • Five greedy requests completed with byte-identical output text before/after the expansion. Matched requests had the same request hash and zero reused prompt tokens; an earlier cached-baseline attempt was excluded and retained separately.
  • The full adapter separately imported the 2,044 MiB claim on both GPUs, wrote two patterns, checked boundaries and released it. Upstream heap validation reported zero mismatches across the full buffer.

Single matched comparison through our serving gateway, cache-only 890 MiB → expanded allocation, not attic-off → on and not upstream main → PR:

Case Prompt tokens Before seconds After seconds
Arithmetic 58 1.642 1.918
JSON 73 2.127 2.177
Long cache 31,467 19.151 19.811
Long index 128,667 79.344 75.581
Decode 65 4.700 4.689

These end-to-end timings include reasoning and answer generation. They are not repeated throughput benchmarks or proof of a general speedup, and they do not establish performance for PR #3592's current head.

Availability and limits

Our local opt-in has an auto mode that uses ordinary memory if the lender cannot be connected/authenticated/imported. Missing-socket fallback passed on the actual adapter; ordinary-memory serving also worked after a real boot-time lender-validation refusal. That optional behavior is useful when system updates temporarily leave no validated shim. It differs from this PR's deliberate missing-daemon load refusal and would need explicit budget/guard checks if adopted upstream.

The earlier cache-only revision passed a paired OS reboot. The expanded revision passed a cold model restart and persistent-pin checks; it has not yet been exercised through another OS reboot or an actual OS/driver upgrade. No full endurance/capacity rerun or independent raw-token-ID comparison is claimed here. The contribution is measured evidence for additional long-lived allocation categories and optional fallback semantics.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. The current-stack carveout-off token checks and logged RAM resume are useful, as are the enabled boot-placement rows. The idle-pair timings, capacity/refusal checks and enabled-versus-off serving equality remain open; the newer expanded-placement report is explicitly an older backport. Please keep those receipts tied to the exact integrated stack, including the shared float-linear patch. #2762 remains the prerequisite.

  • 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.

3 participants