Skip to content

docs(xpu): the prompt cache's state size and what the 2 GiB default holds - #3972

Merged
ashhart merged 2 commits into
ashhart:mainfrom
SergiioB:xpu-docs-prompt-cache-size
Nov 20, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
SergiioB:xpu-docs-prompt-cache-size

Conversation

@SergiioB

Copy link
Copy Markdown
Contributor

What this changes

docs/xpu/README.md gives the prompt cache's 2 GiB default but not the size of a Qwen3.8-27B state. With the DFlash2
drafter and bf16 K/V, a state takes 64 KiB a prompt token plus 187 MiB, so the default keeps nothing past about 29,700
tokens. The server logs kept nothing at N tokens: M MiB passes the 2048 MiB budget. In the measured conversation,
which starts at 32,552 tokens, nothing is kept and every later turn processes its whole prompt again: 22 s to its first
token instead of 0.3–0.6 s. This adds the state size, the log line, that the budget is shared by the streams, and that
a larger budget needs a smaller --context on one card. No code changes.

Checks on this head

  • Head commit: 03985a824
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 189 on the base, 189 on the head, 0 new
    (tools/zig/lean_new.py), run before the last rebase (base 517a44563); the 189 are inherited. On this head,
    python3 tools/pr_check.py --base 6e7f3083b: lean 189 vs 189, 0 new, 0 errors, 0 warnings. git diff --check: clean.
  • Tests run, with the command and pass, fail and skip counts: none; documentation only, no source change.
  • CI: not run yet; the branch is on a fork, and CI runs when this pull request opens.
  • Not run, and why: int8 K/V (the new lines name bf16; source gives 32.5 KiB a token, not measured). Without a drafter
    (147 MiB is source arithmetic, snapBytes without Drafter.ctxBytes, not measured). GPTQ g128 (the state size does
    not depend on the weight format, since a state holds K/V, recurrent state and drafter context; whether a budget and
    --context fit beside GPTQ weights was not run). A conversation that grows through 29,700 tokens (the resume from the
    last state that fit is read from source: prompt_cache_keep.zig refuses a save before it evicts anything; not
    measured). --parallel above 1.

Receipt

n/a: documentation cannot reach inference. Each line:

  • Main against branch: cells and numbers, or why they can't be run: n/a, the branch changes only docs/xpu/README.md;
    the numbers below are from main.
  • Boxes it reaches: n/a, documentation only.
  • New switch? Default, accepted values, profile row: n/a, no new switch.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main
    174010ec7 (between it and 6e7f3083b, docs/xpu/README.md, the prompt cache, the slot states and the drafter are
    unchanged; only zig/src/xpu/tp.zig, tp_bench.zig and ze.zig changed under zig/src/xpu), Zig 0.17.0
    ReleaseFast, one uncommitted local build edit that drops -cl-intel-128-GRF-per-thread from opts_rows in zig/build/xpu.zig
    (our ocloc rejects it; it builds only the Gemma 4 prompt-rows kernel, which Qwen3.8-27B does not use), Level Zero
    compute-runtime 26.05.37020.3, Ubuntu 26.04, Linux 7.0, one Intel Arc Pro B70 32 GB at a 230 W power cap,
    TensorFold/Qwen3.8-27B-MLX-4bit revision 22d8d538, drafter z-lab/Qwen3.8-27B-DFlash2 revision 50307d4c,
    bf16 K/V.
  • Paths and platforms the change reaches, which I ran and which I could not: n/a for code. The numbers cover the XPU
    backend, MLX 4-bit with DFlash2, --parallel 1, one B70. Not run: GPTQ g128, other cards, --tp 2.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: n/a,
    documentation only.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you
    can't): n/a, documentation only.
  • Decode speed before and after, from tools/bench_openai.py: n/a, documentation only.
  • Prompt speed before and after: n/a, documentation cannot reach prompt processing. The table below is the evidence for
    the new lines, not a speed claim for this change.
  • Licence of any new weights or drafter, or "n/a": n/a, no new weights.

Evidence for the new lines. Server: ZE_AFFINITY_MASK=1 tensorfold-native serve Qwen3.8-27B-MLX-4bit --drafter Qwen3.8-27B-DFlash2 --parallel 1 --context CTX --prompt-cache-gib GIB --no-thinking --no-update-check. Client:
greedy (temperature 0, top_p 1, seed 4242, streamed). One conversation: a 32,552-token code prompt (512 tokens out),
then three short follow-up questions (up to 128 tokens out each), each reply appended. Time to first token per turn:

--context --prompt-cache-gib Turn 0 Turns 1, 2, 3 Log
139,264 2 (default) 21.5 s 22.0, 22.2, 22.3 s kept nothing at 32512 tokens: 2219 MiB passes the 2048 MiB budget, refused 4
139,264 3 — — the XPU engine cannot hold a stream of 139264 tokens and a 3.0 GiB prompt cache … on this card
40,960 2 (default) 21.7 s 22.1, 22.2, 22.4 s refused 4
40,960 3 21.7 s 0.56, 0.34, 0.30 s resumed at 32512, 33024, 33216; refused 0

State sizes from the same logs: 2,219 MiB at 32,512 tokens, 2,251 at 33,024, 2,263 at 33,216, 2,271 at 33,344; and
4,195 MiB at 64,128 tokens in an earlier run at --context 73728 with a 5.5 GiB budget (same model and drafter, a fork
binary whose changes do not reach snapBytes or the drafter context). From source: 16 attention layers × K and V × 4
heads × 256 × 2 bytes = 64 KiB a token; 48 GDN layers × (3 MiB recurrent + 60 KiB convolution) = 146.8 MiB, plus the
DFlash2 context ring, 40.6 MiB, = 187.4 MiB. The logs agree: 2,219 − 32,512 × 0.0625 = 187.0 (sizes print rounded
down). 2,048 MiB holds (2,048 − 187.4) / 0.0625 = 29,769 tokens, and states are kept at multiples of 64, so nothing
past 29,760: "about 29,700".

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. (No tests: documentation only.)
  • Comments and docstrings are one line. No measurements or history in the source. (No source change.)
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

The inference-only checklist is n/a because the receipt is documentation-only.

How to revert: revert the merge (or the squashed commit); it touches only docs/xpu/README.md.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @SergiioB. The state-size formula, the 2 GiB cutoff and the measured --context example explain when a conversation will resume and when the cache keeps nothing. The shared-stream budget note also makes the sizing requirement clear. The documentation applies cleanly to current main, and your receipt covers the added numbers. No further changes are needed.

  • Synthena

SergiioB and others added 2 commits November 20, 2026 01:13
…olds

With the DFlash2 drafter, a Qwen3.8-27B state with bf16 K/V takes 64 KiB a prompt
token plus 187 MiB, so the default budget keeps nothing past about 29,700 tokens.
Say so next to the budget, with the log line that shows it, that the budget is
shared by the streams, and that a larger budget needs a smaller --context on one card.
@ashhart
ashhart force-pushed the xpu-docs-prompt-cache-size branch from 03985a8 to f3ea65e Compare November 20, 2026 01:13
@ashhart
ashhart merged commit d019f01 into ashhart:main Nov 20, 2026
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @SergiioB. 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.

ashhart added a commit to jayleaton/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit that referenced this pull request Nov 20, 2026
ashhart added a commit to jayleaton/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit that referenced this pull request Nov 20, 2026
ashhart added a commit to jayleaton/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit that referenced this pull request Nov 20, 2026
ashhart added a commit to jayleaton/TensorFold that referenced this pull request Nov 20, 2026
ashhart added a commit that referenced this pull request Nov 20, 2026
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.

2 participants