Skip to content

Rebase onto upstream ggml-org/llama.cpp (April 2026) - #80

Merged
TheTom merged 0 commit into
feature/turboquant-kv-cachefrom
rebase/upstream-sync-april-2026
Apr 16, 2026
Merged

TheTom merged 0 commit into
feature/turboquant-kv-cachefrom
rebase/upstream-sync-april-2026

Conversation

@TheTom

@TheTom TheTom commented Apr 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Rebases feature/turboquant-kv-cache onto latest ggml-org/llama.cpp master (148 upstream commits)
  • Resolves 10 merge conflicts across enum slots, Vulkan shaders, CUDA, HIP, RPC, and Python gguf constants
  • Bumps turbo type enum IDs to avoid collision with upstream's GGML_TYPE_Q1_0 = 41 (turbo2/3/4 now 42-44, TQ3_1S/TQ4_1S 45-46)
  • Fixes stale QJL references in enum comments → "WHT + N-bit PolarQuant"

Conflict resolution details

File Issue Resolution
ggml.h (3x) Enum slot collision with Q1_0=41 Shifted turbo types to 42+
llama-graph.cpp Upstream renamed inp->self_v_rot → v_rot Kept turbo WHT block + upstream variable
llama.h ftype enum Added both Q1_0 + TQ3_1S/TQ4_1S
ggml-cuda.cu (2x) TQ4_1S load-time conversion Kept opt-in env var guard
hip.h Variadic shfl macros vs simple macros Kept variadic (turbo needs 3+4 arg) + NCCL
mma.cuh CDNA4 comment Kept upstream comment
constants.py (3x) Python enum sync Matched C header numbering
ggml-vulkan.cpp (5x) Pipeline setup, RTE variants, FA types Merged upstream int8 dot + turbo3
Vulkan shaders (4 files) Type defs, shader gen, copy_to_quant Kept both NVFP4 + turbo3
ggml-rpc.h (2x) RPC version Kept upstream 4.0.0
test-backend-ops.cpp FA test type list Added TURBO3_0 to upstream's full list

⚠️ DO NOT MERGE — testing required first

  • Metal build + turbo KV cache inference (M5 Max) — PPL +0.04%, 60% KV savings ✅
  • CUDA build (signalnine's fork compat)
  • Vulkan shader compilation
  • Weight quant (TQ3_1S/TQ4_1S) round-trip — quantize + inference + PPL verified ✅
  • HIP/ROCm build
  • RPC protocol version compat

⚠️ Breaking change: Old GGUF files quantized with previous enum IDs will not load. Must re-quantize from f16/f32 source.

🤖 Generated with Claude Code

@TheTom

TheTom commented Apr 15, 2026

Copy link
Copy Markdown
Owner Author

Metal Build + Test Results (M5 Max, April 15 2026)

Model: Qwen2.5-7B-Instruct-Q3_K_M (3.54 GiB)
Build: 000930170 (commit 503), Metal embedded, BF16 enabled
Context: 16,384

PPL (wikitext-2, 3 chunks × 16K)

Config PPL Δ
Baseline (f16 KV) 6.0291 ± 0.089 —
Turbo4 (q8_0 K / turbo4 V) 6.0540 ± 0.089 +0.04% ✅

Throughput (llama-bench, 3 reps)

Config pp512 (t/s) tg128 (t/s) pp8192+tg128 (t/s)
Baseline (f16 KV) 1,983 ± 5.8 103.7 ± 0.2 1,034 ± 10.4
Turbo4 (q8_0/turbo4) 1,998 ± 2.1 83.8 ± 0.4 998 ± 9.1

Memory

Config KV Cache Total GPU
Baseline (f16 KV) 896 MiB 4,826 MiB
Turbo4 (q8_0/turbo4) 357 MiB 4,287 MiB
Savings -60% -11%

Notes

  • PPL essentially unchanged (+0.04%)
  • Prefill slightly faster with turbo4 (within noise)
  • Decode 19% slower — expected WHT overhead on 7B dense (attention is small fraction)
  • 60% KV memory reduction confirmed
  • Build clean, no errors, 21 warnings (all jinja template related)

@TheTom

TheTom commented Apr 15, 2026

Copy link
Copy Markdown
Owner Author

Testing help needed 🙏

This rebases onto 148 upstream commits — conflicts resolved but needs validation on non-Metal backends before merge.

CUDA — @signalnine could you test a build + turbo KV + TQ4_1S weight quant on your setup? The enum IDs shifted (turbo types now 42-46 instead of 41-45) so want to make sure nothing broke in the CUDA kernels.

Vulkan — @Titaniumtown the Vulkan conflicts were the heaviest (pipeline setup, shader gen, copy_to_quant, types.glsl, dequant_funcs_cm2). Upstream added RTE variants + NVFP4 + Q1_0 — merged alongside turbo3. Would appreciate a shader compilation + basic inference test.

HIP/ROCm — @andyluo7 CDNA4 commit landed clean but the variadic shfl macros in hip.h got merged with upstream's NCCL_CHECK addition. Worth a sanity check if you have access.

Weight quant (TQ3_1S/TQ4_1S) — @iamwavecut Python gguf constants updated to match new enum numbering (TQ3_1S=45, TQ4_1S=46). If you can verify a round-trip quantize+dequant that'd be 👌

Metal is ✅ — results in previous comment.

@TheTom

TheTom commented Apr 15, 2026

Copy link
Copy Markdown
Owner Author

Weight Quant (TQ3_1S / TQ4_1S) — Metal, M5 Max ✅

Model: Qwen2.5-1.5B-Instruct (fresh f16 → TQ quantize with new enum IDs)

Quantize

Both round-tripped clean from f16 source:

  • TQ4_1S: 2944 MiB → 964 MiB (5.24 BPW), 9.7s
  • TQ3_1S: 2944 MiB → 808 MiB (4.39 BPW), 7.1s

Inference

Both produce coherent output. TQ4_1S quality noticeably better than TQ3_1S at 1.5B scale (expected).

PPL (wikitext-2, 3 chunks × 2K)

Config PPL Δ vs f16 Prefill (t/s)
f16 baseline 9.68 — 10,187
TQ4_1S 10.13 +4.7% 8,530
TQ3_1S 13.24 +36.8% 9,438

TQ4_1S PPL delta is reasonable for 5.24 BPW on a 1.5B model. TQ3_1S degrades more but that's expected — 3-bit weight quant on small models hurts.

Enum renumbering (TQ3_1S=45, TQ4_1S=46) works correctly. Old GGUF files with previous IDs will NOT load (expected — must re-quantize).

@signalnine

Copy link
Copy Markdown

CUDA Test Results (RTX 5090, sm_120, April 15 2026)

Build: 000930170, CUDA arch 86;120, Release. Clean: 0 errors, 0 warnings.

Re-quantization (new enum IDs)

Both round-tripped clean from f16 source (Qwen2.5-7B-Instruct):

  • TQ4_1S: 14.2 GiB → 4.53 GiB (5.0 BPW), 153 s
  • TQ3_1S: 14.2 GiB → 3.71 GiB (4.18 BPW), 149 s

Old GGUFs (pre-renumbering) fail to load with failed to load model as expected.

Throughput (llama-bench, Qwen2.5-7B TQ4_1S, 3 reps, ngl=99, p=512 n=128)

KV config pp512 (t/s) tg128 (t/s)
f16 / f16 (default) 13,397 ± 819 182.5 ± 0.4
q8_0 / turbo4 14,241 ± 735 169.7 ± 1.8
q8_0 / turbo3 14,184 ± 794 171.2 ± 0.8
q8_0 / turbo2 ❌ failed to create context —

Findings

✅ TQ4_1S weight kernel works — runs cleanly with new enum IDs, no kernel failures, no NaNs in output during smoke runs.
✅ Turbo3 / turbo4 V cache work on CUDA — both load, run, and produce stable t/s. ~7% prefill bump (cache type doesn't matter much for prefill on this size), ~7% decode cost vs f16 KV (expected WHT overhead).
⚠️ -ctv turbo2 fails to create context on CUDA — main: error: failed to create context with model. Worth investigating before merge; turbo3/turbo4 work so this looks specific to the 2-bit V path. Could be pre-existing (not introduced by this rebase) — happy to bisect if useful.

Notes

  • tg128 of 182 here is below my recent autoresearch peak of 242 t/s on pr/fattn-vec-turbo-opts. That's because this PR rebases an earlier mmvq-tq.cu state; the recent dp4a / register-LUT / SW-pipeline optimizations haven't been integrated yet. Not a regression from the rebase, just a different base.
  • Coherence smoke test attempted with -ctk q8_0 -ctv turbo4 but -no-cnv didn't take cleanly in this build — model loaded fine, mem layout looked sane (7039 MiB model, 111 MiB context). I'll re-test coherence properly if the turbo2 issue gets sorted.

Verdict: CUDA path good to merge modulo the turbo2 V failure (worth confirming whether that's a regression or pre-existing).

@signalnine

Copy link
Copy Markdown

Bisect: turbo2 V failure is pre-existing, not introduced by this PR

Tested on feature/turboquant-kv-cache HEAD (45f8a066e, before the rebase): same failed to create context error with -ctv turbo2. So the rebase didn't introduce it.

Root cause (one-line bug, easy fix)

src/llama-context.cpp:2986 — the FA auto-enable check lists turbo3/turbo4 but omits turbo2:

if (params.flash_attn_type == LLAMA_FLASH_ATTN_TYPE_DISABLED &&
    (params.type_k == GGML_TYPE_TURBO3_0 || params.type_k == GGML_TYPE_TURBO4_0 ||
     params.type_v == GGML_TYPE_TURBO3_0 || params.type_v == GGML_TYPE_TURBO4_0)) {
    LLAMA_LOG_WARN("%s: turbo cache types require flash_attn — enabling automatically\n", __func__);
    params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_ENABLED;
}

Without auto-enable, the next check (V cache quantization requires flash_attn) hard-fails. With -fa 1 passed manually, turbo2 V works fine on CUDA: 173.15 t/s on tg32 with q8_0 K + turbo2 V on the same Qwen-7B TQ4_1S model.

Suggested fix

Add TURBO2_0 to the auto-enable predicate (both K and V):

(params.type_k == GGML_TYPE_TURBO2_0 || params.type_k == GGML_TYPE_TURBO3_0 || params.type_k == GGML_TYPE_TURBO4_0 ||
 params.type_v == GGML_TYPE_TURBO2_0 || params.type_v == GGML_TYPE_TURBO3_0 || params.type_v == GGML_TYPE_TURBO4_0)

Or, simpler: trigger on any ggml_is_quantized(params.type_v) since the check immediately below already mandates FA for that case.

Updated CUDA verdict

✅ Merge unblocked from CUDA's perspective. All three turbo V cache types work; the turbo2 auto-enable gap is a pre-existing one-line bug worth fixing in a follow-up but doesn't block this rebase.

@andyluo7

Copy link
Copy Markdown

HIP/ROCm (MI300X gfx942) — Build + Inference ✅

Platform: 8x AMD Instinct MI300X (gfx942), ROCm 6.3
Model: Qwen2.5-1.5B-Instruct (F16 GGUF)

Build

Compiles clean with -DGGML_HIP=ON -DAMDGPU_TARGETS=gfx942:

[100%] Built target llama-server

No warnings from the variadic shfl macros or NCCL_CHECK merge.

Quantize

Both round-tripped clean from F16:

  • TQ4_1S: 3390 MiB → 1103 MiB (5.21 BPW), 14.0s ✅
  • TQ3_1S: 3390 MiB → 919 MiB (4.34 BPW), 12.6s ✅

Sizes match your Metal results within rounding.

Inference

All three produce correct output via llama-completion:

=== F16 ===
Q: "What is 2+2?" → "2+2 is 4." ✅

=== TQ4_1S ===
Q: "What is 2+2?" → "2+2 is 4." ✅

=== TQ3_1S ===
Q: "What is 2+2?" → "The answer to 2+2 is 4." ✅

MI355X (gfx950) Build

Also compiles clean with -DAMDGPU_TARGETS=gfx950. Haven't run inference there yet (no small GGUF model on that machine).

Note

llama-cli defaults to conversation mode for instruct models after the upstream rebase, which shows > prompts instead of generation output. Use llama-completion for non-interactive testing.

Enum renumbering (TQ3_1S=45, TQ4_1S=46) works correctly on HIP. 👍

@TheTom

TheTom commented Apr 15, 2026

Copy link
Copy Markdown
Owner Author

Thank you for the quick turnaround folks! And thanks for the Root cause @signalnine . Will work on this tonight.

@TheTom
TheTom merged commit 1073622 into feature/turboquant-kv-cache Apr 16, 2026
1 check passed
@TheTom
TheTom force-pushed the feature/turboquant-kv-cache branch from 45f8a06 to 1073622 Compare April 16, 2026 01:14
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
…OADMAP AtomicBot-ai#77-AtomicBot-ai#87

4 parallele Subagents (Vulkan/AMD, CUDA/MoE, arXiv, Multi-GPU/Batching).
26 neue Ansätze identifiziert, davon 3 Tier 1 Quick Wins (AtomicBot-ai#77-AtomicBot-ai#79),
8 Tier 2 (AtomicBot-ai#80-AtomicBot-ai#87), 10 Tier 3, 5 Tier 4. Verifiziert: PR ggml-org#23056 und
ggml-org#16829 bereits im Fork. Top-Empfehlungen: K-Quant MMVQ Fix (AtomicBot-ai#77),
GEAR (AtomicBot-ai#80), PEARL (AtomicBot-ai#81), Fiddler (AtomicBot-ai#82), Vulkan Pipeline Cache (AtomicBot-ai#78).
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
…tomicBot-ai#82 ⏭️ (SPÄTER nach Tiefen-Eval)

AtomicBot-ai#77: Benchmark Mars (1B Q4_K_M): MMVQ vs non-MMVQ ±0.5% (Rauschen).
  tg1: MMVQ 3% schneller. Issue ggml-org#21151 auf Phoenix/RADV nicht reproduzierbar.

AtomicBot-ai#80 GEAR: SPÄTER — TurboQuant (3-5x) stärker als GEAR (2.29x).
  6-8 Wochen Portierung. Nur Mars (224k) profitiert.

AtomicBot-ai#82 Fiddler: SPÄTER — Lizenz unklar, AVX512_BF16 fehlt im Release.
  Mars (UMA) profitiert nicht. 4-6 Wochen Portierung.
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants