Repository navigation
core + cuda: one KV admission ledger; a request reserves its prompt and reply, not a whole window (#1943) - #1945
Conversation
|
Read through all six commits. The ledger itself looks right to me:
The One thing to settle before the first family converts: the order of the prompt cache and the streams. Until the cache can be reclaimed inside the budget (your Two small notes, no change needed:
For #1943's Qwen line: on today's main, Qwen 3.5/3.6 on pages ( |
|
Thanks @jschmied, good catch on the order. Fixed in 426dec7: Agreed on both notes. And thanks for the Qwen identity results at c=1–8; that clears the way for the paged default. |
|
Thanks @laudney, reviewed independently: this lands once its CI is green. With no family opted in, stream counts, plans and refusal bytes are main's across 2,304 comparison cells in both host modes. The first-token release regressions fail on main's |
On the default open path a stream that finishes on its first token ran its trace before releasing its lane, so a failed trace left the backend's caches held: the host discards only unfinished streams, and nothing released them again. The release now runs deferred around the trace, as the first-before-draft path already does, and two tests cover an unresolvable trace and every trace allocation failure on that path.
Unpaged streams need one byte budget that admitted requests promise from, so the lane host can admit by a request's own cost instead of a full window per stream. The ledger holds a total and the promised bytes with one lease per holder; a promise that does not fit fails with LaneMemory and changes nothing, and finishing a lease returns its bytes once. Nothing uses it yet.
An engine can now hand the lane host a byte budget and a per-request cost instead of a fixed stream count. The host promises a job's bytes in the same locked step that takes it from the queue, so staged fills and batched jobs are counted before a later choice; a job that does not fit stays queued, one past the whole budget fails in words, and finish and requeue return the lease. The ledger lives with the lane host, so its export moves out of core.
The CUDA host's openWith sat at 599 lines, too close to the limit for the ledger's admission branch to join it. The stream count, the page plan or whole windows the room holds with its no-stream and too-many refusals, moves unchanged into cuda_streams.zig, so the next change adds a branch there instead of in cuda.zig, which drops to 569 lines.
The CUDA host can now serve a family whose streams allocate a request's rows at open from one KV budget, instead of counting whole windows. Such a family sets Loaded.per_request to its kv_pool.Layout, lookahead rows and scratch; the host prices every request with one formula, places the prompt cache beside one full-window request and serves the rest as the ledger. No family sets it yet, so every current load is unchanged.
A family that sets Loaded.per_request reads these fields, not the issue, so the two rules its cost must keep belong on them, as the pool's author asked in ashhart#1943: fixed_bytes holds every byte the open path allocates for a request beyond its rows, and lookahead covers the widest drafted or verify pass the family runs, not one decode step. No code changes.
The ledger plan sized the prompt cache beside one full-window request, so on a 24-32 GB card the default 16 GiB cache could take everything past one window and a converted family would serve one long request at a time where whole windows serve --parallel. The plan now sizes the cache beside --parallel full-window requests, as the window plan's held bytes do, so streams come first and short requests still get the extra concurrency; a small-room test pins it.
|
Thank you @laudney. 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. |
|
Thanks @laudney! This is in TensorFold 1.2.2, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.2 |
Implements the first change proposed in #1943. That issue stays open for the family conversions that follow, one per family.
What this does
Unpaged CUDA families reserve a whole
--contextwindow per--parallelstream at load, while paged families reserve each request's prompt and reply when they admit it. This PR adds one admission model that any family can use: a byte ledger in the lane host, where a request promises what it can use and waits when it does not fit.It converts no family. Every current family keeps its exact stream count, prompt cache and tokens. A family opts in later, in its own PR, once its streams allocate per request.
fix(lanes): release a stream that finishes on its first tokenopen_first.zigalready does.feat(core): add the KV admission ledgercore/kv_ledger.zig: a byte total and one lease per holder, shaped likekv_pool.Pool's promise, finish and idle.feat(core): admit lane jobs against a byte ledgerInfo.ledger.takeJobpromises a job's bytes in the same locked step that takes it from the queue, so staged fills and batched jobs are counted before the next choice. A job that does not fit stays queued; one past the whole budget fails in words.finishandrequeuereturn the lease. With a ledger, the "nothing running" shortcut inchoosetests outstanding leases.stopwarns if a lease never came back. A round planner, which admits pasttakeJob, is refused beside a ledger.refactor(cuda): decide the stream count in cuda_streams.zignative/cuda.zigwas at 599 lines. Its stream-count decision moves intocuda_streams.zigunchanged, with the refusal texts byte-identical.feat(cuda): serve per-request families from the KV ledgerLoaded.per_requestto itskv_pool.Layout(the type the paged families declare), its lookahead rows and its scratch. The host prices every request asfixed_bytes + token_bytes × (min(prompt + max_tokens, context) + lookahead), sizes the prompt cache after--parallelfull-window requests (as the window plan'shelddoes, so streams come first on a small card), serves the rest as the ledger, and names it in the startup line.--parallelbecomes a cap. The ledger is refused with a warm pass, a lone driver, areservefield, a page layout or a drafter wrap.fix(cuda): size the ledger's prompt cache after every stream--parallelfull-window requests, as the window plan does. A small-room test with--parallel 4pins it.The reply limit is unchanged:
--max-tokenskeeps its 4096 default.Why
#1943 has the full case. In short:
prompt + max_tokensinstead ofroom / window(Canary results on DGX Spark (GB10): memory ceiling forces --parallel 8 → 3, mixed latency/throughput vs vLLM #1292 is the symptom on a DGX Spark);kv_pool.Layoutas the arithmetic half of paging a family;max_tokenswithout preemption.Checks
zig build test-cuda-host test-shared-lane-regressions-host test-kv-poolpass.zig fmt --checkis clean.python3 tools/zig/lean_check.py: 424 problems on this branch and 424 on its base. Every one is inherited, none added.core/lanes/open_trace_test.zig: a first-token finish releases its lane when its trace cannot resolve and when any trace allocation fails. Both tests failed before the fix.core/kv_ledger.zig: the ledger type.core/lane_host_ledger_test.zigon the fake backend: waiting without refusal, the head-of-line bound,LaneMemoryreturning its lease, a request past the budget refused in words, cancellation while queued and while running, batched admission never exceeding the budget, and a round planner refused.native/cuda_ledger.zig: the cost formula, cache placement after--parallelfull-window requests (a large room and a small one), a host cache, the refusal at the boundary, and a saturated cost.main, paged (the default) and unpaged (TF_KV_PAGES=0). The startup line (streams, budget, prompt cache) and the reply hashes of four greedy requests (prose, code, a 512-token reply, and one withoutmax_tokens) are identical in both modes. On GB10 the free room at load moves with page-list memory between runs, so each pair was compared in the same host state.Overlap
atc overlapfinds one textual conflict that this PR adds:native/cuda.zigagainst #1522, #1445 and #1446 (@BlivionIaG's EXL3 Flash Next stack). Those PRs change thegrowline of the stream-count block (preallocates_lanes), and this PR moves that block unchanged intocuda_streams.zigcount. So that change becomes the same two lines incount. I can carry it, or rebase onto whichever lands first. Their stack already conflicts with currentmainin four files of its own, which this PR does not touch.