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

Fix for use_safetensors parameters, allow use of parameter on loading submodels (#9576) #9587

Merged

Conversation

elismasilva
Copy link
Contributor

What does this PR do?

This PR fixes the issue described in (#9576) where use_safetensors parameter from pipeline is not passed to submodules when them is loaded from "from_pretrained" method.

Reproduction tests:

1. If I do not pass use_safetensors in the pipeline, it will set use_safetensors to True and allow_pickle to True and then an alert will be issued if it does not find ".safetensors" in the directory, however it will continue loading the .bin files normally.

from diffusers import StableDiffusionXLPipeline
import torch
pipe = StableDiffusionXLPipeline.from_pretrained('stablediffusionapi/yamermix-v8-vae', torch_dtype=torch.float16)

Log:

███████████████████████████████████████████████████████████████████████▏                                                                                              | 3/7 [00:00<00:00,  4.13it/s]An error occurred while trying to fetch F:/projetos/DiffusersWebUI/models/stablediffusionapi/yamermix-v8-vae\unet: Error no file named diffusion_pytorch_model.safetensors found in directory F:/projetos/DiffusersWebUI/models/stablediffusionapi/yamermix-v8-vae\unet.
Defaulting to unsafe serialization. Pass `allow_pickle=False` to raise an error instead.
Loading pipeline components...:  71%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▌                                               | 5/7 [00:03<00:01,  1.27it/s]An error occurred while trying to fetch F:/projetos/DiffusersWebUI/models/stablediffusionapi/yamermix-v8-vae\vae: Error no file named diffusion_pytorch_model.safetensors found in directory F:/projetos/DiffusersWebUI/models/stablediffusionapi/yamermix-v8-vae\vae.
Defaulting to unsafe serialization. Pass `allow_pickle=False` to raise an error instead.
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7/7 [00:03<00:00,  2.06it/s]

f:\Projetos\diffusers\venv\lib\site-packages\transformers\models\clip\modeling_clip.py:491: UserWarning: 1Torch was not compiled with flash attention. (Triggered internally at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\transformers\cuda\sdp_utils.cpp:555.)

2. If I pass use_safetensors True in the pipeline, it will not issue the warning, it will simply give the error message that it did not find ".safetensors" files in the directory.

from diffusers import StableDiffusionXLPipeline
import torch
pipe = StableDiffusionXLPipeline.from_pretrained('stablediffusionapi/yamermix-v8-vae', torch_dtype=torch.float16, use_safetensors=True)

Log:

"...Error no file named diffusion_pytorch_model.safetensors found in directory F:/projetos/DiffusersWebUI/models/stablediffusionapi/yamermix-v8-vae\vae"

3. If I pass use_safetensors False in the pipeline (the scenario where this PR is fixing), then it means that it will directly search for the .bin files in the directory without throwing errors, except if the model is .safetensors, then it will throw an error saying that it didn't find any .bin files in the directory.

IF model is .bin:

from diffusers import StableDiffusionXLPipeline
import torch
pipe = StableDiffusionXLPipeline.from_pretrained('stablediffusionapi/yamermix-v8-vae', torch_dtype=torch.float16, use_safetensors=False)

IF model is .safetensors:

from diffusers import StableDiffusionXLPipeline
import torch
pipe = StableDiffusionXLPipeline.from_pretrained('wangqixun/YamerMIX_v8', torch_dtype=torch.float16, use_safetensors=False)

Log:

"...raise EnvironmentError(
OSError: Error no file named pytorch_model.bin, model.safetensors, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory F:/projetos/DiffusersWebUI/models/YamerMIX_v8\text_encoder."

Before submitting

Who can review?

@yiyixuxu and @asomoza

@a-r-r-o-w a-r-r-o-w requested a review from yiyixuxu October 6, 2024 23:18
@asomoza
Copy link
Member

asomoza commented Oct 7, 2024

Hi @elismasilva , thanks for the PR, I think that by mistake you committed an image in the root of the project.

@elismasilva
Copy link
Contributor Author

elismasilva commented Oct 7, 2024

Hi @elismasilva , thanks for the PR, I think that by mistake you committed an image in the root of the project.

ah sorry i will update without this, and worse, it's the image of a naked man haha ​​I hadn't even seen the result of the image when I tested it.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

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

thanks!

@HuggingFaceDocBuilderDev

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.

@yiyixuxu yiyixuxu merged commit 1287822 into huggingface:main Oct 7, 2024
15 checks passed
leisuzz pushed a commit to leisuzz/diffusers that referenced this pull request Oct 11, 2024
… submodels (huggingface#9576) (huggingface#9587)

* Fix for use_safetensors parameters, allow use of parameter on loading submodels (huggingface#9576)
sayakpaul pushed a commit that referenced this pull request Dec 23, 2024
… submodels (#9576) (#9587)

* Fix for use_safetensors parameters, allow use of parameter on loading submodels (#9576)
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.

4 participants