-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Single File] Allow loading T5 encoder in mixed precision #8778
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
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. |
if torch_dtype is not None: | ||
pipe.to(dtype=torch_dtype) |
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.
How is this handled then?
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.
At the model level by passing in dtype
to their respective loading methods
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!
@@ -1808,4 +1808,17 @@ def create_diffusers_t5_model_from_checkpoint( | |||
|
|||
else: | |||
model.load_state_dict(diffusers_format_checkpoint) | |||
|
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 is this related to this?
#8604 (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.
Yeah exactly. When you cast the entire model to fp16
the images will be corrupted. You have to use the logic in from_pretrained
.
* update * update * update * update
What does this PR do?
When loading the T5 encoder in SD3 with
from_pretrained
certain layers are are kept in fp32. Currently this is not the case with single file loading as all modules are cast totorch_dtype
when loading the pipeline. This is leading to NaNs being produced by the T5 encoder when loading from single file, leading to a black image.This PR
torch_dtype
. This is now only handled at the model level.Single file tests for SD3 need to be added. I'll handle that in a follow up PR.
Fixes # (issue)
#8759
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.