Repository navigation
Use Flash Attention for RoFormer separation on Vulkan - #1152
Merged
Merged
Conversation
BS-RoFormer and Mel-Band RoFormer take the same F32-accumulating, view-preserving Flash Attention lowering on Vulkan that CUDA already uses; CPU and other backends keep the explicit attention path. On an RX 9070 (RADV, Release, Q8_0) both models run about 1.27-1.31x faster and peak VRAM drops by about 0.9 GiB (BS-RoFormer, 5.4 min song, overlap 4: 108.7 s -> 84.5 s, 3110 -> 2233 MiB). Output differs from the explicit path by 55-74 dB below the signal, and both are equally close to a CPU F32 reference. Intel Vulkan is untested. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UYvC1gKw9CahuP7gXNqo5D
Owner
|
@ruihe774 Thanks! PR merged. |
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.
BS-RoFormer and Mel-Band RoFormer now use the same F32-accumulating, view-preserving Flash Attention lowering on Vulkan that CUDA already uses. CPU and other backends keep the explicit attention path.
On Vulkan the explicit path stores the full matrix of attention scores for every axial attention block. ggml-vulkan's
FLASH_ATTN_EXTaccepts the RoFormer shapes (head dim 64, F32 Q/K/V), and using it cuts both time and memory.attention_from_headsinsrc/models/roformer/runtime.cppnow takes the existingScaledDotProductAttentionModule/FlashPreserveViews/GGML_PREC_F32branch forBackendType::Vulkanas well as CUDA. No other CUDA-only RoFormer paths (strided head views, packed QK RoPE) are extended. The docs are updated to match.Results: AMD RX 9070 (RDNA4, RADV), Release, Q8_0 GGUFs. Inputs: a 4.8 min dialogue-over-music clip (test1) and a 5.4 min pop song (test2), 44.1 kHz stereo. Wall clock including load, mean of two warm runs; cold runs were within 0.2 s.
VRAM is for the whole card; the desktop uses about 0.8–0.9 GiB at idle.
Output equivalence against the explicit Vulkan path (PCM16): the largest difference is 9–153 steps; the difference sits 54.6–74.1 dB below the signal. ggml-vulkan's flash kernel rounds Q, K, V and the attention weights to F16 and accumulates in F32, as the CUDA kernel does.
Against a CPU explicit-F32 reference (test1, overlap 1), both Vulkan paths are equally close:
Repeat runs of the flash path are bit-identical.
This PR was implemented with assistance from AI, and I have reviewed the implementation.