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

ImportError when running diffusers tutorial code in Ubuntu 20.04 #10231

Open
Benson722 opened this issue Dec 16, 2024 · 0 comments
Open

ImportError when running diffusers tutorial code in Ubuntu 20.04 #10231

Benson722 opened this issue Dec 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Benson722
Copy link

Describe the bug

When I try to run:

from diffusers import DDPMPipeline ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda") image = ddpm(num_inference_steps=25).images[0] image

(habitat) /home/zhangyiqing/IROS2025/habitat-lab $ /home/zhangyiqing/miniconda3/envs/habitat/bin/python /home/zhangyiqing/IROS2025/habitat-lab/dirtyHand/PPO_topdownmap.py
Traceback (most recent call last):
File "/home/zhangyiqing/IROS2025/habitat-lab/dirtyHand/PPO_topdownmap.py", line 7, in
ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda")
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py", line 725, in from_pretrained
cached_folder = cls.download(
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py", line 1390, in download
ignore_patterns = _get_ignore_patterns(
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/pipeline_loading_utils.py", line 906, in _get_ignore_patterns
raise EnvironmentError(
OSError: Could not find the necessary safetensors weights in {'diffusion_pytorch_model.safetensors', 'diffusion_pytorch_model.bin'} (variant=None)

Change "use_safetensors" to None to download the model:

Loading pipeline components...: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 30.22it/s]
Traceback (most recent call last):
File "/home/zhangyiqing/IROS2025/habitat-lab/dirtyHand/PPO_topdownmap.py", line 7, in
ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=None).to("cuda")
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
return fn(*args, **kwargs)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py", line 948, in from_pretrained
model = pipeline_class(**init_kwargs)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/ddpm/pipeline_ddpm.py", line 43, in init
self.register_modules(unet=unet, scheduler=scheduler)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py", line 165, in register_modules
library, class_name = _fetch_class_library_tuple(module)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/pipeline_loading_utils.py", line 734, in _fetch_class_library_tuple
not_compiled_module = _unwrap_model(module)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/pipelines/pipeline_loading_utils.py", line 234, in _unwrap_model
if is_compiled_module(model):
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/diffusers/utils/torch_utils.py", line 88, in is_compiled_module
if is_torch_version("<", "2.0.0") or not hasattr(torch, "_dynamo"):
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/init.py", line 2214, in getattr
return importlib.import_module(f".{name}", name)
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_dynamo/init.py", line 2, in
from . import convert_frame, eval_frame, resume_execution
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_dynamo/convert_frame.py", line 48, in
from . import config, exc, trace_rules
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_dynamo/trace_rules.py", line 52, in
from .variables import (
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_dynamo/variables/init.py", line 38, in
from .higher_order_ops import (
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_dynamo/variables/higher_order_ops.py", line 14, in
import torch.onnx.operators
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/onnx/init.py", line 49, in
from ._internal.exporter import ( # usort:skip. needs to be last to avoid circular import
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/onnx/_internal/exporter/init.py", line 13, in
from ._analysis import analyze
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/onnx/_internal/exporter/_analysis.py", line 14, in
import torch._export.serde.schema
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_export/init.py", line 33, in
from torch._export.non_strict_utils import make_constraints
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_export/non_strict_utils.py", line 16, in
from torch._dynamo.variables.builder import TrackedFake
File "/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_dynamo/variables/builder.py", line 73, in
from ..trace_rules import (
ImportError: cannot import name 'is_callable_allowed' from partially initialized module 'torch._dynamo.trace_rules' (most likely due to a circular import) (/home/zhangyiqing/miniconda3/envs/habitat/lib/python3.9/site-packages/torch/_dynamo/trace_rules.py)

Reproduction

from diffusers import DDPMPipeline
import matplotlib.pyplot as plt

from huggingface_hub.hf_api import HfFolder;
HfFolder.save_token("token")

ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda")
image = ddpm(num_inference_steps=25).images[0]

plt.imshow(image)

Logs

No response

System Info

Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

  • 🤗 Diffusers version: 0.31.0
  • Platform: Linux-5.15.0-67-generic-x86_64-with-glibc2.31
  • Running on Google Colab?: No
  • Python version: 3.9.20
  • PyTorch version (GPU?): 2.4.0.post301 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Huggingface_hub version: 0.26.5
  • Transformers version: not installed
  • Accelerate version: 1.2.1
  • PEFT version: not installed
  • Bitsandbytes version: not installed
  • Safetensors version: 0.4.5
  • xFormers version: not installed
  • Accelerator: NVIDIA GeForce RTX 4090, 24564 MiB
  • Using GPU in script?:
  • Using distributed or parallel set-up in script?:

Who can help?

No response

@Benson722 Benson722 added the bug Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant