Repository navigation
CUDA: replace GGML_FA_ALL_QUANTS with GGML_FA_QUANTS, more control over what is compiled - #28079
Conversation
a762b79 to
043aa23
Compare
JohannesGaessler
left a comment
There was a problem hiding this comment.
Instead of adding a new compilation option, refactor the currently existing one into one like GGML_CUDA_FA_QUANTS that has a default of f16-f16;q8_0-q8_0;q4_0-q4_0.
Instead of reporting FA as not supported if the specific quant combination has not been compiled, fall back to the f16-f16 variant. This should automatically result in the correct type conversions to produce correct results. The speed will still be bad though so add a one-time warning that a quant combination is missing.
Please keep the code style consistent, particularly as it relates to closing #ifdef X ... #endif with // X.
043aa23 to
291854b
Compare
|
@JohannesGaessler all right, as per new doc:
|
291854b to
220a78b
Compare
Assisted-by: Codex
220a78b to
22743b4
Compare
|
@JohannesGaessler okay - removed all the flags but "all", added the fallback to f16-f16 + an explicit warning displayed once about the combination not being compiled in. |
JohannesGaessler
left a comment
There was a problem hiding this comment.
As I said off-site, please keep the
Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
|
@JohannesGaessler done. |
|
With Just wanted to confirm if this is expected. |
|
@seadra looks like a bug, going to add a quick PR for it. |
|
@seadra never mind - it looks like iq4_nl was a false positive in the previous build and it was never actually an accepted KV cache quant (it fell back to f16 silently). |
|
The CUDA backend does not and never has had any support for quantized iq4_nl KV cache. |
…er what is compiled (ggml-org#28079) * CUDA: add configurable FA quant combinations Assisted-by: Codex * remove all flags but , add runtime fallback with warning for uncompiled combination * Update docs/build.md Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * apply code review comments --------- Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
Port upstream PR ggml-org#28079 (fcaeeff) so the compiled FlashAttention K/V combinations are selectable at configure time instead of the all-or-nothing GGML_CUDA_FA_ALL_QUANTS switch: -DGGML_CUDA_FA_QUANTS=f16-f16,q4_0-q4_0,q8_0-q8_0,q5_0-q5_0 A combination with no compiled kernel falls back to the f16 kernel instead of silently taking a slow path. f16-f16 is always compiled. Fork delta: GGML_CUDA_FA_ALL_QUANTS is still defined when FA_QUANTS is "all". The KV-stream native path keys off it, so this keeps its trigger unchanged. Measured on the dense 27B (522-token prompt, -c 100000 --ubatch 256): q4_0/q4_0 758 tok/s, q8_0/q4_0 877, q5_1/q5_1 905, q5_0/q5_0 934. q8_0/q4_0 was 186 tok/s before, because its kernel was not compiled. q6_K has no FA kernel and stays on the conversion path.
…er what is compiled (ggml-org#28079) (#317) * CUDA: add configurable FA quant combinations Assisted-by: Codex * remove all flags but , add runtime fallback with warning for uncompiled combination * Update docs/build.md * apply code review comments --------- Co-authored-by: Piotr Wilkin (ilintar) <piotr.wilkin@syndatis.com> Co-authored-by: Johannes Gäßler <johannesg@5d6.de>
…etune kernel selection Three numeric defects made long prompts return NaN logits on an RX 7900 XTX. The tile and vector kernels summed the V-weighted softmax numerator in F16, and that sum is unnormalized: over a long KV cache it saturates and then overflows. Both now accumulate in F32, including the shared buffer the vector kernel combines through. The MMA kernel had the same problem twice over: RDNA3 used an F16 accumulator for every head size except 80 and 112, and even the F32 path writes the unnormalized sum into F16 shared memory before dividing by the row sum. RDNA3 now uses the head-80 tile layout everywhere, and an F32 accumulator is divided by its row sum before that write, with the row sum folded back through the meta data. Upstream carries the second half of that defect too. Kernel selection on RDNA3 with a quantized KV cache at head size 256 was also wrong for the small batches speculative decoding verifies with. The vector kernel's cost grows with batch times GQA ratio while the tile kernel packs the GQA columns, so the vector kernel now only runs below a product of 6 (below a GQA ratio of 16 for a single token) and WMMA only takes over past 32 packed columns instead of 16. Measured with test-backend-ops perf over 85 shapes (GQA 1 to 16, batch 1 to 8, 16K to 131K cells, q8_0 and q4_0): 48.1 ms to 41.8 ms in total, no shape more than 1 percent worse than before, and within 0.5 percent of the best kernel per shape. A batch of two is 1.3 to 2.8 times faster; the 35B's verify batch is 10 percent faster at 65K and beyond. Also ports the upstream flash-attention work this sits on: the kernel refactor (ggml-org#28079, hand-merged to keep the TurboQuant KV types and their fallback), the head-256 and gfx1201 tuning (ggml-org#28102), and the MFMA F32 accumulator (ggml-org#28576). FLASH_ATTN_EXT passes on gfx1100 (3975/3975 at the tip of this series, with the regression cases the last commit adds), and the 35B answers a 112K-token prompt with finite logits. The 27B's deep-context prefill costs 7 to 14 percent more than the saturating F16 path it replaces. Assisted-by: Claude Opus 5
Overview
Currently, to use a cross-quant combination of KV cache quants, you have to build with
-DGGML_CUDA_FA_ALL_QUANTS. However, that forces compilation of large package of quant combinations, some of which are totally unviable (eg. Q_X-F16 KV quants or generally X-Y quants with X < Y) and others are never selected in practice. Thus, adding a new optionGGML_CUDA_FA_QUANTS, where you pick the quants you want built in X-Y format, eg.:-DGGML_CUDA_FA_QUANTS="q8_0-q8_0;q8_0-q5_1;q5_1-q5_1"Additional information
This should greatly reduce compilation time on CUDA/HIP boxes.
Requirements