-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Fix FA2 for models with HybridCache #35681
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. |
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.
For gemma2 it was suppose to work!
Not aligned with the removal of the attentoin mask slicing tho! Let's run slow test on the PR
if attention_mask.shape[-1] <= 1: # when decoding | ||
attention_mask = attention_mask[:, :, :, -self.sliding_window :] |
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.
this is super important ! Why is it removed?
I know it is counter intuitive, but _flash_attention_forward
takes the attention mask to pad / unpad the input itds.
Thus you need the slicing otherwise this operation fails, see the blame !
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.
Indeed, I was too fast on this one, the HybridCache behaves slightly differently than I remembered. There was still an issue in the slicing during prefill for FA2 though!
What does this PR do?
As per the title. Models with HybridCache need to correctly slice the key/value states when using FA2 as inputs needs to be unpadded on the right as well (and the mask has shape [bs, seq_len]). It is currently broken and leads to garbage generation when using padding. This fixes it.
Also do not slice the mask during prefill if longer than the sliding window (I added a test for this case).