-
Notifications
You must be signed in to change notification settings - Fork 19.9k
ggml-webgpu: makes the flash attn vec path subgroup-aware #23040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -770,7 +770,10 @@ inline ggml_webgpu_flash_attn_decisions ggml_webgpu_flash_attn_get_decisions( | |
| (v_offset_elems % GGML_WEBGPU_FLASH_ATTN_TILE_KV_VEC_WIDTH == 0u); | ||
| const bool kv_vec_type_supported = | ||
| K->type == GGML_TYPE_F16 || K->type == GGML_TYPE_Q4_0 || K->type == GGML_TYPE_Q8_0; | ||
| const bool use_vec = context.supports_subgroups && (context.src0->ne[1] < 20) && (context.src0->ne[0] % 32 == 0) && | ||
| // Compile with enough invocations to cover the largest reported subgroup. | ||
| const bool vec_subgroup_supported = context.max_wg_size >= context.max_subgroup_size; | ||
| const bool use_vec = context.supports_subgroups && vec_subgroup_supported && (context.src0->ne[1] < 20) && | ||
| (context.src0->ne[0] % 32 == 0) && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the % 32 for? Especially if we’re trying to be subgroup size agnostic.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment everywhere 32 is still used
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea we can remove other places where 32 is used.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah thanks for the clarification, the code is clearer now too. It seems like llama.cpp does this check up front as well: https://github.com/ggml-org/llama.cpp/blob/master/src/llama-context.cpp#L3275 But I think it's probably good to have the check here too, since ggml is technically independent from llama.cpp. |
||
| (context.src2->ne[0] % GGML_WEBGPU_FLASH_ATTN_TILE_KV_VEC_WIDTH == 0) && | ||
| kv_vec_type_supported && (K->type != GGML_TYPE_F16 || f16_vec4_aligned) && | ||
| (context.src2->type == K->type); | ||
|
|
@@ -808,7 +811,7 @@ inline ggml_webgpu_flash_attn_decisions ggml_webgpu_flash_attn_get_decisions( | |
| decisions.q_tile = 1u; | ||
| decisions.kv_tile = std::max(8u, std::min(32u, max_kv_tile)); | ||
| decisions.kv_tile = (decisions.kv_tile / 8u) * 8u; | ||
| decisions.wg_size = std::max(1u, std::min<uint32_t>(32u, context.max_subgroup_size)); | ||
| decisions.wg_size = context.max_subgroup_size; | ||
| if (decisions.kv_direct) { | ||
| decisions.kv_tile = std::min(decisions.kv_tile, GGML_WEBGPU_KV_SEQ_PAD); | ||
| while (GGML_WEBGPU_KV_SEQ_PAD % decisions.kv_tile != 0) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.