Skip to content

[Engine] Inkling 2 drafter: lend prompt scratch to the expert cache - #316

Open
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/ink-draft-layouts
Open

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/ink-draft-layouts

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem and result

Inkling 2 keeps a small scratch for decode and lends the prompt batch's scratch to the expert cache between prompts.
With the DSpark drafter (--draft-model) this was off, because the drafter's features were laid out by the prompt
batch's rows. So with the drafter the whole prompt scratch (546 MiB at --prompt-batch 1024) stayed in VRAM while
answering.

With this PR the drafter's features follow the scratch layout in use, so the lending works with the drafter too.

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)):

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL decode after chat 302, ctx 32K 35.8 37.9 +5.8%
RTX 2070 Super 8 GB IQ4_NL decode after code 302, ctx 32K 32.0 38.5 +20.4%
RTX 2070 Super 8 GB IQ4_NL decode after prose 302, ctx 32K 51.1 53.9 +5.3%
RTX 2070 Super 8 GB IQ4_NL decode after chat 2,048, ctx 32K 34.4 35.7 +3.9%
RTX 2070 Super 8 GB IQ4_NL decode after code 2,048, ctx 32K 30.6 32.8 +7.2%
RTX 2070 Super 8 GB IQ4_NL decode after prose 2,048, ctx 32K 41.5 45.3 +9.0%
RTX 2070 Super 8 GB IQ4_NL decode after chat 8,192, ctx 32K 30.5 32.4 +6.2%
RTX 2070 Super 8 GB IQ4_NL decode after code 8,192, ctx 32K 32.7 34.5 +5.5%
RTX 2070 Super 8 GB IQ4_NL decode after prose 8,192, ctx 32K 37.5 39.6 +5.4%
RTX 2070 Super 8 GB IQ4_NL decode after chat 2,048, ctx 128K 33.0 34.3 +3.9%
RTX 2070 Super 8 GB IQ4_NL decode after code 2,048, ctx 128K 29.2 33.6 +15.1%

Experts in VRAM after the request, and the share of drafts kept (same runs, mean):

Card Model Request Experts after, main Experts after, this PR Drafts kept, main Drafts kept, this PR
RTX 2070 Super 8 GB IQ4_NL chat 302, ctx 32K 778 902 49% 45%
RTX 2070 Super 8 GB IQ4_NL code 302, ctx 32K 778 902 38% 82%
RTX 2070 Super 8 GB IQ4_NL prose 302, ctx 32K 778 898 84% 84%
RTX 2070 Super 8 GB IQ4_NL chat 2,048, ctx 32K 778 902 28% 39%
RTX 2070 Super 8 GB IQ4_NL code 2,048, ctx 32K 778 902 29% 66%
RTX 2070 Super 8 GB IQ4_NL prose 2,048, ctx 32K 779 895 74% 77%
RTX 2070 Super 8 GB IQ4_NL chat 8,192, ctx 32K 665 778 33% 39%
RTX 2070 Super 8 GB IQ4_NL code 8,192, ctx 32K 662 778 72% 72%
RTX 2070 Super 8 GB IQ4_NL prose 8,192, ctx 32K 662 770 74% 73%
RTX 2070 Super 8 GB IQ4_NL chat 2,048, ctx 128K 702 823 38% 53%
RTX 2070 Super 8 GB IQ4_NL code 2,048, ctx 128K 702 822 49% 79%
Prompt tok/s (same runs)
Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL prompt chat 302, ctx 32K 186.1 179.0 -3.8%
RTX 2070 Super 8 GB IQ4_NL prompt code 302, ctx 32K 193.3 182.1 -5.8%
RTX 2070 Super 8 GB IQ4_NL prompt prose 302, ctx 32K 230.1 226.2 -1.7%
RTX 2070 Super 8 GB IQ4_NL prompt chat 2,048, ctx 32K 369.7 367.3 -0.6%
RTX 2070 Super 8 GB IQ4_NL prompt code 2,048, ctx 32K 381.1 372.3 -2.3%
RTX 2070 Super 8 GB IQ4_NL prompt prose 2,048, ctx 32K 434.0 431.3 -0.6%
RTX 2070 Super 8 GB IQ4_NL prompt chat 8,192, ctx 32K 353.4 352.8 -0.2%
RTX 2070 Super 8 GB IQ4_NL prompt code 8,192, ctx 32K 363.7 362.3 -0.4%
RTX 2070 Super 8 GB IQ4_NL prompt prose 8,192, ctx 32K 395.6 396.8 +0.3%
RTX 2070 Super 8 GB IQ4_NL prompt chat 2,048, ctx 128K 362.2 362.4 +0.1%
RTX 2070 Super 8 GB IQ4_NL prompt code 2,048, ctx 128K 375.3 365.8 -2.5%
Each run (tok/s)
Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super 8 GB IQ4_NL decode after chat 302, ctx 32K main 36.0 35.3 36.2
RTX 2070 Super 8 GB IQ4_NL decode after chat 302, ctx 32K this PR 37.7 38.1 37.9
RTX 2070 Super 8 GB IQ4_NL prompt chat 302, ctx 32K main 185.5 185.5 187.2
RTX 2070 Super 8 GB IQ4_NL prompt chat 302, ctx 32K this PR 178.5 179.4 179.0
RTX 2070 Super 8 GB IQ4_NL decode after code 302, ctx 32K main 30.8 32.6 32.6
RTX 2070 Super 8 GB IQ4_NL decode after code 302, ctx 32K this PR 49.2 32.8 33.6
RTX 2070 Super 8 GB IQ4_NL prompt code 302, ctx 32K main 192.8 194.8 192.3
RTX 2070 Super 8 GB IQ4_NL prompt code 302, ctx 32K this PR 182.3 181.8 182.3
RTX 2070 Super 8 GB IQ4_NL decode after prose 302, ctx 32K main 50.3 51.6 51.5
RTX 2070 Super 8 GB IQ4_NL decode after prose 302, ctx 32K this PR 53.7 53.9 54.0
RTX 2070 Super 8 GB IQ4_NL prompt prose 302, ctx 32K main 226.3 231.2 232.7
RTX 2070 Super 8 GB IQ4_NL prompt prose 302, ctx 32K this PR 224.7 226.6 227.3
RTX 2070 Super 8 GB IQ4_NL decode after chat 2,048, ctx 32K main 34.8 33.7 34.7
RTX 2070 Super 8 GB IQ4_NL decode after chat 2,048, ctx 32K this PR 36.2 35.9 35.1
RTX 2070 Super 8 GB IQ4_NL prompt chat 2,048, ctx 32K main 369.5 369.2 370.3
RTX 2070 Super 8 GB IQ4_NL prompt chat 2,048, ctx 32K this PR 366.3 368.4 367.2
RTX 2070 Super 8 GB IQ4_NL decode after code 2,048, ctx 32K main 30.1 31.1 30.7
RTX 2070 Super 8 GB IQ4_NL decode after code 2,048, ctx 32K this PR 35.0 30.2 33.3
RTX 2070 Super 8 GB IQ4_NL prompt code 2,048, ctx 32K main 380.4 381.6 381.4
RTX 2070 Super 8 GB IQ4_NL prompt code 2,048, ctx 32K this PR 374.0 371.5 371.5
RTX 2070 Super 8 GB IQ4_NL decode after prose 2,048, ctx 32K main 39.1 44.4 41.1
RTX 2070 Super 8 GB IQ4_NL decode after prose 2,048, ctx 32K this PR 47.6 45.2 43.0
RTX 2070 Super 8 GB IQ4_NL prompt prose 2,048, ctx 32K main 433.3 433.7 434.9
RTX 2070 Super 8 GB IQ4_NL prompt prose 2,048, ctx 32K this PR 431.4 430.6 432.0
RTX 2070 Super 8 GB IQ4_NL decode after chat 8,192, ctx 32K main 28.3 31.7 31.6
RTX 2070 Super 8 GB IQ4_NL decode after chat 8,192, ctx 32K this PR 34.2 31.0 32.1
RTX 2070 Super 8 GB IQ4_NL prompt chat 8,192, ctx 32K main 352.9 354.5 352.7
RTX 2070 Super 8 GB IQ4_NL prompt chat 8,192, ctx 32K this PR 352.7 352.4 353.3
RTX 2070 Super 8 GB IQ4_NL decode after code 8,192, ctx 32K main 33.6 32.3 32.2
RTX 2070 Super 8 GB IQ4_NL decode after code 8,192, ctx 32K this PR 35.0 35.1 33.4
RTX 2070 Super 8 GB IQ4_NL prompt code 8,192, ctx 32K main 363.7 363.8 363.6
RTX 2070 Super 8 GB IQ4_NL prompt code 8,192, ctx 32K this PR 361.9 362.6 362.5
RTX 2070 Super 8 GB IQ4_NL decode after prose 8,192, ctx 32K main 34.6 41.2 36.8
RTX 2070 Super 8 GB IQ4_NL decode after prose 8,192, ctx 32K this PR 37.3 42.7 38.7
RTX 2070 Super 8 GB IQ4_NL prompt prose 8,192, ctx 32K main 395.7 395.6 395.6
RTX 2070 Super 8 GB IQ4_NL prompt prose 8,192, ctx 32K this PR 396.5 397.1 396.9
RTX 2070 Super 8 GB IQ4_NL decode after chat 2,048, ctx 128K main 33.3 33.2 32.4
RTX 2070 Super 8 GB IQ4_NL decode after chat 2,048, ctx 128K this PR 33.8 33.1 35.9
RTX 2070 Super 8 GB IQ4_NL prompt chat 2,048, ctx 128K main 363.3 361.5 361.7
RTX 2070 Super 8 GB IQ4_NL prompt chat 2,048, ctx 128K this PR 360.3 362.7 364.1
RTX 2070 Super 8 GB IQ4_NL decode after code 2,048, ctx 128K main 28.7 28.7 30.3
RTX 2070 Super 8 GB IQ4_NL decode after code 2,048, ctx 128K this PR 35.3 32.8 32.8
RTX 2070 Super 8 GB IQ4_NL prompt code 2,048, ctx 128K main 375.1 373.9 376.9
RTX 2070 Super 8 GB IQ4_NL prompt code 2,048, ctx 128K this PR 366.0 364.1 367.4
Earlier runs on a memorized benchmark text (not comparable: drafts kept ~99% after 2K+)

Experts in VRAM after the request, RTX 2070 Super 8 GB, Inkling 2 Mini IQ4_NL, drafter Q8_0, --prompt-batch 1024 --vram-reserve-mib 768 (the speed runs below; one engine a request):

Card Request main this PR alone Change
RTX 2070 Super 8 GB 302 tokens, context 32K 778 892 +114
RTX 2070 Super 8 GB 8,192 tokens, context 32K 662 775 +113
RTX 2070 Super 8 GB 2,048 tokens, context 128K 703 819 +116

Prompt tok/s, mean of 3 runs (RTX 2070 Super 8 GB, IQ4_NL, drafter Q8_0, --prompt-batch 1024 --vram-reserve-mib 768):

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL prompt 302 tokens, ctx 32K 223.3 217.7 -2.5%
RTX 2070 Super 8 GB IQ4_NL prompt 8,192 tokens, ctx 32K 364.9 364.3 -0.2%
RTX 2070 Super 8 GB IQ4_NL prompt 2,048 tokens, ctx 128K 369.4 370.3 +0.3%

Decode tok/s, mean of 3 runs (RTX 2070 Super 8 GB, IQ4_NL, drafter Q8_0, --prompt-batch 1024 --vram-reserve-mib 768):

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL decode after 302 tokens, ctx 32K 37.5 39.6 +5.7%
RTX 2070 Super 8 GB IQ4_NL decode after 8,192 tokens, ctx 32K 43.7 46.8 +7.1%
RTX 2070 Super 8 GB IQ4_NL decode after 2,048 tokens, ctx 128K 42.2 47.6 +12.8%
Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super 8 GB IQ4_NL prompt 302, ctx 32K main 224.1 220.1 225.7
RTX 2070 Super 8 GB IQ4_NL prompt 302, ctx 32K this PR 221.0 213.3 218.7
RTX 2070 Super 8 GB IQ4_NL prompt 8,192, ctx 32K main 365.0 364.5 365.1
RTX 2070 Super 8 GB IQ4_NL prompt 8,192, ctx 32K this PR 364.4 364.0 364.5
RTX 2070 Super 8 GB IQ4_NL prompt 2,048, ctx 128K main 366.4 372.0 369.7
RTX 2070 Super 8 GB IQ4_NL prompt 2,048, ctx 128K this PR 369.2 371.2 370.6
RTX 2070 Super 8 GB IQ4_NL decode 302, ctx 32K main 37.1 37.7 37.7
RTX 2070 Super 8 GB IQ4_NL decode 302, ctx 32K this PR 40.1 39.4 39.4
RTX 2070 Super 8 GB IQ4_NL decode 8,192, ctx 32K main 43.8 43.3 44.1
RTX 2070 Super 8 GB IQ4_NL decode 8,192, ctx 32K this PR 46.0 47.1 47.4
RTX 2070 Super 8 GB IQ4_NL decode 2,048, ctx 128K main 38.9 46.1 41.5
RTX 2070 Super 8 GB IQ4_NL decode 2,048, ctx 128K this PR 50.8 52.1 39.8

Output bits are unchanged (frozen identity below).

Related discussion

none

Approach

  • ds_tap_ is allocated per layout (assign_scratch(), buf_rows_ rows), but three places indexed it with the
    prompt batch's row count. They now use buf_rows_. In one layout buf_rows_ equals the prompt batch, so nothing
    changes there.
  • scores_apart() no longer excludes the drafter, so the two layouts and the lending are on with it.
  • ROCm on Linux keeps one layout, as before (STRATA_VMM_RELEASE_WITH_ADDRESSES).

Validation

Passed:

  • Identity, RTX 2070 Super, CUDA 12.9 sm_75, main 36e654b vs this PR, experts capped and frozen
    (STRATA_GPU_EXPERTS=600 STRATA_FREEZE_EXPERTS=1), STRATA_SPEC_FIXED=1, --draft-model, greedy token ids,
    2,048 + 128 and 8,192 + 128 tokens: SAME.
  • The freeze turns the two layouts off, so the same runs were also made with a test build that keeps the two layouts
    on under the freeze: SAME for both prompts. Without the drafter that build is SAME as main too.
  • VRAM: the table above, from a trace build that reports every allocation.
  • Speed: the table above (e2e-nw.sh, 3 rounds).
  • Builds: CUDA sm_75 (this branch). HIP gfx1201: the same change, in a test tree with VRAM tracing, built and ran on an RX 9070 XT (ROCm on Linux).
  • Independent code review of the diff.

Failed:

  • none observed

Not run:

  • Native Windows HIP with the drafter (there the two layouts are now on with the drafter, as they already are
    without it).
  • Metal: no Mac (no VMM there, so one layout and no change).

Limits

🤖 Generated with Claude Code

…r too

With --draft-model, Inkling 2 kept its prompt batch's scratch in VRAM for the
whole run (one layout), because the drafter's features were strided by the
prompt batch's rows: 546 MiB on an RTX 2070 Super at --prompt-batch 1024,
where the drafter's run without it has 32 MiB for the few tokens' layout.
The features are now strided by the rows of the layout in use (buf_rows_),
which is the prompt batch's in one layout as before, so the two scratch
layouts (VecSzn's, as Qwen3.6 has them) and the lending to the expert cache
between prompts are on with the drafter as well.

Placement only: every call computes the same values in the same order; the
features sit at another stride in the few tokens' layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant