-
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! |
src/diffusers/pipelines/qwenimage/pipeline_qwenimage_img2img.py
Outdated
Show resolved
Hide resolved
| model = self.model_class(**init_dict).to(torch_device) | ||
| model.eval() | ||
|
|
||
| compiled_model = torch.compile(model, mode="default", fullgraph=False) |
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.
Some notes:
- Usually, it should be
model.compile()as it doesn't wrap the underlyingmodelinto a dynamo wrapper. This way, we don't have to add any extra code to handle it. - Why is
fullgraph=Falsehere?
| with torch.no_grad(): | ||
| output_no_mask = compiled_model(**inputs_no_mask) |
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.
Does it lead to graph breaks? If not, then we should add additional contexts:
diffusers/tests/models/test_modeling_common.py
Line 2145 in 3996788
| torch._dynamo.config.patch(error_on_recompile=True), |
|
does this PR lack a merge, or is the amount of code changes intentional and really part of this PR only? (+318 - 170) avoiding masks if they're not necessary has been one line before |
|
@dxqb i intially mis-calculated and was adding support for the pipeline to be compiled, i will revert and simplify |
thanks!
Therefore, I'd suggest to
|
Here is a benchmark of the impact of using a mask unnecessarily (second graph): #12870 (comment) |
|
thanks @dxqb please check now |

What does this PR do?
This pull request sets all ones masks to None.
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.