llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Vulkan: MoE decode on RDNA4 is GPU-busy but uses only ~25% of memory bandwidth

Open lucad87 opened this issue 6 days ago • 2 comments

Vulkan: MoE decode on RDNA4 is GPU-busy but uses only ~25% of memory bandwidth

Summary. With a Mixture-of-Experts model fully resident in VRAM, Vulkan decode reaches ~50–67 tok/s where the bandwidth roofline for this model and quantization is ~260–280 tok/s. The GPU engine is busy ~92% of the time during generation, so this is not idle time between submissions. The pattern points at GGML_OP_MUL_MAT_ID being executed as one small dispatch per (token, expert, matrix) — roughly 576 kernels of ~1.4 MB each per token here — which are latency/occupancy bound rather than bandwidth bound.

Environment

OS Windows 11 Pro, build 26300 (26H2)
GPU AMD Radeon RX 9070 XT (RDNA4, gfx1201), 16 GB
Driver 32.0.31041.1004 (Adrenalin, no ROCm/HIP SDK installed)
llama.cpp llama-b12651-bin-win-vulkan-x64.zip, build 12651, commit f5e6915c2
Vulkan device rebar: 1, fp16: 1, bf16: 1, fp4: 0, warp size: 64, shared memory: 32768, int dot: 1, matrix cores: KHR_coopmat

Model and command

AtomicChat/Inkling-2-Mini-GGUF → Inkling-2-Mini-AD-IQ3_S.gguf (12.42 GiB, arch inkling2_loop, 26B MoE with 3.4B active params, ~5.4B effective active per token because layers 6–17 are looped three times).

llama-server.exe ^
  -m Inkling-2-Mini-AD-IQ3_S.gguf --mmproj mmproj-Inkling-2-Mini-Uncensored-F16.gguf ^
  -ngl 99 --n-cpu-moe 0 -fa on -ctk q8_0 -ctv q8_0 -c 32768 --jinja -np 1 ^
  --temp 1.0 --top-p 1.0 --top-k 0 --min-p 0.0

All layers, including every expert, are offloaded to the GPU (--n-cpu-moe 0), so the DDR4 path is not involved.

Measurements

test result
decode, 400 generated tokens 66.7 tok/s
decode, 420 generated tokens (32K ctx) 49.8 tok/s
prompt processing, 8192-token prompt (Q4_K_M, 6 layers on CPU) 867 tok/s
VRAM at 64K ctx, KV Q8_0 15.1 GiB of 15.9
GPU engine utilization during decode 92.4% avg, 92.6% peak

Roofline: 5.4B effective active parameters × ~3.4 bits ≈ 2.3 GB read per token; at ~640 GB/s that is ~260–280 tok/s. We get ~25% of it.

Utilization was sampled with Get-Counter '\GPU Engine(*)\Utilization Percentage' filtered to engtype_Compute|3D, every 250 ms during generation. High utilization with low achieved bandwidth is the signature of kernels too small to saturate memory rather than of gaps between submissions.

Why I think it is MUL_MAT_ID granularity

For each token and layer, 8 of 128 experts are routed and three matvecs run per expert (ffn_gate_up and ffn_down). Across 24 layers that is ~576 small matvecs per token, each reading on the order of 1.4 MB. A 1.4 MB read at 640 GB/s is ~2 µs, so each dispatch is dominated by ramp-up and partial CU occupancy rather than by memory throughput.

Corroboration: a third-party engine on the same GPU and the same model family reports ~220 tok/s decode and ~1569 tok/s prefill (5831 tokens) and states that it reduced launches per step from 2222 to 585 by fusing work into megakernels. That is a ~4.4x gap on identical hardware, so the ceiling is not the GPU.

One possibly related detail: this device reports KHR_coopmat but not coopmat2, and ggml_vk_mul_mat_vec_max_cols() takes the coopmat2 branch:

return device->coopmat2 && !device->disable_narrow_mul_mat ? 4u : mul_mat_vec_max_cols;

so RDNA4 currently uses the generic narrow matmul path.

Suggestion

The highest-value change for batch-1 MoE decode seems to be fusing the experts of one layer into a single dispatch, keeping the (shared) activation vector in LDS and looping over the active experts inside the kernel, with the weighted-sum epilogue currently in add_id.comp folded in. A grouped-GEMM path (sort tokens per expert, one dense GEMM per expert) would help prompt processing for the same reason, and mul_mmq.comp already carries a mul_mat_id variant with BK_STEP = 1 where the non-MoE path uses 4.

Questions

  1. Is this a known limitation of the Vulkan MoE path on RDNA4, or worth a targeted optimization?
  2. Would a fused multi-expert matvec, or a grouped-GEMM variant that keeps BK_STEP at 4, be an acceptable direction upstream?
  3. Is there any flag/profile hook you would recommend to confirm the per-dispatch attribution before writing code? I can provide RGP captures if that helps.

Happy to build, test, and post measurements for any experiment you want tried on this card.

lucad87 avatar Nov 28 '26 22:11 lucad87

Adding two data points that may help, from a third-party report on the same GPU (r/llamacpp, "Inkling 2 Mini at 256k context on a single 16 GB RX 9070 XT"):

1. A patched fork closes most of the gap, and the gap is kernel work. The author runs a fork with 26 patches (24 of them private: custom HIP kernels, scheduler and launcher changes, plus PRs #32215 and #30685) and reports, on the same RX 9070 XT 16 GB:

config their patched build stock b12651 Vulkan (this machine)
IQ3_XXS, 64k, all in VRAM, decode ~90 tok/s 63.5 tok/s
same, prefill (~5.8k prompt) 1,689 tok/s 920 tok/s
IQ4_XS, 128k, code edit 171 tok/s —
IQ4_XS, 128k, 54k prompt 1,459 tok/s —
upstream master, 256k chat 19.4 tok/s (21.9 tok/s here, ub 512)

So roughly 70% of decode and 54% of prefill on stock Vulkan, with the difference attributed to the missing MoE/attention kernels — consistent with the 92% GPU-busy / 25% bandwidth observation above.

2. DSpark alone does not explain their numbers. Their own comparison shows upstream + PR #32218 at 88.8 tok/s (128k code edit) versus 89.6 for upstream without it. I measured the same: draft acceptance 15–21% and decode 30–37% slower with the drafter, both with the base model and with the matching uncensored model/drafter pair.

Question about ubatch and the attention buffer. The same report notes that upstream must drop ubatch to 64 (128k) / 32 (256k) because "Inkling attention wants a 12.9 GB buffer at ub 512". I can confirm the symptom from this side, though I first misattributed it to the KV cache:

  • -ub 512, 256k, KV q8_0: loads, 21.9 tok/s
  • -ub 32, 256k, KV q4_0: 49.3 tok/s
  • -ub 32, 1M, KV q4_0, --n-cpu-moe 3: loads at 15.19 GiB and runs 40.4 tok/s (before this, 1M failed in create_context)

Is the attention buffer growing with ubatch an expected property of this architecture's current implementation, or a sizing choice that could be decoupled from ubatch? If it is the latter, that alone would make long contexts practical on 16 GB cards without any kernel work.

I can run any build you want measured on this card (Windows 11, Adrenalin, Vulkan b12651, RX 9070 XT) and report numbers.

lucad87 avatar Nov 29 '26 12:11 lucad87

Another data point on the same card and OS build (RX 9070 XT, Windows 11 26300, Adrenalin 26.11.2), official b12843 Vulkan, Qwen3-Coder-30B-A3B UD-Q3_K_XL (48 layers, 128 experts, 8 active, fully in VRAM), -fa 1 -ctk q8_0 -ctv q8_0:

  • Decode 200–201 tok/s (llama-bench tg128, ±0.2% across 8 fresh processes), 194 tok/s from llama-server. That implies roughly 1.5–1.6 GB read per token, about half of the 640 GB/s spec.
  • GGML_VK_PERF_LOGGER per-token shares: MUL_MAT_ID 41.6%, dense MUL_MAT 35.5%, RMS_NORM 9.7%, routing 3.2%, FA 5.8%. Dispatches per token (sum of counts): 821. The LM head (q6_K 151936×2048) reaches ~96% of spec bandwidth (616 GB/s); the expert matvecs reach 283–476 GB/s, and the down-projection (k=768) is the slowest per byte (Q3_K down at 283 GB/s, ~44% of spec).
  • So the gap here is about half, not three-quarters as in the original report. That fits the same explanation: small per-layer expert dispatches, plus ~17% of the token in norms, routing and other small kernels (RMS_NORM 9.7%, routing 3.2%, rest ~4%).
  • GGML_VK_DISABLE_FUSION=1 changes decode by −17.6% (200.9 → 165.6 tok/s, tg128, ±1.6 both arms; dispatches per token rise 821 → 1,829 with fusion off). Happy to run builds or capture traces on request.

coryord15-ship-it avatar Nov 29 '26 23:11 coryord15-ship-it