Skip to content

fix: CUDA warp-to-block mapping for block_size=128 - #32

Merged
TheTom merged 1 commit into
TheTom:feature/turboquant-kv-cachefrom
HyperionMS2040:fix/cuda-block-size-128
Mar 30, 2026
Merged

TheTom merged 1 commit into
TheTom:feature/turboquant-kv-cachefrom
HyperionMS2040:fix/cuda-block-size-128

Conversation

@HyperionMS2040

Copy link
Copy Markdown

Summary

The block_size=128 change (adac2c6) broke CUDA quantization in set-rows.cu. With QK_TURBO3=128, blocks_per_group = 1, but the warp-cooperative packing still computed blk = blk_base + warp_id — warps 1-3 wrote qs, signs, and norm out of bounds, corrupting adjacent KV cache memory.

Short llama-bench runs (pp512, tg128) could appear to pass because the OOB writes don't immediately affect the active attention window. llama-perplexity over full WikiText-2 produces all-NaN or segfaults.

Fix

Compute element position within the block generically:

const int elem_in_block = j % QK_TURBO3;
block_turbo3_0 * blk = blk_base + (j / QK_TURBO3);
  • elem_in_block / 4 for qs byte offset (range 0..31 for QK=128, 0..7 for QK=32)
  • elem_in_block / 8 for signs byte offset (range 0..15 for QK=128, 0..3 for QK=32)
  • elem_in_block == 0 for norm write gate (one per block)

Backward compatible — produces identical results with QK=32. Same fix applied to k_set_rows_turbo2.

Validation

RTX 3090 (sm_86), llama3.1:8b Q4_K_M, q8_0/turbo3, WikiText-2, 512 context:

Condition Block size PPL
spiritbuun build (pre-change baseline) 32 7.587
This branch, block_size reverted to 32 32 7.587
This branch, block_size=128 with fix 128 7.587

Zero deviation across all three conditions. The 5.12x compression ratio is now validated on CUDA Ampere.

Context

@seanrasch independently reported the same crash on SM 86 in Discussion ggml-org#20969.

The block_size=128 change (adac2c6) broke CUDA quantization:
with QK=128, blocks_per_group=1, but the warp-cooperative packing
still used blk_base+warp_id, causing warps 1-3 to write OOB.

Fix: compute elem_in_block = j % QK_TURBO_N and use it for block
pointer (j / QK_TURBO_N) and byte offsets (elem_in_block / 4 for qs,
elem_in_block / 8 for signs). Works for both QK=32 and QK=128.

Validated on RTX 3090 (sm_86), llama3.1:8b Q4_K_M, q8_0/turbo3:
PPL = 7.587 (matches QK=32 baseline exactly).
@TheTom

TheTom commented Mar 30, 2026

Copy link
Copy Markdown
Owner

Looking now

@TheTom
TheTom merged commit 7b75078 into TheTom:feature/turboquant-kv-cache Mar 30, 2026
1 check passed
@TheTom

TheTom commented Mar 30, 2026

Copy link
Copy Markdown
Owner

Thank you for the contribution! Apologies for the regression

mihai-chiorean pushed a commit to mihai-chiorean/turbo3-cuda that referenced this pull request Mar 31, 2026
…n data

Part of TheTom#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
terrysimons pushed a commit to terrysimons/llama-cpp-turboquant that referenced this pull request Mar 31, 2026
…n data

Part of TheTom#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
TheTom added a commit that referenced this pull request Apr 2, 2026
…n data

Part of #32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
TheTom added a commit that referenced this pull request Apr 2, 2026
…n data

Part of #32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
iamwavecut pushed a commit to iamwavecut/llama-cpp-turboquant that referenced this pull request Apr 8, 2026
…n data

Part of TheTom#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
KGardevoir pushed a commit to KGardevoir/llama-cpp-turboquant that referenced this pull request Apr 14, 2026
…n data

Part of TheTom#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
TheTom added a commit that referenced this pull request Apr 15, 2026
…n data

Part of #32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
LogicDaemon pushed a commit to LogicDaemon/llama-cpp-turboquant that referenced this pull request May 27, 2026
…n data

Part of TheTom#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
wel97459 pushed a commit to wel97459/llama-cpp-turboquant that referenced this pull request Jun 4, 2026
…n data

Part of TheTom#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
KGardevoir pushed a commit to KGardevoir/llama-cpp-turboquant that referenced this pull request Jun 16, 2026
…n data

Part of TheTom#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 5, 2026
…n data

Part of AtomicBot-ai#32: turbo3 prefill degrades relative to q8_0 with context length.

Changes so far:
- Skip ggml_cont when tensors already contiguous (+1%, minimal)
- Generated 32x32 rotation matrices (turbo-rotation-data-32.h) for
  reduced group size approach (16x less matmul compute)
- Fixed V un-rotation to check v->type not k->type

Next: update QK_TURBO3_GROUP, Metal WHT kernel, and KV cache for d=32.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: [email protected]
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 12, 2026
…026-07-12)

4 parallele Subagents (Vulkan/AMD, CUDA/MoE, arXiv, Multi-GPU/Batching)
konsolidiert zu 25 neuen Items in ROADMAP:

Tier 1 Quick Wins (3 neu):
- AtomicBot-ai#31 K-Quant A-Matrix Transpose CM1 (PR ggml-org#22970, +5-15% PP auf Mars)
- AtomicBot-ai#32 Pascal L1 Cache Tuning (-Xptxas -dlcm=ca, Styx)
- AtomicBot-ai#33 Per-Quant MMVQ/MMQ Batch Threshold (AMD MFMA, Mars/Venus)

Tier 2 (7 neu):
- AtomicBot-ai#34 UBBoost, AtomicBot-ai#35 Row-Packing DMMV, AtomicBot-ai#36 Auto Param Fitting TP
- AtomicBot-ai#37 LFRU Expert Caching, AtomicBot-ai#38 Conf-KV, AtomicBot-ai#39 Talon, AtomicBot-ai#40 MoE Load Balancing

Tier 3 (5 neu):
- AtomicBot-ai#41 GRKV, AtomicBot-ai#42 CapKV, AtomicBot-ai#43 SliderQuant, AtomicBot-ai#44 Alloc-MoE, AtomicBot-ai#45 CUDA Streams QKV

Tier 4 (10 neu):
- AtomicBot-ai#46-55: SpecMD, QUICK, FluxMoE, STAR-KV, VQKV, CompilerKV,
  SliceMoE, MoBiE, DASH-Q, GOOSE

7 PRs als bereits im Fork identifiziert (nicht erneut vorschlagen):
ggml-org#21472, ggml-org#23764, ggml-org#22299, ggml-org#21611, ggml-org#22423, ggml-org#18749, Warp Shuffle, Constant Memory
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 12, 2026
AtomicBot-ai#31 K-Quant Transpose CM1 (PR ggml-org#22970): ❌ CM1-only, Mars nutzt CM2
AtomicBot-ai#32 Pascal L1 Cache Tuning: ❌ kein Speedup (pp128 -0.5%, tg64 -0.04%)
  - GGML_CUDA_L1_CACHE=ON Option hinzugefügt (verfügbar aber wirkungslos)
  - GTX 1070 hat nur 48KB L1/Shared per SM, Streaming evictet sofort
AtomicBot-ai#33 Per-Quant MMVQ/MMQ Threshold: ⏭️ verschoben
  - Fork hat bereits ggml_vk_should_use_mmvq() mit vendor+quant Logik
  - +76% waren auf MI250X, nicht Phoenix RDNA3
fukuro-kun referenced this pull request in fukuro-kun/fukuro-llama-cpp-turboquant Jul 12, 2026
…chätzungen

Kalibrierung aus 14h Solo-Session (2026-07-11/12):
- AtomicBot-ai#3 Pascal MMVQ: geschätzt '2-3 Tage', tatsächlich ~3-4h mit PR-Vorlage
- AtomicBot-ai#32 L1 Cache: geschätzt '1-2h', tatsächlich ~1h (trivialer Flag)
- Bulk der Zeit ging in Evaluation, Doku, Build/Benchmark-Zyklen

Realität vs. Subagent-Schätzungen:
- Remote-Build: 5-15 min/Zyklus
- Benchmark: 5-10 min/Run + Server-Management
- Doku + Commit: 15-30 min/Item
- Subagent-Latenz: 2-5 min/Round-Trip

Neue Tier-Definitionen:
- Tier 1: < 2 Tage Solo-Agent (war < 1 Woche)
- Tier 2: 2-6 Wochen (war 1-3 Wochen)
- Tier 3: 6-12 Wochen (war 3-6 Wochen)
- Tier 4: 3+ Monate (war 6+ Wochen)

Alle 55 Items mit kalibrierten Schätzungen aktualisiert.
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.

2 participants