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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

elismasilva
Copy link

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

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.

1 participant