Add selectable masking strategies for attention#204
Merged
LoserCheems merged 1 commit intomainfrom Nov 6, 2025
Merged
Conversation
Introduces selectable masking strategies to support both top-k and ReLU flows, enabling experimentation with bias-driven sparsity. Normalizes the top-k path to use detached bias casting and rejects unsupported mask types to avoid silent misuse.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the mask generation functionality to support multiple mask types. It renames dynamic_mask to topk_mask, introduces a new relu_mask function, and adds a type parameter to create_mask to select between different masking strategies.
- Renamed
dynamic_maskfunction totopk_maskfor clarity - Added new
relu_maskfunction implementing ReLU-based masking - Updated
create_maskto support both "topk" and "relu" mask types via a newtypeparameter
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| attention_mask = relu_mask( | ||
| attention_bias=attention_bias, | ||
| attention_mask=attention_mask, | ||
| window_size=window_size, |
There was a problem hiding this comment.
The relu_mask function does not accept a window_size parameter, but it's being passed here. This will cause an error when type == 'relu' is used. The window_size parameter should be removed from this function call, or the relu_mask function signature should be updated to accept and use it.
Suggested change
| window_size=window_size, |
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.
Introduce selectable masking strategies for attention mechanisms, enabling both top-k and ReLU flows. This allows for experimentation with bias-driven sparsity and normalizes the top-k path to prevent misuse of unsupported mask types.