Repository navigation
[Engine] Inkling 2: pick the prompt batch size from free VRAM - #320
Draft
okada-shogo wants to merge 1 commit into
Draft
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
okada-shogo
marked this pull request as draft
November 24, 2026 19:01
… the default) A prompt read in calls of more tokens is faster, but the calls' buffers come out of the expert cache. With --prompt-batch auto (now strata-poly's default; an explicit N works as before, up to 4096) Inkling 2 keeps 1,024-token calls for short prompts and outside reads, and a long read takes calls of up to 4,096 (8,192 on CUDA where every expert fits in VRAM), out of free VRAM or the expert cache (at most three quarters of it); end_read() gives it back and refills the cache at once (narrow_rows()). - CUDA (VMM): widen_rows() maps more of the prompt's buffers (addresses reserved for the widest batch at load), the window layers' rings and the products' work memory. With the DSpark drafter too. - HIP on native Linux (no lending on ROCm): a read of about 4,000 tokens or more gets buffers and rings of its own for calls of 4,096 (2,048 if 4,096 does not fit), freed after it. The free VRAM after the cut is counted from the bytes given back: ROCm counts them a few ms later. Not under WSL2 (each cut is a remap stall there) or on Windows. - Elsewhere (WSL2, a layer split, batch slots, Metal): one batch for the run, 4,096 where every expert fits. Other models resolve auto to 1,024; their paths are unchanged. Class: placement + batch split (a call's tokens change how sums are split, as --prompt-batch N does). Same bits at a fixed batch: --prompt-batch 1024 vs main, frozen, SAME on CUDA sm_75 and ROCm gfx1201 (native and WSL2), with and without the drafter; auto vs a fixed batch of the size it picks, frozen, SAME. RTX 2070 Super, IQ4_NL / UD-Q2_K_XL, vs main: prompt 2K +13/+33%, 8K +59/+66%, 32K +42/+64%; decode -1.1..+3.8%; with the DSpark drafter 2K +44%, 8K +55%. RX 9070 XT native Linux: IQ4_NL 8K +62%, 32K +68%, UD-Q2_K_XL 2K +42%, 8K +79%, 32K +75%; decode within 1%. Idea: the user's (scale the batch with the VRAM, per prompt where the experts do not fit). Builds on VecSzn's prompt-buffer lending (lend_prompt()/take_prompt()) and staging-buffer widening in main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
force-pushed
the
port/prompt-batch-auto
branch
from
November 25, 2026 01:39
88c2e93 to
0f8a702
Compare
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.
Branch: okada-shogo/PolyStrata
port/prompt-batch-auto, one commit 0f8a702 on simplex/main 36e654b.Problem and result
A bigger prompt batch reads long prompts much faster, but its buffers take VRAM from the expert cache. A fixed
--prompt-batch 4096reads 8K prompts about 65% faster on an RTX 2070 Super. But it makes 302-token prompts 22%slower and decode 3-12% slower, because 2.4 GiB of the 4.4 GiB cache is gone for the whole run.
--prompt-batch autois now the default for Inkling 2.--prompt-batch Nworks as before.expert cache for calls of up to 4,096, and gives it back before the answer starts. This also works with the
DSpark drafter.
out of the expert cache. They are freed, and the cache refilled, when the read ends.
expert fits in VRAM beside it, else 1,024.
Prompt tok/s, mean of 3 runs (warm server, kv fp16):
302-token prompts (and 2K on AMD) are within ±1% of main, apart from one slow run (−2.1%).
Decode after the prompt, 5 rounds (tok/s, mean):
On the RX 9070 XT the 8K change goes with the text: −1.2% to −2.3% on chat and code, +2.5% on prose. After a long
read the cache is refilled with its most used experts, not exactly the set main keeps. With the drafter, decode
after 8K is +11.7%.
All speed tables, each run (tok/s)
Decode reruns, 5 rounds, each run (tok/s). The RX 9070 XT runs are on the texts chat, code, prose, chat, code.
Prompt (tok/s, mean of 3 runs)
Decode (256 tokens after the prompt; tok/s, mean of 3 runs)
Setup:
kv fp16.
RX 9070 XT on native Linux (Fedora, amdgpu, ROCm 7.2.4 container, Ryzen 7 7800X3D,
--threads 11; tok/s.IQ4_NL: mean of 3 runs, one each on a chat, a code and a prose text. UD-Q2_K_XL: median of 3 rotated runs.)
cache is cut for the read in 30-48 ms and refilled after it. 2K reads keep 1,024: on HIP, calls of 2,048 do not
pay for the cut and refill (2K −7.8% when allowed).
IQ4_NL keeps 1,024 (see Limits).
On the RTX 2070 Super, the UD-Q2_K_XL 302 row comes from one slow run of this PR (258.6 tok/s). main also had slow
runs in its third round, which inflate the UD-Q2_K_XL 2K and decode-after-8K changes. The per-run tables show
both.
With the DSpark drafter (RTX 2070 Super, IQ4_NL,
--draft-model dspark-Inkling-2-Mini-Q8_0.gguf; tok/s, mean of3 runs). With the drafter's VRAM taken, auto reads long prompts in calls of 2,048.
Each run: prompt (tok/s)
Native Linux IQ4_NL: Run 1, 2, 3 are the chat, code and prose texts.
With the DSpark drafter:
Each run: decode (tok/s)
Native Linux IQ4_NL: Run 1, 2, 3 are the chat, code and prose texts.
With the DSpark drafter:
Why not a fixed --prompt-batch 4096 (RTX 2070 Super, tok/s, mean of 3 runs)
The "fixed 4096" column is main with
--prompt-batch 4096, measured in the same session.decode after 8K was 39.7 tok/s that way, against 42.4 on main.
Related discussion
none. It follows our own measurement: a plain
--prompt-batch 2048read 8K prompts 13-14% faster, but read302-token prompts 9-17% slower and kept a smaller expert cache.
Approach
on main. A read maps more of them, plus the window layers' rings and the products' work memory. The VRAM comes
from free VRAM or the expert cache, at most three quarters of it.
end_read()shrinks it all back and refillsthe cache at once.
(scratch, products' buffers, window rings). alloc()'s buffers stay in place, so recorded launches stay valid.
ROCm counts freed VRAM a few ms late, so the free figure after the cut adds the bytes given back.
--prompt-batch Ndoes. Nothing is skipped, and at a fixed batch the output is bit-identical to main.builds on VecSzn's prompt-buffer lending (
lend_prompt()/take_prompt()) and the staging-buffer widening inmain.
Validation
Passed:
STRATA_FREEZE_EXPERTS=1), once mode, 32 tokens, ids and top-20 probabilities bytefor byte:
--prompt-batch 1024vs main: SAME on CUDA (RTX 2070), and on ROCm gfx1201 (RX 9070 XT, nativeand WSL2), with and without the DSpark drafter.
without the drafter) and on HIP (IQ4_NL).
--prompt-int8roundingchange: 0.002-0.13 on 2K texts, 0.000 on 5K-8K texts. Table below.
Accuracy: KL and top-1 of the bigger batch (RTX 2070, frozen)
Accuracy of the bigger batch. Each row: the run at 1,024 is the reference; the other build is fed the reference's
tokens. KL is over the reference's top 20, mean of 32 steps. The int8 column is the accepted
--prompt-int8rounding change, as a control. The cap−10 column caches 10 fewer experts, as a placement control.
In each 2K text, one step dominates the mean (max 2.0 and 2.9; medians 0.0005 and 0.010). The int8 control shows
the same pattern on these texts.
The same comparison on the default cache (not frozen), this PR against main's default:
against main is SAME.
32/32.
Failed: none observed.
Not run:
--batchslots: auto uses 1,024 or a one-time pick there by design.memory", main's bug that [Engine] Retry instead of failing when a CUDA graph is out of VRAM #301 fixes.
Limits
states, as with any
--prompt-batchchoice. Identity and A/B tests should pin--prompt-batch 1024.the refill took 2.5-2.7 s (with [Engine] AMD on WSL2: remove a 4 s stall when the cache shrinks #302: 32K +43%, 8K −7%). Turning it on there can follow [Engine] AMD on WSL2: remove a 4 s stall when the cache shrinks #302.
🤖 Generated with Claude Code