Skip to content

feat(inkling2): read fp8 / int8 per-token-head KV in the attention kernels - #962

Merged
jason-fxz merged 4 commits into
mainfrom
feat/inkling2-kv-quant
Nov 28, 2026
Merged

jason-fxz merged 4 commits into
mainfrom
feat/inkling2-kv-quant

Conversation

@jason-fxz

Copy link
Copy Markdown
Collaborator

Serve Inkling 2 Mini with --kv-cache-dtype fp8_per_token_head or int8_per_token_head (refused at startup since #957). Both attention kernels read the 8-bit cache, and prefill moves to a new kernel that bf16 uses too.

Changes

  • Prefill (_extend_attention_split_kernel): this chunk's K/V come as bf16 rows (k_extend / v_extend) and the prefix from the cache, as in the shared triton backend. One program covers 128 rows = 42 tokens x the 3 q heads of a KV head, so each K/V tile is loaded and decoded once per KV head. Key tiles far from the query rows skip the bias and the mask; tiles inside the bias extent skip the mask; only the edges are fully masked. 8-bit tiles are decoded once per CTA and reach the MMA through shared memory. Their scales are applied in powers of two, so no rounding is added. The cache-only extend kernel is removed.
  • Decode: the split count is chosen per request at run time (power of two, at least 512 keys per split for long requests), within a cap that depends only on the batch size, so CUDA graphs still replay. Previously the count was static per batch.
  • models/inkling2/attention.py passes the KV format, the scales and the chunk's K/V rows.

Kernel time (RTX PRO 6000 Blackwell, sm_120)

Ratio = kernel time / vLLM bf16 kernel time, measured in the same process; below 1 is faster. vLLM 49ab32c, its sm_12x Triton kernels: attention + gate_sink for prefill, split attention + combine for decode; its fp8 KV is unit-scale e4m3. main = 42ccacd.

Prefill, one request (T = chunk tokens, p = prefix), median of 3 runs:

layer T2K p0 T2K p16K T2K p128K T8K p0 T8K p16K T8K p128K
full vLLM bf16 246 us 2863 us 21858 us 2294 us 9805 us 66529 us
vLLM fp8 1.11 1.13 1.13 1.13 1.15 1.12
main bf16 2.00 0.79 0.64 1.15 0.80 0.66
this PR bf16 0.79 0.79 0.78 0.72 0.76 0.77
this PR fp8 0.80 0.86 0.92 0.80 0.85 0.89
this PR int8 0.80 0.85 0.91 0.80 0.84 0.89
SWA 1024 vLLM bf16 168 us 232 us 233 us 731 us 795 us 795 us
vLLM fp8 1.10 1.11 1.10 1.11 1.11 1.11
main bf16 1.34 1.25 1.24 1.27 1.26 1.25
this PR bf16 0.82 0.92 0.88 0.92 0.94 0.92
this PR fp8 0.85 1.00 0.96 0.97 0.99 0.98
this PR int8 0.87 1.01 0.96 0.95 0.98 0.97

main's extend kernel spills registers; it is faster at a 128K prefix on full layers (bf16 here 1.21x / 1.17x of main) and slower everywhere else.

Decode (B requests of ctx tokens each), one run:

layer point vLLM bf16 vLLM fp8 main bf16 this PR bf16 this PR fp8 this PR int8
full B=1, 8K 32.6 us 0.69 1.02 0.95 0.67 0.68
full B=1, 128K 358.8 us 0.53 1.03 1.02 0.55 0.55
full B=8, 8K 188.5 us 0.55 1.01 1.01 0.57 0.58
full B=8, 128K 2815 us 0.51 1.00 1.00 0.52 0.52
full B=64, 8K 1412 us 0.52 1.00 1.00 0.54 0.54
full B=64, 128K 22375 us 0.51 1.01 1.00 0.53 0.53
full 16 requests, 1K-128K 1351 us 0.58 1.27 1.04 0.79 0.78
full 4 requests, 1K/4K/32K/128K 463 us 0.52 1.10 1.11 1.14 1.13
SWA 1024 B=1 12.3 us 1.02 0.99 1.01 0.94 0.88
SWA 1024 B=8 35.0 us 0.71 0.92 0.92 0.65 0.64
SWA 1024 B=64 189.6 us 0.67 0.99 0.99 0.58 0.57

The 4-request batch is slower than vLLM on main too: its 128K request runs alone after the short ones finish, on 16 splits of 32-key steps against vLLM's 23 splits of 128-key steps.

End to end (ft serve --moe-strategy fused, median of 5; 128K: 3)

--kv-cache-dtype GSM8K /100 full / window KV tokens prefill 2K / 8K / 32K / 128K tok/s decode bs1 1K / 32K / 128K tok/s
auto (bf16) 96 1.39M / 139K 17800 / 19925 / 17418 / 12279 120.8 / 114.6 / 92.2
fp8_per_token_head 98 2.67M / 267K 18058 / 19743 / 16969 / 10759 122.3 / 120.2 / 105.9
int8_per_token_head 97 2.67M / 267K 18014 / 19673 / 17136 / 11266 122.3 / 120.2 / 105.9
  • GSM8K: first 100 test questions, greedy, 16 concurrent requests, at most 4096 tokens; none truncated.
  • Against main: bf16 prefill +5% at 2K, +6% at 8K, +3% at 32K, -4% at 128K; decode unchanged.
  • Measured on the first commit, before the masked-key fix.

Tests

RTX PRO 6000 (sm_120):

  • pytest tests/models/inkling2/test_kernels.py: 36 passed. Extend and decode for bf16 / fp8 / int8, full and window layers; one request with two bias row windows, three requests in one launch (prefix 0, a chunk shorter than one tile), and a decode batch wide enough for two rounds of splits. Pool rows outside the slot list, row 0 among them, hold NaN. With FREETOKEN_FORCE_E4M3_EMU=1 -k fp8: 10 passed.
  • FREETOKEN_INKLING2_MODEL=<checkpoint> pytest tests/models/inkling2: 43 passed.
  • Registers: no spills and no stack for every extend and decode kernel and KV format on sm_80/86/89/90/100/120 (Triton 3.8 ptxas, --regAllocOptLevel=2, real launch specializations). Only sm_120 was run.

…rnels

- prefill reads this chunk's K/V from k_extend / v_extend and the prefix from the cache, with the 3 q heads of a KV head packed into one 128-row tile; bf16 uses the same kernel
- decode picks its split count per request at run time instead of a static count per batch
- drop the quantized-KV refusal and the cache-only extend kernel
Masked prefix tiles read slot 0 for keys past the prefix without a mask, so a NaN in that slot turned whole output rows into NaN.

- fill pool rows outside the slot list, row 0 among them, with NaN in the kernel tests
- test several requests in one extend launch and a decode batch wide enough for two rounds of splits
- round the window split cap down to a power of two
- drop the native e4m3 branch the HIP-only path never takes; rename BITS to BIT_DECODE
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