Conditinally passing and_mask_function arg to create_causal_mask #44641
Draft
kmbhattt-aws wants to merge 1 commit intohuggingface:mainfrom
Draft
Conditinally passing and_mask_function arg to create_causal_mask #44641kmbhattt-aws wants to merge 1 commit intohuggingface:mainfrom
kmbhattt-aws wants to merge 1 commit intohuggingface:mainfrom
Conversation
…d on position embedding type
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: falcon |
vasqu
reviewed
Mar 13, 2026
| past_key_values=past_key_values, | ||
| # Force mask creation for alibi | ||
| and_mask_function=lambda *args: torch.tensor(True, dtype=torch.bool), | ||
| and_mask_function=(lambda *args: torch.tensor(True, dtype=torch.bool)) if self.use_alibi else None, |
Contributor
There was a problem hiding this comment.
Yea, valid point. However we should probably check whether the alibi tensor is none - not sure how reliable that flag is tbh 👀
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.
What does this PR do?
Issue: A full 4D attention mask of shape
[1, 1, seq_len, seq_len]is being created during attention, even when not using alibi for positional embeddings.Root Cause:
The
create_causal_maskcall in the Falcon model was passing anand_mask_functionargument:This was added with the comment "Force mask creation for alibi" - as ALiBi positional encoding requires the materialized mask to apply linear biases to attention scores.
However, in Falcon model even when alibi is not used, the
and_mask_functionargument unconditionally setsallow_is_causal_skip = False, which materializes a fullseq_len x seq_lenshaped mask.Fix:
Only pass
and_mask_functiontocreate_causal_maskfunction when alibi is used.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.