Skip to content
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

Improve single loading file #4041

Merged
merged 5 commits into from
Jul 11, 2023
Merged

Improve single loading file #4041

merged 5 commits into from
Jul 11, 2023

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Jul 11, 2023

What does this PR do?

This PR improves the single model loading file so that it now works very well for:

  • SD 1.5 (both normal and inpainting)
  • SD 2.0 and 2.1
  • SDXL

All unnecessary downloads are removed and loading is sped up as much as possible.

StableDiffusionXLPipeline.from_single_file(...) now only takes 2 seconds which is almost as fast as the official diffusers format: StableDiffusionXLPipeline.from_pretrained(...) which takes 0.7 seconds.

Fixes

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 11, 2023

The documentation is not available anymore as the PR was closed or merged.

@patrickvonplaten patrickvonplaten changed the title start improving single file load Improve single loading file Jul 11, 2023
@patrickvonplaten patrickvonplaten merged commit 8bff782 into main Jul 11, 2023
10 checks passed
@patrickvonplaten patrickvonplaten deleted the fix_single_file_loading branch July 11, 2023 15:01
patrickvonplaten added a commit that referenced this pull request Jul 11, 2023
* start improving single file load

* Fix more

* start improving single file load

* Fix sd 2.1

* further improve from_single_file
# )
config = CLIPTextConfig.from_pretrained(config_name, **config_kwargs)

with init_empty_weights():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break downstream if you don't have accelerate and we probably need a if is_accelerate_available(): check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! I think we should actually just force the user here to install accelerate since this method only exists for PyTorch anyways and there is no harm in installing accelerate for PyTorch

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we can avoid forcing an accelerate install ? We ship nightly HF libraries (transformers, diffusers) and then export out via torch-mlir to SHARK so we don't use PyTorch/Accelerate and would like to avoid adding the dependency to our shipping binaries if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in: #4132

@@ -1318,25 +1340,45 @@ def download_from_original_stable_diffusion_ckpt(
# Convert the UNet2DConditionModel model.
unet_config = create_unet_diffusers_config(original_config, image_size=image_size)
unet_config["upcast_attention"] = upcast_attention
unet = UNet2DConditionModel(**unet_config)
with init_empty_weights():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably need to qualify this with if is_accelerate_available(): check if we don't have accelerate

@hckj588ku
Copy link

It seems that when I use StableDiffusionPipeline to load another model with from_pretrained, and then try to load an SDXL model with StableDiffusionXlPipeline using from_single_file, the program gets stuck for a long time. I have already updated to the latest code.

@patrickvonplaten
Copy link
Contributor Author

Can you open a new issue and add a reproducible? :-)

orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* start improving single file load

* Fix more

* start improving single file load

* Fix sd 2.1

* further improve from_single_file
orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* start improving single file load

* Fix more

* start improving single file load

* Fix sd 2.1

* further improve from_single_file
orpatashnik pushed a commit to orpatashnik/diffusers that referenced this pull request Aug 1, 2023
* start improving single file load

* Fix more

* start improving single file load

* Fix sd 2.1

* further improve from_single_file
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* start improving single file load

* Fix more

* start improving single file load

* Fix sd 2.1

* further improve from_single_file
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* start improving single file load

* Fix more

* start improving single file load

* Fix sd 2.1

* further improve from_single_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants