NameError: name 'safe_open' is not defined (same code running fine yesterday)
System Info
Running in Google Colab:
transformersversion: 4.26.1- Platform: Linux-5.10.147+-x86_64-with-glibc2.29
- Python version: 3.8.10
- Huggingface_hub version: 0.12.0
- PyTorch version (GPU?): 1.13.1+cu116 (True)
- Tensorflow version (GPU?): 2.11.0 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No
Who can help?
@ArthurZucker @younesbelkada @amyeroberts
Information
- [X] The official example scripts
- [ ] My own modified scripts
Tasks
- [X] An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - [ ] My own task or dataset (give details below)
Reproduction
!pip install diffusers transformers accelerate scipy safetensors torch sentence-transformers from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler from safetensors import safe_open import torch
model_id = "stabilityai/stable-diffusion-2"
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler") pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16) pipe = pipe.to("cuda")
prompt = "Monkey eating pizza with friends" image = pipe(prompt).images[0]
image.save("monkey_pizza.png") image
Expected behavior
The code should be able to produce an image. The thing is exactly the same code was working yesterday. This code is from official example for stable diffusion
This issue seems to be related to diffusers
Transferring the issue there!
Hey @VijCodes,
I don't think you need to import this line:
from safetensors import safe_open
Could you just try:
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
import torch
model_id = "stabilityai/stable-diffusion-2"
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16)
pipe = pipe.to("cuda")
prompt = "Monkey eating pizza with friends"
image = pipe(prompt).images[0]
image.save("monkey_pizza.png")
image
Hey,
Thank you for the response, I initially did not include that line, I got the same error. A few hours later exactly same code seems to be working, not sure what fixed it, it's exactly the same everything.
Regards, Vijay
From: Patrick von Platen @.> Sent: 16 February 2023 10:48 To: huggingface/diffusers @.> Cc: Katta, Vijay (kattavy) @.>; Mention @.> Subject: Re: [huggingface/diffusers] NameError: name 'safe_open' is not defined (same code running fine yesterday) (Issue #2375)
Hey @VijCodeshttps://github.com/VijCodes,
I don't think you need to import this line:
from safetensors import safe_open
Could you just try:
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler import torch
model_id = "stabilityai/stable-diffusion-2"
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler") pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16) pipe = pipe.to("cuda")
prompt = "Monkey eating pizza with friends" image = pipe(prompt).images[0]
image.save("monkey_pizza.png") image
— Reply to this email directly, view it on GitHubhttps://github.com/huggingface/diffusers/issues/2375#issuecomment-1433390146, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFPCZV6IABARIUWE5KC56P3WXZK43ANCNFSM6AAAAAAU52STF4. You are receiving this because you were mentioned.Message ID: @.***>
Hello,
same issue here. Running on Google Colab with diffusers version 0.16.1. Issue happens with both stable-diffusion-2 and stable-diffusion-2-1-base. Running below code (taken from Stable Diffusion model card examples) causes NameError: name 'safe_open' is not defined.
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
import torch
model_id = "stabilityai/stable-diffusion-2"
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16)
Hey @diegochine,
I cannot reproduce your error. Could you maybe try updating safetensors?
pip install --upgrade safetensors
?
so I'm working on jupyter notebook and I encountered the same error I tried everything including installing and upgrading the necessary packages I even waited for few hours in hope that it will run itself like @VijCodes but it didn't worked for me what are the next step guys that Is should be taking ?
this is just an error in the user environment, do a:
!pip freeze
and search for the safetensors library:
safetensors==0.4.2
If the safetensors is listed with a relative newer version, we'll need more information, the best you can do since you're using a jupyter notebook is to share a google collab.