r/llamacpp • • 10h ago

14 drop-in ROCm/HIP patches for llama.cpp on AMD RDNA 2 (RX 6900 XT / gfx1030): Wave32 FlashAttention, v_dot8_u32_u4, Qwen3.5 fusions, and benchmarks vs. Mesa RADV

8 Upvotes

My main local GPU is a consumer 16 GiB Radeon RX 6900 XT (gfx1030, Navi 21). Until now I kept most AMD routes on Mesa RADV (Vulkan0) because stock upstream llama.cpp (ee46715 on ROCm 7.2) lost to RADV on 18 out of 18 single-token decode (tg128) tests by -6% to -14%.

When I audited libggml-hip.so and ran rocprofv3 traces, five big bottlenecks popped out:

  1. Upstream routed RDNA 2 MMVQ onto a single-warp fallback (nwarps = 1), capping Wave32 residency at 16/32 waves per CU.
  2. 3,470 of 7,632 compiled HSACO kernels (45.5%) were spilling to private scratch (273 in FlashAttention and 1,299 in MMQ/MMQ-few alone).
  3. Small-batch quantized-KV FlashAttention (B = 1..8) was converting KV tiles through FP16 staging buffers, thrashing Infinity Cache.
  4. nsm = 40 (WGPs) instead of 80 physical CUs left 40–80% of CUs idle around pp=64.
  5. Unfused Qwen3.5 hybrid Gated-DeltaNet / SSM_CONV ops and standalone quantize_q8_1 launches burned 31% of wall time in AQL dispatch gaps.

What's in the Patch Stack (14 atomic MIT patches, ggml/src/ggml-cuda/ only)

Everything is strictly gated to RDNA 2 (gfx1030, zero core/model/server edits, non-RDNA2 HIP/CUDA/Vulkan/CPU untouched):

  • Multi-warp Wave32 MMVQ & DPP: Decoupled MMVQ_PARAMETERS_RDNA2 (2–4 warps) + native Wave32 v_permlanex16_b32 / v_pk_max_f16.
  • Zero-scratch Wave32 flash_attn_ext_rdna2: Eliminated all 273/273 FA spills; stages raw Q8_0/Q4_0/Q4_1/F16 KV directly in LDS (0 B FP16 staging) and uses lossless v_dot8_u32_u4 for Q4_0/Q4_1 KV (-32.2% FA active time vs q8_0 at d=16384).
  • Zero-spill MMQ + bit-parallel IQ + 80-CU guard: Eliminated all 1,299 MMQ/MMQ-few spills, added v_xad_u32+v_perm_b32 IQ2/IQ3 sign unpackers (helpful for fitting 27B + 16K ctx inside 16 GiB), and kept J=32 when J=64 would under-fill 80 CUs.
  • Qwen3.5 GDN/SSM fusions + inline Q8_1 epilogues: Thin mmvf routing (pp=16..64 +10.1%..+34.7%), fused GDN gate/beta + SSM_CONV -> SiLU -> Q/K L2 norm, and inline Q8_1 quantization inside RMSNorm / GLU (-75.2% decode quantize_q8_1 dispatches, -34.6% AQL gaps, -309 to -752 MiB peak server VRAM).

Selected Benchmarks (RX 6900 XT, ROCm 7.2, llama-bench -r 3 -fa 1)

Format: Stock HIP -> Patched HIP (vs Stock HIP | vs Mesa RADV)

WorkloadKV9B UD-Q4_K_XL9B UD-IQ3_XXS27B UD-IQ3_XXS
tg=128 (d=0)q8_065.92 -> 70.25 (+6.6% | 0.962x)83.91 -> 94.11 (+12.2% | 0.982x)30.69 -> 32.81 (+6.9% | 0.982x)
tg=128 (d=16384)q4_062.99 -> 68.05 (+8.0% | 1.006x)80.51 -> 88.77 (+10.2% | 1.019x)29.16 -> 30.81 (+5.7% | 0.993x)
pp=4 (d=8192)q8_0192.10 -> 229.13 (+19.3% | 1.684x)220.06 -> 281.68 (+28.0% | 2.147x)78.75 -> 104.92 (+33.2% | 1.596x)
pp=8 (d=8192)q8_0283.26 -> 347.39 (+22.6% | 1.824x)310.91 -> 459.77 (+47.9% | 2.227x)105.65 -> 161.14 (+52.5% | 1.795x)
pp=8 (d=16384)q4_0270.75 -> 340.85 (+25.9% | 1.511x)305.74 -> 442.56 (+44.8% | 2.177x)101.62 -> 152.38 (+49.9% | 1.788x)
pp=512 (d=0)q8_01634.35 -> 1656.87 (+1.4% | 1.031x)1951.65 -> 2004.62 (+2.7% | 1.401x)585.44 -> 604.19 (+3.2% | 1.427x)

On single-request llama-server (draft-mtp, cache_prompt: false):

  • 27B UD-IQ3_XXS (n=3, short_temp07 70/256): 43.71 -> 56.92 tg tok/s (1.302x vs stock HIP, 1.276x vs RADV; wall 6.03s -> 4.67s, +29.0%).
  • 27B UD-IQ3_XXS (n=3, ctx4k_greedy 6,775/192): 44.25 -> 55.56 tg tok/s (1.256x vs stock HIP; wall 16.92s -> 15.62s vs RADV 21.57s, 1.38x faster than RADV).
  • 9B UD-IQ3_XXS (n=2, ctx4k_greedy 6,775/192): 105.70 -> 123.66 tg tok/s (1.170x vs stock HIP; wall 5.78s -> 5.36s vs RADV 7.17s).

Honest Caveats & What Didn't Work

  • Failed ablations kept out: Non-temporal MALL weight loads (-10% to -22% decode), Gate+Up fusion above B = 1 (-30% to -37% pp=8), and v_dot8 inside MMVQ/MMQ (-13% to -17.5% pp=16..32 because v_dot8 shares the same 1 op/cycle SIMD32 rate as v_dot4 on RDNA 2 and only wins when O(1) prologue packing amortizes over long KV tiles).
  • Greedy divergence (DIFF!): test-backend-ops (7/7) passed 100% and 6-chunk WikiText-2 KLD hit Mean KLD = 0.000000, but multi-warp reduction reordering still nudges borderline greedy tokens and can swing draft acceptance on individual single-shot runs (one 9B IQ3_XXS short greedy row dipped to 0.984x tg on a -10.6 pp acceptance swing).
  • Pure q8_0 decode vs RADV: Patched HIP ties or beats RADV on 9B q4_0 decode (1.000x–1.019x), while pure q8_0 tg128 still sits 1–4% behind RADV (0.953x–0.989x) — traded against HIP's 1.34x–2.28x verify and 1.03x–1.44x prefill lead.
  • Hardware tested: Physically validated on an RX 6900 XT (gfx1030). gfx1031 (6700 XT) / gfx1032 (6600 XT) share the same Wave32 / v_dot4 / v_dot8 ISA, so feedback from anyone testing on those cards would be awesome.
  • MIT Repo (14 patches, spill auditor, fail-closed A/B harness, AGENT_ADOPT_PROMPT.md): https://github.com/s1mply-parad0x1cal/llama-cpp-navi21-optimizations
  • Full write-up (ad-free, with ablations and comparison to llama-navi21-furnace / llama-cpp-rdna-boosts): https://nocthoughts.com/2026/12/04/navi21-gfx1030-rocm-hip-optimizations-for-llama-cpp.html

r/llamacpp • • 19h ago

Ternary Bonsai 2.5 27B on 8GB VRAM - Local AI With Vision (llama.cpp Windows Setup)

Thumbnail
youtu.be
6 Upvotes

Ternary Bonsai 2.5 27B is a new open model from PrismML: a full 27-billion-parameter model where every weight is just minus one, zero or plus one. That shrinks the file from 53.8 GB to about 6 GB, so it fits on an 8 GB gaming card, and it can read pictures too. On my RTX 5060 Laptop GPU (8 GB) it answered at about 26 tokens a second.

Model (GGUF files, PrismML): https://huggingface.co/prism-ml/Ternary-Bonsai-2.5-27B-GGUF/tree/main


r/llamacpp • • 3h ago

0.02690, 93.33% (UD-Q6_K_XL); 0.06587, 89.72% (UD-IQ4_XS), against our own BF16 base (Qwen4-35B-A3B)

2 Upvotes

I measured yesterday 12/04 and today 12/05

BF16 base built with llama-perplexity --kl-divergence-base from Unsloth's BF16 GGUF (wikitext-2, 100 chunks of 512, base PPL 7.5364, sha256 ca42cdb0a114c9192e6f854279725ed74be09ea43d91fbdcf082574b2d70f641)

I haven’t measured UD-Q8_K_XL. I saw earlier someone had worse results with Q8 XL vs Q8_0

Any experience from Q8_K_XL vs Q8_0 before I start this next run?

Reference: unsloth docs

Everything is in the repo as well - Halocline


r/llamacpp • • 15h ago

Qwen 4 35B-A3B - Dual RTX 3060 (24GB) - 70 t/s at 200K+ Context (Procedure & Parameters)

Post image
2 Upvotes

I hope my setup note will help others configure their Qwen 4 35B-A3B on older consumer grade systems (Ryzen 5 + DDR4 + RTX3060).


r/llamacpp • • 3h ago

Running Qwen4-35B-A3B on an AMD Strix Halo with llama.cpp

Thumbnail
reddit.com
1 Upvotes

r/llamacpp • • 11h ago

Qwen4-35B-A3B on a 12GB/30GB laptop: 128K ctx @ ~51 tok/s decode, 256K works, 512K with q4 KV, 1M OOMs

Thumbnail gallery
1 Upvotes

r/llamacpp • • 11h ago

Qwen4 35B A3B (37 GB) on a 16 GB laptop GPU: 27.8 → 77.5 tok/s with an expert cache and MTP drafts off

Thumbnail
reddit.com
1 Upvotes

r/llamacpp • • 11h ago

Qwen4-35B-A3B on an 8 GB laptop 5070: the 12 GB expert-cache recipe backfires, plain defaults win (48 tok/s)

1 Upvotes

Saw the post getting about 90 tok/s on a 12 GB 5070 with -cmoe --moe-cache-mib 7168 and MTP, so I tried the same idea on my laptop. Short version: on 8 GB it doesn't carry over. Plain llama.cpp with no placement flags was the fastest thing I tried.

Setup

Lenovo laptop, Core Ultra 9 275HX, RTX 5070 Laptop 8 GB, 32 GB RAM, Windows 11
llama.cpp b12973 (CUDA), Unsloth UD-IQ4_XS and UD-Q4_K_M, plus Unsloth's Q8_0 MTP file for the draft runs
-c 40960 -fa on -ctk q8_0 -ctv q8_0 on everything, plus whatever's listed in the table
Each setup gets a fresh server, then 3 runs of a 1,500-token coding answer (temp 1.0, top-p 0.95, top-k 20, thinking on). Median shown. Prompt speed is one 12.7K-token prompt.

Results (tg = generation tok/s, pp = prompt tok/s)

Setup IQ4_XS tg IQ4_XS pp Q4_K_M tg Q4_K_M pp
No placement flags 47.8 384 42.2 309
No placement flags + MTP draft 2 46.2 344 44.0 303
-cmoe, 2 GB cache 35.4 387 28.5 308
-cmoe, 4 GB cache 47.3 347 7.9 41
-cmoe, 5 GB cache 7.7 45 7.1 40
-cmoe, 3 GB cache + MTP draft 1 29.7 210 19.9 181
-cmoe, 4 GB cache + MTP draft 1 14.6 210 6.3 37
-cmoe, 4 GB cache + MTP draft 2 10.3 241 5.5 38

What I take from it

There's a cliff at about 7.8 GB used on the card. Anything that goes past it drops to 5 to 8 tok/s, and prompt speed falls off too. IQ4_XS with a 4 GB cache sat just under the line (47 tok/s), Q4_K_M with the same cache went just over (8 tok/s). My guess is the Windows driver spilling into shared system memory instead of throwing an out-of-memory error. I haven't tried turning sysmem fallback off in the NVIDIA control panel yet, so treat that as a guess.
The cache only pays off when it's big enough to hold the hot experts, and on 8 GB there isn't room for that once the KV cache and the rest of the model are loaded. 2 GB was clearly slower than just leaving it alone.

MTP did nothing for me with no placement flags. Draft 2 accepted about half the drafted tokens, draft 1 about 70 to 90%, and the speed didn't move. Add MTP to the cache setups and it gets much worse, I think because the 2 GB draft model pushes the card over the edge. Earlier the same day I got 54 tok/s with MTP draft 2 on a different prompt and couldn't reproduce it here, so I wouldn't count on MTP on this card either way.
Q4_K_M is about 12% slower than IQ4_XS on generation. I'm running it anyway because on a set of harder coding tasks it held up better over long agent loops (4/5 vs 1/5). That's one run each though, so I'm redoing that properly, with 8-bit and full precision for comparison, before I post anything about quality.

If you're on 8 GB: load it with no placement flags and let llama.cpp sort it out. 48 tok/s from a 35B MoE on a laptop is pretty good for a coding model.

Caveats: one machine, 3 runs per setup, one kind of prompt. Happy to try other flag combos if anyone's got one that works on 8 GB cards.


r/llamacpp • • 21h ago

Hey r/StrixHalo — Qwen4-35B-A3B PaoAI STRIX (Q4..Q8 + shared PLE + vision) + Engine 2.1.0 is live with 1M context unlocked

Post image
1 Upvotes

r/llamacpp • • 18h ago

Built my own (pretty strict) benchmark for local models and ran everything I had on a 3090. Qwen3.8 Flash Next IQ3_S kinda smoked everything

Thumbnail reddit.com
0 Upvotes