Repository navigation
hip: faster Q1_0, Q2_0 and PQ2_0 decode on AMD - #125
Conversation
Use the hardware byte permute (v_perm_b32) for the Q1_0 sign unpack and the Q2_0/PQ2_0 symbol expansion on HIP, where __byte_perm is a software routine, and keep the default split-K MMVQ geometry for these types on CDNA, where the small_k geometry runs several times slower per call. Bit-exact: test-backend-ops MUL_MAT and MUL_MAT_ID pass unchanged and greedy generations match the CPU backend. MI300X decode: 4B Q1_0 112 -> 322 tok/s, 8B Q1_0 81 -> 269, 27B Q1_0 31.5 -> 97, 8B PQ2_0 113 -> 259, 27B PQ2_0 48.6 -> 91.7. CUDA and MUSA are unchanged (HIP device-compile guards); other quant types are unchanged (type-scoped rule).
There was a problem hiding this comment.
Good catch, seem the __byte_perm optimization made things slower for AMD lol
We probably need to test on few AMD GPUs for more evidence, and try to upstream.
That might be why more people complain AMD gpu is slow, the __byte_perm was merged in mainline too.
Did we run KL test too for accuracy? Should not change I guess much.
There was a problem hiding this comment.
Pull request overview
Optimizes HIP decode kernels for low-bit quantization while leaving CUDA and MUSA paths unchanged.
Changes:
- Uses AMD hardware byte permutation for Q1_0, Q2_0, and PQ2_0 decoding.
- Disables slower small-K MMVQ geometry for these types on CDNA.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ggml/src/ggml-cuda/vecdotq.cuh |
Adds HIP-specific quantized symbol unpacking. |
ggml/src/ggml-cuda/mmvq.cu |
Adjusts CDNA MMVQ geometry selection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
KL run done on a fresh MI300X (ROCm 6.4.1), this branch vs Method: the base build saves logits with
The patched rows match the self-score control, so the two builds produce the same logits to the limit the tool can express. Second check: scoring both builds against CPU-backend logits (40 chunks) gives identical statistics to every printed digit for 8B Q1_0, 8B PQ2_0 and 27B Q1_0 (the 27B PQ2_0 CPU control did not finish before the pod was shut down). That HIP vs CPU floor is max KLD 0.03 to 0.06 for the 8B models, about 1000x the patched vs base numbers. On more AMD GPUs: RunPod only has MI300X, so RDNA will have to wait for a laptop or desktop card. The v_perm change applies to every AMD target; the small_k rule is scoped to CDNA on purpose until wave32 parts are measured. |
Add group-128 ternary MMQ, MMVQ, conversion and row lookup support. Use native byte permutes on HIP and retain the CDNA split-K geometry. Use the PQ2_0 type name and explicit Q8 MMQ precision. Source: PrismML-Eng#125 Source commits (PrismML-Eng/llama.cpp): c09e6de 8bbb28b a7cc296 5476d46 Co-authored-by: bri-prism <[email protected]> Co-authored-by: Mark Schatza <[email protected]> Assisted-by: GitHub Copilot Assisted-by: SWE-2 Max (Devin) Assisted-by: OpenAI Codex (Astra) Assisted-by: OpenAI Codex Ported and rebased by Codex.
Add group-128 ternary MMQ, MMVQ, conversion and row lookup support. Use native byte permutes on HIP and retain the CDNA split-K geometry. Use the PQ2_0 type name and explicit Q8 MMQ precision. Source: PrismML-Eng#125 Source commits (PrismML-Eng/llama.cpp): c09e6de 8bbb28b a7cc296 5476d46 Co-authored-by: bri-prism <[email protected]> Co-authored-by: Mark Schatza <[email protected]> Assisted-by: GitHub Copilot Assisted-by: SWE-2 Max (Devin) Assisted-by: OpenAI Codex (Astra) Assisted-by: OpenAI Codex Ported and rebased by Codex.
Add group-128 ternary MMQ, MMVQ, conversion and row lookup support. Use native byte permutes on HIP and retain the CDNA split-K geometry. Use the PQ2_0 type name and explicit Q8 MMQ precision. Source: PrismML-Eng#125 Source commits (PrismML-Eng/llama.cpp): c09e6de 8bbb28b a7cc296 5476d46 Co-authored-by: bri-prism <[email protected]> Co-authored-by: Mark Schatza <[email protected]> Assisted-by: GitHub Copilot Assisted-by: SWE-2 Max (Devin) Assisted-by: OpenAI Codex (Astra) Assisted-by: OpenAI Codex Assisted-by: Claude (Opus 5.5), rebase onto ggml-org master with conflict resolution Ported and rebased by Codex.
Add group-128 ternary MMQ, MMVQ, conversion and row lookup support. Use native byte permutes on HIP and retain the CDNA split-K geometry. Use the PQ2_0 type name and explicit Q8 MMQ precision. Source: PrismML-Eng#125 Source commits (PrismML-Eng/llama.cpp): c09e6de 8bbb28b a7cc296 5476d46 Co-authored-by: bri-prism <[email protected]> Co-authored-by: Mark Schatza <[email protected]> Assisted-by: GitHub Copilot Assisted-by: SWE-2 Max (Devin) Assisted-by: OpenAI Codex (Astra) Assisted-by: OpenAI Codex Assisted-by: Claude (Opus 5.5), rebase onto ggml-org master with conflict resolution Ported and rebased by Codex.
What
HIP (AMD) speedups for the 1-bit and 2-bit weight kernels in
ggml-cuda, guarded so CUDA and MUSA are untouched:vecdotq.cuh: on HIP,__byte_permis a software routine, so the Q1_0 sign unpack (ten permutes per 16 weights) and the Q2_0 / PQ2_0 symbol expansion (four permutes per 8 codes) were the dominant VALU cost of every decode dot product. Both now use the hardware byte permute (v_perm_b32via__builtin_amdgcn_perm): Q1_0 spreads each nibble's bits into byte lanes and selects the constant +1/-1 bytes; Q2_0 and PQ2_0 spread the four 2-bit codes into byte lanes and do one LUT lookup for{-1, 0, 1, 2}.mmvq.cu: on CDNA, never pick thesmall_kMMVQ geometry (rows_per_block = nwarps) for Q1_0 / Q2_0 / PQ2_0. With wave64 it triggers for every K < 4096 projection and runs 2 to 4x slower per call than the default split-K geometry.Why
Profiling on an MI300X (ROCm 6.4.1) showed decode for these formats running at a few percent of HBM bandwidth with the mat-vec kernel bound on the software permutes, and the 4B model decoding slower than 8B because its K = 2560 projections fell into the
small_kpath.How verified
test-backend-ops -b ROCm0 -o MUL_MATand-o MUL_MAT_ID: all Q1_0 / Q2_0 / PQ2_0 cases pass before and after. The change is bit-exact by construction; the HIP helpers were also checked offline against the CUDA__byte_permsequences for all 65536 16-bit inputs.llama-benchon MI300X,-ngl 99 -fa 1, 5 repetitions, interleaved A-B-A-B on this branch (prism-v7); prompt processing is unchanged because it goes through MMQ. Decode tokens/s:No change on NVIDIA (the HIP branches are behind
GGML_USE_HIPdevice-compile guards) and no change for other quant types (thesmall_krule is type-scoped).