Skip to content

Inkling 2: depth mix with wide blocks for decode and as rows, no copies of its columns - #142

Merged
rafasmour merged 3 commits into
masterfrom
opt/inkling2-depth-mix
Dec 4, 2026
Merged

rafasmour merged 3 commits into
masterfrom
opt/inkling2-depth-mix

Conversation

@rafasmour

Copy link
Copy Markdown
Owner

Inkling 2: the depth mix (attention over the block outputs, 120 launches per token) ran with one 256-thread block per (query, token), so a decode step had 1 to 4 blocks that each looped 9 times over 2304-wide rows twice: 15.7 us per launch. Its result was [Q, n_embd, n_tokens], and every Q/K/V input and every loop controller message was a ggml_cont of one column of it, also for the single query of the SWA layers (3 identical copies per SWA layer pass).

Change

  • inkling2.cu: 1024-thread blocks when there are at most one block per SM and rows of at least 2048 (decode).
  • inkling2.cpp: the mix is computed as states^T x scores -> [n_embd, Q, n_tokens], so the mix of one query is a row per token; the rows are used as views, with a copy only when the rows of several tokens are apart (Q > 1 at T > 1). The fused kernel writes either layout (template flag), the matcher accepts both operand orders.
  • test-backend-ops: DEPTH_MIX cases for the new layout.

Results

RX 7900 XT (gfx1100), ROCm 10.1, Inkling-2-Mini-UD-IQ4_XS, llama-bench -fa on, f16 KV, median of 5:

Measured on a stack of the open Inkling 2 branches, each line adds one change (pairs in the same block of runs):

state pp512 tg128
master + relpos 1560.8 46.1
+ 1024-thread depth mix blocks 1573.3 47.4 (+2.8%)
stack with bias table, FA, short conv, small-M branches 1624.2 58.1
+ row layout of the mix (+ the loop controller prompt path, which only changes batches of more than 8 tokens) 1676.7 (+3.2%) 61.0 (+5.0%)

The loop controller prompt path alone gave +1.8% pp512 in the same comparison, so the row layout is about +1.4% pp512 and all of the +5.0% tg128. Kernel launches per decode token on the full stack: 1968 (master: 3035).

A first version of the row layout expanded only the scores early, which split the chain and lost the depth mix fusion (tg 58.1 -> 55.7); the result is now expanded right after the scores.

KL divergence against master (llama-perplexity, 3 x 2048 tokens) on the stack: mean 0.0052 / PPL 3.5238 (master 3.5361), at the level of the flash attention change below it and of master -fa on vs -fa off (0.0053).

test-backend-ops -o DEPTH_MIX on ROCm0: 30/30 passed.

AI disclosure: written and measured with Claude Code on the hardware above.

…tiguous rows

The mix of a query was a column of [Q, n_embd, n_tokens] and every Q, K, V and
controller input was a copy of it, also for the one query of the SWA layers.
Now each mix is a row; the fused depth mix kernel writes either layout.

Assisted-by: Claude Opus 5.5
@rafasmour
rafasmour merged commit c9b053c into master Dec 4, 2026
10 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant