Repository navigation
Open
Description
Issue: Using KV-quantization kvarn6 results in extremely slow performance compared to q8_0 on AMD ROCm hardware.
Performance Comparison
Both tests used the same prompt (10,410 tokens) and identical settings except for KV quantization.
Note: The kvarn6 run was canceled early due to excessive runtime.
| Metric | q8_0 | kvarn6 | Regression |
|---|---|---|---|
| Prompt Processing | 821.19 tokens/sec | 53.79 tokens/sec | ~15.3x slower |
| Text Generation | 29.52 tokens/sec | 1.34 tokens/sec | ~22x slower |
This is a severe performance regression that makes kvarn6 practically unusable.
Steps to Reproduce
- Use llama.cpp build
11192 (ee8754c57)with ROCm backend on Windows - Load a large model (tested with Qwen3.6-27B-Fable-Fusion-Q4_K_M)
- Run with full offload (
-ngl 99) and flash attention (-fa 1) - Compare these two configurations:
q8_0 (baseline):
llama-server.exe -m <model> -ngl 99 -fa 1 -ctk q8_0 -ctv q8_0 -c 40000kvarn6 (regression):
llama-server.exe -m <model> -ngl 99 -fa 1 -ctk kvarn6 -ctv kvarn6 -c 40000System Information
- GPU: AMD Radeon RX 7900 XTX (24 GB VRAM)
- CPU: AMD Ryzen 9 7900X 12-Core
- RAM: 64 GB
- OS: Windows
- Backend: ROCm (HIP), NO_VMM = 1
- Build: 11192 (ee8754c) with Clang 20.1.8 for Windows x86_64
- Model: Qwen3.6-27B-Fable-Fusion (Q4_K_M, 65 layers, 27.32B params, 17.22 GiB)
Relevant Log Excerpts
q8_0 performance:
prompt processing, n_tokens = 10410, progress = 1.00, t = 11.93 s / 872.56 tokens per second
prompt eval time = 12681.67 ms / 10414 tokens (1.22 ms per token, 821.19 tokens per second)
eval time = 73468.79 ms / 2169 tokens (33.87 ms per token, 29.52 tokens per second)
kvarn6 performance (run canceled after ~5.5 minutes):
prompt processing, n_tokens = 10410, progress = 1.00, t = 193.54 s / 53.79 tokens per second
n_decoded = 144, tg = 1.34 t/s
Expected Behavior
kvarn6 should provide competitive or better performance than q8_0 while using less VRAM, or at least not be an order of magnitude slower.
Actual Behavior
kvarn6 is 15-22x slower than q8_0 on ROCm hardware, making it impractical for use.
Additional Notes
- This appears to be ROCm-specific; the kvarn6 implementation may not be optimized for AMD GPUs
- The issue affects both prompt processing and token generation equally severely
- The kvarn6 run was manually canceled due to excessive runtime; actual degradation may be even more severe over longer generations
- Full log level 5 logs for both q8_0 and kvarn6 runs are attached to this issue
Metadata
Metadata
Assignees
Labels
No labels
Activity
raufaser commentedon Aug 28, 2026
The problem still exists. kvarn is unusable with ROCm.
Anbeeld commentedon Aug 28, 2026
Sorry, I do keep this in mind. It's just the past week or so was very saturated, and also I was trying to fix tensor split instability on CUDA but unfortunately just wasted a lot of time... for now
raufaser commentedon Aug 29, 2026
Chances are high that we encounter two different problems which cause similar outcomes. Your decoding speed was 3x slower, mine was 22x slower.
raufaser commentedon Sep 2, 2026
I did some investigation assisted by AI and I want to share my findings with you. Perhaps you already know all of that and since I do not really no what that all means, the findings can be completely bogus.
Testing this on RX 7900 XTX (gfx1100, Windows x64 HIP release build) — found the cause of the slowdown, plus a separate crash worth tracking.
1. The 15-22x slowdown is the expected
portable-nativefallback, not a broken kernelThe model here is head-dim 256 (
n_embd=5120, n_head=24, n_head_kv=4, gqa=6).GGML_KVARN_DEBUG_ROUTES=1shows every layer on the fallback:Why: on HIP the specialized decode routes (split/vector) are disabled in
fattn-kvarn-route-policy.h, and the WMMA eligibility check rejectshead_dim > 128(only CDNA MFMA allows 256). So all D=256 KVarN layers on RDNA3 run the 128-thread sequential portable kernel — correct but ~15x (pp) / ~22x (tg) slower than q8_0 at long context. ROCm docs confirm the HW can do f16 WMMA on gfx1100, so this is a tile-coverage gap, not hardware. Fix direction: extend WMMA to D=256, or port the CUDA split/vector decode to HIP.2. Separate bug:
prompt-generic-mmahangs the driver on D=128, nq ≥ ~256With a D=128 model (Qwen3-4B-Thinking-2507,
n_embd=2560, n_head=32, n_kv=8, gqa=4), KVarN correctly takes the fast route, but crashes at-p 256:-p 128 -n 32-p 256 -n 64-p 256 -n 1Crash route line:
route=prompt-generic-mma ... nq=256 nkv=256. Identical commands with-ctk q8_0 -ctv q8_0are stable (pp512: 4732 t/s), so the fault is in the KVarN prompt MMA kernel, unrelated to #122's portable fallback. Threshold is between pp128 (ok) and pp256 (crash).Suggest splitting this issue: D=256 RDNA portable fallback (the perf report above) stays here as a roadmap item; the D=128 prompt-generic-mma crash should be a separate bug. Happy to bisect further (nq=192/224, kvarn4/5/6,
GGML_KVARN_TEST_FORCE_PORTABLE_FATTN=1) if useful.johny-mnemonic commentedon Sep 4, 2026
I can confirm it's not just about ROCm. I am running Vulkan build on RDNA2 (RX6800) and here are my results:
beellama-v0.4.5 q8/q5.1
beellama-v0.4.5 kvarn5/kvarn4
Edit: I have interesting update.
I wanted to give up on kvarn for now and just use q8/q5.1 like normally, but with the added
--kv-tail-tokens 1024. It tanked the performance to the same level as using kvarn cache. So seems like once I try to use these new kv cache changes it goes different code path and tanks the performance completely. Most probably it is using something specific for NV GPUs and hence doesn't work well with AMD.raufaser commentedon Sep 7, 2026
Status update (RX 7900 XTX, gfx1100):
1. The 15–22x gap — root cause confirmed, fix exists
As in my Sep 2 analysis, every D256 KVarN layer fell back to
portable-native(fallback=generic_shape_rejected), because RDNA WMMA rejectedhead_dim > 128.While enabling that path I found a real race on top:
flash_attn_ext_f16_process_tile(ggml/src/ggml-cuda/fattn-mma-f16.cuh) is missing a__syncthreads()betweenk00combine iterations whenevernp == 1with multiple iterations. Fast warps overwrite sharedtile_Qwhile lagging warps still read it — so the newly enabled D256 path produced garbage, not just slow output.The complete fix is 3 files:
fattn-mma-f16.cuhnp==1multi-iteration configsfattn-kvarn-route-policy.h+ device invariant>128→>256eligibilitytest-cuda-fattn-route-policy.cppPost-fix, short context (Qwen3.6-27B):
The 15–22x is gone here — but I have not retested your exact setup (llama-server,
-c 40000, 10k prompt). Please re-verify there before closing.2. New finding: watch quality before shipping this on ROCm
KLD vs f16/bf16, Wikitext-2, same files/settings throughout:
But: forced-portable (
GGML_KVARN_TEST_FORCE_PORTABLE_FATTN=1) gives KLD 0.004 on identical records, and 100+ isolated sweep configs (all bit pairs, tails, eager, 24/4 heads, n_kv up to 16k) all pass at RMSE ≤1e-3 with no bias.So compression and kernel math are per-call exact — yet the WMMA prompt path carries ~4e-4/call noise (vs ~1e-5 portable) that accumulates over layers and context. Cross-check on RTX 4090 + same weights shows KLD 0.002, but note its prompt bypasses KVarN dispatch entirely, so that number flatters the kernels.
Bottom line: the fast path fixes the speed but is currently lossy on ROCm. It needs WMMA prompt-tile accuracy work before becoming the default.
3. Other reports in this thread
@gashap0n's Vulkan 3x and @johny-mnemonic's "
--kv-tail-tokens 1024tanks even q8_0 to kvarn levels" both point at AMD fallback/tail paths rather than KVarN math — same family as this issue. The D128prompt-generic-mmadriver hang from my Sep 2 comment is still a separate bug worth splitting out, IMO.Happy to post the patch,
GGML_KVARN_DEBUG_ROUTES=1logs, and full KLD tables if useful.raufaser commentedon Sep 7, 2026
Status update (2026-09-07, RX 7900 XTX,
v0.4.5base)Re-measured with Qwen3.6-27B-Q5_K_S,
-fa 1 -ngl 99 -p 4096 -n 1028(
llama-bench):Decode is fixed
The 22x tg collapse from the original report is gone.
30 vs 33 t/s is ordinary weight-bound parity.
That half was a D256
k00-combine race in the WMMA flash-attention kernel: shared staging memory is reused across loop iterations without a barrier when running single-warp-column configs (2 iterations at D256 with a 64-column tile), so fast warps overwrote data lagging warps still read. Fixed with the missing barrier, plus enabling the RDNA D256 route that was previously rejected before kernel launch.Prefill turned out to be a second, separate bug (quality, not speed)
Measured GPU-native vs CPU-materialized attention error directly (D256, 6-bit K/V, production head/group layout, 256-query prompt tiles): the RDNA3 WMMA value-accumulator is fp16, giving ~3e-4 error per call vs ~1e-5 for an fp32 reference path, independent of sequence length.
It compounds through 64 layers: KLD 0.186 at 512 tokens, PPL 44.9 vs 6.3 at 32k context. (CUDA never showed this — its prompt path doesn't use the WMMA kernel.)
Fix being validated
route the HIP prompt-prefill through the exact fp32 direct-record path (same compressed records, exact math); decode stays on WMMA.
Perplexity confirmation (wikitext-2,
-c 4096):Q5_K_S f16 PPL 6.6375 vs kvarn6 6.6298; second weight file (UD-Q4_K_XL)
f16 6.6522, q8_0 6.6527, kvarn6 6.6269.
Quality at parity everywhere.
What remains:
prefill speed. The exact path has no tensor-core throughput, so prefill runs ~7.5x slower than q8_0 here (107 vs 804 t/s; decode unaffected).
The issue is now purely "prefill too slow", no longer "wrong + slow". Options from here: an fp32 WMMA accumulator (full recovery, needs RDNA3 fragment-layout work) or a reworked kernel that shares K tiles across queries.
raufaser commentedon Sep 7, 2026
@gashap0n
I'm not proposing this for merge (prefill is still ~7x slower than q8_0, see my status update above; this is a correctness fix with a known perf cost, not shippable as-is).
But you're welcome to test the branch directly:
That's 4 commits on top of v0.4.5 (
593e6d590).What I'd like to know from your setup:
decode t/s (expect ~parity with q8_0)
and
perplexity or KLD vs f16 (expect parity), plus your GPU/VRAM.
Thanks for testing!
raufaser commentedon Sep 7, 2026
Prefill update (same setup, branch
kvarn-rocm-prompt-precision)The exact portable prompt path got 2.7x faster with no accuracy change:
What changed (all in the portable direct-record kernel):
Perplexity still at parity (Q5_K_S f16 6.6375 vs kvarn6 6.6298).
Remaining gap to q8_0 (~2.8x) is raw per-element dequant work, that needs either a tensor-core (fp32 WMMA accumulator) path or a kernel tiling project.
Reporting for the record.
Merge pull request #149 from raufaser/kvarn-rocm-prompt-precision
Anbeeld commentedon Sep 12, 2026
Dear AMD users, branch v0.4.7 now has a lot of ROCm performance work merged in, kindly provided by @raufaser
Please test it!
skewty commentedon Oct 26, 2026
Just tried with a R9700 AI Pro (gfx1201) and results are awful.
Version 0.4.8 gives:
@Anbeeld so basically not usable on AMD as it is.
@raufaser can you please update subject to something like: "kvarn quantizations cause catastrophic performance regressions on AMD ROCm devices"
raufaser commentedon Nov 4, 2026
I made some improvements. Should be more or less on par now. #197