Repository navigation
docs(xpu): the prompt cache's state size and what the 2 GiB default holds - #3972
Merged
Merged
Conversation
Owner
|
Thanks @SergiioB. The state-size formula, the 2 GiB cutoff and the measured
|
…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
force-pushed
the
xpu-docs-prompt-cache-size
branch
from
November 20, 2026 01:13
03985a8 to
f3ea65e
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
docs/xpu/README.mdgives the prompt cache's 2 GiB default but not the size of a Qwen3.8-27B state. With the DFlash2drafter 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
--contexton one card. No code changes.6e7f3083b.atc overlap --json: ATC 0.9.6, 2026-11-19 14:22 UTC, base main6e7f3083b, head03985a824. No row has"source": "workingTree"and"worktreeOverlaps"is[], so the tool finds no overlap for this branch. Result:"complete": false, limitationsotherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit;"changedFiles": 1; 13 overlaps, all with"source": 2595(my other open pull request): 10clean, 3unknown, 0 conflicts.atc overlap --pulls 2595,3586,3587,3603,3703,3706,3960 --json(14:23 UTC):"complete": true,"overlaps": [], all seven inspected,"repositoryComplete": false.git merge-tree --write-treeof the headbefore this rebase (
ada74fc52, on main517a44563) with each of the seven: none changesdocs/xpu/README.md;xpu(qwen27): serve Qwen3.8-27B across TP={1, 2, 4} with DFlash2 #3586 and prompt cache: a miss reason on every lookup, with the removal ring and bounded /metrics labels #3706 merge clean; XPU 27B decode attention: tree rows of a key slice run back to back (bit-identical, +23 % at 32K, +33 % at 131K) #2595, xpu(flashnext): serve Qwen3.8 Flash Next (qwen4_exp) at TP={1, 2, 4} with host-RAM PLE and MTP #3587, xpu(flashnext): Xe2 DPAS tile kernels, adaptive solo chunks, and confidence MTP #3603, prompt cache: say why a request resumed no further, on the log, /metrics and (opt-in) the reply (#3686 step 1) #3703 and XPU: Qwen3.8-27B attention merge with 16 subgroups per head, bit-identical (lands #2799) #3960 conflict in the same files against main itself
(
zig/build/xpu.zig,zig/src/server/server.zig, the XPU contract files), so this branch adds no conflict.Checks on this head
03985a824python3 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 (base517a44563); 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.(147 MiB is source arithmetic,
snapByteswithoutDrafter.ctxBytes, not measured). GPTQ g128 (the state size doesnot depend on the weight format, since a state holds K/V, recurrent state and drafter context; whether a budget and
--contextfit beside GPTQ weights was not run). A conversation that grows through 29,700 tokens (the resume from thelast state that fit is read from source:
prompt_cache_keep.zigrefuses a save before it evicts anything; notmeasured).
--parallelabove 1.Receipt
n/a: documentation cannot reach inference. Each line:
docs/xpu/README.md;the numbers below are from main.
174010ec7(between it and6e7f3083b,docs/xpu/README.md, the prompt cache, the slot states and the drafter areunchanged; only
zig/src/xpu/tp.zig,tp_bench.zigandze.zigchanged underzig/src/xpu), Zig 0.17.0ReleaseFast, one uncommitted local build edit that drops
-cl-intel-128-GRF-per-threadfromopts_rowsinzig/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-4bitrevision22d8d538, drafterz-lab/Qwen3.8-27B-DFlash2revision50307d4c,bf16 K/V.
backend, MLX 4-bit with DFlash2,
--parallel 1, one B70. Not run: GPTQ g128, other cards,--tp 2.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: n/a,documentation only.
can't): n/a, documentation only.
tools/bench_openai.py: n/a, documentation only.the new lines, not a speed claim for this change.
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-gibkept nothing at 32512 tokens: 2219 MiB passes the 2048 MiB budget, refused 4the XPU engine cannot hold a stream of 139264 tokens and a 3.0 GiB prompt cache … on this cardresumed at 32512,33024,33216; refused 0State 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 73728with a 5.5 GiB budget (same model and drafter, a forkbinary whose changes do not reach
snapBytesor the drafter context). From source: 16 attention layers × K and V × 4heads × 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 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.