Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
216 commits
Select commit Hold shift + click to select a range
0b37448
WIP: add TurboQuant KV cache types (turbo3, turbo4)
TheTom Mar 25, 2026
b37e5f0
feat: Metal kernels for TurboQuant KV cache (turbo3, turbo4) #21
TheTom Mar 25, 2026
63e25a5
feat: full TurboQuant with rotation matrices in Metal kernels #21
TheTom Mar 25, 2026
f40ccae
feat: inline rotation matrices in Metal shader + C round-trip test #21
TheTom Mar 25, 2026
d10ca51
fix: remove thread static from Metal dequantize, fix stale code #23
TheTom Mar 25, 2026
3777275
feat: replace dense 128x128 matvec with Fast Walsh-Hadamard rotation #26
TheTom Mar 25, 2026
fa52236
docs: detailed speed investigation plan for TurboQuant Metal shader #23
TheTom Mar 25, 2026
8cf626a
docs: log simd_broadcast attempt — no speed improvement #23
TheTom Mar 25, 2026
2448468
docs: log threadgroup attempt — no speed improvement, rethinking #23
TheTom Mar 25, 2026
d675e12
docs: CRITICAL — dequant is NOT the bottleneck, no-op still 2.4 tok/s…
TheTom Mar 25, 2026
adfbc59
fix: inline turbo-wht.h — was causing CPU fallback, not Metal! #23
TheTom Mar 25, 2026
e8f23eb
docs: real Metal benchmarks after #include fix — 8× gap not 35× #23
TheTom Mar 25, 2026
447ca79
docs: final investigation summary + upstream tracking #23 #27
TheTom Mar 25, 2026
5787361
docs: upstream competitive intel — pre-rotate-queries is the key #28
TheTom Mar 25, 2026
786f0c9
docs: speed ceiling test — 49 tok/s without dequant rotation (4.6× ga…
TheTom Mar 25, 2026
79c08dd
docs: pre-rotate-queries implementation plan + speed ceiling 49 tok/s
TheTom Mar 25, 2026
808e171
feat: pre-rotate-queries optimization — 51.4 tok/s (5× speedup) #23
TheTom Mar 25, 2026
ac157ee
docs: final investigation summary — 2.4 → 51.4 tok/s journey complete…
TheTom Mar 25, 2026
d044965
feat: MSE-only mode — drop QJL, all 3 bits to PolarQuant #23
TheTom Mar 25, 2026
068715c
docs: Change 2 not needed — Q rotation overhead is negligible
TheTom Mar 25, 2026
c551be4
docs: block size is the bottleneck — q4_0 at block 32 = 100% of q8_0
TheTom Mar 25, 2026
fff2092
feat: block size 32 — 77.7 tok/s MoE (91% of q8_0), 17.0 Qwopus (97%) 🎉
TheTom Mar 25, 2026
6a52a43
fix: TURBO_D=128 independent of QK_TURBO3, file turbo4 bugs #29
TheTom Mar 25, 2026
2462ab3
docs: final investigation log — 77.7 tok/s, 91% of q8_0
TheTom Mar 25, 2026
b4270ec
CRITICAL: turbo3 perplexity is 165.6 vs q8_0 6.1 — quality broken #30
TheTom Mar 25, 2026
8755e26
CRITICAL: found TWO root causes for PPL=165 #30
TheTom Mar 25, 2026
b0234bd
docs: bisect confirms block size innocent, rotation access is the bug…
TheTom Mar 25, 2026
ebe0a23
fix: restore inverse rotation in dequant — PPL 6.19 (1.2% of q8_0) #3…
TheTom Mar 25, 2026
091e12a
docs: perplexity 6.194 confirmed — 1.4% of q8_0 #30
TheTom Mar 25, 2026
538e5af
docs: complete quality benchmark summary + lessons learned #30
TheTom Mar 25, 2026
7300255
perf: fp16 WHT dequant + SIMD cooperative dequant — 45% speedup
TheTom Mar 25, 2026
095aa0b
chore: move turboquant docs to turboquant_plus repo
TheTom Mar 25, 2026
557b033
perf: vectorized half4 WHT butterfly — 31% speedup (1074 → 1411 tok/s)
TheTom Mar 25, 2026
cc31405
perf: pre-packed half4 sign arrays — minor speedup (1411 → 1424 tok/s)
TheTom Mar 25, 2026
4de7c1c
perf: graph-side WHT rotation — 2095 tok/s (0.78x q8_0, was 0.53x)
TheTom Mar 25, 2026
e5b7470
perf: block-32 + graph WHT — 2747 tok/s (1.02x q8_0!!!)
TheTom Mar 25, 2026
73f0008
feat: layer-adaptive KV cache — q8_0 quality with 80% turbo3 compression
TheTom Mar 25, 2026
701e085
fix: address Codex review on layer-adaptive — thread safety + underfl…
TheTom Mar 25, 2026
6267548
wip: context scaling fix — skip unnecessary ggml_cont + 32x32 rotatio…
TheTom Mar 26, 2026
af0cb0a
experiment: group-32 rotation FAILED — PPL 7.06 (target 6.19)
TheTom Mar 26, 2026
012faec
feat: add GGML_OP_TURBO_WHT — custom O(d log d) Walsh-Hadamard Transform
TheTom Mar 26, 2026
7173be9
perf: optimized turbo3 dequant — eliminates context scaling regression
TheTom Mar 26, 2026
8fa5bff
ci: quality+speed gate script — PPL + context scaling check before push
TheTom Mar 26, 2026
b696c5d
perf: fp16 centroid LUT — decode +6-14% at long context (#33)
TheTom Mar 26, 2026
e398a4e
perf: float norm broadcast in vec dequant — decode +2-3% over fp16 LUT
TheTom Mar 26, 2026
5e6277b
fix: add turbo3/turbo4 cache types to llama-bench arg parser
TheTom Mar 26, 2026
6c9cfb1
experiment: split 2x4-entry constant LUT for M1 decode fix
TheTom Mar 26, 2026
d96703a
fix: Metal shader comment accuracy per Codex review
TheTom Mar 26, 2026
33b3d8a
cleanup: remove stray diagnostic output files
TheTom Mar 26, 2026
440d324
feat: turbo3 norm correction — PPL 6.211 → 6.176 (free quality win)
TheTom Mar 26, 2026
4bf7ddc
fix: auto-enable flash attention for turbo cache types + fix ggml con…
TheTom Mar 26, 2026
884da3f
experiment: register centroid LUT tested — register spill on Metal
TheTom Mar 26, 2026
3eca09a
fix: turbo4 SET_ROWS corruption, tail-block truncation, constant coup…
seanrasch Mar 27, 2026
a5a0f7b
fix: stack overflow in turbo4 CPU init — 64KB array on worker thread …
seanrasch Mar 27, 2026
06a6b62
experiment: batched byte extraction + explicit bit field pre-extract
TheTom Mar 27, 2026
86a5bbf
experiment: profiling modes for turbo3 decode bottleneck isolation
TheTom Mar 27, 2026
baa6116
experiment: 4-entry magnitude LUT + branchless sign (XOR trick)
TheTom Mar 27, 2026
1c2e558
experiment: force non-vec FA path for turbo3 (nl=2 vs nl=8)
TheTom Mar 27, 2026
c527333
experiment: zero-LUT select chain — 2-level ternary, no constant memory
TheTom Mar 27, 2026
f19c98c
feat: auto-detect hardware, use 4-mag LUT on pre-M5 (+38-45% decode)
TheTom Mar 27, 2026
fbd5ec9
experiment: 2-pair half2 LUT — only 2 constant addresses per lookup
TheTom Mar 27, 2026
7c2d880
experiment: deferred norm multiply (batch float4 * norm at end)
TheTom Mar 27, 2026
35034f1
revert to proven 4-mag + per-element norm (deferred norm was slower)
TheTom Mar 27, 2026
616c7b9
experiment: named-register centroid×norm — 4 constant reads upfront, …
TheTom Mar 27, 2026
73d512c
revert to 4-mag LUT (proven best), document all findings
TheTom Mar 27, 2026
bdcd8ec
experiment: inline block processing — bypass template dequant in FA i…
TheTom Mar 27, 2026
b596a5c
experiment: inline block WORSE on M2 (-10-15%), reverted to 4-mag
TheTom Mar 27, 2026
34f7c39
experiment: FULLY BRANCHLESS FMA decode — zero ternary, zero memory, …
TheTom Mar 27, 2026
9637c1c
final: 12 approaches tested, 4-mag LUT is the hardware limit
TheTom Mar 27, 2026
5755740
experiment: SIMD SHUFFLE magnitude select — cross-lane LUT replacement
TheTom Mar 27, 2026
927e68a
experiment: simd_shuffle 14.7 at 8K — close to 4-mag (15.1) but not b…
TheTom Mar 27, 2026
4b44b2b
experiment: fused block dot — per-centroid Q accumulation, 4 constant…
TheTom Mar 27, 2026
d9ba9bf
experiment: fused block dot 8.1 at 8K — worst result, 64 comparisons …
TheTom Mar 27, 2026
b3cd6a7
experiment: 4-mag helps M5 at 16K (+2.4%) but hurts at 32K (-7.3%)
TheTom Mar 27, 2026
927cfc1
experiment: M5 LUT cost grows to 34% at 32K context
TheTom Mar 27, 2026
26b0bcc
feat: sparse V dequant — +12% decode at 32K, zero quality loss
TheTom Mar 27, 2026
de44bfe
feat: sparse V dequant — +22% decode at 32K on M5, auto-enabled
TheTom Mar 27, 2026
687b184
Revert "Merge pull request #4 from seanrasch/feature/turboquant-kv-ca…
TheTom Mar 27, 2026
3d40ac4
experiment: dedicated turbo4 SET_ROWS kernel + prefill FA kernels
TheTom Mar 28, 2026
cb4d495
experiment: turbo4 2+1 bit packing — +33% decode, drop QJL
TheTom Mar 28, 2026
280c242
experiment: direct-extract turbo4 dequant — matches turbo3 speed
TheTom Mar 28, 2026
a56ed21
experiment: 4-bit half-precision centroid LUT for turbo4 vec path
TheTom Mar 28, 2026
b4b6a30
experiment: fix turbo4 struct for 4-bit — Codex-caught OOB bug
TheTom Mar 28, 2026
c4e98a5
experiment: 8-mag LUT tested, reverted — direct 16-LUT faster on M5
TheTom Mar 28, 2026
7053f4d
experiment: add turbo4_dequant_f16 compute shader (prefill prep)
TheTom Mar 28, 2026
e7ac14d
feat: TURBO4_USE_4BIT ifdef for ABI compatibility
TheTom Mar 28, 2026
f4d9d3e
feat: complete 4-bit C reference for turbo4 — quantize + dequant
TheTom Mar 28, 2026
5e954d4
fix: add turbo WHT rotation to ISWA build_attn — fixes Gemma 2
TheTom Mar 28, 2026
4489686
feat: CUDA port of TurboQuant3 KV cache compression (RTX 5090 / SM 12.0)
signalnine Mar 26, 2026
1127f5b
perf: enable MMA/TILE flash attention for turbo3 — 0.97x q8_0 prefill
signalnine Mar 26, 2026
9a4afd8
perf: parallel k_set_rows_turbo3 + optimise KQ/V dequant — +31% decod…
signalnine Mar 27, 2026
a17a63a
fix: VEC flash-attn Q/K stride mismatch in vec_dot_fattn_vec_KQ_turbo3_0
signalnine Mar 27, 2026
e9ab045
fix: graceful fallback for turbo3 with non-128-aligned head dims (iss…
signalnine Mar 28, 2026
fb2d86d
fix: graceful fallback for turbo3 on non-128-aligned head dims (issue…
signalnine Mar 28, 2026
d86034d
feat: 64-element WHT groups + MLA Q rotation fix (issue #13)
signalnine Mar 28, 2026
567fadf
feat: mixed turbo3/q8_0 KV cache types (-ctk turbo3 -ctv q8_0 and vic…
signalnine Mar 28, 2026
f0601a7
fix: implement CPU turbo3 quantize (was a stub that zeroed qs/signs)
signalnine Mar 28, 2026
25a19f2
feat: GGML_TYPE_TURBO2_0 — 2-bit TurboQuant KV cache (6.4x compression)
signalnine Mar 28, 2026
52178bb
fix: MLA inverse WHT group_size derived from K (not V) — fixes GLM-4.7
signalnine Mar 28, 2026
f3f7c3c
feat: InnerQ per-channel equalization + turbo2 64-group fallback
signalnine Mar 28, 2026
65a2c69
perf: sparse V dequant — skip negligible attention weights in VEC kernel
signalnine Mar 28, 2026
df33248
fix: require head_dim % 128 for turbo KV — fall back to q8_0 otherwise
signalnine Mar 29, 2026
e3b87f8
feat: Metal support for turbo2 (2-bit KV cache, 6.4x compression)
TheTom Mar 29, 2026
fe6749f
feat: asymmetric K/V quant support for Metal flash attention
TheTom Mar 29, 2026
59e2139
feat: asymmetric K/V support + q8_0 × turbo FA kernel instantiations
TheTom Mar 29, 2026
d158db5
feat: zero-pad non-128 heads for full 7-stage WHT (replaces q8_0 fall…
signalnine Mar 29, 2026
0836309
perf: CUDA MMA flash attention for D=640 (GLM-4.7 turbo3: 37→192 t/s)
signalnine Mar 29, 2026
1d5f5c7
fix: add turbo3/turbo2 cross-type VEC FA instances (issue #25 bug 2)
signalnine Mar 29, 2026
821f843
feat: CUDA port of turbo4 (4-bit, 3.8x compression) — fixes issue #25…
signalnine Mar 29, 2026
de03f39
fix: turbo4 on GLM-4.7 — context init check accounts for zero-padding…
signalnine Mar 29, 2026
a3e97d8
feat: Boundary V (experimental) — layer-aware V compression
TheTom Mar 29, 2026
ee82c55
fix: KV state serialization uses padded tensor width (issue #28 follo…
signalnine Mar 29, 2026
a30a59e
feat: HIP/ROCm porting for TheTom's turbo3/turbo2 warp-cooperative ke…
Tuklus Mar 29, 2026
b9df4c3
Increase turbo3/turbo2 block size from 32 to 128
TheTom Mar 30, 2026
f028c66
fix: CUDA warp-to-block mapping for block_size=128 (turbo3, turbo2)
Mar 30, 2026
a6ff538
Enable Sparse V on all Metal, auto-enable Boundary V for turbo2-V
TheTom Mar 31, 2026
d9552b9
fix: add missing TurboQuant FA template instances for HIP/ROCm build
terrysimons Mar 31, 2026
d11b426
Remove unused CENTROIDS_1BIT constant
TheTom Mar 31, 2026
3a2fad1
feat: TQ3_1S + TQ4_1S weight quantization with V2.1 fused Metal kernels
TheTom Apr 1, 2026
7b5094b
fix: add post-unrotate memory barrier for in-layer mixing safety
TheTom Apr 2, 2026
c452be6
fix: disable upstream attn rotation by default (conflicts with TurboQ…
TheTom Apr 2, 2026
2ebd519
feat: CUDA port of TQ4_1S/TQ3_1S weight dequant (signalnine)
TheTom Apr 2, 2026
bf9bf31
fix: TQ4_1S CUDA — mmvq exclusion for fused path + quantize tool regi…
signalnine Apr 2, 2026
8c2e0d8
perf: fused TQ4_1S/TQ3_1S mul_mat_vec — 3.4x decode speedup
signalnine Apr 2, 2026
ec6b8d4
fix: TQ4_1S on MoE models — disable CUDA graphs for TQ MUL_MAT_ID
signalnine Apr 2, 2026
76ebd26
perf: V12 single-phase fused TQ mmvq — shmem activation, no global sc…
TheTom Apr 2, 2026
adda3bc
fix: Windows MSVC build compatibility for TQ weight types
TheTom Apr 2, 2026
694ed03
fix: AMD HIP/ROCm build support for TQ4_1S weight compression
TheTom Apr 2, 2026
2962592
fix: add dk512 Metal FA kernel instances for turbo types (Gemma 4 sup…
TheTom Apr 2, 2026
b1a6f79
fix: CPU vec_dot heap allocation for turbo/TQ types (n > 4096 models)
TheTom Apr 2, 2026
fe2ead9
Fix turbo4 C reference WHT dequant mismatch (#43)
TheTom Apr 2, 2026
e3ce079
feat: load-time TQ4_1S -> q8_0 conversion for CUDA dp4a speed
TheTom Apr 2, 2026
71c7a4c
fix: remove redundant extern from GGML_API macro (GCC 13.3 hard error)
TheTom Apr 3, 2026
c29fab6
Enhance Metal operations for TQ weights and concurrency handling for …
iamwavecut Apr 4, 2026
5bad823
Update GGMLQuantizationType and LlamaFileType enums to include TQ3_1S…
iamwavecut Apr 4, 2026
e5ac94d
fix: GCC double extern in ops.cpp turbo3_cpu_wht_group_size
TheTom Apr 5, 2026
753f199
feat: add MoE expert count kernel instantiations + TQ4_1S backend tests
TheTom Apr 6, 2026
6571604
fix: cap map0 kernel shmem for 256-expert MoE models
TheTom Apr 7, 2026
51481c3
perf: TQ4_1S native kernel 3.5× faster — 240 t/s (was 68), smaller VR…
signalnine Apr 6, 2026
cc1bae2
perf: warp-cooperative TQ4_1S dequant (16× less compute per block)
signalnine Apr 6, 2026
941d456
feat: multi-token TQ4_1S dp4a kernel + multi-GPU fix + static build fix
signalnine Apr 6, 2026
579db29
fix: replace __dp4a with ggml_cuda_dp4a for HIP/ROCm compatibility
signalnine Apr 6, 2026
0bf1eef
fix: AMD/RDNA4 arch dispatch — scalar half path for TQ4_1S on AMD GPUs
TheTom Apr 7, 2026
a494833
feat: Vulkan compute shader support for turbo3 KV cache
Tuklus Mar 30, 2026
e596f47
metal: add TurboFlash attention kernel for turbo3 KV cache decode
TheTom Apr 8, 2026
3b5e148
docs: add AMD Instinct MI300X (gfx942) ROCm test results
andyluo7 Apr 7, 2026
1df4783
feat: add CDNA4 (gfx950/MI355X) support + test results
andyluo7 Apr 7, 2026
ff8bb73
vulkan: fix and complete turbo3 KV cache support
Titaniumtown Apr 9, 2026
88fcb67
vulkan: add turbo3 backend tests
Titaniumtown Apr 9, 2026
a4736ff
Add GitHub Sponsors funding link
TheTom Apr 14, 2026
e53f802
Fix memory explosion on Apple Silicon
huwprosser Apr 13, 2026
6775542
Fix GGML_OP_COUNT assertion for RPC
cpburnz Apr 10, 2026
0009301
ci: fix turbo build and test failures
Tuklus Apr 10, 2026
1073622
fix: add TURBO2_0 to flash_attn auto-enable check
TheTom Apr 16, 2026
59798f1
fix(cuda): allow f16/bf16 + q8_0 mixed KV without GGML_CUDA_FA_ALL_QU…
TheTom Apr 17, 2026
fa4e8be
fix(cuda): add F16-K + TURBO-V dispatch cases in fattn.cu
dentity007 Apr 17, 2026
f9ee92b
fix nix build: Add spirv-headers to vulkanBuildInputs
cguentherTUChemnitz Apr 17, 2026
93bf21d
fix(metal): add turbo2/3/4 types to FLASH_ATTN_EXT and CPY support ch…
tomwolfe Apr 17, 2026
0198d58
vulkan: fix turbo3 build + coopmat FA after April upstream sync
Tuklus Apr 17, 2026
8993d4f
fix: force VEC FA path for quantized KV on HIP/ROCm
TheTom Apr 18, 2026
0757ff4
fix(hip): bypass pool for FA f16 temp buffers to prevent OOM
TheTom Apr 18, 2026
7ca13d2
Merge pull request #90 from TheTom/fix/hip-force-vec-quantized-kv
TheTom Apr 18, 2026
627ebbc
Merge pull request #87 from apollosenvy/pr/vulkan-turbo3-april-fix
TheTom Apr 18, 2026
6112eb4
fix: gate turbo V unpad on V type, not K type
TheTom Apr 20, 2026
a1bcb34
fix(metal): disable TurboFlash by default — corrupt output on Apple10
TheTom Apr 20, 2026
d3271ac
fix: gate turbo V unpad on V type + disable TurboFlash on Apple10 (#91)
TheTom Apr 20, 2026
90968cc
Merge pull request #84 from dentity007/fix/cuda-fattn-f16-turbo-dispatch
TheTom Apr 20, 2026
6e0630d
Merge pull request #85 from cguentherTUChemnitz/patch-1
TheTom Apr 20, 2026
74450af
Merge pull request #86 from tomwolfe/bugfix/metal
TheTom Apr 20, 2026
0759506
fix: inverse WHT in test-turbo-quant.c round-trip (#59)
TheTom Apr 20, 2026
f4ffeb4
Merge pull request #93 from TheTom/fix/test-turbo-quant-inverse-wht
TheTom Apr 20, 2026
8ba9f12
vulkan: TQ4_1s support for model weights (#69)
Titaniumtown Apr 20, 2026
4d24ad8
ci: add TurboQuant+ release workflow
TheTom Apr 21, 2026
dad4e2e
Cherry-pick upstream speculative decoding for hybrid models
TheTom Apr 22, 2026
b3401ea
Cherry-pick upstream CMake glob for model sources
TheTom Apr 22, 2026
9e3fb40
fix(hip): add missing f16-turbo fattn-vec instances to HIP CMakeLists
TheTom Apr 22, 2026
70de249
fix(cuda): allow f16/bf16 + q8_0 mixed KV without GGML_CUDA_FA_ALL_QU…
TheTom Apr 17, 2026
58bbe55
fix(cuda): add F16-K + TURBO-V dispatch cases in fattn.cu
dentity007 Apr 17, 2026
d9adc24
fix nix build: Add spirv-headers to vulkanBuildInputs
cguentherTUChemnitz Apr 17, 2026
a4a09dc
fix(metal): add turbo2/3/4 types to FLASH_ATTN_EXT and CPY support ch…
tomwolfe Apr 17, 2026
458c7f1
vulkan: fix turbo3 build + coopmat FA after April upstream sync
Tuklus Apr 17, 2026
4d75460
fix: force VEC FA path for quantized KV on HIP/ROCm
TheTom Apr 18, 2026
d7b5334
fix(hip): bypass pool for FA f16 temp buffers to prevent OOM
TheTom Apr 18, 2026
1565920
fix: gate turbo V unpad on V type, not K type
TheTom Apr 20, 2026
67f076f
fix(metal): disable TurboFlash by default — corrupt output on Apple10
TheTom Apr 20, 2026
037047e
fix: inverse WHT in test-turbo-quant.c round-trip (#59)
TheTom Apr 20, 2026
f03d331
vulkan: TQ4_1s support for model weights (#69)
Titaniumtown Apr 20, 2026
99c2ed7
ci: add TurboQuant+ release workflow
TheTom Apr 21, 2026
991301f
Cherry-pick upstream speculative decoding for hybrid models
TheTom Apr 22, 2026
f64e879
Cherry-pick upstream CMake glob for model sources
TheTom Apr 22, 2026
b8b1d49
fix(hip): add missing f16-turbo fattn-vec instances to HIP CMakeLists
TheTom Apr 22, 2026
7f320bb
Merge commit '7fc1c4ef7' into rebase/upstream-sync-april-2026
TheTom Apr 22, 2026
67559e5
Upstream sync to b8871 (64 commits)
TheTom Apr 23, 2026
f2dc968
cuda: disable sparse V skip (warp divergence regression)
TheTom Apr 24, 2026
11a241d
Merge pull request #105 from TheTom/fix/disable-sparse-v-cuda
TheTom Apr 24, 2026
db3595a
fix(kv-cache): per-side env-knob control for upstream attn rotation, …
TheTom Apr 29, 2026
817e913
fix(kv-cache): unblock per-side ROT_OVERRIDE knobs (default attn_rot_…
TheTom Apr 29, 2026
157f27f
perf: turbo VEC flash attention — +9% decode on CUDA via autoresearch
signalnine Apr 9, 2026
b6f8e7f
fix(llama-graph): n_head_v reshape uses Q-head count, not KV-head cou…
TheTom May 1, 2026
cde3e1a
Merge pull request #116 from TheTom/fix/issue-78-gqa-reshape
TheTom May 1, 2026
0fa61d7
Merge pull request #115 from TheTom/pr53-auto-asymmetric
TheTom May 1, 2026
e0954d1
Merge pull request #111 from TheTom/fix/enable-attn-rot-by-default
TheTom May 1, 2026
d2d0d6e
fix(nix): remove duplicate spirv-headers function arg (#81)
TheTom May 1, 2026
4f33166
Merge pull request #117 from TheTom/fix/issue-81-nix-spirv-dupe
TheTom May 1, 2026
fec0719
vulkan: add SET_ROWS support for turbo2_0 and turbo4_0 (#50)
TheTom May 2, 2026
60fc495
Merge pull request #118 from TheTom/fix/issue-50-vulkan-set-rows-turbo24
TheTom May 3, 2026
170bd4b
server: fix heap-buffer-overflow from negative n_discard (CVE-2026-21…
SongTonyLi Apr 23, 2026
69d8e4b
Merge pull request #122 from TheTom/fix/cve-2026-21869-n-discard-clamp
TheTom May 4, 2026
e69af78
fix(fattn): add (turbo*, F16) template instantiations
TheTom May 9, 2026
7e34166
fix(perplexity): cast n_ctx * nv to size_t in KL logits save (#138)
Defilan May 9, 2026
5aeb2fd
fix(hip): add (turbo*, F16) template-instance .cu files to HIP build
TheTom May 9, 2026
10cb371
vulkan: add TurboQuant KV cache support (turbo2/3/4, tq3_1s, tq4_1s)
Fenix46 May 10, 2026
70997d3
fix(vulkan): extend set_rows workgroup size to TURBO2_0 and TURBO4_0
Fenix46 May 10, 2026
e448a46
perf(vulkan): vectorize turbo dequantize4 in flash attention
Fenix46 May 10, 2026
941f04a
feat(vulkan): register dedicated mul_mat_vec pipelines for turbo types
Fenix46 May 10, 2026
a3c149e
Merge branch 'feature/turboquant-kv-cache' into turbo/vulkan
Fenix46 May 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devops/nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
rocmPackages,
vulkan-headers,
vulkan-loader,
spirv-headers,
openssl,
shaderc,
spirv-headers,
useBlas ?
builtins.all (x: !x) [
useCuda
Expand Down Expand Up @@ -103,6 +103,7 @@ let
vulkan-headers
vulkan-loader
shaderc
spirv-headers
];
in

Expand Down
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [TheTom]
109 changes: 109 additions & 0 deletions .github/workflows/tqp-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: TurboQuant+ Release

on:
push:
tags:
- 'tqp-v*'

env:
CMAKE_ARGS: "-DLLAMA_BUILD_EXAMPLES=OFF -DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_TOOLS=ON -DLLAMA_BUILD_SERVER=ON"

jobs:
macos-metal:
runs-on: macos-14

steps:
- name: Clone
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Build
run: |
cmake -B build \
-DGGML_METAL_USE_BF16=ON \
-DGGML_METAL_EMBED_LIBRARY=ON \
-DCMAKE_INSTALL_RPATH='@loader_path' \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
${{ env.CMAKE_ARGS }}
cmake --build build --config Release -j $(sysctl -n hw.logicalcpu)

- name: Pack
run: |
cp LICENSE ./build/bin/
tar -czvf turboquant-plus-${{ github.ref_name }}-macos-arm64-metal.tar.gz \
-s ",./,turboquant-plus-${{ github.ref_name }}/," -C ./build/bin .

- name: Upload
uses: actions/upload-artifact@v6
with:
name: macos-arm64-metal
path: turboquant-plus-${{ github.ref_name }}-macos-arm64-metal.tar.gz

windows-cuda:
runs-on: windows-2022

strategy:
matrix:
cuda: ['12.4']

steps:
- name: Clone
uses: actions/checkout@v6

- name: Install Cuda Toolkit
uses: ./.github/actions/windows-setup-cuda
with:
cuda_version: ${{ matrix.cuda }}

- name: Install Ninja
run: choco install ninja

- name: Build
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
cmake -S . -B build -G "Ninja Multi-Config" ^
-DGGML_NATIVE=OFF ^
-DGGML_CUDA=ON ^
-DGGML_CUDA_FA_ALL_QUANTS=ON ^
${{ env.CMAKE_ARGS }}
set /A NINJA_JOBS=%NUMBER_OF_PROCESSORS%-1
cmake --build build --config Release -j %NINJA_JOBS%

- name: Pack
run: |
cp LICENSE ./build/bin/Release/
$dst='.\build\bin\Release\'
robocopy "${{env.CUDA_PATH}}\bin" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll
robocopy "${{env.CUDA_PATH}}\lib" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll
robocopy "${{env.CUDA_PATH}}\bin\x64" $dst cudart64_*.dll cublas64_*.dll cublasLt64_*.dll
7z a turboquant-plus-${{ github.ref_name }}-windows-x64-cuda${{ matrix.cuda }}.zip .\build\bin\Release\*

- name: Upload
uses: actions/upload-artifact@v6
with:
name: windows-x64-cuda${{ matrix.cuda }}
path: turboquant-plus-${{ github.ref_name }}-windows-x64-cuda${{ matrix.cuda }}.zip

release:
needs: [macos-metal, windows-cuda]
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Download artifacts
uses: actions/download-artifact@v7
with:
path: ./release
merge-multiple: true

- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: TurboQuant+ ${{ github.ref_name }}
files: ./release/*
draft: false
prerelease: false
362 changes: 362 additions & 0 deletions bench-smem-m5-baseline.txt

Large diffs are not rendered by default.

413 changes: 413 additions & 0 deletions bench-smem-m5-smem.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions common/arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ const std::vector<ggml_type> kv_cache_types = {
GGML_TYPE_IQ4_NL,
GGML_TYPE_Q5_0,
GGML_TYPE_Q5_1,
GGML_TYPE_TURBO2_0,
GGML_TYPE_TURBO3_0,
GGML_TYPE_TURBO4_0,
};

static ggml_type kv_cache_type_from_str(const std::string & s) {
Expand Down Expand Up @@ -3902,6 +3905,17 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
}
).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));

add_opt(common_arg(
{"--spec-default"},
string_format("enable default speculative decoding config"),
[](common_params & params) {
params.speculative.type = COMMON_SPECULATIVE_TYPE_NGRAM_MOD;
params.speculative.ngram_size_n = 24;
params.speculative.n_min = 48;
params.speculative.n_max = 64;
}
).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));

return ctx_arg;
}

Expand Down
6 changes: 6 additions & 0 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
#include <string.h>
#include <fcntl.h>
#include <io.h>
#ifndef fileno
#define fileno _fileno
#endif
#ifndef isatty
#define isatty _isatty
#endif
#else
#include <sys/ioctl.h>
#include <sys/stat.h>
Expand Down
1 change: 1 addition & 0 deletions common/speculative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ struct common_speculative_state_ngram_mod : public common_speculative_state {

mod.reset();
n_low = 0;
i_last = 0;
}
} else {
n_low = 0;
Expand Down
95 changes: 95 additions & 0 deletions docs/rocm-mi300x-test-results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# TurboQuant on AMD Instinct MI300X & MI355X (ROCm/HIP)

## Summary

TurboQuant KV cache compression (turbo2/turbo3/turbo4) builds and runs correctly on AMD Instinct MI300X (gfx942) and MI355X (gfx950). MI300X requires zero code changes. MI355X requires adding CDNA4 arch defines to the HIP vendor header.

## Test Environment

| Component | MI300X | MI355X |
|-----------|--------|--------|
| GPU | MI300X (gfx942), 192 GB HBM3 | MI355X (gfx950), 288 GB HBM3e |
| ROCm | 7.0.2 | 7.0.1 |
| Wave Size | 64 | 64 |
| Build | `-DAMDGPU_TARGETS="gfx942"` | `-DAMDGPU_TARGETS="gfx950"` |
| Model | Qwen2.5-1.5B Q4_K_M (1.04 GiB) | same |

## WHT Kernel Correctness

Standalone roundtrip test (forward WHT → inverse WHT) confirms the Walsh-Hadamard Transform kernel works correctly on HIP with 64-wide wavefronts:

```
=== TurboQuant WHT Roundtrip Test (HIP/gfx942) ===
Total elements: 512 (4 heads x 128 dim)
Forward WHT zeros: 0 / 512
Roundtrip max error: 2.980232e-07
Roundtrip RMSE: 6.816018e-08
Result: PASS ✅
```

The kernel uses shared memory + `__syncthreads()` (no warp shuffles), so it works correctly with GCN's 64-thread wavefronts without modification.

## Performance Results

### MI300X (single GPU, Qwen2.5-1.5B Q4_K_M)

| KV Cache | pp512 (tok/s) | tg128 (tok/s) | Prefill vs f16 | Decode vs f16 |
|----------|--------------|--------------|----------------|---------------|
| f16 | 24,453 ± 230 | 181.2 ± 2.0 | baseline | baseline |
| turbo3 | ~25,200 | ~160 | **+3%** | 88% |
| turbo4 | 25,427 ± 17 | 161.1 ± 0.2 | **+4%** | 89% |

### MI355X (single GPU, Qwen2.5-1.5B Q4_K_M)

| KV Cache | pp512 (tok/s) | tg128 (tok/s) | Prefill vs f16 | Decode vs f16 |
|----------|--------------|--------------|----------------|---------------|
| f16+FA | 40,013 ± 902 | 254.5 ± 1.0 | baseline | baseline |
| turbo3 | 39,140 ± 475 | 162.3 ± 0.1 | 98% | 64% |
| turbo4 | 39,232 ± 508 | 214.1 ± 0.7 | 98% | **84%** |

### Key Observations

1. **MI300X prefill is faster with TurboQuant** (+3-4%) — less KV cache data to write to HBM.
2. **MI300X decode at 88-89% of f16** — consistent with Apple Silicon community results.
3. **MI355X turbo4 decode at 84%** — turbo4 outperforms turbo3 in decode due to simpler 4-bit dequant.
4. **MI355X turbo3 decode at 64%** — the 3-bit codebook + sign extraction is more expensive on gfx950.
5. **MI355X non-FA MMQ path crashes** (xf32 MFMA issue) — turbo types force FA and work correctly.

## Build Instructions

```bash
git clone https://github.com/TheTom/llama-cpp-turboquant.git
cd llama-cpp-turboquant
git checkout feature/turboquant-kv-cache

# MI300X (gfx942) — works without code changes
cmake -B build -DGGML_HIP=ON -DCMAKE_BUILD_TYPE=Release -DAMDGPU_TARGETS="gfx942"
cmake --build build --config Release -j

# MI355X (gfx950) — requires CDNA4 define patch (see commit)
cmake -B build -DGGML_HIP=ON -DCMAKE_BUILD_TYPE=Release -DAMDGPU_TARGETS="gfx950"
cmake --build build --config Release -j

# Test
HIP_VISIBLE_DEVICES=0 ./build/bin/llama-bench \
-m model.gguf -ctk turbo3 -ctv turbo3 -ngl 99 -r 3 -p 512 -n 128
```

## Code Changes for gfx950 (MI355X)

Three files modified to add CDNA4 (gfx950) architecture support:

1. **`ggml/src/ggml-cuda/vendors/hip.h`** — Add `CDNA4` define for `__gfx950__`, include in `CDNA` family
2. **`ggml/src/ggml-cuda/common.cuh`** — Add `GGML_CUDA_CC_CDNA4` constant and `GGML_CUDA_CC_IS_CDNA4` macro
3. **`ggml/src/ggml-cuda/mma.cuh`** — Route CDNA4 to compatible MFMA instructions (bf16_1k, i32x16x32_i8, f32x16x4f32 — NOT xf32 which doesn't exist on gfx950)

## Known Limitations

- **MI355X non-FA MMQ crashes**: The default (non-flash-attention) matrix multiply path crashes on gfx950 due to the xf32 MFMA instruction (`mfma_f32_16x16x8_xf32`) not being available. TurboQuant types force flash attention and work correctly. Standard f16/q8_0 KV cache types need `-fa 1` flag on MI355X.
- **llama-cli text output**: Interactive mode produces empty tokens on ROCm (display issue), but `llama-bench` confirms computation is correct.

## Tested By

Andy Luo (@andyluo7)
- AMD Instinct MI300X (gfx942), ROCm 7.0.2 — April 2026
- AMD Instinct MI355X (gfx950), ROCm 7.0.1 — April 2026
2 changes: 1 addition & 1 deletion ggml/include/ggml-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
#define RPC_PROTO_PATCH_VERSION 0

#ifdef __cplusplus
static_assert(GGML_OP_COUNT == 96, "GGML_OP_COUNT has changed - update RPC_PROTO_PATCH_VERSION");
static_assert(GGML_OP_COUNT == 97, "GGML_OP_COUNT has changed - update RPC_PROTO_PATCH_VERSION");
#endif

#define GGML_RPC_MAX_SERVERS 16
Expand Down
20 changes: 18 additions & 2 deletions ggml/include/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
# define GGML_API __declspec(dllimport) extern
# endif
# else
# define GGML_API __attribute__ ((visibility ("default"))) extern
# define GGML_API __attribute__ ((visibility ("default")))
# endif
#else
# define GGML_API extern
Expand Down Expand Up @@ -429,7 +429,12 @@ extern "C" {
GGML_TYPE_MXFP4 = 39, // MXFP4 (1 block)
GGML_TYPE_NVFP4 = 40, // NVFP4 (4 blocks, E4M3 scale)
GGML_TYPE_Q1_0 = 41,
GGML_TYPE_COUNT = 42,
GGML_TYPE_TURBO2_0 = 42, // TurboQuant 2-bit KV cache: WHT + 2-bit PolarQuant
GGML_TYPE_TURBO3_0 = 43, // TurboQuant 3-bit KV cache: WHT + 3-bit PolarQuant
GGML_TYPE_TURBO4_0 = 44, // TurboQuant 4-bit KV cache: WHT + 4-bit PolarQuant
GGML_TYPE_TQ3_1S = 45, // TurboQuant 3-bit weight: WHT-rotated 8-level Lloyd-Max, block_size=32
GGML_TYPE_TQ4_1S = 46, // TurboQuant 4-bit weight: WHT-rotated 16-level Lloyd-Max, block_size=32
GGML_TYPE_COUNT = 47,
};

// precision
Expand Down Expand Up @@ -561,6 +566,7 @@ extern "C" {
GGML_OP_RWKV_WKV7,
GGML_OP_SOLVE_TRI,
GGML_OP_GATED_DELTA_NET,
GGML_OP_TURBO_WHT,

GGML_OP_UNARY,

Expand Down Expand Up @@ -2539,6 +2545,16 @@ extern "C" {
struct ggml_tensor * beta,
struct ggml_tensor * state);

// TurboQuant Walsh-Hadamard Transform (O(d log d) rotation for KV cache compression)
// Applies WHT rotation to 128-element groups along ne[0]: sign1 → butterfly → sign2 → normalize
// direction: 0 = forward (signs1 → WHT → signs2), 1 = inverse (signs2 → WHT → signs1)
GGML_API struct ggml_tensor * ggml_turbo_wht(
struct ggml_context * ctx,
struct ggml_tensor * a,
int direction,
int group_size, // 0 = auto (64 or 128 from ne[0])
struct ggml_tensor * scale); // NULL = no InnerQ scaling

// custom operators

typedef void (*ggml_custom1_op_t)(struct ggml_tensor * dst , const struct ggml_tensor * a, int ith, int nth, void * userdata);
Expand Down
1 change: 1 addition & 0 deletions ggml/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ add_library(ggml-base
ggml-threading.h
ggml-quants.c
ggml-quants.h
ggml-turbo-quant.c
gguf.cpp)

set_target_properties(ggml-base PROPERTIES
Expand Down
Loading