Repository navigation
[Engine] Inkling 2 drafter: grow its attention cache with the context - #317
Open
okada-shogo wants to merge 1 commit into
Open
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
The DSpark drafter's full-attention layer kept keys and values for the whole --max-context from the start (fp16, 4 KiB a position): 128 MiB at 32K and 512 MiB at 128K that the expert cache never had. They are now two more of the engine's growing attention caches (kv_alloc(), mapped by cover() with the target's rows and given back by trim_kv()), so a short conversation maps only the rows it reaches. The window layers' rings stay as they were. Metal keeps one allocation. A conversation brought back (load_card_rows()) does not carry the drafter's rows; the ones mapped again for it can be VRAM the expert cache had, so they are zeroed there, as fresh VRAM was before. Placement only: the drafter writes and reads the same cells; only the VRAM behind the rows it does not reach yet is not mapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem and result
With the DSpark drafter (
--draft-model), Inkling 2 allocated the drafter's full-attention layer cache for the whole--max-contextat load: 128 MiB at 32K and 512 MiB at 128K. A short chat uses a few MiB of it. That VRAM is missingfrom the expert cache for the whole run.
With this PR that cache grows with the conversation, like the target's own full-attention caches already do.
Experts in VRAM, Inkling 2 Mini IQ4_NL, drafter Q8_0,
--prompt-batch 1024, default reserve (one engine, one run):Decode tok/s, mean of 3 runs (RTX 2070 Super 8 GB, Inkling 2 Mini IQ4_NL, drafter Q8_0,
--prompt-batch 1024 --vram-reserve-mib 768, 256 tokens written; three texts in place of the memorized benchmark text: code (C++ source of this engine), a multi-turn chat in the model's template, and novel prose (Pride and Prejudice, from chapter 20; a well-known book, so its drafts are kept more often)):Experts in VRAM after the request, and the share of drafts kept (same runs, mean):
Prompt tok/s (same runs)
Each run (tok/s)
Earlier runs on a memorized benchmark text (not comparable: drafts kept ~99% after 2K+)
After the request in the speed runs below (
--vram-reserve-mib 768): 778 -> 803 (302 tokens, 32K), 662 -> 688 (8,192tokens, 32K), 703 -> 802 (2,048 tokens, 128K).
Prompt tok/s, mean of 3 runs (RTX 2070 Super 8 GB, IQ4_NL, drafter Q8_0,
--prompt-batch 1024 --vram-reserve-mib 768):Decode tok/s, mean of 3 runs (RTX 2070 Super 8 GB, IQ4_NL, drafter Q8_0,
--prompt-batch 1024 --vram-reserve-mib 768):Why decode is faster after the longer prompts on both sides: the benchmark prompt is a text the model knows by heart (a software licence), so after 2K–8K tokens of it the drafter's guesses are almost all accepted, while after 302 tokens far fewer are. Compare each row's two columns, not the rows with each other. The 128K gain comes from the 99 extra experts in VRAM (703 → 802); main's three runs there spread from 38.9 to 46.1 tok/s, this PR's from 49.2 to 50.7.
Output bits are unchanged (frozen identity below).
Related discussion
none
Approach
kv_alloc()inInkling2::alloc_caches().cover()mapsrows as the target's rows grow, and
trim_kv()gives them back. The window layers' small rings stay as before.guess_block()limits a block to the room left),so
max_contextrows are enough.may be VRAM the expert cache used before, so
load_card_rows()zeroes them (before, fresh VRAM was zero).Validation
Passed:
(
STRATA_GPU_EXPERTS=600 STRATA_FREEZE_EXPERTS=1), drafter draft lengths fixed (STRATA_SPEC_FIXED=1),--serve --kv fp16 --prompt-batch 1024 --draft-model dspark-Inkling-2-Mini-Q8_0.gguf, greedy token ids:e2e-nw.sh, 3 rounds).Failed:
Not run:
#if-guarded out there.Limits
--vram-reserve-mib 768: at the default reserve, main ends some drafter requests withcudaGraphInstantiate: out of memory(fixed separately in [Engine] Retry instead of failing when a CUDA graph is out of VRAM #301), which spoils a speed comparison.STRATA_SPEC_FIXED=1, drafter runs differ from run to run on main too (the draft policy learns fromtimings), so the identity runs fix it.
cudaGraphInstantiate: out of memoryon main and here; [Engine] Retry instead of failing when a CUDA graph is out of VRAM #301fixes that separately.
🤖 Generated with Claude Code