Repository navigation
Description
On a unified-memory GPU (GB10), the startup plan splits the room left after the reserve between the streams' windows, the prompt cache and the KV pool's pages. The settings that decide the split live at two scopes, and the pool has none of its own:
- the reserve (
TENSORFOLD_MEMORY_RESERVE_GIB, in the environment): the host's headroom; - the launch's shape (
--context,--parallel,--prompt-cache-gib, flags), and the number of kept states (TF_KV_SHARE, in the environment); - the pool's pages: whatever is left.
The docs don't say which setting decides which part, or at which scope each one belongs. In practice the reserve ends up shaping the pool and the cache as well as the host's headroom. This issue lays out what main (000b534a28) does, with GB10 numbers, and proposes writing the roles and scopes down. It changes no default and adds no name.
What main does
| Setting | Kind | Scope | Unset | What it decides |
|---|---|---|---|---|
TENSORFOLD_MEMORY_RESERVE_GIB |
environment | every CUDA native family | a tenth of MemTotal, at least 4 GiB, on unified memory | what the startup budget leaves free (#133) |
TENSORFOLD_CUDA_MEMORY_LIMIT_GB |
environment | every CUDA native family | none | a cap on the plan's room, weights included (#165) |
--context, --parallel |
flags | every family | GLM: 8192; auto: up to 8 streams |
a stream's window and the streams |
--prompt-cache-gib |
flag | CUDA native | half of what the whole windows leave, at least 16 GiB of it (#2699) | the prompt cache's budget; a named one comes before every window but the engine's own (#2220) |
TF_KV_SHARE |
environment, in the profile registry | the core page adapter's families | off | the kept states; their slots come out of the cache's budget, and the rest of it becomes pool pages (#2358) |
TF_GLM_KV_HOST_GIB |
environment, outside the registry | GLM | one window and 16 pages | GLM's host KV pages |
| the pool's pages | none | the core plan | — | what is left: the room less the fixed parts, the slots and the copies, at most the streams' windows plus the cache's pages (zig/src/core/kv_pool.zig, plan) |
With pages, GLM's plan takes the engine's own window, then each other stream's fixed part, then the cache (a named one here, an unnamed one after every whole window the room holds), then the slots, and makes the rest pages.
What that does on GB10
GLM-5.3-Flash at TP=3 on three GB10s, --context 1048576 --parallel 8, TF_KV_SHARE=32, no --prompt-cache-gib. The plan (kv_pool.zig, cuda_kv_pool.zig, cuda_memory.zig) is the same at 000b534a28 as in the engine these ran on.
| Reserve | Left after the reserve | Pool pages | Kept states' slots | Rank 0's free memory after load |
|---|---|---|---|---|
| 16 GiB (4 launches) | 37.2 to 37.3 GiB | 4,777 to 4,794 | 32 (5.3 GiB) | 16.44 to 16.72 GiB |
| 20 GiB (4 launches) | 33.3 to 33.4 GiB | 4,146 to 4,159 | 32 (5.3 GiB) | 20.51 to 20.57 GiB |
- Once the streams asked for exceed the room, the free memory after load is the reserve. Eight 1M windows need 16,392 pages, more than the room holds, so the pool takes everything past the fixed parts and the slots. That matches feat(cuda): TENSORFOLD_MEMORY_RESERVE_GIB sets what the startup budget leaves free #133's meaning.
docs/api.md, though, says the server "sizes its window" from MemAvailable less the reserve; native GLM keeps the window at--contextand sizes the streams and the pages instead. With--parallel 1 --context 2097152 --prompt-cache-gib 0, the pool stopped at the window's 4,097 pages, and about 10 GiB above the reserve stayed free. - An unnamed cache follows the number of whole windows the room holds. A small change in MemTotal or in the checkpoint moves the kept states (GLM CUDA: under TF_KV_SHARE, a band of rooms leaves the startup cache at 0, and since #2358 no state is kept #2547; in GLM CUDA: a named TF_KV_SHARE is planned after every window the room holds, so at TP=3 on a lighter checkpoint it keeps 8 of 32 states #2987, all 32 are kept on one checkpoint and 8 of 32 on one 4.5 GiB lighter, at the same 16 GiB reserve).
- So a config that wants a given pool and a given cache has one lever for both, the reserve, and that lever is the host's. Ours uses it that way: 16 GiB at TP=3 to keep the pool at two windows ahead of the cache, and 9 GiB at TP=2 so the 1M window fits. The host needs far less: in these runs the free memory fell 1 to 1.5 GiB from load to its lowest point, at TP=2 and at TP=3.
Proposal
-
Docs: one table of the memory settings on unified memory, with what each one decides and its scope:
- the host (environment): the reserve and the limit, set by the machine and what else runs on it;
- the launch (flags):
--context,--parallel,--prompt-cache-gib,--kv-cache, set by what the server is for; - the request (fields), as
docs/api.mdalready says for sampling ("A request's own fields win over the defaults").
The table would also say that on unified memory, once the pool fills the room, the reserve is the free memory after load, and it would correct "sizes its window" for native CUDA.
-
Registry (RFC: --profile stable | fast-exact | fast, one table for the opt-in switches #1660, Environment variables: refuse a bad value by name instead of reading it as a default, and register the ones that change outputs #2370): a scope column.
TF_KV_SHARE(a launch's count, read from the environment) andTF_GLM_KV_HOST_GIB(a size, outside the registry) would then show as the two settings whose scope isn't the rule's. Whether either should become a flag is a separate question. -
A question: would a bound on the pool's pages be welcome, with unset keeping today's plan exactly? DeepSeek V4.1's
TF_DSV41_POOL_TOKENSsizes its own pool that way. A config could then fix the pool and the cache without moving the reserve. It touches Roadmap: one paged KV pool and a radix prompt cache for every family #2444's open question 3 ("under one budget or a share?"), so it may belong there. We would measure it on GB10 before any PR.
Related: #133 and #165 (the reserve and the limit), #1660 and #2370 (the registry), #2444 (one pool), #2547 and #2987 (the cache after whole windows).
Written with Weave (My Symbiotic AI)
Activity
ashhart commentedon Nov 12, 2026
Thanks @Bizuayeu, this is a clear write-up. Your account of the plan matches
zig/src/core/kv_pool.zigon today's main. The engine's own window comes first, then each other stream's fixed part, then the cache: a named one before every other window, an unnamed one after the whole windows the room holds. After that come the slots, and the rest becomes pages, up to the streams' windows plus the kept pages. The reserve's default is as you say too: a tenth of RAM, at least 4 GiB, on unified memory (zig/src/native/cuda_memory.zig:141).On your three points:
docs/api.mdunder "Context and errors", where the reserve is described today. Please include:docs/api.md:706, and the same words at:713for discrete cards, since the plan is the same there). On native CUDA the window is--context, or the family's default when it's unset. On the paged families the streams and pages fill the room up to the streams' windows plus the cache's pages. Once those exceed the room, the free memory after load is the reserve.--prompt-cache-gibcomes before every window but the engine's own, and an unnamed one after the whole windows (GLM CUDA: a named TF_KV_SHARE is planned after every window the room holds, so at TP=3 on a lighter checkpoint it keeps 8 of 32 states #2987 covers what that does toTF_KV_SHARE).docs/recipes/cuda.md:357-360describes the Python 0.6.6 engine; a link from there to the new table is enough.scopesthere also already means backend and families (zig/src/core/profile.zig:85). The docs table can carry the scope. We agree that makingTF_KV_SHAREorTF_GLM_KV_HOST_GIBa flag is a separate question.--prompt-cache-gibnamed, the cache is set before the windows: in your GLM CUDA: a named TF_KV_SHARE is planned after every window the room holds, so at TP=3 on a lighter checkpoint it keeps 8 of 32 states #2987 table,6keeps all 32 states. The reserve then decides only the pool and the free memory after load, so it's one setting with one job. A pool bound would be a second way to say "leave this much free", at the launch's scope. If you still find a launch the reserve can't express with the cache named, bring the measured case to Roadmap: one paged KV pool and a radix prompt cache for every family #2444 under its question 3, and we'll take it up there.Bizuayeu commentedon Nov 12, 2026
#3000 (comment)
Thanks for checking the plan against
kv_pool.zig. I'll send that docs-only PR with the points you listed, with no new names or default changes. The registry column and the pool bound are dropped. On our GB10 configs I'll try naming the cache first, and if a launch still can't be expressed that way, I'll bring the measured case to #2444 under its question 3.docs: --context's unset and 0 windows, the files that size the unname…
docs: --context's unset and 0 windows, the files that size the unname…
docs: --context's unset and 0 windows, the files that size the unname…
ashhart commentedon Nov 14, 2026
Thanks @Bizuayeu for the careful write-up and for the docs PR: #3028 has landed, so the API reference now lays out what each setting decides and which file reads it. We're closing this as done; if a launch still can't be expressed with the cache named first, please bring it to #2444, or comment here and we'll reopen.