ggml-webgpu: tune subgroup split (d_split) in flash_attn_vec#25418
Merged
Conversation
yomaytk
commented
Jul 7, 2026
| if (key.common.k_type == GGML_TYPE_F16 && key.common.v_type == GGML_TYPE_F16) { | ||
| const uint32_t D = key.common.head_dim_qk | key.common.head_dim_v; | ||
| const uint32_t D_lsb = D & (~(D - 1u)); | ||
| d_split = std::min(std::min(context.min_subgroup_size, 4u), std::max(D_lsb / 4u, 1u)); |
Member
Author
There was a problem hiding this comment.
Vulkan sets this upper limit of D_SPLIT to 8u, but I can confirm that 4u works better on both M2 and V100.
Contributor
|
pretty nice speedups! |
reeselevine
approved these changes
Jul 8, 2026
Member
Author
|
@ggml-org/maintainers can I get a second review please? |
ruixiang63
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds tuning of
D_SPLIT(=subgroup_size / VEC_NE, whereVEC_NEwas the value hardcoded on master) in flash_attn_vec to split the subgroup when accumulatingQ * KandP * V, based on head_dim and subgroup_size, instead of hardcoding it. The following table shows the TG performance improvement when the context length reaches 16K.The command is like this:
llama-bench -m Llama-3.2-3B-Instruct-Q4_K_M.gguf -fa 1 -p 0 -n 128 -d 16384 -r 3 -dev WebGPUNVIDIA V100
M2
This tuning is similar to the Vulkan backend. In practice,
VEC_NEis set to 8 in many cases, and I can confirm that it performs better than other values of master branch.Requirements