-
Notifications
You must be signed in to change notification settings - Fork 6.7k
[Qwen] avoid creating attention masks when there is no padding #12987
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
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. |
sayakpaul
left a comment
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!
Could you update with the following things?
- Shed light into what caused the speed regression
- Add a test with masks in the compilation tests here
- Do a before and after comparison in the outputs with the PR
|
will do! |
| encoder_attention_mask = torch.stack( | ||
| [torch.cat([u, u.new_zeros(max_seq_len - u.size(0))]) for u in attn_mask_list] | ||
| ) | ||
| prompt_embeds, encoder_attention_mask = build_prompt_embeds_and_mask(split_hidden_states) |
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.
curiously, cant we just do
if encoder_attention_mask.all():
encoder_attention_mask = NoneThere 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.
the issue was that this was giving trouble with torch.compile...
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.
ohh, but I think we typically just torch.compile the models (e.g. pipeline.transformer.compile(...), pipeline.text_encoder.compile())
the computations on the pipeline won't be part of it though
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.
oh ok let me check that then
What does this PR do?
We now have a unified Qwen prompt-embed handling to avoid creating attention masks when there is no padding (keeps flash SDPA eligible, removes unnecessary masks). This fixes the inference speed regression.
Before submitting
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.