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

Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error (DmlExecutionProvider) #1127

Closed
averad opened this issue Nov 3, 2022 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@averad
Copy link

averad commented Nov 3, 2022

Intro

Diffusers provides a Stable Diffusion pipeline compatible with the ONNX Runtime. This allows you to run Stable Diffusion on any hardware that supports ONNX (including CPUs), and where an accelerated version of PyTorch is not available.

Describe the bug

Calling "from diffusers import OnnxStableDiffusionPipeline" results in Traceback Error when using diffusers 0.7.0
Diffusers 0.7.0 now requires the accelerate library be installed. Accelerate breaks onnxruntime-directml (Windows)

Removing accelerate and installing diffusers==0.6.0 fixes the issue.

Please remove the requirement to install accelerate and only use it if its appropriate for the hardware being used.

Reproduction

pip install virtualenv
python -m venv sd_env
sd_env\scripts\activate
pip install diffusers
pip install transformers
pip install onnxruntime
pip install onnx
pip install torch
pip install onnxruntime-directml --force-reinstall

run sample code:

from diffusers import OnnxStableDiffusionPipeline
height=512
width=512
num_inference_steps=50
guidance_scale=7.5
eta=0.0
prompt = "a photo of an astronaut riding a horse on mars"
negative_prompt="bad hands, blurry"
pipe = OnnxStableDiffusionPipeline.from_pretrained("./stable-diffusion-v1-5", revision="onnx", provider="DmlExecutionProvider", device_map="auto")
image = pipe(prompt, height, width, num_inference_steps, guidance_scale, negative_prompt, eta).images[0] 
image.save("astronaut_rides_horse.png")

Logs

Traceback (most recent call last):
  File "D:\ai\1.py", line 1, in <module>
    from diffusers import OnnxStableDiffusionPipeline
  File "D:\ai\sd_env\lib\site-packages\diffusers\__init__.py", line 24, in <module>
    raise ImportError(error_msg)
ImportError: Please install the `accelerate` library to use Diffusers with PyTorch. You can do so by running `pip install diffusers[torch]`. Or if torch is already installed, you can run `pip install accelerate`.

After installing accelerate:

NOTE: Redirects are currently not supported in Windows or MacOs.
Traceback (most recent call last):
  File "D:\ai\1.py", line 1, in <module>
    from diffusers import OnnxStableDiffusionPipeline
  File "D:\ai\sd_env\lib\site-packages\diffusers\__init__.py", line 28, in <module>
    from .modeling_utils import ModelMixin
  File "D:\ai\sd_env\lib\site-packages\diffusers\modeling_utils.py", line 24, in <module>
    import accelerate
  File "D:\ai\sd_env\lib\site-packages\accelerate\__init__.py", line 7, in <module>
    from .accelerator import Accelerator
  File "D:\ai\sd_env\lib\site-packages\accelerate\accelerator.py", line 27, in <module>
    from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state
  File "D:\ai\sd_env\lib\site-packages\accelerate\checkpointing.py", line 24, in <module>
    from .utils import (
  File "D:\ai\sd_env\lib\site-packages\accelerate\utils\__init__.py", line 96, in <module>
    from .launch import PrepareForLaunch, _filter_args, get_launch_prefix
  File "D:\ai\sd_env\lib\site-packages\accelerate\utils\launch.py", line 25, in <module>
    import torch.distributed.run as distrib_run
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\run.py", line 386, in <module>
    from torch.distributed.launcher.api import LaunchConfig, elastic_launch
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\launcher\__init__.py", line 10, in <module>
    from torch.distributed.launcher.api import (  # noqa: F401
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\launcher\api.py", line 15, in <module>
    from torch.distributed.elastic.agent.server.api import WorkerSpec
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\elastic\agent\server\__init__.py", line 40, in <module>
    from .local_elastic_agent import TORCHELASTIC_ENABLE_FILE_TIMER, TORCHELASTIC_TIMER_FILE
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\elastic\agent\server\local_elastic_agent.py", line 19, in <module>
    import torch.distributed.elastic.timer as timer
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\elastic\timer\__init__.py", line 44, in <module>
    from .file_based_local_timer import FileTimerClient, FileTimerServer, FileTimerRequest  # noqa: F401
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\elastic\timer\file_based_local_timer.py", line 63, in <module>
    class FileTimerClient(TimerClient):
  File "D:\ai\sd_env\lib\site-packages\torch\distributed\elastic\timer\file_based_local_timer.py", line 81, in FileTimerClient
    def __init__(self, file_path: str, signal=signal.SIGKILL) -> None:
AttributeError: module 'signal' has no attribute 'SIGKILL'. Did you mean: 'SIGILL'?

System Info

Windows 11
Python 3.10.x
Diffusers 0.7.0
Transformers 4.24.0
Torch 1.13.0
Onnxruntime 1.13.1
Onnxruntime-directml 1.13.1

@averad averad added the bug Something isn't working label Nov 3, 2022
@averad averad changed the title Diffusers 0.7.0 - "import OnnxStableDiffusionPipeline" results in Traceback Error Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error Nov 3, 2022
@averad averad changed the title Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error (Windows & MacOs) Nov 3, 2022
@averad averad changed the title Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error (Windows & MacOs) Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error Nov 3, 2022
@averad averad changed the title Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error Diffusers 0.7.0 - Torch Accelerator - "import OnnxStableDiffusionPipeline" results in Traceback Error (DmlExecutionProvider) Nov 3, 2022
@averad
Copy link
Author

averad commented Nov 4, 2022

@anton-l verified that this has been fixed in 0.7.1 Patch via pull#1134

  • Patch is now live as of 11/4/2022

Note:

  • safety_checker=None does not work in the OnnxStableDiffusionPipeline (Opened Issue#1138)
  • pipe.safety_checker = lambda images, **kwargs: (images, False) no longer works in diffusers 0.7.1

@averad averad closed this as completed Nov 4, 2022
@teddybee
Copy link

teddybee commented Nov 4, 2022

Actually the issue is still exist for me with 0.71:
Python 3.10.4, it fails at the line of import.
NOTE: Redirects are currently not supported in Windows or MacOs. Traceback (most recent call last): File "D:\Python\stablediffusion-api\backend\test2.py", line 3, in <module> from diffusers import StableDiffusionPipeline File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\diffusers\__init__.py", line 20, in <module> from .modeling_utils import ModelMixin File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\diffusers\modeling_utils.py", line 50, in <module> import accelerate File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\accelerate\__init__.py", line 7, in <module> from .accelerator import Accelerator File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\accelerate\accelerator.py", line 27, in <module> from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\accelerate\checkpointing.py", line 24, in <module> from .utils import ( File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\accelerate\utils\__init__.py", line 96, in <module> from .launch import PrepareForLaunch, _filter_args, get_launch_prefix File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\accelerate\utils\launch.py", line 25, in <module> import torch.distributed.run as distrib_run File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\run.py", line 386, in <module> from torch.distributed.launcher.api import LaunchConfig, elastic_launch File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\launcher\__init__.py", line 10, in <module> from torch.distributed.launcher.api import ( # noqa: F401 File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\launcher\api.py", line 15, in <module> from torch.distributed.elastic.agent.server.api import WorkerSpec File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\elastic\agent\server\__init__.py", line 40, in <module> from .local_elastic_agent import TORCHELASTIC_ENABLE_FILE_TIMER, TORCHELASTIC_TIMER_FILE File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\elastic\agent\server\local_elastic_agent.py", line 19, in <module> import torch.distributed.elastic.timer as timer File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\elastic\timer\__init__.py", line 44, in <module> from .file_based_local_timer import FileTimerClient, FileTimerServer, FileTimerRequest # noqa: F401 File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\elastic\timer\file_based_local_timer.py", line 63, in <module> class FileTimerClient(TimerClient): File "D:\Python\stablediffusion-api\backend\.venv\lib\site-packages\torch\distributed\elastic\timer\file_based_local_timer.py", line 81, in FileTimerClient def __init__(self, file_path: str, signal=signal.SIGKILL) -> None: AttributeError: module 'signal' has no attribute 'SIGKILL'. Did you mean: 'SIGILL'?

@averad
Copy link
Author

averad commented Nov 4, 2022

@teddybee you need to remove the accelerate package

pip uninstall accelerate

@teddybee
Copy link

teddybee commented Nov 4, 2022

@averad Thank you, its working now.

@patrickvonplaten
Copy link
Contributor

Note that from diffusers==0.7.2 onward accelerate is not a hard dependency anymore. It is nevertheless surprising to get a 'SIGILL' issue when running on Windows or Mac.

@anton-l could you maybe check if you can reproduce this error with accelerate is installed?
E.g. do you also get this error when running:

from diffusers import OnnxStableDiffusionPipeline
height=512
width=512
num_inference_steps=50
guidance_scale=7.5
eta=0.0
prompt = "a photo of an astronaut riding a horse on mars"
negative_prompt="bad hands, blurry"
pipe = OnnxStableDiffusionPipeline.from_pretrained("./stable-diffusion-v1-5", revision="onnx", provider="DmlExecutionProvider", device_map="auto")
image = pipe(prompt, height, width, num_inference_steps, guidance_scale, negative_prompt, eta).images[0] 
image.save("astronaut_rides_horse.png")

?

Also @pcuenca @anton-l, we should not get this error when having accelerate installed and not using ONNX on Mac or Windows no?

E.g. the following should always work with accelerate installed on all Linux, Windows and Mac:

import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipe = pipe.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]  

@anton-l @pcuenca could we maybe verify this? If it doesn't work we need to adapt the warning.

@anton-l
Copy link
Member

anton-l commented Nov 7, 2022

@patrickvonplaten the Windows API does not implement signal.SIGKILL (see available signals here), so the access to signal.SIGKILL imported by torch.distributed imported by accelerate causes the error.

The quick solution is to not import accelerate if the platform is Win.

@pcuenca
Copy link
Member

pcuenca commented Nov 7, 2022

@patrickvonplaten It works on macOS with accelerate versions 0.13.2 and 0.14 from main (replacing "cuda" with "mps"). Tested with diffusers 0.7.2 and main.

@patrickvonplaten
Copy link
Contributor

patrickvonplaten commented Nov 7, 2022

Gotcha - thanks @anton-l ! So I guess the solution is to relax this warning to a logger.info if the platform is windows no?

Maybe also cc @sgugger in case this is relevant/interesting for accelerate

@sgugger
Copy link
Contributor

sgugger commented Nov 7, 2022

The cause is in torch 1.13, not Accelerate. Downgrading PyTorch to 1.12 should fix the issue.

@anton-l
Copy link
Member

anton-l commented Nov 7, 2022

Ah, sorry for missing that, thanks @sgugger!

Linking the issue to track:
pytorch/pytorch#85427

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

6 participants