AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
143.48k stars 27.01k forks source link

[Bug]: Can't get SDXL1.0_base to run in Automatic111 on Apple Silicon, how to fix? #12137

Open LgnGithub opened 1 year ago

LgnGithub commented 1 year ago

Is there an existing issue for this?

What happened?

Updated Automatic1111 to latest version.

Apple Silicon 32GB RAM.

Disabled all extensions to be safe.

sd_xl_offset model works fine, but when I try to load

sd_xl_base_1.0 does not load. I get this error


Loading weights [31e35c80fc] from /Users/Documents/GitHub/stable-diffusion-webui/models/Stable-diffusion/sd_xl_base_1.0.safetensors

WARNING:modules.mac_specific:MPS garbage collection failed

Traceback (most recent call last):
  File "/Users/Documents/GitHub/stable-diffusion-webui/modules/mac_specific.py", line 37, in torch_mps_gc
    from torch.mps import empty_cache

ModuleNotFoundError: No module named 'torch.mps'

Creating model from config: /Users/Documents/GitHub/stable-diffusion-webui/repositories/generative-models/configs/inference/sd_xl_base.yaml

Failed to create model quickly; will retry using slow method.
changing setting sd_model_checkpoint to sd_xl_base_1.0.safetensors [31e35c80fc]: AssertionError

Traceback (most recent call last):

  File "/Users/Documents/GitHub/stable-diffusion-webui/modules/shared.py", line 633, in set
    self.data_labels[key].onchange()

  File "/Users/Documents/GitHub/stable-diffusion-webui/modules/call_queue.py", line 14, in f
    res = func(*args, **kwargs)

  File "/Users/Documents/GitHub/stable-diffusion-webui/webui.py", line 238, in <lambda>
    shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: modules.sd_models.reload_model_weights()), call=False)

  File "/Users/Documents/GitHub/stable-diffusion-webui/modules/sd_models.py", line 578, in reload_model_weights
    load_model(checkpoint_info, already_loaded_state_dict=state_dict)

  File "/Users/Documents/GitHub/stable-diffusion-webui/modules/sd_models.py", line 504, in load_model
    sd_model = instantiate_from_config(sd_config.model)

  File "/Users/Documents/GitHub/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/util.py", line 89, in instantiate_from_config
    return get_obj_from_str(config["target"])(**config.get("params", dict()))

  File "/Users/Documents/GitHub/stable-diffusion-webui/repositories/generative-models/sgm/models/diffusion.py", line 65, in __init__
    self._init_first_stage(first_stage_config)

  File "/Users/Documents/GitHub/stable-diffusion-webui/repositories/generative-models/sgm/models/diffusion.py", line 106, in _init_first_stage
    model = instantiate_from_config(config).eval()

  File "/Users/Documents/GitHub/stable-diffusion-webui/repositories/generative-models/sgm/util.py", line 175, in instantiate_from_config
    return get_obj_from_str(config["target"])(**config.get("params", dict()))

  File "/Users/Documents/GitHub/stable-diffusion-webui/repositories/generative-models/sgm/models/autoencoder.py", line 295, in __init__
    self.encoder = Encoder(**ddconfig)

  File "/Users/Documents/GitHub/stable-diffusion-webui/repositories/generative-models/sgm/modules/diffusionmodules/model.py", line 553, in __init__
    self.mid.attn_1 = make_attn(block_in, attn_type=attn_type)

  File "/Users/Documents/GitHub/stable-diffusion-webui/repositories/generative-models/sgm/modules/diffusionmodules/model.py", line 286, in make_attn
    assert XFORMERS_IS_AVAILABLE, (

AssertionError: We do not support vanilla attention in 1.12.1 anymore, as it is too expensive. Please install xformers via e.g. 'pip install xformers==0.0.16'

How to resolve this?

All the other models run fine and previous models run fine, too, so it's something to do with SD_XL_1.0 base specifically.

Steps to reproduce the problem

described above

What should have happened?

should have loaded model

Version or Commit where the problem happens

version: v1.5.1

What Python version are you running on ?

Python 3.10.x

What platforms do you use to access the UI ?

MacOS

What device are you running WebUI on?

Other GPUs

Cross attention optimization

Automatic

What browsers do you use to access the UI ?

Mozilla Firefox

Command Line Arguments

#!/bin/bash
#########################################################
# Uncomment and change the variables below to your need:#
#########################################################

# Install directory without trailing slash
#install_dir="/home/$(whoami)"

# Name of the subdirectory
#clone_dir="stable-diffusion-webui"

# Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS="--medvram --opt-split-attention"
#export COMMANDLINE_ARGS=""

# python3 executable
#python_cmd="python3"

# git executable
#export GIT="git"

# python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
#venv_dir="venv"

# script to launch to start the app
#export LAUNCH_SCRIPT="launch.py"

# install command for torch
#export TORCH_COMMAND="pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113"

# Requirements file to use for stable-diffusion-webui
#export REQS_FILE="requirements_versions.txt"

# Fixed git repos
#export K_DIFFUSION_PACKAGE=""
#export GFPGAN_PACKAGE=""

# Fixed git commits
#export STABLE_DIFFUSION_COMMIT_HASH=""
#export CODEFORMER_COMMIT_HASH=""
#export BLIP_COMMIT_HASH=""

# Uncomment to enable accelerated launch
#export ACCELERATE="True"

# Uncomment to disable TCMalloc
#export NO_TCMALLOC="True"

###########################################

List of extensions

all disabled

Console logs

-

Additional information

No response

Zak088 commented 1 year ago

I have the same issue regarding the load of SDXL but a different error , it start to download a 10GB file and I don't know why, I already downloaded the Model and put it in the models directory but when I Load inside the A1111 it start this

Screenshot 2023-07-28 at 4 48 27 PM
ClashSAN commented 1 year ago

I'm not sure if things work on macos properly yet. https://github.com/brkirch/stable-diffusion-webui best check the releases here, and check the commits. Some people get this working in cpu mode and use --upcast-sampling to improve performance.

remystic commented 1 year ago

were you able to get it started? i couldn't even with version 0.9

hlktrkn commented 1 year ago

Same error on M1Mac 32GB , waiting for the solution.

vincentmaikel commented 1 year ago

Same, M1 Max 64 GB , waiting for solution.

Torch is installed but I still get the error:

answerWJ commented 1 year ago

Same error on M1Mac 16GB , waiting for the solution. but,It doesn't affect my use,roll back to version 1.4

answerWJ commented 1 year ago

Same error on M1Mac 16GB , waiting for the solution. but,It doesn't affect my use,oll back to version 1.4

sij-ai commented 1 year ago

The experimental offline standalone Mac installer worked for me (M1 Max 64gb) - https://github.com/brkirch/stable-diffusion-webui/releases/tag/20230804_experimental

justbuilding commented 1 year ago

pip install torch==2.0.1 , it solved when the error is "Traceback (most recent call last): File "/Users/huangjiajun/Desktop/NovelAI/stable-diffusion-webui/modules/mac_specific.py", line 37, in torch_mps_gc

from torch.mps import empty_cache

ModuleNotFoundError: No module named 'torch.mps'"

uakihir0 commented 1 year ago

reinstalled torch and solved this problem. sh webui.sh --reinstall-torch

abstractrealism commented 10 months ago

pip install torch==2.0.1 , it solved when the error is "Traceback (most recent call last): File "/Users/huangjiajun/Desktop/NovelAI/stable-diffusion-webui/modules/mac_specific.py", line 37, in torch_mps_gc #from torch.mps import empty_cache ModuleNotFoundError: No module named 'torch.mps'"

Thank you! This fixed my issue, which was slightly different (kept getting a NansException) and none of the other solutions I found here or on reddit were fixing it

PRIxMAL commented 9 months ago

reinstalled torch and solved this problem. sh webui.sh --reinstall-torch

where to type this?

PRIxMAL commented 9 months ago

pip install torch==2.0.1 , it solved when the error is "Traceback (most recent call last): File "/Users/huangjiajun/Desktop/NovelAI/stable-diffusion-webui/modules/mac_specific.py", line 37, in torch_mps_gc #from torch.mps import empty_cache ModuleNotFoundError: No module named 'torch.mps'"

Thank you! This fixed my issue, which was slightly different (kept getting a NansException) and none of the other solutions I found here or on reddit were fixing it

hi, please help me, I have same problem, how did you solve it? I tried reinstalling torch it doesn't work

abstractrealism commented 9 months ago

pip install torch==2.0.1 , it solved when the error is "Traceback (most recent call last): File "/Users/huangjiajun/Desktop/NovelAI/stable-diffusion-webui/modules/mac_specific.py", line 37, in torch_mps_gc #from torch.mps import empty_cache ModuleNotFoundError: No module named 'torch.mps'"

Thank you! This fixed my issue, which was slightly different (kept getting a NansException) and none of the other solutions I found here or on reddit were fixing it

hi, please help me, I have same problem, how did you solve it? I tried reinstalling torch it doesn't work

Just type pip install torch==2.0.1 in a terminal window and hit enter. An incompatible version was getting installed by default. That said, I'm getting a different error now..

Jamie-Rodriguez commented 9 months ago

reinstalled torch and solved this problem. sh webui.sh --reinstall-torch

Just to add another data point, I have an M1 Macbook and was getting the same error as the original poster. Reinstalling PyTorch as above fixed the issue for me. Thank you!


The existing installation of PyTorch was 1.12.1. Below are all the Python packages that were updated with this command:

Collecting mpmath>=0.19
  Using cached mpmath-1.3.0-py3-none-any.whl (536 kB)
Installing collected packages: mpmath, sympy, torch, torchvision
  Attempting uninstall: torch
    Found existing installation: torch 1.12.1
    Uninstalling torch-1.12.1:
      Successfully uninstalled torch-1.12.1
  Attempting uninstall: torchvision
    Found existing installation: torchvision 0.13.1
    Uninstalling torchvision-0.13.1:
      Successfully uninstalled torchvision-0.13.1
Successfully installed mpmath-1.3.0 sympy-1.12 torch-2.0.1 torchvision-0.15.2
yaoang commented 7 months ago

reinstalled torch and solved this problem. sh webui.sh --reinstall-torch

I tried this and fixed, thanks

wastu01 commented 6 months ago

reinstalled torch and solved this problem. sh webui.sh --reinstall-torch

I tried this and fixed too, thanks