Skip to content

turbo5 and turbo6 KV cache types - #381

Merged
TheTom merged 9 commits into
TheTom:feature/turboquant-kv-cachefrom
JakeATX:tq5-tq6-kv-cache
Oct 22, 2026
Merged

TheTom merged 9 commits into
TheTom:feature/turboquant-kv-cachefrom
JakeATX:tq5-tq6-kv-cache

Conversation

@JakeATX

@JakeATX JakeATX commented Sep 22, 2026 •

Copy link
Copy Markdown

turbo5 and turbo6 KV cache types

Summary

Two new runtime-only KV cache types that sit between q8_0 and turbo4:

Type Enum Block Layout bpv
turbo5 51 128 values / 82 B f16 norm + 64 B 4-bit magnitudes + 16 B sign bits 5.125
turbo6 52 128 values / 98 B f16 norm + 64 B 4-bit low plane + 32 B 2-bit high plane 6.125

Both reuse the turbo4 pipeline with a larger codebook: the fixed 128x128 WHT
rotation, a Lloyd-Max codebook for the rotated N(0, 1/128) distribution, and a
per-block corrected L2 norm. turbo6 has 64 centroids (per-coordinate rmse
0.025 sigma), turbo5 has 32 antisymmetric centroids (0.050 sigma). Because the
turbo5 codebook is antisymmetric it is stored sign-magnitude, a 4-bit
magnitude index plus a sign bit, which makes the CUDA decode a single
byte-permute lookup instead of a 32-entry gather.

Motivation

turbo4 at 4.125 bits is the current ceiling below q8_0's 8.5. The two new
types fill that gap, mainly as V types and as K types on models where the
auto-asymmetric rule does not apply (GQA below 6, or hybrid models). On dense
high-GQA models they fall under the auto-asymmetric rule like turbo2/3/4, see
Evidence.

Design

Codec: ggml/src/ggml-turbo-quant.c holds the centroid tables and the
reference quantize/dequantize, wired into ggml.c type traits, the CPU
backend vec_dot and ggml_quantize_chunk. CUDA gets the same codec in
ggml-cuda/turbo-quant.cuh plus SET_ROWS, CPY and dequant paths. There is
no GET_ROWS for these types, as for turbo2/3/4.

Flash attention, CUDA:

  • vec path, default build (head dims 128 and 256): turbo5/turbo6 K with V
    of the same type, turbo3, turbo4, q8_0 or f16; turbo6 K with
    turbo5 V; q8_0 K with turbo5/turbo6 V (what the auto-asymmetric rule
    produces). GGML_CUDA_FA_ALL_QUANTS adds the remaining cross pairs with
    f16, q8_0 and turbo2/3/4.
  • fused GQA-packed MMA path (fattn-mma-turbo.cuh): turbo5/turbo5,
    turbo6/turbo6, turbo5/turbo3, turbo6/turbo3 at head dims 128 and
    256, plus turbo5/turbo4, turbo6/turbo4 and turbo6/turbo5 at head
    dim 256. As with the existing turbo pairs the fused path is used for
    Q->ne[1] <= 4 and otherwise falls back to vec.
  • The MMA tile loaders decode a whole K or V tile into shared memory. turbo6
    uses a warp shuffle over the 64-entry table; turbo5 uses a 16-entry prmt
    magnitude table plus the sign bit. A turbo4 V under a turbo5/turbo6 K is
    decoded by a flat prmt variant of the turbo4 loader; turbo4/turbo4 is
    untouched. Both loaders build their tables from the centroid arrays.
  • supports_op reports no kernel for any pair without a vec instance, so an
    unsupported pairing (bf16, q4/q5, iq4_nl) is rejected up front instead of
    aborting at decode. The same check now also covers bf16 mixed with anything
    but q8_0 in the default build, which already affected turbo2/3/4.
  • Head dims that are not a multiple of 128 are zero-padded on the llama side,
    as for the other turbo types, so head dim 64 models work.

llama side: -ctk/-ctv (and the draft variants) accept turbo5 and
turbo6, llama-bench parses them, and both types join every predicate that
already lists the turbo types (FA auto-enable, head padding, rotation tensors,
Q pre-rotation, inverse WHT on the FA output, the auto-asymmetric rule).

Backends: CPU and CUDA (HIP builds the same kernels; the turbo5 sign packing
uses width-32 shuffles so it is wave64-safe, but it is untested on AMD
hardware). Metal, Vulkan and SYCL have no SET_ROWS for these types; KV cache
creation now fails with a clear error on such a device instead of aborting in
the scheduler, and -nkvo keeps the cache in host memory. The check applies to
every cache type, not only the new ones.

No new environment variables. GGML_TURBO_MMA_FUSED covers the new fused pairs.

Evidence

Dense model (Qwen2.5-7B)

Qwen2.5-7B-Instruct Q8_0 (28 full-attention layers, GQA 28:4 = 7), wikitext-2
test, 20 x 2048 tokens, -fa on, RTX 3090 Ti. "rule off" = TURBO_AUTO_ASYMMETRIC=0.

K / V PPL
f16 / f16 6.434 +/- 0.112
q8_0 / q8_0 6.432 +/- 0.112
q8_0 / turbo6 6.435 +/- 0.112
q8_0 / turbo5 6.433 +/- 0.112
turbo6 / turbo6, rule on (K upgraded to q8_0) 6.435 +/- 0.112
turbo6 / turbo6, rule off 7.383 +/- 0.133
turbo6 / f16 7.390 +/- 0.133
turbo6 / q8_0 7.387 +/- 0.133
turbo5 / turbo5, rule off 32.15 +/- 0.72
turbo5 / f16 31.86 +/- 0.71

As V types both are free on this model. As K types they are not: turbo6 K
costs about 15% perplexity and turbo5 K about 5x, so both stay under the
auto-asymmetric rule, which maps them to q8_0 K here.

Hybrid model (Qwen3.8-27B)

Qwen3.8-27B is a hybrid: 16 of its 64 layers are full attention (GQA 24:4 = 6,
head dim 256), the rest are Gated DeltaNet, so it dilutes K error and cannot
show the high-GQA K problem. These numbers are the V-side and pair evidence.

Protocol: for each prompt depth D a SWE-style prompt of D tokens, then the model
generates at least 6,144 tokens on top of it (temp 1.0). llama-kld-depth (a
position-resolved KLD tool; -fit off, KLD stride 1) writes an f16/f16 base per
depth and scores each K/V config against it. Only the generated positions are
scored; n is about 6,140 positions per depth. RTX 3090 Ti.

Mean KLD on generated tokens vs f16/f16 (nats), range over depths 10K, 25K, 51K
and 77K:

K / V bits K+V KLD vs f16 top-1 agreement
q8_0 / q8_0 8.5 + 8.5 0.00025–0.00036 0.994–0.996
q8_0 / turbo6 8.5 + 6.125 0.00037–0.00050 0.993–0.995
q8_0 / q5_1 8.5 + 6 0.00046–0.00054 0.992–0.994
q8_0 / turbo5 8.5 + 5.125 0.00056–0.00066 0.992–0.994
turbo6 / turbo6 6.125 + 6.125 0.00050–0.00056 0.992–0.994
turbo6 / turbo5 6.125 + 5.125 0.00071–0.00081 0.991–0.993
q5_1 / q5_1 6 + 6 0.00084 (77K)
turbo5 / turbo5 5.125 + 5.125 0.00096–0.00116 0.989–0.992
q8_0 / turbo4 8.5 + 4.125 0.00124–0.00145 0.989–0.990
turbo5 / turbo4 5.125 + 4.125 0.00155–0.00241 0.985–0.990
q4_0 / q4_0 4.5 + 4.5 0.00356 (77K)
q8_0 / turbo3 8.5 + 3.125 0.00362–0.00455 0.979–0.982

Paired per-token K deltas (same positions, same base, SE = sd(diff)/sqrt(n)),
with turbo6 V: turbo6 K minus q8_0 K is +0.00006 to +0.00013 nats (t 2.6
to 9.1), and turbo5 K minus turbo6 K is +0.00030 to +0.00043 (t 10 to 16).
So on this model turbo6 K is measurably but only slightly worse than q8_0 K.
Two f16 runs of the same config differ by about 0.00024, which is the tool's floor.

Test plan

cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86 -DGGML_NATIVE=OFF -DLLAMA_CURL=OFF
cmake --build build -j12 --target test-backend-ops test-quantize-fns test-turbo-quant llama-perplexity

build/bin/test-quantize-fns
build/bin/test-turbo-quant
build/bin/test-backend-ops test -b CUDA0 -o SET_ROWS_TURBO6
build/bin/test-backend-ops test -b CUDA0 -o SET_ROWS_TURBO5
build/bin/test-backend-ops test -b CUDA0 -o CPY -p 'turbo[56]'
build/bin/test-backend-ops test -b CUDA0 -o FLASH_ATTN_EXT -p 'turbo[56]'
GGML_TURBO_MMA_FUSED=0 build/bin/test-backend-ops test -b CUDA0 -o FLASH_ATTN_EXT -p 'turbo[56]'
build/bin/test-backend-ops test -b CUDA0 -o FLASH_ATTN_EXT

Results on an RTX 3090 Ti (sm_86), CUDA build at the PR head:

run result
-o SET_ROWS_TURBO6 21/21
-o SET_ROWS_TURBO5 21/21
-o CPY -p 'turbo[56]' 4/4
-o FLASH_ATTN_EXT -p 'turbo[56]' 1773/1773
same, GGML_TURBO_MMA_FUSED=0 1773/1773
-o FLASH_ATTN_EXT, all cases 10547/10547
-o SET_ROWS / CPY / GET_ROWS, all cases 159/159, 260/260, 119/119

The FA counts are 4 lower than before the review because the cross pairs moved
behind GGML_CUDA_FA_ALL_QUANTS now report unsupported in a default build.
A GGML_CUDA_FA_ALL_QUANTS=ON build compiles; the wave64 HIP path is untested.

test-turbo-quant covers the reference codec and its round-trip error;
test-quantize-fns skips the new types the same way it skips the other
rotated-domain KV types.

Scope notes

  • These are KV-cache-only types; there is no weight quantization and nothing
    is written to GGUF files. Rejecting KV-only types in llama-quantize and the
    model loader is left for the follow-up that covers turbo2/3/4 too.
  • -ctk help lists the new types on every build, as it does for turbo2/3/4;
    non-CUDA KV devices now get a clear error at context creation.
  • Block KV cache streaming: bound VRAM at long context via a shared CUDA phase arena #357 (block KV streaming) will need turbo5/turbo6 added to its
    layer-adaptive helpers once it lands.

@TheTom TheTom left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, the codec side is careful work. The tq6 table is sorted and symmetric, the tq5 table is exactly antisymmetric, and the CUDA and CPU tables and midpoints match in f32. A 512k-value CPU round trip hit every code with zero mismatches, and the tq5 prmt loader, the tq6 shuffle lookup and the flat turbo4 loader all matched scalar references over 20,000 random chunks. The llama-side wiring is also right on the CPU reference: q8_0 K with tq6_0 V gives 8.12 PPL on Qwen2.5-0.5B against 8.11 for q8_0/q8_0.

A few things need to change before this goes in. I also ran the CUDA side on a GB10, and those numbers are at the bottom.

Before merge

  1. tq5 sign bits are wrong on wave64 HIP. k_set_rows_tq5 packs the signs with __ballot_sync, and vendors/hip.h:55 maps that to (uint32_t)__ballot(var). On CDNA (wave64), lanes 32 to 63 get the low 32 bits of the ballot. So qh bytes 4-7 and 12-15 come out as copies of bytes 0-3 and 8-11, and half the signs in every block are wrong. The turbo3 writer hit the same trap and uses a width-32 shuffle instead (see the comment at set-rows.cu:393). Reusing that idiom, or shifting the 64-bit ballot by lane & 32, fixes it. The last commit builds the HIP vec instances, so MI210 and MI300 can reach this path. The tq6 writer only uses width-32 shuffles and is fine.

  2. Keep tq K under the auto-asymmetric rule, or show dense high-GQA data. That rule exists because of Qwen2.5 at GQA 7:1; the comment above it in llama-kv-cache.cpp has the numbers. Qwen2.5-0.5B has 14 query heads over 2 KV heads, and head dim 64 (padded to 128). Perplexity over 4 x 512 tokens:

K / V CPU CUDA (GB10)
f16 / f16 8.02 8.04
q8_0 / q8_0 8.11 8.09
f16 / tq6_0 8.03 8.03
q8_0 / tq6_0 8.12 8.08
tq6_0 / f16 21.99 22.84
tq6_0 / tq6_0 22.35 22.44
tq5_0 / tq5_0 31.64 31.80
q5_1 / q8_0 16.10 not run
turbo4 / turbo4, K upgraded to q8_0 by the rule 8.20 8.11
turbo4 / turbo4, TURBO_AUTO_ASYMMETRIC=0 52.66 not run

The error bars are about +/- 0.69 on the rows near 8 and +/- 2.2 to 3.2 on the tq K rows, and CPU and CUDA agree, so this is the codec on this model and not a kernel bug.

tq6_0 as V costs nothing. As K it nearly triples perplexity, and it does worse than q5_1 K at about the same size. This is a small model and a hard case, but it is the case the rule was written for. The Qwen3.8-27B numbers in the description come from a hybrid model where only some layers have attention, which dilutes K error. On Qwen3.6-35B-A3B, a hybrid with GQA 8:1 where 10 of 40 layers are attention, every K type I tried on the GB10 lands inside the error bars over 6 x 2048 tokens: f16/f16 3.356, tq6_0/tq6_0 3.364, tq5_0/tq5_0 3.377, and turbo4 K with the rule turned off 3.378, all +/- 0.09. A hybrid model can't show this problem either way, even for turbo4 K. Until there's a dense GQA 6+ result (Qwen2.5-7B is the one the rule cites), please add tq6_0 and tq5_0 to the rule's K check, and drop "indistinguishable from q8_0" from the docs.

  1. Naming. In this fork turboN means a KV cache type and the tq prefix means a weight type (TQ3_1S, TQ4_1S). Upstream tq1_0 and tq2_0 are ternary weight types too. tq5_0 is also one letter away from q5_0, and both are valid -ctk values. The mix-up already bites: llama-quantize --allow-requantize --tensor-type attn_k=tq6_0 writes a GGUF with type-51 weights. That file loads with no warning on CPU (PPL 8998 against 8.02) and aborts on Metal with "Asserting on type 51". Your own comment says the codec is the turbo4 pipeline with a bigger codebook, so please rename to turbo5 and turbo6 (GGML_TYPE_TURBO5_0 and GGML_TYPE_TURBO6_0, keeping enums 51 and 52, listed in ascending order). Renaming now costs nothing, while renaming after merge breaks people's flags. Rejecting KV-only types in llama-quantize and the model loader is a separate follow-up, because turbo2/3/4 have the same hole.

  2. Non-CUDA builds abort at startup. On Metal with -ngl 99, -ctk tq6_0 -ctv tq6_0 dies during context creation:

    pre-allocated tensor (cache_k_l0 (reshaped) (view)) in a buffer (MTL0) that cannot run the operation (SET_ROWS)
    

    With -nkvo it runs. From reading the code, Vulkan and SYCL take the same path. The description says these work "like the other turbo KV types", but turbo2/3/4 have kernels on those backends. At minimum, fail in llama_init_from_model with a clear message when the KV cache backend can't run SET_ROWS for the type, and fix the doc. The -ctk help also lists the new types on every build.

  3. The test plan doesn't run the new kernels. -o matches the op name exactly, so -o SET_ROWS runs the 159 generic cases and none of the SET_ROWS_TQ6 or SET_ROWS_TQ5 cases. There is no tq GET_ROWS test case at all, CUDA supports_op doesn't advertise GET_ROWS for tq, and CPU GET_ROWS aborts on tq6_0 ("unsupported GET_ROWS source ... type = 51"). So the "GET_ROWS works" part of the description isn't true yet. The new SET_ROWS cases do pass when you name them; the commands I used are in the GB10 section.

  4. Rebase. Since #372 landed today, this conflicts with the base in fattn-vec.cuh. Both sides insert at the same line, so keep your tq declarations above the new #ifdef GGML_USE_HIP block. The rebase also matters for CUDA 13 users: on this branch's current base, an sm_89 build with nvcc 13.0 still fails ptxas on the old D=512 vec instances (#380), and #372 is the fix. #357 (block KV streaming) is about to land too, and it conflicts in llama-kv-cache.cpp, llama-context.cpp and set-rows.cu. It moves the layer-adaptive logic into helpers that list only turbo2/3/4, so tq needs adding there after the rebase.

Worth settling before merge

  • Build cost. Nothing new is behind GGML_CUDA_FA_ALL_QUANTS. fattn.cu goes from 87 to 135 FATTN_VEC_CASE entries, and the 14 turbo MMA instance files go from 42 to 119 cases, with each D=256 file going from 3 to 10. The hosted cuda job took 34 minutes on both of this PR's runs, against 18 to 29 minutes on the last dozen runs from other branches, and that job only builds sm_89. I'd put the speculative cross pairs behind FA_ALL_QUANTS (turbo, f16 or q8_0 K with a tq V; tq K with turbo2 V; tq5 K with tq6 V) and keep the default set to the pairs you measured.
  • Register spills. I compiled the flash attention instance objects for sm_89 with nvcc 13.0 and -Xptxas=-v. The fused MMA tq kernels don't spill. 80 of the new vec kernels sit at the 255-register cap and spill. At D=256 with two columns they average 135 bytes and peak at 196, against a 144-byte peak for the existing turbo3-V kernels in the same shape. The existing turbo vec kernels already spill at D=256, so this isn't a blocker, but it's another reason to keep the default set small.
  • bf16 abort. is_kv_compat includes BF16, so tq with bf16 in either order passes supports_op, then hits GGML_ABORT("fatal error") at decode because there's no vec instance. tq with q4_0, q4_1, q5_0, q5_1 or iq4_nl does the same under FA_ALL_QUANTS. turbo with bf16 already had this hole, and this PR widens it.
  • Evidence. In your KLD table q5_1/q5_1 ties tq6_0/tq5_0. It would help to see q5_0 and q5_1 K with the same V, a dense-attention model, and plain decode, prefill and VRAM from llama-bench -d next to the MTP numbers. Please also include the exact KLD command, text, context length and token count, and raw means with intervals in place of "at the floor".

Smaller things

  • quantize_f32_tq{6,5}_0_block in the CUDA code are dead and never write norm. NL_TQ6, NL_TQ6_VEC, NL_TQ5, NL_TQ5_VEC, QK_TQ6_GROUP and QK_TQ5_GROUP are unused.
  • The tq5 loader and the flat turbo4 loader hardcode copies of the centroid values, which can drift if a table changes.
  • turbo4 is 4.125 bits per value (66 bytes per 128 values), not 4.25. The old docs had that wrong too.
  • The description says head dim 64 isn't supported, but the llama side pads 64 up to 128. That padding is how the Qwen2.5-0.5B runs above work.

GB10 (sm_121) on the PR head, test-backend-ops -b CUDA0

run result
-o SET_ROWS_TQ6 21/21
-o SET_ROWS_TQ5 21/21
-o CPY -p 'tq[56]_0' 4/4
-o FLASH_ATTN_EXT -p 'tq[56]_0' 1777/1777
same, with GGML_TURBO_MMA_FUSED=0 1777/1777
-o GET_ROWS -p 'tq[56]_0' 0/0, no cases exist
-o FLASH_ATTN_EXT, all cases 8774/8774 on base, 10551/10551 here
-o SET_ROWS / CPY / GET_ROWS 159, 256 and 119 on base; 159, 260 and 119 here; all pass

So the CUDA kernels pass every test that exists for them on warp32 hardware, and the existing types are unchanged. The wave64 bug in item 1 can't show up on this card. Your SET_ROWS_TQ6/TQ5 cases can run on CUDA because this PR adds the CPY they end in. The turbo ones can't, which is now #385.

@JakeATX JakeATX changed the title tq6_0 and tq5_0 KV cache types turbo5 and turbo6 KV cache types Sep 23, 2026
@JakeATX

JakeATX commented Sep 23, 2026

Copy link
Copy Markdown
Author

Thanks for the thorough review and for running it on the GB10. I rebased onto the current base (after #372) and pushed 84a6285b5 with the fixes. Point by point:

Before merge

  1. wave64 sign bits. k_set_rows_turbo5 no longer uses __ballot_sync. Each lane of 8 gathers its group's high bits with width-32 __shfl_sync, as the turbo3 writer does, and lane 0 of each group writes the qh byte. I have no AMD hardware, so this is compile-checked only on HIP.
  2. Auto-asymmetric rule. turbo5 and turbo6 K are now in the rule's K check, with your Qwen2.5-0.5B numbers in the comment. The "indistinguishable from q8_0" wording is gone from the docs and the description, and the Qwen3.8 KLD is now labelled as hybrid-model evidence. You were right that a hybrid model can't settle the K question. A dense Qwen2.5-7B sweep is running now (20 x 2048 wikitext, f16/q8_0/turbo4/5/6/q5_x K arms with the rule on and off). I'll post it here; the rule stays unless that data says otherwise.
  3. Rename. Now turbo5/turbo6, GGML_TYPE_TURBO5_0 = 51, GGML_TYPE_TURBO6_0 = 52, listed in ascending order. That swaps the old numbering (tq6 was 51), which is safe since the types are runtime-only and nothing on disk uses them. Say if you meant to keep 51 = 6-bit instead. Instance files, flags, llama-bench and docs are renamed to match.
  4. Non-CUDA abort. KV cache creation now builds a dummy SET_ROWS for each offloaded layer's K and V type and asks the device's supports_op. If the device can't run it, context creation fails with "cache type X is not supported on device Y (no SET_ROWS kernel for it); use a different cache type or keep the KV cache in host memory (-nkvo)" instead of the scheduler abort. It applies to every cache type. The docs now say CPU + CUDA only, and list the -nkvo workaround.
  5. Test plan. Fixed to -o SET_ROWS_TURBO6 / SET_ROWS_TURBO5, -o CPY -p 'turbo[56]' and -o FLASH_ATTN_EXT -p 'turbo[56]'. The GET_ROWS claim is removed; the docs say there's no GET_ROWS for any turbo type.
  6. Rebase. Done; the declarations sit above the GGML_USE_HIP block. I'll add turbo5/turbo6 to Block KV cache streaming: bound VRAM at long context via a shared CUDA phase arena #357's helpers once it lands.

Worth settling

  • Build cost / spills. The default vec set is now only the pairs I measured: turbo5/turbo6 K with V of the same type, turbo3, turbo4, q8_0 or f16; turbo6 K with turbo5 V; and q8_0 K with turbo5/turbo6 V, which is what the rule produces. The other cross pairs (turbo2/3/4 or f16 K with a turbo5/6 V, turbo5/6 K with turbo2 V, turbo5 K with turbo6 V) moved behind GGML_CUDA_FA_ALL_QUANTS, along with their 11 instance files in the CUDA and HIP CMake lists. supports_op checks the same pair list, so a gated pair reports unsupported. That leaves 26 new default cases instead of 48.
  • bf16. In a default build, bf16 now mixes only with q8_0 in supports_op, which also closes the existing turbo2/3/4 + bf16 hole. Under ALL_QUANTS, a turbo5/6 pair must be within {turbo2..6, q8_0, f16}, so q4/q5/iq4_nl are rejected up front.
  • Evidence. The description now gives the KLD protocol: SWE-style prompts at 10K/25K/51K/77K depth, 6,144+ generated tokens at temp 1.0, KLD on the ~6,140 generated positions only, and raw means as ranges. It also adds q5_1 and q4_0 reference rows and paired per-token deltas with t values. Dense q5_0/q5_1 K arms and llama-bench -d 0,16384,32768 decode/prefill/VRAM on Qwen2.5-7B are in the sweep that's running.

Smaller things

  • Removed the dead quantize_f32_turbo{6,5}_0_block and the unused NL_*/QK_*_GROUP macros.
  • The turbo5 and flat-turbo4 MMA loaders build their tables from TURBO5_CENTROIDS / TURBO_CENTROIDS_4BIT instead of hardcoded copies.
  • The bpv table is fixed (turbo4 4.125, turbo3 3.125, turbo2 2.125) along with the compression ratios.
  • The description says head dim 64 works via padding.

RTX 3090 Ti (sm_86), test-backend-ops -b CUDA0 at 84a6285b5

run result
-o SET_ROWS_TURBO6 / SET_ROWS_TURBO5 21/21, 21/21
-o CPY -p 'turbo[56]' 4/4
-o FLASH_ATTN_EXT -p 'turbo[56]' 1773/1773
same, GGML_TURBO_MMA_FUSED=0 1773/1773
-o FLASH_ATTN_EXT, all 10547/10547
-o SET_ROWS / CPY / GET_ROWS, all 159, 260, 119, all pass

The 4 fewer FA cases than your 1777 / 10551 are the pairs now behind ALL_QUANTS (turbo6/turbo2, turbo5/turbo6, turbo4/turbo5, f16/turbo5 in the test matrix). A GGML_CUDA_FA_ALL_QUANTS=ON build compiles cleanly.

@JakeATX

JakeATX commented Sep 23, 2026

Copy link
Copy Markdown
Author

Dense results are in (Qwen2.5-7B-Instruct Q8_0, wikitext-2, 20 x 2048, -fa on, 3090 Ti). They agree with your 0.5B numbers:

K / V PPL
f16 / f16 6.434 +/- 0.112
q8_0 / q8_0 6.432 +/- 0.112
q8_0 / turbo6 6.435 +/- 0.112
q8_0 / turbo5 6.433 +/- 0.112
turbo6 / turbo6, rule on 6.435 +/- 0.112
turbo6 / turbo6, rule off 7.383 +/- 0.133
turbo6 / f16 7.390 +/- 0.133
turbo5 / turbo5, rule off 32.15 +/- 0.72
turbo5 / f16 31.86 +/- 0.71

As V types they're free; as K types they're not, so turbo5/turbo6 K stay under the auto-asymmetric rule as pushed. The table is also in the description. I've dropped the q5_x K arms and the llama-bench run from this PR's scope. From my side the PR is ready for another look.

@TheTom

TheTom commented Sep 23, 2026

Copy link
Copy Markdown
Owner

GB10 (Spark, sm_121) numbers for 84a6285b5, default build. The op tests all pass: SET_ROWS_TURBO6 and SET_ROWS_TURBO5 are 21/21 each with the new shuffle-based writer, CPY is 4/4, and FLASH_ATTN_EXT turbo5/6 is 1773/1773 both fused and with GGML_TURBO_MMA_FUSED=0.

KL divergence against an f16 KV cache, wikitext-2.

Qwen3.6-35B-A3B Q4_K_M (hybrid, GQA 8:1, head dim 256), 8 x 4096:

K / V KLD top-1
q8_0 / q8_0 0.00441 97.53%
q8_0 / turbo4 0.00688 96.84%
q8_0 / turbo5 0.00511 97.24%
q8_0 / turbo6 0.00461 97.44%
turbo4 / turbo4, rule off 0.00889 95.96%
turbo5 / turbo5, rule off 0.00546 96.81%
turbo6 / turbo6, rule off 0.00466 97.42%
q4_0 / q4_0 0.01090 95.46%

Qwen2.5-0.5B-Instruct Q8_0 (dense, GQA 7:1), 16 x 2048, rule off. The last column keeps the first 4 and last 4 layers at q8_0 with TURBO_LAYER_ADAPTIVE=1:

K / V KLD KLD, first 4 + last 4 at q8_0
q8_0 / q8_0 0.0269
q8_0 / turbo6 0.0285
turbo4 / turbo4 2.748 0.162
turbo5 / turbo5 1.438 0.0755
turbo6 / turbo6 0.572 0.0375

Decode on the 35B, llama-bench tg128 in t/s:

K / V depth 0 16384 32768
f16 / f16 67.3 60.9 54.9
q8_0 / q8_0 66.7 52.2 42.6
q8_0 / turbo4 66.3 54.7 45.8
q8_0 / turbo5 65.8 44.2 33.1
q8_0 / turbo6 65.7 40.3 29.0
turbo5 / turbo5, rule off 66.3 63.3 59.4
turbo6 / turbo6, rule off 66.1 62.0 57.2

Prefill is flat across all of them, 1763 to 1810 t/s for pp512 at depth 32768.

Three things from the numbers:

  • On the hybrid, turbo6/turbo6 matches q8_0/q8_0 at 72% of the size, and the fused MMA path makes it faster than f16 at depth.
  • q8_0 K with turbo5 or turbo6 V is the slowest config here, 29 to 33 t/s at 32K against 42.6 for q8_0/q8_0. q8_0/turbo4 also runs on vec and is faster than q8_0/q8_0, so the cost looks like the per-element V table lookup. That pair is what the auto-asymmetric rule makes out of turbo6/turbo6 on this model, where it buys no KLD (0.00466 against 0.00461).
  • On the dense model the rule is still right: turbo6 K without protection is 0.572. Keeping the first 4 and last 4 layers at q8_0 brings it to 0.0375, while protecting only the last 8 changes nothing.

Not a blocker for this PR, but the q8_0 K + turbo5/6 V decode speed is worth a look, either with a fused MMA instance for those two pairs or a faster V lookup on the vec path. How the rule should treat hybrid models is a question for the fork, separate from this PR.

#357 has landed, so this needs a rebase and turbo5/turbo6 added to the kv-stream helpers, as you planned.

@grogroningem-code

Copy link
Copy Markdown

I've been running this PR on top of #392 on two laptops. On one the KV cache spills to host RAM; the other also serves from the CPU and a Radeon 780M iGPU over Vulkan. Getting turbo5/turbo6 usable in those setups took a few more changes, so I'm listing them here to avoid duplicate work. They depend on both this PR and #392, so I'd send them as a small follow-up once both land rather than push them into this one.

Branch with the whole stack (this PR merged onto #392, then the commits below): grogroningem-code/llama-cpp-turboquant turbo56-kvstream, head 5cd3d40ac.

kv-stream (CUDA)

  1. turbo5/turbo6 -> f16 for streamed spans. Streamed prefill converts each span to f16 and runs the f16 MMA. The generic dequantize_block path reads the centroid table from __constant__ memory with per-thread indices, which serializes. The new converter keeps the table in registers (turbo6: two entries per lane; turbo5: 16 magnitudes plus the sign bit) and looks it up with __shfl_sync, with a half-warp per 128-value block and 16-byte stores.
  2. Split-span MMA partial for turbo5/turbo6 K decode. Streamed decode with K in {turbo6, turbo5} and V in {turbo5, turbo4, turbo3} now uses the fused turbo MMA partial with 64 KV splits instead of the vec partial. It is gated to D=256, n_q <= 4 and GQA ratio 5-8; other shapes keep the existing path. test-kv-stream-cuda-attn covers all six pairs (max abs error 6.7e-6 against plain attention).

Vulkan. The description says CPU + CUDA only; this adds Vulkan.

  1. turbo5/turbo6 on Vulkan. Block structs, fused dequantize4() in the scalar and coopmat1 FA shaders, a SET_ROWS quantizer (same normalize + WHT as turbo4, then the nearest of 32/64 centroids by midpoint search, then norm correction), and dequant/get_rows/cpy-to-f32 shaders. With these, the SET_ROWS probe from point 4 of your update passes on Vulkan, so context creation there succeeds instead of failing.
  2. Turbo FA stays off coopmat2. flash_attn_cm2.comp has no turbo decode, so coopmat2 devices returned wrong results for every turbo type, including the existing turbo3/turbo4. Turbo K/V now uses coopmat1/scalar there. The type-independent part of this is in cuda: native turbo routing, width-gated MMA, batched H2D for deep-spill decode #392.

CPU

  1. AVX512 row dequant for turbo5/turbo6, on top of the tiled quantized-K/V flash attention in cuda: native turbo routing, width-gated MMA, batched H2D for deep-spill decode #392. turbo5 does a 16-entry magnitude permute and a sign mask; turbo6 uses two permutex2var over the 64-entry table. The output is bit-identical to the scalar to_float.

Radeon 780M (Vulkan, coopmat1), Qwen3.5-4B, llama-bench, t/s:

K / V pp2048 tg64 pp2048 @ 8k tg64 @ 8k
turbo4 / turbo4 185.5 15.33 163.4 14.35
turbo5 / turbo4 180.2 14.60 160.1 13.73
turbo6 / turbo5 180.1 14.52 161.1 13.75
turbo5 / turbo5 181.5 14.62 160.8 13.77
f16 / f16 186.4 14.94 154.6 13.29

Zen 4 CPU, 8 threads, t/s, before -> after:

model, K / V prefill decode
Qwen3.5-4B, turbo5 / turbo4, pp2048 / tg at 4k 28.2 -> 69.9 5.76 -> 11.32
Qwen3.5-4B, turbo6 / turbo5 26.1 -> 69.0 5.30 -> 11.64
Qwen3.6-35B-A3B, turbo5 / turbo4, 16k depth (after) 54.9 9.97
Qwen3.6-35B-A3B, turbo6 / turbo5, 16k depth (after) 53.3 8.13

Qwen3.8-27B (hybrid, 16 of 64 layers full attention, GQA 6:1, D=256), RTX 4090 Laptop 16 GB, 180k context spilled to host, t/s:

K / V prefill decode
q8_0 / turbo3 697 18.2
turbo6 / turbo4 703 38
turbo6 / turbo5 703 31
turbo5 / turbo4 697 50

Decode here is with MTP on a repetitive prompt (acceptance 169/170), so the absolute numbers are optimistic. The order holds.

KLD against an f16 cache on the same 27B model, 8k context (4 chunks) and 180k context (2 chunks, last 8192 tokens of each scored):

K / V KLD 8k KLD 180k top-1 180k
q8_0 / turbo3 0.00667 - -
turbo5 / turbo4 0.00282 0.00174 99.12%
turbo6 / turbo4 0.00251 0.00136 99.05%
turbo6 / turbo5 0.00131 0.00084 99.24%

The 180k corpus is easier than the 8k one (f16 PPL 1.69 against 4.39), so compare within a column, not across. These are hybrid-model numbers and say nothing against your dense results. None of this changes the auto-asymmetric rule.

test-backend-ops on the stack: FLASH_ATTN_EXT turbo 4385/4385 on CPU, CUDA (RTX 4070), Vulkan coopmat1 (780M) and Vulkan coopmat2 (RTX 4070). SET_ROWS_TURBO5 and SET_ROWS_TURBO6 are 21/21 each on Vulkan.

Still open on my side:

  • The new MMA partial instances compile in default builds, but their only caller is under GGML_CUDA_FA_ALL_QUANTS. I'll gate them to match the pair split here.
  • None of this addresses the q8_0 K + turbo5/turbo6 V decode cost @TheTom measured; it only covers turbo K. On CPU the remaining turbo decode gap is the per-head dequant repeated across the GQA group, which is next on my list.

Written with Claude Code (Claude Opus 5.5): code, benchmarks and this write-up. Everything above was run on my own hardware.

@TheTom

TheTom commented Oct 8, 2026

Copy link
Copy Markdown
Owner

#392 just landed (native turbo routing for kv-stream, the faster turbo3/turbo4 to f16 converter, CPU tiled flash attention for quantized K/V, and turbo off the Vulkan coopmat2 path). This branch now conflicts with feature/turboquant-kv-cache in:

  • ggml/src/ggml-cuda/convert.cu
  • ggml/src/ggml-cuda/fattn-vec.cuh
  • ggml/src/ggml-cuda/set-rows.cu
  • src/llama-context.cpp
  • src/llama-kv-cache.cpp

Could you rebase onto the current tip? Once it's green I'll rerun the GB10 checks from my last comment on the new head, existing turbo types and speed included, before it goes in. grogroningem-code's turbo5/turbo6 follow-up for kv-stream, Vulkan and CPU can come after this lands.

@TheTom

TheTom commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Status from my side: holding this for more investigation before merge, on top of the rebase above. The kernels themselves look good. What I want to settle first is how turbo5/turbo6 behave once the auto-asymmetric rule gets involved, because that decides whether users ever see the good case.

Recap of the GB10 numbers posted earlier (Qwen3.6-35B-A3B, hybrid, GQA 8:1, head dim 256; KLD against an f16 cache, decode tg128 at 32K):

K / V KLD decode at 32K
q8_0 / q8_0 0.00441 42.6 t/s
turbo6 / turbo6, rule off 0.00466 57.2 t/s
turbo5 / turbo5, rule off 0.00546 59.4 t/s
q8_0 / turbo6 (what the rule produces) 0.00461 29.0 t/s
q8_0 / turbo5 (what the rule produces) 0.00511 33.1 t/s

Concerns:

  1. The rule turns the best case into the slowest one on hybrid models. On this model -ctk turbo6 -ctv turbo6 becomes q8_0/turbo6: no KLD gain, about half the decode speed at 32K, and a bigger K cache. Symmetric turbo6 is q8_0-class here at 72% of the size and faster than f16 at depth. An independent hybrid data point in Permission to submit your turbo KV (HIP port) to halo-box/strix-llama.cpp, credited to you #394 agrees: turbo3 K is fine there at GQA 6:1.
  2. On dense high-GQA models the rule is still required. Your Qwen2.5-7B run shows turbo6 K at 7.38 PPL against 6.43, and on Qwen2.5-0.5B turbo6 K is 0.572 KLD against 0.027 for q8_0. So "drop the rule for turbo5/6" is not an option either.
  3. q8_0 K with turbo5/turbo6 V is slow on its own. It runs on the vec path, where q8_0/turbo4 is fast (45.8 t/s at 32K), so the cost looks like the per-element turbo5/6 V table lookup. Since this is the pair the rule produces, it needs a fused MMA instance or a faster V lookup before turbo5/6 are worth recommending on GQA 6+ models.
  4. The rule only checks matching K/V types. -ctk turbo3 -ctv turbo4 on a dense GQA 7:1 model skips it entirely. That's an older fork issue, not this PR's, but whatever we decide for turbo5/6 should cover it too.

What I want to investigate before deciding: whether the rule should key on the model's attention structure (hybrid vs dense) instead of GQA alone, and whether the q8_0 K + turbo5/6 V decode gap closes with a fused path. I'll post findings here.

Two TurboQuant PolarQuant KV cache types that sit between turbo4_0 and
q8_0: a WHT rotation over the 128-element head group, then a Lloyd-Max
codebook for N(0, 1/128) plus a per-block corrected L2 norm, the same
pipeline turbo2_0 / turbo3_0 / turbo4_0 already use.

  tq6_0: 64 centroids, norm + 4-bit low plane + 2-bit high plane,
         98 B per 128 values = 6.125 bpw, per-coordinate rmse 0.025 sigma
  tq5_0: 32 antisymmetric centroids stored sign-magnitude (4-bit
         magnitude index + sign bit), 82 B per 128 values = 5.125 bpw,
         per-coordinate rmse 0.050 sigma (turbo4_0: 0.097 sigma)

Both keep the low nibble plane in the element order of block_turbo4_0.qs
so the existing nibble readers and tile loaders carry over; a dense 6-bit
packing would put element boundaries at bit 6/12/18 and break the
half2-pair extraction the KQ dot and the tile loaders rely on.

This commit adds the type enum entries, the block structs, the reference
codec, the CPU backend traits and the round-trip tests. Like the other
TurboQuant KV types, dequantization stays in the rotated domain; the
inverse WHT is applied to the attention output by GGML_OP_TURBO_WHT.
Device-side codec for the two new KV cache types, mirroring the CPU
reference: the Lloyd-Max tables, the nearest-centroid search, the
per-block quantizer and the per-element dequantizer.

SET_ROWS quantizes an f32 KV row in place with the same warp-cooperative
shape the turbo types use: one warp per 128-element rotation group, a
warp-level WHT, a warp reduction for the norm and for the norm
correction, then a ballot to pack the high plane (tq6) or the sign plane
(tq5) in element order. CPY and the to_fp16 / to_fp32 converters give the
read-back path used by GET_ROWS and by KV cache defragmentation.

test-backend-ops gains SET_ROWS round-trip cases for both types over the
index types, head dims and row counts the KV cache uses, plus CPY
dequant cases.
Add the tq6_0 / tq5_0 KQ dot products and V dequantizers to the VEC path and
tile loaders to the GQA-packed MMA path, so both types can be used as K and as
V caches.

VEC: every combination of tq6_0 / tq5_0 with f16, q8_0, turbo2_0, turbo3_0,
turbo4_0 and with each other is instantiated, for head dims 128 and 256 (a
tq6_0 / tq5_0 block holds 128 values, so head dim 64 has no instance).

MMA: the matched tq6_0 / tq5_0 pairs and tq6_0 / tq5_0 K over a turbo3_0 V are
fused at head dims 128 and 256; turbo4_0 V under a tq6_0 / tq5_0 K and tq5_0 V
under a tq6_0 K are fused at head dim 256. The tq6_0 loader keeps the 32
positive centroid magnitudes in one register per lane and looks them up with a
single warp shuffle; the tq5_0 and turbo4_0 loaders build a per-block fp16
magnitude table and select from it with PRMT, decoding 32 values per lane and
storing four aligned uint4 into the swizzled tile.
Accept tq6_0 and tq5_0 for -ctk/-ctv (and the draft variants) and for
llama-bench's -ctk/-ctv, and add them to every KV-cache predicate that
already lists the turbo types: flash attention auto-enable, head-dim
padding and block-size validation, WHT rotation tensor creation, the Q
pre-rotation and the inverse WHT on the attention output.

The auto-asymmetric rule deliberately keeps its turbo2/3/4 condition: at
5-6 bits the K error is small enough that a high GQA ratio does not need
the upgrade to q8_0, so a tq6_0/tq5_0 K is left as requested.

Document both types in docs/KV-cache-quantization.md, including the
block layouts, the supported head dims and the pairs that take the fused
GQA-packed MMA kernel.
The HIP backend keeps its own list of fattn-vec template instances; the TQ6_0/TQ5_0
instances were only added to the CUDA list, so libggml-hip failed to link
(undefined ggml_cuda_flash_attn_ext_vec_case<..., 51/52>).
- Rename tq5_0/tq6_0 to turbo5/turbo6 (GGML_TYPE_TURBO5_0 = 51,
  GGML_TYPE_TURBO6_0 = 52, ggml type names and -ctk values turbo5/turbo6).
- k_set_rows_turbo5: pack the sign bits with the width-32 shuffle idiom
  instead of __ballot_sync, which truncates to 32 bits on wave64 HIP.
- Auto-asymmetric rule: turbo5 and turbo6 K are upgraded to q8_0 at
  GQA >= 6 like turbo2/3/4.
- FA vec: the unmeasured cross pairs (turbo2/3/4 or f16 K with a
  turbo5/6 V, turbo5/6 K with turbo2 V, turbo5 K with turbo6 V) move
  behind GGML_CUDA_FA_ALL_QUANTS. q8_0 K with turbo5/6 V stays in the
  default build since the auto-asymmetric rule produces it.
- supports_op: report no FA kernel for turbo5/6 pairs without a vec
  instance (bf16, q4/q5, iq4_nl), and for bf16 mixed with anything but
  q8_0 in the default build, instead of aborting at decode.
- KV cache creation fails with a clear error when the device holding a
  layer cannot run SET_ROWS for the cache type (Metal, Vulkan, SYCL).
- Remove the dead quantize_f32_turbo{5,6}_0_block and unused NL_/GROUP
  defines; the turbo5 and flat turbo4 tile loaders read their centroids
  from the tables instead of literal copies.
- Docs: bits per value for turbo2/3/4 (2.125/3.125/4.125), backend
  support, head dim padding, supported pairs, the auto-asymmetric rule.
ggml-org#357 (kv-stream phase arena) added a set of helpers that enumerate the KV
cache types the streaming runtime understands. turbo5_0/turbo6_0 were added
on a branch that predates it, so they were missing from all of them:

- fattn.cu: kv_stream_resolve_native_partial{,_for_v} (K switch and V switch
  plus the k_is_turbo gate), the classified/online_write/decode_f16/
  direct_attention capability switches, kv_stream_direct_attention_pair_
  supported and ggml_cuda_kv_stream_padded_head_dim (turbo5/turbo6 pad head
  dims to a multiple of 128 exactly like turbo4).
- ggml-cuda.cu: ggml_cuda_kv_stream_staged_set_rows_range must reject
  turbo5/turbo6 too. set_rows_cuda_turbo5/6 ignore the row-base offset the
  page-staging path passes, so without this the staged path would have
  written every dirty row at the wrong offset.
- llama-kv-cache.cpp: llama_kv_cache_resolve_stream_type_k and the
  llama_kv_cache_turbo_layer_adaptive_type_k/_v helpers the streaming
  bootstrap pre-scan calls.
- tests/test-kv-stream-cuda-attn.cpp: turbo5/turbo6 in the turbo
  direct-attention pair test (HEAD_DIM is 256, one of the two head dims
  they have vec instances for), and backend_supports_plain_kv_pair now
  mirrors ggml_cuda_fattn_turbo56_pair_supported so default builds skip
  pairs with no instance instead of failing.

Also fix fattn-vec.cuh: ggml-org#357 made DECL_FATTN_VEC_CASE expand to two explicit
instantiations (the ordinary case plus the new partial_case), so the
turbo5/turbo6 `extern DECL_FATTN_VEC_CASE(...)` lines made the partial_case
an explicit instantiation definition in a header. Use the new
EXTERN_DECL_FATTN_VEC_CASE for all 48 of them.
ggml-org#392 lets fully resident (or single-page) streamed runs skip the per-page
f16 conversion when a turbo type is on either side. Its turbo lists named
only turbo2/3/4; add turbo5/turbo6 so they take the same native path.
Pairs without a vec instance in this build still fail the
ggml_cuda_flash_attn_ext_supported check and keep the f16 conversion.
The resident multi-page test now covers the turbo5/turbo6 pairs that the
default build instantiates.
On the vec path, q8_0 K with turbo5/turbo6 V (the pair the auto-asymmetric
rule produces from turbo5/turbo5 and turbo6/turbo6 on GQA >= 6 models)
dequantized V through the generic per-element helper, which indexes the
32/64-entry centroid table in __constant__ memory. Constant memory
serializes a warp over every distinct index, so each V lookup cost up to
32 passes; turbo4 V avoids this with a 16-entry register table.

Copy the table to shared memory once per block and decode 4 values per
thread from 2 qs bytes plus 1 qh byte, like the turbo4 V path. The
products are the same c[idx] * norm as before, so outputs are unchanged.
Applies to the f32 V path (CUDA); the half2 path (HIP with
V_DOT2_F32_F16) keeps the generic helper.
@JakeATX

JakeATX commented Oct 8, 2026

Copy link
Copy Markdown
Author

Rebased onto 6e09de1 (after #392) and pushed. Conflicts were in convert.cu (kept #392's fast turbo4 converter and added turbo5/6 next to it) and llama-kv-cache.cpp (kept the kv-stream rotation context, with turbo5/6 added to its check). #392's native-routing lists in ggml_cuda_flash_attn_ext_streamed named only turbo2/3/4, so turbo5/6 are added there too (d7c629d). Pairs that aren't instantiated still take the f16 conversion. The resident multi-page kv-stream test now covers the instantiated turbo5/6 pairs.

On (3): you were right that it's the V lookup. The generic turbo5/6 V helper indexed the 32/64-entry centroid table in __constant__ memory per element, and constant memory serializes a warp over every distinct index. turbo4 V avoids that with its register table. ccd0e40 stages the table in shared memory once per block and decodes 4 values per thread like the turbo4 path. Products are unchanged. On an RTX 3090, Qwen2.5-7B-Instruct Q8_0, llama-bench tg1024 x5, before -> after at 16K / 32K depth: q8_0/turbo6 36.5 -> 70.7 / 22.8 -> 55.0 t/s, q8_0/turbo5 41.8 -> 70.3 / 27.1 -> 54.7 t/s (both repeated in a second interleaved pass, within 0.3%). For reference on the same card: q8_0/turbo4 68.8 / 52.9 and q8_0/q8_0 63.3 / 47.0, so the mixed pairs now decode at least as fast as both. turbo6/turbo6 is unchanged (86.0 / 78.5). Greedy decode (512 tokens, temp 0) is byte-identical before and after for q8_0/turbo5 and q8_0/turbo6. CUDA test-backend-ops: FLASH_ATTN_EXT -p turbo 4367/4367 fused and with GGML_TURBO_MMA_FUSED=0, SET_ROWS_TURBO5/6 21/21, CPY turbo5/6, SET_ROWS/CPY/GET_ROWS all pass, test-kv-stream-cuda-attn passes. The HIP half2 path still uses the generic helper; I have no AMD card to test a port.

On (1), (2) and (4): agreed that these are rule questions for the fork, and I haven't changed the rule in this PR. One data point for the hybrid question: on Qwen3.8-27B (hybrid, 16 of 64 layers attend, GQA 6:1) turbo6/turbo6 with no K upgrade measured 0.00036 and 0.00074 nats of generated-token KLD on two of our harnesses, against 0.00025 and 0.00043 for q8_0/q8_0 on the same runs, so about 1.4-1.7x the q8_0 floor and nowhere near the dense-model breakdown. If the rule ends up keying on attention structure, I'm happy to run the dense and hybrid arms here. For (4), applying the rule to mismatched pairs would also need a check that the upgraded pair (e.g. q8_0/f16 from turbo K + f16 V) has a default vec instance.

@JakeATX

JakeATX commented Oct 22, 2026

Copy link
Copy Markdown
Author

Hi Tom, friendly check-in. This merges cleanly with the current feature branch tip (ca28b4b), no rebase needed. When you get to the hybrid-versus-dense question for the auto-asymmetric rule, I am happy to run whichever hybrid model and context lengths you want and post the numbers. The failing self-hosted checks look like runner timeouts (about 2h57m each); could you re-run them? Thanks for the careful review.

@TheTom

TheTom commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Checked this against the current tip. git merge-tree of ca28b4bc0 with ccd0e4096 comes back clean, so no rebase needed.

Hosted jobs on ccd0e4096 are green: cuda, cuda-13, hip, hip-quality-check, musa, ubuntu (x64, arm64, plain) and the windows lanes. The red ones are the self-hosted gpu-*, cpu-*, s390x, ppc64le and cmake-pkg jobs. They never get picked up on this fork and sit until they time out, so a re-run won't change them. Ignore those.

The V table fix is the right call. Staging the centroids in shared memory and decoding 4 per thread matches what turbo4 already does, and q8_0/turbo6 going from 36.5 to 70.7 t/s at 16K on the 3090 with byte-identical greedy output is a clean result.

One small ask: say in the description that the speedup is CUDA only, since the HIP path still uses the generic helper. No port needed.

The remaining step on this PR is mine: I'll rerun the GB10 rows from my earlier comment on this head. The hybrid vs dense question for the rule is not part of this PR. I split it into #404 and you're welcome to pick it up there.

@TheTom
TheTom merged commit 787b404 into TheTom:feature/turboquant-kv-cache Oct 22, 2026
14 of 31 checks passed
@TheTom

TheTom commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Merged as 787b404. Thanks Jake, the V table fix and the rebases were clean work. I'll put the GB10 rows on #404 instead of holding this for them. The CUDA-only note for the speedup can go in a follow-up if you want it, not needed to land.

giveen added a commit to giveen/llama-cpp-turboquant that referenced this pull request Oct 28, 2026
Turbo5/turbo6 (51/52) landed in TheTom#381 with 82/98 byte blocks, so the type
tables, the KV cache size table and the backend matrix list all ten fork
types. The flag parser accepts turbo5/turbo6; only CPU and CUDA/HIP have
kernels, and Metal's three mixed K/V pairs are spelled out.

docs/KV-cache-quantization.md is now the source of truth for the env knobs
(TQ_NATIVE, FUSE_CHAIN, Q8CACHE and ROT_K_NROT were missing) and the
TURBO_LAYER_ADAPTIVE auto default is corrected there. README and AGENTS
point at it instead of claiming it is stale.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA documentation Improvements or additions to documentation examples ggml testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants