Repository navigation
[attention] Make the FlexAttention mask type configurable - #5
Open
aws-arashj wants to merge 2 commits into
Open
aws-arashj wants to merge 2 commits into
aws-arashj wants to merge 2 commits into
Conversation
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.
Summary
FlexAttention always builds a block-causal mask, which is causal within each packed document. This PR adds
FlexInnerAttention.Config.mask_typeso a model can choose plain"causal"instead, matching the transformers backend'sattn_mask_type."block_causal"is the default and keeps today's behavior."causal"doesn't depend onpositions, so the mask is the same for every batch. It's only correct when each sequence holds one document.A new helper,
get_flex_causal_mask_mods(positions, config), returns the selectedmask_mods. The decoder, GPT-OSS, and Muse Glimmer mask builders use it instead of composing the masks inline. Masks are unchanged for every existing config.Test plan
tests/unit_tests/cpu/test_flex_mask_type.py(2 tests, 9 subtests, all passing):mask_mods. On packed and single-document positions,block_causalis causal ∧ same-document andcausalis causal. The two agree on single-document sequences."causal"equals the lower-triangular block mask, and the defaultblock_causalkeeps fewer blocks. That covers both the full and sliding-window masks. It fails if either model's builder ignoresmask_type.test_flex_attention.py,test_gpt_oss_moe.py,test_muse_glimmer.py, andtest_varlen_attention.py: 13 passed, the same as onmain.