CUDA: enable sparse fa for qwen4 - #28770
Conversation
JohannesGaessler
left a comment
There was a problem hiding this comment.
I don't really have anything to add. The implementation seems straightforwardly correct to me and is done well in terms of software architecture. One thing to keep in mind is that this is in essence the exact same infrastructure as would be needed for things like PagedAttention.
| return (DKQ == 512 && DV == 512 && ncols1 == 1 && ncols2 == 8) || | ||
| (DKQ == 576 && DV == 512 && ncols1 == 1 && ncols2 == 16); | ||
| (DKQ == 576 && DV == 512 && ncols1 == 1 && ncols2 == 16) || | ||
| (DKQ == 256 && DV == 256 && ncols1 == 1 && ncols2 == 8) || | ||
| (DKQ == 256 && DV == 256 && ncols1 == 8 && ncols2 == 8); | ||
| } |
There was a problem hiding this comment.
It is good to enable sparse attention for ncols1 > 1 since that will drastically improve the prefill performance. However, if it is only enabled for 1 and 8 it will cause trouble in combination with speculative methods. My opinion is that we should compile the template specializations for batch sizes 2 and 4; if the compilation becomes too bloated we should shave off template specializations somewhere else.
It's also not clear to me why the new code for sparse attention with ncols1 > 1 would work for Qwen 4 but not the other models.
There was a problem hiding this comment.
I only tested it with Qwen's headsizes, I guess it work anyway. I think I can expand the condition to be ncols==1, 2, 4, 8 and ncols2=8, 16.
|
One thing I forgot: the optimal |
Overview
Cont #27970. Enable sparse-fa for Qwen4. This model's attention is un-optimized at the moment, the entire kv-cache is re-scored everytime, we should fix that as well.
How this works ncols1=8 is take all the union of the tokens being used, so at max it will use see
ncols1 * n_kv_maxtokens, at twice this value we enable the sparse FA. For Qwen4 this value is 32768 ctx.Additional information
Results on a DGX spark:
Requirements