Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModernBERT FlexAttention #35423

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

staghado
Copy link
Contributor

What does this PR do?

This PR adds FlexAttention support for ModernBERT:

  • Combines sliding window and document masking to implement the alternating local/global attention pattern in ModernBERT
  • Mask creation is expensive so the two masks are cached at the model level and then re-used across layers.
  • Similar to the FA2 path, it works directly on the unpadded sequences
  • Re-uses the existing ModernBertRotaryEmbedding to avoid requiring FA2.

Note:
The current version requires one of the latest torch nightlies (e.g 2.6.0.dev20241112)
Currently transformers does not allow compiling the flex_attention function IIUC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant