-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
Adding FlexAttention Support for Qwen2 models #35155
base: main
Are you sure you want to change the base?
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Hey @ArthurZucker, I fixed the issue related to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry @MekkCyber, was workiing on #35235 which might include some of these changes, and stabilized the api! Do you mind updating? 🤗
query, | ||
key, | ||
value, | ||
score_mod=causal_mod, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, I've had a great experience with FlexAttention so far.
Wouldn't it make sense to create a BlockMask
with a specified mask_mod
once and reuse it in every layer?
Rather that calculating attention and zeroing it via score_mod
, we could just not calculate attention between tokens excluded from the mask. Something like
def get_block_mask(position_ids):
def make_mask_mod(b, h, q_idx, kv_idx):
return (position_ids[q_idx] >= position_ids[kv_idx]) & (q_idx - kv_idx < sliding_window_size)
S = position_ids.size(0)
return create_block_mask(make_mask_mod, None, None, S, S)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I did not try both but using block_mask should be faster in case the mask is large enough and sparse: https://pytorch.org/blog/flexattention/#q-why-are-score_mod-and-mask_mod-different-isnt-mask_mod-just-a-special-case-of-score_mod
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, this is the case for all archs, Transformers only makes use of score_mod
:
score_mod=causal_mod, |
What does this PR do?
Adding flex_attention for Qwen2 models following #34809
Who can review ?
@ArthurZucker