Repository navigation
CUDA: sparse FlashAttention on Volta - #33848
Open
PabloSoage wants to merge 1 commit into
Open
PabloSoage wants to merge 1 commit into
PabloSoage wants to merge 1 commit into
Conversation
Assisted-by: Claude Opus 5.5
1 of 5 tasks
This branch has not been deployed
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 enables the sparse FlashAttention path (
n_kv_max, used by the DSA layers of GLM-5.x and DeepSeek-V4) on Volta, both for prompt processing and for token generation. On master the path is gated to Turing and newer, so on V100 these models attend densely over the whole KV cache and slow down with context length.llama.cpp/ggml/src/ggml-cuda/fattn.cu
Line 220 in 4066b9d
The Volta MMA kernel has no device code below 32 columns per CTA, so the existing
ncols1 = 1, ncols2 = 8sparse variant cannot run there:llama.cpp/ggml/src/ggml-cuda/fattn-mma-f16.cuh
Lines 1902 to 1907 in 4066b9d
Instead of a new
ncols2 = 32instance (the approach of #28887), this keepsncols2 = 8, whichswitch_ncols2already picks on Volta for 512-wide heads, and builds the sparse gather atncols1 = 4and8(32 and 64 columns). Batches of up to 4 queries use the 4x8 variant, so token generation also gathers only the selected rows instead of running a dense tile pass. The mask-to-indices kernel gets a group of 4 for this.Additional information
Kernel time on a V100-SXM2-16GB (CUDA 12.9), GLM-5.3-Flash shape: 512-wide heads, 64 Q heads per K head, V a view of K, 2048 selected keys. Measured with
test-backend-ops perfand temporary perf cases (not part of this PR).End-to-end numbers and tests
End to end, GLM-5.3-Flash UD-IQ3_XXS on 4x V100 (layer split, experts partly in host RAM),
llama-bench -p 2048 -n 64with the context already filled. Measured on an older base (59b7165) with the same change:Tests:
test-backend-ops -o FLASH_ATTN_EXTon V100: 4502/4502 passed. With a temporary debug print, the 4 new cases take the sparse path (4x8 for batch 1 and 3, 8x8 for batch 64 and 512).test-backend-ops -o FLASH_ATTN_EXTon RTX 5070 Ti (sm_120) and RTX 2060 SUPER (sm_75): 4647/4647 passed on both after rebasing on 7258196, no change on non-Volta paths.n_kv_max = 512, the smallest size whereshall_use_sparseaccepts both variants, to keep the CPU reference cheap.Requirements
Written with Claude Opus 5.5