question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

diffusers 0.5.1 crashs on MPS with unexpected keyword argument 'device_map' error

See original GitHub issue

Describe the bug

Trying to run Stable Diffusion code with the default scheduler and it simply crashes out every single time with the following error:

Traceback (most recent call last):
  File "/Users/fahim/Code/Python/sd-gui/test.py", line 6, in <module>
    pipe = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-4").to(device)
  File "/Users/fahim/miniconda3/envs/ml/lib/python3.9/site-packages/diffusers/pipeline_utils.py", line 517, in from_pretrained
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "/Users/fahim/miniconda3/envs/ml/lib/python3.9/site-packages/transformers/modeling_utils.py", line 1843, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
TypeError: __init__() got an unexpected keyword argument 'device_map'

Reproduction

Just run the following code:

import torch
from diffusers import StableDiffusionPipeline

device = torch.device("cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu")
pipe = StableDiffusionPipeline.from_pretrained("stable-diffusion-v1-4").to(device)
prompt = "an elf sitting on a toadstool"
result = pipe(prompt)
image = result["sample"][0]

Logs

No response

System Info

macOS Monterey 12.6 Apple M1 Max 32GB diffusers 0.5.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
FahimFcommented, Oct 17, 2022

@patrickvonplaten Upgrading to the the latest transformers did the trick. Thanks!

0reactions
patrickvonplatencommented, Oct 16, 2022

Hey @FahimF,

Thanks a lot for the issue! Could you try updating your transformers version here? Also see: https://github.com/huggingface/diffusers/issues/859

I’ll now also open a PR to prevent this for lower transformers versions

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: __init__() got an unexpected keyword ... - GitHub
from torch import autocast from diffusers import ... Full error message: ... __init__() got an unexpected keyword argument 'device_map'.
Read more >
patrickvonplaten - PullAnswer
have a small problem after upgrade diffusers and others ... diffusers 0.5.1 crashs on MPS with unexpected keyword argument 'device_map' error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found