[1/2] cuda: native TQ4_1S MMQ prefill on CDNA - #336
Conversation
TQ4_1S weights previously had no MMQ path, so prefill dequantised them to f16 and went through hipBLAS. That threw away the format's whole point: the 5bpw footprint was paid for at load time and then not used at compute time. Add a TQ4_1S tile loader, MMQ type traits, and dispatch, and pre-rotate the activation so the block-local turbo WHT cancels against the weights. The weights stay in their rotated-domain int8 centroid form, so the stock MFMA-i8 MMQ kernel consumes them directly. The type reuses the Q3_K shared-memory layout, since its per-16 scales have the same shape, and so takes the same tile geometry Q3_K and IQ2_XS use on CDNA (occupancy 1, I=128); other geometries do not match what that layout expects and write out of bounds. Measured on an MI210 with Qwen3.6-35B-A3B-TQ4max, against this same branch with the path disabled: prefill 971 -> 2124 t/s (2.19x) decode 95 -> 93 t/s (-2.6%, this is a prefill-only path) ppl 3.2653 -> 3.2653 (identical) It also keeps roughly 13GB less VRAM than converting the experts to Q8_0. All 147 tq4_1s MUL_MAT cases pass. The path is env-gated behind GGML_TQ_MMQ so it can be A/B'd against the hipBLAS fallback. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NxP6x5bmUDYFvmouceN2mR
…and MUSA tq4_1s_qs_to_int8x4() called the AMD-only byte-permute builtin unconditionally, so the CUDA and MUSA CI builds failed to compile mmq-load-tiles.cuh. Keep v_perm_b32 on HIP and use the equivalent __byte_perm selector elsewhere. The TQ4_1S MMQ path itself is still gated to AMD at dispatch time; this only makes the header compile on the other toolchains.
|
Pushed one commit to this branch (03ee3ed): the CUDA and MUSA jobs were failing to compile because Same builtin shows up in #337 (inherited) and twice more in #338's The windows job failure on this PR is |
|
Thanks for the guard, and for carrying it into #337 and #338. I checked the two selectors against each other: One thing on the |
1cd7921
into
TheTom:feature/turboquant-kv-cache
Overview
TQ4_1S has no MMQ path, so prefill dequantises the weights to f16 and calls hipBLAS. That throws away the point of the format: the 5bpw footprint is paid for at load time and then not used at compute time.
This adds a TQ4_1S tile loader, MMQ type traits, and dispatch. The activation is pre-rotated so the block-local turbo WHT cancels against the weights, which lets the weights stay in their rotated-domain int8 centroid form and be consumed directly by the stock MFMA-i8 MMQ kernel.
The path is env-gated behind
GGML_TQ_MMQso it can be A/B'd against the hipBLAS fallback.Additional information
MI210 (gfx90a), ROCm 7.2.3, Qwen3.6-35B-A3B-TQ4max, measured against this same branch with the path disabled:
2.19x prefill at identical perplexity, and roughly 13GB less VRAM than converting the experts to Q8_0. The ~2.6% decode cost is real; this is a prefill-only path.
test-backend-ops -o MUL_MATwithGGML_TQ_MMQ=1: 147/147 tq4_1s cases pass.Note for reviewers: the tile geometry is not free to choose
TQ4_1S reuses
GGML_CUDA_MMQ_SRAM_LAYOUT_Q3_K, because its per-16 scales have the same shape. It therefore has to take the same tile geometry Q3_K and IQ2_XS use on CDNA —occupancy 1, I=128. Other geometries do not match what that layout expects and write out of bounds; the symptom is non-deterministic NaN plus test-harness sentinel mismatches rather than a clean failure.And a warning about how to validate it
Because the path is env-gated,
test-backend-opsrun withoutGGML_TQ_MMQ=1silently exercises the hipBLAS fallback and reports a clean pass for a kernel that was never invoked.llama-benchdoes not check output at all, so a broken kernel still reports a plausible tokens/s. During development we spent a while trusting exactly that combination without realising the path under test was switched off.This is the failure mode AGENTS.md already describes — "a green run means the cases that ran passed, not that your change was exercised" — so the reliable check is
llama-perplexitywith the flag on versus off. Any corpus works, since only the delta matters.Requirements