Skip to content

opencl: fold gqa heads for f16 decomposed FA - #32631

Merged
lhez merged 1 commit into
ggml-org:masterfrom
qualcomm:lh/fa-f16-gqa-head-fold
Nov 20, 2026
Merged

lhez merged 1 commit into
ggml-org:masterfrom
qualcomm:lh/fa-f16-gqa-head-fold

Conversation

@shaofeiqi

@shaofeiqi shaofeiqi commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Overview

When doing spec verification, the input tokens are usually very few, which get padded to tile boundary, making a large portion of compute in the tile to be useless.

This PR improves this for f16 KV P8 path in decomposed FA (i.e., decomposed FA with int8 output of KQ) by folding Q heads into the shared KQ tile.

Additional information

Details

gemma-4-E4B-Q4_K_M

master

1.15.127.529 I encoded 32099 tokens in   37.836 seconds, speed:  848.378 t/s
1.15.127.531 I decoded  513 tokens in   29.049 seconds, speed:   17.660 t/s
1.15.127.531 I
1.15.127.532 I n_draft   = 3
1.15.127.532 I n_predict = 513
1.15.127.532 I n_drafted = 589
1.15.127.533 I n_accept  = 316
1.15.127.533 I accept    = 53.650%

PR

1.09.125.065 I encoded 32099 tokens in   36.860 seconds, speed:  870.831 t/s
1.09.125.066 I decoded  515 tokens in   23.691 seconds, speed:   21.738 t/s
1.09.125.066 I
1.09.125.066 I n_draft   = 3
1.09.125.066 I n_predict = 515
1.09.125.066 I n_drafted = 577
1.09.125.067 I n_accept  = 322
1.09.125.067 I accept    = 55.806%

Requirements

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend labels Nov 19, 2026
@lhez lhez changed the title opencl: fold gqa heads for f16 FA opencl: fold gqa heads for f16 FA for more efficient spec verify Nov 20, 2026
@lhez lhez changed the title opencl: fold gqa heads for f16 FA for more efficient spec verify opencl: fold gqa heads for f16 decomposed FA Nov 20, 2026
Co-authored-by: Shaofei Qi <[email protected]>
Co-authored-by: Hongqiang Wang <[email protected]>
Assisted-by: Codex
@lhez
lhez force-pushed the lh/fa-f16-gqa-head-fold branch from 5caaba0 to 1e09da9 Compare November 20, 2026 04:37
@lhez
lhez marked this pull request as ready for review November 20, 2026 04:42
@lhez
lhez requested a review from a team as a code owner November 20, 2026 04:42
@lhez

lhez commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@max-krasnyansky @wanghqc please review/ack when you get a chance

@lhez
lhez merged commit 7e960f4 into ggml-org:master Nov 20, 2026
23 checks passed
Kidplayer666 pushed a commit to Kidplayer666/llama.cpp that referenced this pull request Nov 20, 2026
Assisted-by: Codex

Co-authored-by: Li He <[email protected]>
Co-authored-by: Hongqiang Wang <[email protected]>
wanghqc added a commit to qualcomm/llama.cpp that referenced this pull request Nov 22, 2026
OpenCL keeps x2ue's ggml-opencl.cpp and ports the upstream changes by hand:
the A7 non-MoE binary GEMMs for q4_0, q4_K, q5_K, q6_K and q8_0 (ggml-org#30947,
ggml-org#30948, ggml-org#31002, ggml-org#30949, ggml-org#31003; the bin layout stays default-on for the X2E
only, and the q8_0 A7 GEMM leaves the verify band to the cooperative-K GEMM),
the DIAG_MASK_INF prune (ggml-org#29801), bf16 support_op flags (ggml-org#32135, ggml-org#32202,
ggml-org#32387), f16 and non-contiguous silu (ggml-org#32319), and the bf16 sigmoid and
batched group_norm parts of ggml-org#32251 (its add/mul row period, f16 swiglu_oai
and q4_K flat GEMV tail were already fixed here).
Upstream's decomposed flash attention (ggml-org#32046, ggml-org#32522, ggml-org#32577, ggml-org#32631) is not
taken: x2ue keeps its own decomposition, so those kernels are dropped.
speculative.cpp keeps x2ue's driver and accepts the new draft-dflash2 and
draft-lilicorr types, which route to its single DFlash implementation.
qwen4exp keeps its 128-row hc down/inject padding as an override of the merge
helper that moved to qwen.py.
Annieren pushed a commit to Annieren/llama.cpp-upstream that referenced this pull request Nov 23, 2026
Assisted-by: Codex

Co-authored-by: Li He <[email protected]>
Co-authored-by: Hongqiang Wang <[email protected]>
Mr-J-369 pushed a commit to Mr-J-369/llama.cpp-Android that referenced this pull request Nov 25, 2026
Assisted-by: Codex

Co-authored-by: Li He <[email protected]>
Co-authored-by: Hongqiang Wang <[email protected]>
(cherry picked from commit 7e960f4)
Nindaleth pushed a commit to Nindaleth/llama.cpp that referenced this pull request Nov 26, 2026
Assisted-by: Codex

Co-authored-by: Li He <[email protected]>
Co-authored-by: Hongqiang Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants