webgpu: support head_sink in flash attention#27410
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enables flash attention support for head_sink in WebGPU, specifically to support gpt-oss models. The changes remove the restriction that prevented flash attention from being used when head_sink is present, and thread the head_sink parameter through the entire flash attention call chain.
Changes:
- Removed the head_sink nullptr check that was blocking flash attention usage with head_sink
- Added head_sink parameter throughout the flash attention implementation with backward-compatible default value
- Updated WGSL shader templates to handle head_sink logic for proper attention computation
- Fixed numerical precision issue with explicit f32 casting in exponential calculations
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/contrib_ops/webgpu/bert/group_query_attention.cc | Removed head_sink nullptr check blocking flash attention; added head_sink parameter to ApplyFlashAttention calls |
| onnxruntime/contrib_ops/webgpu/bert/flash_attention.h | Added head_sink parameter to ApplyFlashAttention signature and FlashAttentionDecodeSplitVxProgram; added num_heads uniform variable |
| onnxruntime/contrib_ops/webgpu/bert/flash_attention.cc | Threaded head_sink parameter through flash attention implementation; added shader input and uniform handling for head_sink |
| onnxruntime/contrib_ops/webgpu/bert/flash_attention.wgsl.template | Added head_sink support with conditional initialization of previous_max; fixed numerical precision with explicit f32 casting |
| onnxruntime/contrib_ops/webgpu/bert/flash_attention_decode_split_vx.wgsl.template | Added head_sink support in global max/sum calculation using head_idx derived from batch_head_idx |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fs-eire
previously approved these changes
Feb 25, 2026
fs-eire
approved these changes
Feb 25, 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.
This enables flash attention for gpt-oss