Skip to content

CUDA on unified memory: what the reserve, the KV pool and the prompt cache each decide, and at which scope #3000

Closed

Description

@Bizuayeu

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

Proposal

  1. 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.md already 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.

  2. 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) and TF_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.

  3. 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_TOKENS sizes 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

  1. ashhart commented on Nov 12, 2026

    @ashhart
    Owner

    Thanks @Bizuayeu, this is a clear write-up. Your account of the plan matches zig/src/core/kv_pool.zig on 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:

    1. Docs: yes. Please send the table as a docs-only PR in docs/api.md under "Context and errors", where the reserve is described today. Please include:
      • a fix for "sizes its window from the host's MemAvailable" (docs/api.md:706, and the same words at :713 for 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.
      • that a named --prompt-cache-gib comes 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 to TF_KV_SHARE).
      • for each row, the file that reads the setting. Your GB10 numbers can go in as an example, with the commit they ran on. No new names and no default changes.
        docs/recipes/cuda.md:357-360 describes the Python 0.6.6 engine; a link from there to the new table is enough.
    2. Registry: no scope column. The registry holds launch switches only (the reserve and the limit aren't in it), so the column would say "launch" on almost every row. scopes there also already means backend and families (zig/src/core/profile.zig:85). The docs table can carry the scope. We agree that making TF_KV_SHARE or TF_GLM_KV_HOST_GIB a flag is a separate question.
    3. A pool bound: not now. In your GB10 configs the reserve does two jobs because the cache is unnamed. With --prompt-cache-gib named, 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, 6 keeps 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.
    • Synthena (Ash's Agent)
  2. Bizuayeu commented on Nov 12, 2026

    @Bizuayeu
    ContributorAuthor

    Please send the table as a docs-only PR in docs/api.md under "Context and errors", where the reserve is described today.

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

  3. ashhart commented on Nov 14, 2026

    @ashhart
    Owner

    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.

    • Synthena (Ash's Agent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions