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

M1 issues (multiple) #1135

Closed
Homemaderobot opened this issue Sep 26, 2022 · 59 comments
Closed

M1 issues (multiple) #1135

Homemaderobot opened this issue Sep 26, 2022 · 59 comments
Labels
asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance

Comments

@Homemaderobot
Copy link

Homemaderobot commented Sep 26, 2022

Am new to SD web ui, looks awesome but had issues installing on my M1 Max 32GB, and also a performance issue which I think could be bugs.

As others have noted, following the installation instructions on https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon by running curl -s https://raw.githubusercontent.com/dylancl/stable-diffusion-webui-mps/master/setup_mac.sh just prints in the terminal window.

and https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/setup_mac.sh gives a 404

So I ran https://raw.githubusercontent.com/dylancl/stable-diffusion-webui-mps/master/setup_mac.sh locally. This ran but terminates early after installing the repositories, with this error:

ERROR
The check for the models & required repositories has failed.
Please check if the model is in place and the repos are cloned.
You can find the model in stable-diffusion-webui/models/sd-v1-4.ckpt
You can find the repos in stable-diffusion-webui/repositories/
ERROR

[model and repos are all in place from what I can tell].

I tried the .sh installer here dylancl@f78c018 which ran OK, to completion, and launched web ui. Great, however...

... with these settings: Txt2Img / 20 step / Euler / 1 iteration / 7 CFG scale ... it takes 91 seconds (4.28 s/it)

and I get this message in the terminal...

/Users/[me]/miniconda/lib/python3.9/site-packages/k_diffusion/external.py:71: UserWarning: The operator 'aten::frac.out' is not currently supported on the MPS backend and will fall back to run on the CPU. This may have performance implications. (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/aten/src/ATen/mps/MPSFallback.mm:11.)

With exact same settings + prompt on my M1 using InvokeAI, it takes just 15 seconds (6 times faster). I'd guess the GPU isn't being used for me with webui?

When I finish my session, I get this error:

Interrupted with signal 2 in <frame at 0x2b2a36cf0, file '/Users/[me]/miniconda/lib/python3.9/site-packages/gradio/blocks.py', line 1249, code block_thread>
(base) MacBook-Pro-2:~ [me]$ /Users/[me]/miniconda/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
warnings.warn('resource_tracker: There appear to be %d '

Then when I try and re-launch it fails and I get this...

WARNING: overwriting environment variables set in the machine
overwriting variable PYTORCH_ENABLE_MPS_FALLBACK
Already up to date.
Warning: LDSR not found at path /Users/jonathansykes/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py
Traceback (most recent call last):
File "/Users/[me]/stable-diffusion-webui/webui.py", line 8, in
from modules.shared import opts, cmd_opts, state
File "/Users/[me]/stable-diffusion-webui/modules/shared.py", line 5, in
import gradio as gr
ModuleNotFoundError: No module named 'gradio'

... a reinstallation gets it running again, but get exact same results i.e. runs OK once, then dies.

I do have InvokeAI installed too - could that be an issue or is it something else?

Thanks! Jon

@Homemaderobot Homemaderobot added the bug-report Report of a bug, yet to be confirmed label Sep 26, 2022
@dfaker dfaker added asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance and removed bug-report Report of a bug, yet to be confirmed labels Sep 27, 2022
@L0CKZ0R
Copy link

L0CKZ0R commented Sep 27, 2022

I'm having the same issue with performance
The operator 'aten::frac.out' is not currently supported on the MPS backend and will fall back to run on the CPU

@dylancl
Copy link
Collaborator

dylancl commented Sep 27, 2022

Hi, the instructions and install script have been updated. Could you try the latest changes and see if it's any different?

I'm having the same issue with performance The operator 'aten::frac.out' is not currently supported on the MPS backend and will fall back to run on the CPU

This is expected and not a bug. The warning has no impact on the performance of images being generated - for more information read: pytorch/pytorch#80278 (comment)

@Homemaderobot
Copy link
Author

Homemaderobot commented Sep 27, 2022

Hi, the instructions and install script have been updated. Could you try the latest changes and see if it's any different?

Thank you for your support,

I reinstalled via instructions on https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon

Seemingly runs and installs, however upon completion the auto-run returns this error:

Warning: LDSR not found at path /Users/[me]/Documents/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py
Traceback (most recent call last):
File "/Users/[me]/Documents/stable-diffusion-webui/webui.py", line 8, in
from modules.shared import opts, cmd_opts, state
File "/Users/[me]/Documents/stable-diffusion-webui/modules/shared.py", line 5, in
import gradio as gr
ModuleNotFoundError: No module named 'gradio'

Cleaned up and re-installed and got the same. Manual launch with python webui.py also fails with same error.

Running run_webui_mac.sh I get the following:

The PYTORCH_ENABLE_MPS_FALLBACK variable is not set.
This means that the script will either fall back to CPU or fail.
To fix this, please run the following command:
conda env config vars set PYTORCH_ENABLE_MPS_FALLBACK=1
Or, try running the script again.

So I follow those instructions and run_webui_mac.sh again:

WARNING: overwriting environment variables set in the machine
overwriting variable PYTORCH_ENABLE_MPS_FALLBACK
All files are in place. Continuing installation.
ERROR
The web-ui conda environment is not activated.
Please activate the web-ui conda environment and try again.
HINT: conda activate web-ui
ERROR

(web-ui conda environment is activated)

Tried python webui.py again but still returns that same error after installation / auto-run.

Thanks. Jon

@dylancl
Copy link
Collaborator

dylancl commented Sep 27, 2022

That's odd.

Warning: LDSR not found at path /Users/[me]/Documents/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py
Traceback (most recent call last):
File "/Users/[me]/Documents/stable-diffusion-webui/webui.py", line 8, in
from modules.shared import opts, cmd_opts, state
File "/Users/[me]/Documents/stable-diffusion-webui/modules/shared.py", line 5, in
import gradio as gr
ModuleNotFoundError: No module named 'gradio'

This indicates that the dependencies either didn't get installed, or did get installed but not in the right environment.

The other warnings/failures seem to be because I screwed up the checks in the run_webu_mac.sh script - I've temporarily removed them in the latest commit.

Could you try curling the setup script and running it again? Should it fail, please include a full log of your terminal (you can paste this on GitHub Gist or pastebin for example).

Thanks!

@Homemaderobot
Copy link
Author

Homemaderobot commented Sep 27, 2022

Could you try curling the setup script and running it again?

You mean as per the instructions?

$ cd ~/Documents/
$ curl https://raw.githubusercontent.com/dylancl/stable-diffusion-webui-mps/master/setup_mac.sh -o setup_mac.sh
$ chmod +x setup_mac.sh
$ ./setup_mac.sh

That's what I did previously (Sorry the terminal isn't my natural habitat)

Edit: Sorry think I'm missing your intent... you just want me to do it again in order to get the full log? Anyway, will reinstall and get back

@Homemaderobot
Copy link
Author

Homemaderobot commented Sep 27, 2022

Could you try curling the setup script and running it again? Should it fail, please include a full log of your terminal (you can paste this on GitHub Gist or pastebin for example).

Full [failed] install log...
https://gist.github.com/Homemaderobot/d4923cf2171de3724ae42370d0a986c8

@L0CKZ0R
Copy link

L0CKZ0R commented Sep 27, 2022

That's odd.

Warning: LDSR not found at path /Users/[me]/Documents/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py
Traceback (most recent call last):
File "/Users/[me]/Documents/stable-diffusion-webui/webui.py", line 8, in
from modules.shared import opts, cmd_opts, state
File "/Users/[me]/Documents/stable-diffusion-webui/modules/shared.py", line 5, in
import gradio as gr
ModuleNotFoundError: No module named 'gradio'

This indicates that the dependencies either didn't get installed, or did get installed but not in the right environment.

The other warnings/failures seem to be because I screwed up the checks in the run_webu_mac.sh script - I've temporarily removed them in the latest commit.

Could you try curling the setup script and running it again? Should it fail, please include a full log of your terminal (you can paste this on GitHub Gist or pastebin for example).

Thanks!

I tried this and it failed for me. First therewas no run_webui_mac.sh file in the stable-diffusion-webui folder. I copied the old one but then got the failure of a lack of models

`(base) user@Mac-Studio ~ % cd ~/Documents/
(base) user@Mac-Studio Documents % curl https://raw.githubusercontent.com/dylancl/stable-diffusion-webui-mps/master/setup_mac.sh -o setup_mac.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6165 100 6165 0 0 4443 0 0:00:01 0:00:01 --:--:-- 4470
(base) user@Mac-Studio Documents % chmod +x setup_mac.sh
(base) user@Mac-Studio Documents % ./setup_mac.sh
conda is installed.
no change /Users/user/miniconda/condabin/conda
no change /Users/user/miniconda/bin/conda
no change /Users/user/miniconda/bin/conda-env
no change /Users/user/miniconda/bin/activate
no change /Users/user/miniconda/bin/deactivate
no change /Users/user/miniconda/etc/profile.d/conda.sh
no change /Users/user/miniconda/etc/fish/conf.d/conda.fish
no change /Users/user/miniconda/shell/condabin/Conda.psm1
no change /Users/user/miniconda/shell/condabin/conda-hook.ps1
no change /Users/user/miniconda/lib/python3.9/site-packages/xontrib/conda.xsh
no change /Users/user/miniconda/etc/profile.d/conda.csh
no change /Users/user/.bash_profile
No action taken.

Remove all packages in environment /Users/user/miniconda/envs/web-ui:

Package Plan

environment location: /Users/user/miniconda/envs/web-ui

The following packages will be REMOVED:

bzip2-1.0.8-h620ffc9_4
ca-certificates-2022.07.19-hca03da5_0
certifi-2022.9.14-py310hca03da5_0
libcxx-14.0.6-h848a8c0_0
libffi-3.4.2-hc377ac9_4
ncurses-6.3-h1a28f6b_3
openssl-1.1.1q-h1a28f6b_0
pip-22.1.2-py310hca03da5_0
python-3.10.4-hbdb9e5c_0
readline-8.1.2-h1a28f6b_1
setuptools-63.4.1-py310hca03da5_0
sqlite-3.39.2-h1058600_0
tk-8.6.12-hb8d0fd4_0
tzdata-2022c-h04d1e81_0
wheel-0.37.1-pyhd3eb1b0_0
xz-5.2.5-h1a28f6b_1
zlib-1.2.12-h5a0b063_3

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Collecting package metadata (current_repodata.json): done
Solving environment: done

==> WARNING: A newer version of conda exists. <==
current version: 4.12.0
latest version: 22.9.0

Please update conda by running

$ conda update -n base -c defaults conda

Package Plan

environment location: /Users/user/miniconda/envs/web-ui

added / updated specs:
- python=3.10

The following NEW packages will be INSTALLED:

bzip2 pkgs/main/osx-arm64::bzip2-1.0.8-h620ffc9_4
ca-certificates pkgs/main/osx-arm64::ca-certificates-2022.07.19-hca03da5_0
certifi pkgs/main/osx-arm64::certifi-2022.9.14-py310hca03da5_0
libcxx pkgs/main/osx-arm64::libcxx-14.0.6-h848a8c0_0
libffi pkgs/main/osx-arm64::libffi-3.4.2-hc377ac9_4
ncurses pkgs/main/osx-arm64::ncurses-6.3-h1a28f6b_3
openssl pkgs/main/osx-arm64::openssl-1.1.1q-h1a28f6b_0
pip pkgs/main/osx-arm64::pip-22.1.2-py310hca03da5_0
python pkgs/main/osx-arm64::python-3.10.4-hbdb9e5c_0
readline pkgs/main/osx-arm64::readline-8.1.2-h1a28f6b_1
setuptools pkgs/main/osx-arm64::setuptools-63.4.1-py310hca03da5_0
sqlite pkgs/main/osx-arm64::sqlite-3.39.2-h1058600_0
tk pkgs/main/osx-arm64::tk-8.6.12-hb8d0fd4_0
tzdata pkgs/main/noarch::tzdata-2022c-h04d1e81_0
wheel pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
xz pkgs/main/osx-arm64::xz-5.2.5-h1a28f6b_1
zlib pkgs/main/osx-arm64::zlib-1.2.12-h5a0b063_3

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

To activate this environment, use

$ conda activate web-ui

To deactivate an active environment, use

$ conda deactivate

Cloning into 'stable-diffusion-webui'...
remote: Enumerating objects: 3302, done.
remote: Total 3302 (delta 0), reused 0 (delta 0), pack-reused 3302
Receiving objects: 100% (3302/3302), 19.96 MiB | 172.00 KiB/s, done.
Resolving deltas: 100% (2295/2295), done.

=============================================
===========STABLE DIFFUSION MODEL============

=============================================
If you've already downloaded the model, you now have time to copy it yourself to stable-diffusion-webui/models/
If you haven't downloaded the model yet, you can enter n to downloaded the model from hugging face.
Have you already installed the model? (y/n) y
Skipping model installation
Cloning into 'repositories/stable-diffusion'...
remote: Enumerating objects: 313, done.
remote: Total 313 (delta 0), reused 0 (delta 0), pack-reused 313
Receiving objects: 100% (313/313), 42.62 MiB | 162.00 KiB/s, done.
Resolving deltas: 100% (114/114), done.
Cloning into 'repositories/taming-transformers'...
remote: Enumerating objects: 1335, done.
remote: Total 1335 (delta 0), reused 0 (delta 0), pack-reused 1335
Receiving objects: 100% (1335/1335), 409.77 MiB | 158.00 KiB/s, done.
Resolving deltas: 100% (280/280), done.
Cloning into 'repositories/CodeFormer'...
remote: Enumerating objects: 346, done.
remote: Counting objects: 100% (72/72), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 346 (delta 53), reused 43 (delta 43), pack-reused 274
Receiving objects: 100% (346/346), 12.03 MiB | 163.00 KiB/s, done.
Resolving deltas: 100% (135/135), done.
Cloning into 'repositories/BLIP'...
remote: Enumerating objects: 274, done.
remote: Counting objects: 100% (109/109), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 274 (delta 89), reused 80 (delta 80), pack-reused 165
Receiving objects: 100% (274/274), 7.67 MiB | 189.00 KiB/s, done.
Resolving deltas: 100% (146/146), done.

====================ERROR====================

The check for the models & required repositories has failed.
Please check if the model is in place and the repos are cloned.
You can find the model in stable-diffusion-webui/models/sd-v1-4.ckpt
You can find the repos in stable-diffusion-webui/repositories/

====================ERROR====================

(base) user@Mac-Studio Documents % ./run_webui_mac.sh
zsh: no such file or directory: ./run_webui_mac.sh
(base) user@Mac-Studio Documents % run_webui_mac.sh
zsh: command not found: run_webui_mac.sh
(base) user@Mac-Studio Documents % cd stable-diffusion-webui
(base) user@Mac-Studio stable-diffusion-webui % run_webui_mac.sh
zsh: command not found: run_webui_mac.sh
(base) user@Mac-Studio stable-diffusion-webui % ls
ESRGAN requirements_versions.txt
README.md screenshot.png
SwinIR script.js
artists.csv scripts
environment-wsl2.yaml style.css
javascript txt2img_Screenshot.png
launch.py webui-user.bat
models webui-user.sh
modules webui.bat
repositories webui.py
requirements.txt webui.sh
(base) user@Mac-Studio stable-diffusion-webui % ./run_webui_mac.sh
zsh: no such file or directory: ./run_webui_mac.sh
(base) user@Mac-Studio stable-diffusion-webui % ./run_webui_mac.sh
Already up to date.
Warning: LDSR not found at path /Users/user/Documents/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py
Traceback (most recent call last):
File "/Users/user/Documents/stable-diffusion-webui/webui.py", line 8, in
from modules.shared import opts, cmd_opts, state
File "/Users/user/Documents/stable-diffusion-webui/modules/shared.py", line 5, in
import gradio as gr
ModuleNotFoundError: No module named 'gradio'

`

@dev-fredericfox
Copy link

Mac M1 here. Getting the same:

Warning: LDSR not found at path /Users/user/Documents/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py error. The WebUI generates a black image not sure if related.
I've tried running it with:

  • run_webui_mac.sh script (but it is missing --precision full --no-half --opt-split-attention-v1 btw)
  • and tried to run python webui.py --precision full --no-half --opt-split-attention-v1 directly.

Always the same LDSR error and black image.

Full Error:

Warning: LDSR not found at path /Users/user/Documents/Code/Stablediffusion/WUI/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
WARNING:root:Pytorch pre-release version 1.13.0.dev20220927 - assuming intent to test it
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Loading weights [7460a6fa] from /Users/user/Documents/Code/Stablediffusion/WUI/stable-diffusion-webui/models/sd-v1-4.ckpt
Global Step: 470000
Model loaded.
Running on local URL:  http://127.0.0.1:7860

@dylancl
Copy link
Collaborator

dylancl commented Sep 27, 2022

  • run_webui_mac.sh script (but it is missing --precision full --no-half --opt-split-attention-v1 btw)

Good catch, fixed.

As mentioned on the wiki, the only 2 samplers that work (for me, but I'm pretty sure it's for everyone running Apple Silicon) are Euler and DPM2. Are you testing with these 2? Aside from that, I don't include the LSDR repo since it also didn't work (for me), and upscaling with REAL-ESRGAN felt good enough.

EDIT: I've just tried a completely clean reinstall using the script and it seems to work fine for me - I'm not sure what the issue is that's causing the repositories not to be cloned correctly...

@selimyaman
Copy link

Mac M2 here. Library loading issue. Same as others above.

  File "/Users/username/Documents/stable-diffusion-webui/modules/shared.py", line 5, in <module>
    import gradio as gr
ModuleNotFoundError: No module named 'gradio'

@dylancl
Copy link
Collaborator

dylancl commented Sep 27, 2022

Could someone having these issues join the Stable Diffusion discord and tag freebo#1770 in #developers-corner please? It'd make it much easier to debug the issue.

@selimyaman
Copy link

Could someone having these issues join the Stable Diffusion discord and tag freebo#1770 in #developers-corner please? It'd make it much easier to debug the issue.

Just did.

@dev-fredericfox
Copy link

As mentioned on the wiki, the only 2 samplers that work (for me, but I'm pretty sure it's for everyone running Apple Silicon) are Euler and DPM2.

@dylancl my bad, I missed the sampeling method caveat for Apple Silicone, that actually did the trick.

@dylancl
Copy link
Collaborator

dylancl commented Sep 27, 2022

@Homemaderobot

I've got an idea of what's causing your issue, I think you're not in the web-ui conda environment (which is where the packages get installed)
/Users/[me]/miniconda/lib/python3.9/... should be /Users/[me]/miniconda3/envs/web-ui/lib/python3.10/...

You've got (a) previous installation(s) of Anaconda, and perhaps Python which is most likely causing the issue.
Please follow this guide to remove all previous installations of Python, and then remove all previous installations of Anaconda/Miniconda. After this, the install should completely without problems.

@selimyaman
Copy link

@Homemaderobot

I've got an idea of what's causing your issue, I think you're not in the web-ui conda environment (which is where the packages get installed) /Users/[me]/miniconda/lib/python3.9/... should be /Users/[me]/miniconda3/envs/web-ui/lib/python3.10/...

You've got (a) previous installation(s) of Anaconda, and perhaps Python which is most likely causing the issue. Please follow this guide to remove all previous installations of Python, and then remove all previous installations of Anaconda/Miniconda. After this, the install should completely without problems.

I followed this and solved the issue. Thanks!

@Homemaderobot
Copy link
Author

You've got (a) previous installation(s) of Anaconda, and perhaps Python which is most likely causing the issue.
Please follow this guide to remove all previous installations of Python, and then remove all previous installations of Anaconda/Miniconda. After this, the install should completely without problems.

Thanks so much Dylancl - sounds like could well be it! Machine is currently tied up doing textual inversion with invoke but will try when it eventually finishes. Does this mean having both invoke and webui forks on my system is not workable?

@dylancl
Copy link
Collaborator

dylancl commented Sep 28, 2022

You've got (a) previous installation(s) of Anaconda, and perhaps Python which is most likely causing the issue.
Please follow this guide to remove all previous installations of Python, and then remove all previous installations of Anaconda/Miniconda. After this, the install should completely without problems.

Does this mean having both invoke and webui forks on my system is not workable?

No, but it's important to keep the environments completely separate. InvokeAI creates the environment ldm while we create the environment web-ui. If you're for example working in InvokeAI first, you always have to conda deactivate first before running ./run_webui_mac.sh.

The best thing to do now would be to just have 1 installation of Python and 1 installation of Miniconda - this will prevent a lot of issues that seem to appear when having multiple installations of Python and/or Miniconda.

@Homemaderobot
Copy link
Author

I had been ensuring I was in the correct environment and both environments were in miniconda3/envs (even though my webui install created a miniconda dir). Sounds like there could well be some conflict going on though. Anyway, will wipe all and start from scratch. Will return with results. Thanks again.

@Homemaderobot
Copy link
Author

I've got an idea of what's causing your issue, I think you're not in the web-ui conda environment (which is where the packages get installed) /Users/[me]/miniconda/lib/python3.9/... should be /Users/[me]/miniconda3/envs/web-ui/lib/python3.10/...

You've got (a) previous installation(s) of Anaconda, and perhaps Python which is most likely causing the issue. Please follow this guide to remove all previous installations of Python, and then remove all previous installations of Anaconda/Miniconda. After this, the install should completely without problems.

Hey @dylancl - I'm still running into problems. I believe I've uninstalled python / anaconda but the install is failing I think when conda activate / deactivate is required because a terminal restart is required?

Full log: https://gist.github.com/Homemaderobot/4c2f35df238a6bbad5d9b26ba8035b69

So I go through the last install steps manually and then getting the following...

Warning: LDSR not found at path /Users/jonathansykes/Documents/stable-diffusion-webui/repositories/latent-diffusion/LDSR.py
Warning: k_diffusion not found at path /Users/jonathansykes/Documents/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/sampling.py
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
Traceback (most recent call last):
File "/Users/jonathansykes/Documents/stable-diffusion-webui/webui.py", line 11, in
import modules.ui
File "/Users/jonathansykes/Documents/stable-diffusion-webui/modules/ui.py", line 26, in
from modules.sd_samplers import samplers, samplers_for_img2img
File "/Users/jonathansykes/Documents/stable-diffusion-webui/modules/sd_samplers.py", line 8, in
import k_diffusion.sampling
ModuleNotFoundError: No module named 'k_diffusion'

Full log here: https://gist.github.com/Homemaderobot/0eeabade880368343b70bdd7b5089da2

@victorca25
Copy link
Contributor

@Homemaderobot LDSR is not a hard requirement, but k_diffusion is imported in the webui script. You can fix this by cloning the repo to the expected directory or by adding it in the installation script (setup_mac.sh). For example, add this in line 76 of the script:
git clone https://github.com/crowsonkb/k-diffusion.git repositories/k-diffusion
And running it again.

@Homemaderobot
Copy link
Author

git clone https://github.com/crowsonkb/k-diffusion.git repositories/k-diffusion
And running it again.

It worked! Thanks so much @victorca25 and @dylancl for helping me out. Even better I've got Invoke running as well with seemingly no issues.

Performance is still an issue though (as per my first post in the thread). With the following settings: Txt2Img / 20 step / Euler / 1 iteration / 7 CFG scale - I'm consistently getting a generation time of 91 secs (compared to just 15 seconds with Invoke with exact same settings). Any thoughts on why that might be? I do get a warning about 'aten::frac.out' not being supported:

txt2img: an astronaut on a horse
/Users/jon/Documents/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/external.py:71: UserWarning: The operator 'aten::frac.out' is not currently supported on the MPS backend and will fall back to run on the CPU. This may have performance implications. (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/aten/src/ATen/mps/MPSFallback.mm:11.)
low_idx, high_idx, w = t.floor().long(), t.ceil().long(), t.frac()
100%|████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [01:30<00:00, 4.51s/it]
Total progress: 100%|████████████████████████████████████████████████████████████████████████████████| 20/20 [01:25<00:00, 4.29s/it]

(GPU does seem to be maxing out looking at GPU history.).

@dylancl
Copy link
Collaborator

dylancl commented Sep 30, 2022

git clone https://github.com/crowsonkb/k-diffusion.git repositories/k-diffusion

I've updated the installation instructions to include this repo, but IIRC wasn't this normally included as a submodule in the 4 previously cloned repositories? 🤔 Either way, fixed.

@Birch-san
Copy link

Birch-san commented Sep 30, 2022

@Homemaderobot try my fork of k-diffusion; I wrote a GPU implementation of Tensor#frac(), and a few other fixes for M1. Whilst I've not tried every sampler: I confirm that Heun, Euler and Euler ancestral work (I fixed the black image problem).

https://github.com/Birch-san/k-diffusion

@Birch-san
Copy link

If you're seeing speed issues: are you using PyTorch nightly? There was a 6x perf regression introduced a few days ago:
pytorch/pytorch#85224 (comment)

Even overlooking that recent issue: generally nightly is 5~6% slower than stable right now, even though it supports more operations on-GPU:
pytorch/pytorch#85297

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

can the installer just be more simpler....

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

The check for the models & required repositories has failed.
Please check if the model is in place and the repos are cloned.
You can find the model in stable-diffusion-webui/models/sd-v1-4.ckpt
You can find the repos in stable-diffusion-webui/repositories/

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

@Maki9009 this is now fixed in the install script, run through the download steps again to get the latest version and it should work significantly faster.

Also updated the script to use @Birch-san's k-diffusion fork instead, which indeed fixes most samplers, so now we have access to most samplers and great performance again 😄

i just had the you cant find model and repo issue again... this is what i meant why it wasnt easy to install the way i managed to make it work, was by using this

https://raw.githubusercontent.com/dylancl/stable-diffusion-webui-mps/f78c018f577e744fb9b2a44d0ca82cec06c1b035/setup_mac.sh

this worked in installing perfectly, but i had to add k-sampler by myself..and it was slow, Now with this new update. It cant find the models nor repos

@dylancl
Copy link
Collaborator

dylancl commented Oct 1, 2022

this worked in installing perfectly, but i had to add k-sampler by myself..and it was slow, Now with this new update. It cant find the models nor repos

I would need to see the log of the install, the errors during install are pretty clear in that they explain exactly what's wrong, in this case either the modal not being in the correct location or some of the repos not being cloned.

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

this worked in installing perfectly, but i had to add k-sampler by myself..and it was slow, Now with this new update. It cant find the models nor repos

I would need to see the log of the install, the errors during install are pretty clear in that they explain exactly what's wrong, in this case either the modal not being in the correct location or some of the repos not being cloned.

it doesnt say error.. it just cant find them,

If you've already downloaded the model, you now have time to copy it yourself to stable-diffusion-webui/models/
If you haven't downloaded the model yet, you can enter n to downloaded the model from hugging face.
Have you already installed the model? (y/n) y
Skipping model installation
Cloning into 'repositories/stable-diffusion'...
remote: Enumerating objects: 313, done.
remote: Total 313 (delta 0), reused 0 (delta 0), pack-reused 313
Receiving objects: 100% (313/313), 42.63 MiB | 16.13 MiB/s, done.
Resolving deltas: 100% (103/103), done.
Cloning into 'repositories/taming-transformers'...
remote: Enumerating objects: 1335, done.
remote: Total 1335 (delta 0), reused 0 (delta 0), pack-reused 1335
Receiving objects: 100% (1335/1335), 409.77 MiB | 12.19 MiB/s, done.
Resolving deltas: 100% (280/280), done.
Cloning into 'repositories/CodeFormer'...
remote: Enumerating objects: 359, done.
remote: Counting objects: 100% (85/85), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 359 (delta 57), reused 50 (delta 45), pack-reused 274
Receiving objects: 100% (359/359), 12.58 MiB | 5.39 MiB/s, done.
Resolving deltas: 100% (139/139), done.
Cloning into 'repositories/BLIP'...
remote: Enumerating objects: 274, done.
remote: Counting objects: 100% (105/105), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 274 (delta 87), reused 80 (delta 80), pack-reused 169
Receiving objects: 100% (274/274), 7.67 MiB | 4.14 MiB/s, done.
Resolving deltas: 100% (145/145), done.
Cloning into 'repositories/k-diffusion'...
remote: Enumerating objects: 676, done.
remote: Counting objects: 100% (214/214), done.
remote: Compressing objects: 100% (47/47), done.
remote: Total 676 (delta 188), reused 178 (delta 167), pack-reused 462
Receiving objects: 100% (676/676), 138.27 KiB | 393.00 KiB/s, done.
Resolving deltas: 100% (460/460), done.
=============================================
====================ERROR====================
=============================================
The check for the models & required repositories has failed.
Please check if the model is in place and the repos are cloned.
You can find the model in stable-diffusion-webui/models/sd-v1-4.ckpt
You can find the repos in stable-diffusion-webui/repositories/
=============================================
====================ERROR====================
=============================================

But like i said... it works with the
https://raw.githubusercontent.com/dylancl/stable-diffusion-webui-mps/f78c018f577e744fb9b2a44d0ca82cec06c1b035/setup_mac.sh
form 6 days ago
this one only needs the k-sampler and pytorch update that you just added.

@Vrk3ds
Copy link

Vrk3ds commented Oct 1, 2022

The check for the models & required repositories has failed.
Please check if the model is in place and the repos are cloned.
You can find the model in stable-diffusion-webui/models/sd-v1-4.ckpt
You can find the repos in stable-diffusion-webui/repositories/

I just had this same error, and then said no on the checkpoint download and just let it download the file from hugginface and it worked.

I also just figured out that you put the checkpoint file in the models directory since that is where it downloads the file to, and then later in the process it moves it into the Stable-Diffusion directory. Is this correct?

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

The check for the models & required repositories has failed.
Please check if the model is in place and the repos are cloned.
You can find the model in stable-diffusion-webui/models/sd-v1-4.ckpt
You can find the repos in stable-diffusion-webui/repositories/

I just had this same error, and then said no on the checkpoint download and just let it download the file from hugginface and it worked.

I also just figured out that you put the checkpoint file in the models directory since that is where it downloads the file to, and then later in the process it moves it into the Stable-Diffusion directory. Is this correct?

yeah ur supposed to put it in there and it should work on from there, but for somereason it isnt working... i made it work with an older fork... not this new though, attempt to rewrite the old one with the new updates.

@dylancl
Copy link
Collaborator

dylancl commented Oct 1, 2022

You're selecting yes when asked if you've downloaded & moved sd-v1-4.ckpt into /stable-diffusion-webui/models/, is this actually the case?

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

You're selecting yes when asked if you've downloaded & moved sd-v1-4.ckpt into /stable-diffusion-webui/models/, is this actually the case?

yes

@dylancl
Copy link
Collaborator

dylancl commented Oct 1, 2022

Are you sure? Since the script deletes the previous stable-diffusion-webui directory so the model placed inside is also deleted every time you run the installation script.

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

Are you sure? Since the script deletes the previous stable-diffusion-webui directory so the model placed inside is also deleted every time you run the installation script.

im 100% sure, anyways I just fixed it. by using the 6-day-old scripts and just adding the k-sampler and PyTorch update you just did it works perfectly. i think something about the new script doesn't work for everyone. it now works and its much faster with the new pytorch fix.

ACTUALLY nvm... im getting a black generated images.. hmmm. i think its the pytorch update...

cuz it worked before

actually nvm nvm... it now works? im so confused.. my first image was black and now they arent black anymore lol.

@Vrk3ds
Copy link

Vrk3ds commented Oct 1, 2022

copying the checkpoint file into the models directory and letting the script move it worked for me.

@Maki9009
Copy link

Maki9009 commented Oct 1, 2022

copying the checkpoint file into the models directory and letting the script move it worked for me.

for me for some odd, reason it didnt work when i tried that. but anyways got it working

@Vrk3ds
Copy link

Vrk3ds commented Oct 1, 2022

I did get this error?

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed cleaning build dir for gfpgan

something to do with GFPGAN?

Any ideas how to fix that?

@Gitterman69
Copy link

I finally got it to run - BUT after checking out https://github.com/TheLastBen/fast-stable-diffusion I feel sad to go back to those slow local speeds.... any way to include those changes for m1 Macs? the speed increase in the colab is insane!

@Vrk3ds
Copy link

Vrk3ds commented Oct 2, 2022

anyone now how to make the webui available on a local network? I see the command line arguments but can't seem to make them work on M1?

@Maki9009
Copy link

Maki9009 commented Oct 2, 2022

I finally got it to run - BUT after checking out https://github.com/TheLastBen/fast-stable-diffusion I feel sad to go back to those slow local speeds.... any way to include those changes for m1 Macs? the speed increase in the colab is insane!

this would be amazing cuz even with the pytorch fix still takes 30 seconds for 20sample image

@Birch-san
Copy link

@Maki9009 I don't think it's straightforward to port those optimizations to Mac. Flash attention takes advantage of how to efficiently use the I/O of the GPU, which means it's programmed natively in CUDA. for M1 we would need somebody to write an implementation from scratch in Metal or Metal Performance Shaders. well, I think lucid has an implementation that just uses PyTorch operations, but I don't know that it's faster. that could be worth checking.

@Gitterman69
Copy link

@Birch-san Thanks for the explanation - a bit sad though! :)
Can't wait to play with SD in 12 month in blazing fast speed to be honest! :)

@Maki9009
Copy link

Maki9009 commented Oct 2, 2022

@Maki9009 I don't think it's straightforward to port those optimizations to Mac. Flash attention takes advantage of how to efficiently use the I/O of the GPU, which means it's programmed natively in CUDA. for M1 we would need somebody to write an implementation from scratch in Metal or Metal Performance Shaders. well, I think lucid has an implementation that just uses PyTorch operations, but I don't know that it's faster. that could be worth checking.

we need an ai that figures out how to port stuff.

@tensojka
Copy link

tensojka commented Oct 2, 2022

Hi, I just got a new M2 Mac and this webui is approximately 3x slower for me than Diffusion Bee out of the box. Are there any optimizations that they do that I perhaps have to turn on? I would love to play with all these features, but it's just so much slower on the same hardware :/

I have a MB Air M2 16 GB

The Mac is passively cooled and gets a bit hot and I didn't save any timing info from earlier runs, but I'm getting approximately 16s per iteration in this current run (I'm running a text prompt file with prompts I enqueued), which is pretty terrible...

I read on the invokeAI website that Apple Silicon users should enable full precision for example.

@dylancl
Copy link
Collaborator

dylancl commented Oct 2, 2022

@tensojka did you run the latest version of the installation script? This downgrades the PyTorch version to a previous one that doesn't have the performance regression. I ran a bunch of prompts today and getting great speeds:
image

@tensojka
Copy link

tensojka commented Oct 2, 2022

@dylancl I installed it a few days back and got to playing with it only now. How do I update? Do I have to reinstall it completely?

It says this on startup: WARNING:root:Pytorch pre-release version 1.13.0.dev20221001 - assuming intent to test it

(Speeds did not improve much after letting the laptop cool down)

@dylancl
Copy link
Collaborator

dylancl commented Oct 2, 2022

@tensojka curl the script again like it says in the instructions and follow those steps. That'll remove the old installation and create a new, clean one.

Also, since Apple Silicone is so well optimized it never reaches temperatures where it starts throttling when using Stable Diffusion, so it's not something you need to worry about 😄

Repository owner deleted a comment from Gitterman69 Oct 3, 2022
Repository owner deleted a comment from Gitterman69 Oct 3, 2022
@Gitterman69
Copy link

Gitterman69 commented Oct 4, 2022

@tensojka did you run the latest version of the installation script? This downgrades the PyTorch version to a previous one that doesn't have the performance regression. I ran a bunch of prompts today and getting great speeds:

I also reinstalled the M1 version with the newest script. my 512x512 speed is perfeect (1.58 s/it) but as soon as you change the resolution to 512x1024 the it/s drops significantly to 18.36 s/it.

============================================
=============================================
=============================================
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
Moving sd-v1-4.ckpt from /Users/bamboozle/stable-diffusion-webui/models to /Users/bamboozle/stable-diffusion-webui/models/Stable-diffusion.
WARNING:root:Pytorch pre-release version 1.13.0.dev20220922 - assuming intent to test it
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Loading weights [7460a6fa] from /Users/bamboozle/stable-diffusion-webui/models/Stable-diffusion/sd-v1-4.ckpt
Global Step: 470000
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
100%|███████████████████████████████████████████| 20/20 [00:34<00:00,  1.71s/it]
Total progress: 100%|███████████████████████████| 20/20 [00:31<00:00,  1.58s/it]
 40%|█████████████████▌                          | 8/20 [02:29<03:40, 18.36s/it]
Total progress:  40%|███████████▏                | 8/20 [02:11<03:32, 17.69s/it]


@blakelee
Copy link

blakelee commented Oct 5, 2022

I finally got this script working. I had to do a few things and maybe others have a similar situation to me. I had transferred everything from my old intel mac to my new m1 mac which copied over /usr/local/bin with all the intel compiled programs. I deleted that as well as removed rosetta and then reran the script. The script now works. For anyone else having issues that no one else seems to be having, that may be one of the issues

@Gitterman69
Copy link

Error while inpainting on M1 with "restore faces" option activated.

=============================================
=============================================
=============================================
=============================================
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
Moving sd-v1-4.ckpt from /Users/bamboozle/stable-diffusion-webui/models to /Users/bamboozle/stable-diffusion-webui/models/Stable-diffusion.
WARNING:root:Pytorch pre-release version 1.13.0.dev20220922 - assuming intent to test it
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Loading weights [7460a6fa] from /Users/bamboozle/stable-diffusion-webui/models/Stable-diffusion/sd-v1-4.ckpt
Global Step: 470000
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
100%|███████████████████████████████████████████| 20/20 [00:34<00:00,  1.71s/it]
Total progress: 100%|███████████████████████████| 20/20 [00:31<00:00,  1.58s/it]
100%|███████████████████████████████████████████| 20/20 [06:24<00:00, 19.21s/it]
Total progress: 100%|███████████████████████████| 20/20 [06:08<00:00, 18.43s/it]
100%|█████████████████████████████████████████████| 8/8 [02:22<00:00, 17.78s/it]
Total progress: 100%|█████████████████████████████| 8/8 [02:04<00:00, 15.54s/it]100%|███████████████████████████████████████████| 16/16 [00:30<00:00,  1.92s/it]
Total progress: 100%|███████████████████████████| 16/16 [00:26<00:00,  1.63s/it]
  0%|                                                    | 0/16 [00:00<?, ?it/s]100%|███████████████████████████████████████| 16/16 [4:29:45<00:00, 1011.58s/it]
Total progress: 100%|███████████████████████| 16/16 [4:45:57<00:00, 1072.31s/it]
100%|█████████████████████████████████████████████| 8/8 [01:53<00:00, 14.22s/it]
Total progress: 100%|█████████████████████████████| 8/8 [01:33<00:00, 11.70s/it]
100%|█████████████████████████████████████████████| 8/8 [02:28<00:00, 18.52s/it]
Total progress: 100%|█████████████████████████████| 8/8 [02:07<00:00, 15.92s/it]
100%|███████████████████████████████████████████| 20/20 [00:44<00:00,  2.25s/it]
Total progress: 100%|███████████████████████████| 20/20 [00:31<00:00,  1.55s/it]
100%|███████████████████████████████████████████| 14/14 [03:58<00:00, 17.03s/it]
Downloading: "https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth" to /Users/bamboozle/stable-diffusion-webui/models/Codeformer/codeformer-v0.1.0.pth

100%|████████████████████████████████████████| 359M/359M [00:10<00:00, 36.8MB/s]
Downloading: "https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/detection_Resnet50_Final.pth" to /Users/bamboozle/stable-diffusion-webui/repositories/CodeFormer/weights/facelib/detection_Resnet50_Final.pth

100%|████████████████████████████████████████| 104M/104M [00:05<00:00, 20.3MB/s]
Downloading: "https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_parsenet.pth" to /Users/bamboozle/stable-diffusion-webui/repositories/CodeFormer/weights/facelib/parsing_parsenet.pth

100%|██████████████████████████████████████| 81.4M/81.4M [00:03<00:00, 24.4MB/s]
Error completing request
Arguments: (1, 'man dancing with the death by magritte, surreal, detailed, scarlet red, oil painting, high resolution, 4k', '', 'None', 'None', None, {'image': <PIL.Image.Image image mode=RGBA size=640x832 at 0x3694E5B40>, 'mask': <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=640x832 at 0x3694E4160>}, None, None, 0, 18, 0, 4, 1, True, False, 1, 1, 10.5, 0.75, -1.0, -1.0, 0, 0, 0, False, 832, 640, 0, False, 32, 0, '', '', 0, '', '', 1, 50, 0, False, 4, 1, '<p style="margin-bottom:0.75em">Recommended settings: Sampling Steps: 80-100, Sampler: Euler a, Denoising strength: 0.8</p>', 128, 8, ['left', 'right', 'up', 'down'], 1, 0.05, 128, 4, 0, ['left', 'right', 'up', 'down'], False, False, None, '', '<p style="margin-bottom:0.75em">Will upscale the image to twice the dimensions; use width and height sliders to set tile size</p>', 64, 0, 1, '', 4, '', True, False) {}
Traceback (most recent call last):
  File "/Users/bamboozle/stable-diffusion-webui/modules/ui.py", line 184, in f
    res = list(func(*args, **kwargs))
  File "/Users/bamboozle/stable-diffusion-webui/webui.py", line 64, in f
    res = func(*args, **kwargs)
  File "/Users/bamboozle/stable-diffusion-webui/modules/img2img.py", line 124, in img2img
    processed = process_images(p)
  File "/Users/bamboozle/stable-diffusion-webui/modules/processing.py", line 400, in process_images
    x_sample = modules.face_restoration.restore_faces(x_sample)
  File "/Users/bamboozle/stable-diffusion-webui/modules/face_restoration.py", line 19, in restore_faces
    return face_restorer.restore(np_image)
  File "/Users/bamboozle/stable-diffusion-webui/modules/codeformer_model.py", line 93, in restore
    self.face_helper.get_face_landmarks_5(only_center_face=False, resize=640, eye_dist_threshold=5)
  File "/Users/bamboozle/stable-diffusion-webui/repositories/CodeFormer/facelib/utils/face_restoration_helper.py", line 154, in get_face_landmarks_5
    bboxes = self.face_det.detect_faces(input_img)
  File "/Users/bamboozle/stable-diffusion-webui/repositories/CodeFormer/facelib/detection/retinaface/retinaface.py", line 209, in detect_faces
    loc, conf, landmarks, priors = self.__detect_faces(image)
  File "/Users/bamboozle/stable-diffusion-webui/repositories/CodeFormer/facelib/detection/retinaface/retinaface.py", line 156, in __detect_faces
    loc, conf, landmarks = self(inputs)
  File "/Users/bamboozle/opt/miniconda3/envs/web-ui/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/bamboozle/stable-diffusion-webui/repositories/CodeFormer/facelib/detection/retinaface/retinaface.py", line 121, in forward
    out = self.body(inputs)
  File "/Users/bamboozle/opt/miniconda3/envs/web-ui/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/bamboozle/opt/miniconda3/envs/web-ui/lib/python3.10/site-packages/torchvision/models/_utils.py", line 69, in forward
    x = module(x)
  File "/Users/bamboozle/opt/miniconda3/envs/web-ui/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
  File "/Users/bamboozle/opt/miniconda3/envs/web-ui/lib/python3.10/site-packages/torch/nn/modules/batchnorm.py", line 171, in forward
    return F.batch_norm(
  File "/Users/bamboozle/opt/miniconda3/envs/web-ui/lib/python3.10/site-packages/torch/nn/functional.py", line 2446, in batch_norm
    return torch.batch_norm(
RuntimeError: Placeholder storage has not been allocated on MPS device!


@dylancl
Copy link
Collaborator

dylancl commented Oct 5, 2022

Closing this issue since the OP's issue has been solved. Please create a new issue for any future problems you run into.

@dylancl dylancl closed this as completed Oct 5, 2022
@alelordelo
Copy link

@Maki9009 , what performance do you get in your Mac Studio, and what config does it have?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance
Projects
None yet
Development

No branches or pull requests