Repository navigation
[Engine] Inkling 2: --kv q8_0, an 8-bit attention cache without FP8 hardware - #214
Open
okada-shogo wants to merge 5 commits into
Open
okada-shogo wants to merge 5 commits into
okada-shogo wants to merge 5 commits into
Conversation
The row layout other work builds on: a cache row is the n_kv heads' dim int8 codes, then one half scale for each block of 32 values in the codes' order (ink_kvq8_row(): 1,088 bytes for Inkling 2 Mini's 8 heads of 128, fp16 takes 2,048). A block's scale is its largest magnitude over 127 and a code round(x / scale), llama.cpp's quantize_row_q8_0 rule. Codes start 4-aligned in a row (row bytes are a multiple of 16). Rows are allocated like the fp8 ones (kv_alloc(kv_row(), 1), seq_alloc for the rings), so save/load of rows is unchanged. Token kernels (ink_qkv, ink_clips, score, value) and the sm80 flash kernel decode the codes as they read them; attend_batch() (Turing, HIP) dequantizes a block of rows into a workspace through Kvq8 with a new scale stride (Kvq8::ss, 0 = old rule). Not built or tested yet. Port of our simplexai-labs#200 engine's --kv q8_0 (src/poly/inkling.cpp) onto VecSzn's Inkling 2 engine, shaped like his --kv fp8 (abdb3b4). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…HIP nodiscard) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under STRATA_HIP_PREFILL_FP32=1 or 2, attend_batch() on HIP took dequant_q8_f32_kernel or gemm_q8 (hip_prefill_gemm.cuh), which read a q8 cache as width codes and width / 32 scales a row in two arrays. Inkling 2's --kv q8_0 cache keeps a row's codes and scales together (Kvq8::rs / ss), so a prompt batch on an AMD card would have read them at the wrong offsets. A cache with its own strides now keeps the half path, which takes them. Laguna, Kolibri, LFM2-MoE and Qwen3.5 on HIP pass rs = ss = 0 and keep the path they had. Found by an independent review of the PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/models/inkling.md said q8_0 works on every card, Turing and AMD included, and the usage text said Inkling 2 takes it on every card, but only the Turing kernel test has run, nothing on AMD, and a Mac refuses it (inkling2.cpp). Say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 23, 2026
okada-shogo
marked this pull request as ready for review
November 23, 2026 01:47
okada-shogo
added a commit
to okada-shogo/PolyStrata
that referenced
this pull request
Nov 23, 2026
…ention cache without FP8 hardware # Conflicts: # engine/cmake/strata_poly.cmake # engine/src/poly/inkling2.cpp # engine/src/poly/inkling2.cu Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
added a commit
to okada-shogo/PolyStrata
that referenced
this pull request
Nov 23, 2026
simplexai-labs#209 sends a Turing prompt batch to ink_flash75_kernel unless the caches are FP8; simplexai-labs#214 adds Q8_0 caches, which that kernel would read as halves (poly_inkling2_kvq8_test on an RTX 2070: ink_attend_batch rel rms nan). With --kv q8_0 on Turing the batch goes to attend_batch() again, simplexai-labs#214's checked path there. Only the combination of the two changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
okada-shogo
added a commit
to okada-shogo/PolyStrata
that referenced
this pull request
Nov 23, 2026
simplexai-labs#229's ink_fast_kernel loads fp16 and FP8 rows; simplexai-labs#214's Q8_0 rows would be read as halves there. With --kv q8_0 and STRATA_FAST_ATTN=1 a full layer stays on ink_flash_kernel, which decodes them. Only the combination of the two opt-in changes. 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
--kv fp8halves Inkling 2's attention cache, but needs NVIDIA Ampere or newer. This adds an opt-in--kv q8_0cachethat saves about the same VRAM and does not need FP8 hardware, so it can also serve Turing (sm_75) and AMD (HIP).
fp16 stays the default and is unchanged.
The size is from the layout (int8 codes plus one fp16 scale per 32 values).
Speed (RTX 2070 Super 8 GB, IQ4_NL, default placement): at a 115.5K prompt, q8_0 keeps 654 experts in VRAM against fp16's 266: prompt +43.5%, decode +9.8%. From 8K to 64K both run at the same speed within run-to-run noise. The fp16 default runs at main's speed.
The same build,
--kv q8_0against its fp16 default (= main's, see Speed under Validation):Prompt speed, tok/s, higher is better, mean of 3 runs (115.5K: 1 run). Change is computed from the unrounded means:
--kv fp16(= main's default)--kv q8_0Decode speed, tok/s, higher is better, mean of 3 runs (115.5K: 1 run). Change is computed from the unrounded means:
--kv fp16(= main's default)--kv q8_0RTX 2070 (8 GB, sm_75), IQ4_NL, q8_0 against fp16 (details under Validation):
an 8,192-token prompt; KL mean 0.034 (max 0.82), top-1 125 of 128 after the 2,048-token prompt (the sensitive one,
see below). fp16 against itself is 0.
--kv-whole: 518 experts fit in VRAM with q8_0, 129 with fp16. A 115,500-token prompt loads andanswers with q8_0 (941 experts in VRAM, prompt 386 tok/s, decode 13.8 tok/s).
Related discussion
Split out of #200, as the maintainer asked there:
#200 (comment)
Approach
quantize_row_q8_0rule).ink_qkv,ink_clips) store codes and scales. Decode (ink_attend) and the Ampere flash kernel turn thecodes into floats as they read them. On Turing/HIP,
attend_batch()dequantizes blocks of rows into a 16 MiBworkspace.
Kvq8gets a scale stride (ss, 0 = the old rule), so other models are unchanged.attend_batch()'s FP32 products (STRATA_HIP_PREFILL_FP32=1or2) read a q8 cache as two plain arrays,so a cache with its own strides (this one) keeps the half path there.
ink_attend_batchreads the cache directly: it is whatattend_batch()needs underSTRATA_INK_FLASH=0.poly_inkling2_kvq8_test.--kv fp8.Validation
Passed:
CUDA 12.9 build, sm_75, GCC 11.4, at this branch's head:
strata-polyandpoly_inkling2_kvq8_testbuild.poly_inkling2_kvq8_test, RTX 2070 Super (sm_75): 13 checks pass, 1 skipped (Ampere-only),PASS: 0 failed:quantize_row_q8_0byte for byte (full and ring caches, 0 of 2,506,752 / 1,114,112 bytesdiffer);
ink_attendwithin 2.7e-7 relative RMS of a float64 reference (1 and 4 rows, full and window);attend_batchwithin 5.3e-4 relative RMS (halves of queries and weights), and the same bits as an fp16 cache ofthe dequantized halves.
(void)casts tocudaFreecalls in thetest (for HIP's nodiscard).
HIP build (compile only, no AMD card), built on top of [Engine] build Inkling 2's DSpark screen on HIP #206 (this head merged with b681c69), ROCm 7.2.4 container,
gfx1100;gfx1201:cmake -S engine -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DCMAKE_HIP_ARCHITECTURES="gfx1100;gfx1201" -DSTRATA_BUILD_TESTS=ON -DSTRATA_NATIVE_EXPERTS=ON -DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ -DCMAKE_PREFIX_PATH=/opt/rocm && ninja -C build -k 0 strata-poly poly_inkling2_kvq8_test: both build, 0 errors.Head (d57f5d0): CUDA 12.9 sm_75 build of
strata-polyandpoly_inkling2_kvq8_test. HIP (ROCm 7.2.4, gfx1201):kernels.cucompiles forstrata-poly,poly_hip_prefill_fp32_testandpoly_inkling2_kvq8_test(the full HIP link needs [Engine] build Inkling 2's DSpark screen on HIP #206).python3 tools/check --only docs: 6 of 6.AMD, RX 9070 XT (gfx1201), SaladCloud container, ROCm 7.2.4: this branch on top of [Engine] Inkling 2 on AMD (RDNA3/RDNA4): HIP support #217's tip 64830fb, with the
merge fix below (fork branch
port/kvq8-on-hip, 141963a). HIP build ofstrata-polyandpoly_inkling2_kvq8_test0 errors.
poly_inkling2_kvq8_test: 13 checks pass, 1 skipped (Ampere-only),PASS: 0 failed(stores 0 of2,506,752 / 1,114,112 bytes differ;
ink_attendrel RMS 2.2-2.7e-7;attend_batch4.9-5.3e-4).End to end, IQ4_NL,
strata-poly --tokens <N ids> --max-new 16 --top-probs 20 --kv q8_0against--kv fp16, q8_0also fed fp16's tokens (
--follow). KL over the top 20 in nats (lower is better), top-1 as a count of 16 tokens:--kv q8_0--no-gpu-experts)--no-gpu-experts)--no-gpu-experts)--no-gpu-experts)--no-gpu-experts)--no-gpu-experts)Greedy tokens: the same as fp16's at 302 (
--no-gpu-experts) and 8,192; first differ at 302 with experts in VRAM(token 6, ln p1/p2 = 0.07), 2,048 with experts in VRAM (token 2, ln p1/p2 = 3.87) and 2,048
--no-gpu-experts(token 5, ln p1/p2 = 0.89). Largest step's KL: 0.0079, 0.0068, 2.53, 0.46, 0.00000 (rows in order). At 8,192 the
top-20 values differ slightly but the next tokens are near-certain. No fp16-vs-fp16 noise floor on this card.
The 2,048 prompt is the one that is unusually sensitive on every engine ([Engine] Inkling 2 on AMD (RDNA3/RDNA4): HIP support #217: HIP against CUDA, fp16, KL 0.215 on
this card; the CUDA card against itself, experts on the card vs on the CPU, 0.095). Logs:
kit44
progress44.logandres/(container/work/c44).CUDA end to end, RTX 2070 8 GB (sm_75), Ryzen 7 5800X, IQ4_NL, CUDA 12.9 sm_75 build of e4cce18 with a test-only
patch that dumps each step's full logits (the head's later commits are a test cast, a HIP-only fix and docs):
2,048 and 8,192-token prompts (and the branch against itself).
floor), Q = q8_0 fed F1's tokens, Qg = q8_0 greedy:
KL against F1 in nats (lower is better), top-1 as a count of 128 tokens:
--kv q8_0, QGreedy q8_0 (Qg) against F1: first differs at token 8 after the 2,048 prompt; the same 128 of 128 after 8,192.
q8_0: the same 128 tokens; prompt 505 -> 512 tok/s, decode 28.7 -> 28.9 tok/s.
--max-context 131072 --kv-whole, 2,048-token prompt: fp16 loads with 129 experts in VRAM, q8_0 with 518.--max-context 131072 --kv q8_0, a 115,500-token prompt + 32 tokens: runs, 941 experts in VRAM, prompt 385.9 tok/s,decode 13.8 tok/s.
CUDA, RTX 3060 12 GB (sm_86), a 75;86 build of d97dd7e:
poly_inkling2_kvq8_testPASS: 0 failed, now with theAmpere-only
ink_attend_batch(flash kernel) checks too (full rel RMS 5.3e-4, window 4.9e-4). The fp16 defaultagainst main (frozen split, IQ4_NL, 2,048 + 32 and 8,192 + 16 tokens): ids and every top line the same.
Speed, RTX 2070 Super 8 GB (sm_75), Ryzen 7 5800X, IQ4_NL, CUDA 12.9 sm_75 builds of main d1f711e and this head d57f5d0. One
strata-poly --serveengine per run, one greedy request: the prompt, then 128 tokens. Default placement (no expert profile, no freeze, no--kv-wholein any mode: the attention cache grows and takes VRAM from the expert cache).--max-context16384 / 36864 / 69632 / 131072 for the 8K / 32K / 64K / 115.5K prompts, the same in each row. 3 rounds, the order rotated each round. Main was left out at 64K and 115.5K to keep the job near 60 min. "Experts in VRAM" is the expert cache after the request. fp16 fits at 115.5K too (no failure), with 266 experts left.Decode at 8K and 32K moves by about 10% between runs (single slow runs: 26.1 for q8_0 at 8K, 20.5 for fp16 at 32K), so the decode differences there are noise. Prompt and 64K/115.5K figures are steady.
Default (
--kv fp16) against main:Prompt speed, tok/s, higher is better, mean of 3 runs. Change is computed from the unrounded means:
--kv fp16Decode speed, tok/s, higher is better, mean of 3 runs. Change is computed from the unrounded means:
--kv fp16Each run (tok/s)
Prompt speed, tok/s, each run:
--kv fp16--kv q8_0--kv fp16--kv q8_0--kv fp16--kv q8_0--kv fp16--kv q8_0Decode speed, tok/s, each run:
--kv fp16--kv q8_0--kv fp16--kv q8_0--kv fp16--kv q8_0--kv fp16--kv q8_0Experts in VRAM after each request, of 3,072:
--kv fp16--kv q8_0--kv fp16--kv q8_0--kv fp16--kv q8_0--kv fp16--kv q8_0Job:
kvq8-speed.sh(NAME=sp1), log~/inkling-work/kvq8-speed/sp1/progress.log; window 64 min, rc=0, server restored, live expert profiles unchanged.Failed: none observed.
Not run:
poly_inkling2_kvq8_testwithSTRATA_HIP_PREFILL_FP32=1, and any AMD run of this branch without [Engine] Inkling 2 on AMD (RDNA3/RDNA4): HIP support #217 (main alonedoes not run Inkling 2 on AMD). RDNA3 (RX 7900 XT): not run.
ink_qkvwith q8_0); the test checks stores throughink_clipsonly.Limits
inkling2.cu'sink_clips()/ink_qkv(): [Engine] Inkling 2 on AMD (RDNA3/RDNA4): HIP support #217 replaces the fused clips and q/k/v kernels on HIP with separate launches (clips_apart()), and thisPR makes the fused kernels store Q8_0 rows. Whichever merges second must carry the HIP Q8_0 store: a small HIP-only
ink_store_q8_kernelthat callskvq8_store(), used byclips_apart()whenkvq8is set (andink_qkvpassingkvq8on). The resolved merge is commit b4fd0c6 on fork branchport/kvq8-on-hip([Engine] Inkling 2 on AMD (RDNA3/RDNA4): HIP support #217's tip + this PR's fivecommits); the AMD run above used it.
--kv q8_0for every strata-poly model on a gfx1012 card (Radeon RX 5500 / Pro 5500M class,rdna1_poly_args()). Beforethis PR Inkling 2 stopped at load there; now it would run on q8_0, untested on AMD.
read fp16 (and FP8) rows only. [Engine] Inkling 2: prompt attention on Turing's tensor cores #209: add
!a.kvq8to its Turing flash gate inink_attend_batch(), or--kv q8_0on Turing gets wrong prompt attention (
poly_inkling2_kvq8_teston an RTX 2070:ink_attend_batchrel rms nan);resolution 43fa074dc. [Engine] Inkling 2: STRATA_FAST_ATTN, a faster lossy prompt attention (opt-in, sm80+) #229: add
!a.kvq8to theSTRATA_FAST_ATTNbranch (both opt-in);resolution a99d203b7. Both commits are on fork branch
combined/ready.Credits: ported from our engine's
--kv q8_0(#200) onto VecSzn's Inkling 2 engine, following his--kv fp8.🤖 Generated with Claude Code