diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

[Single File] Allow loading T5 encoder in mixed precision

Open DN6 opened this issue 1 year ago • 1 comments

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 to torch_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

  1. Adds a check to T5 loading to convert the required modules to fp32
  2. Removes casting the entire pipeline to torch_dtype. This is now only handled at the model level.
  3. Adds additional tests to the single file suite to check that dtypes are set correctly in the pipeline

Single file tests for SD3 need to be added. I'll handle that in a follow up PR.

Fixes # (issue) https://github.com/huggingface/diffusers/issues/8759

Before submitting

  • [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • [ ] Did you read the contributor guideline?
  • [ ] Did you read our philosophy doc (important for complex PRs)?
  • [ ] Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • [ ] Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • [ ] Did you write any new necessary tests?

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.

DN6 avatar Jul 03 '24 05:07 DN6

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.