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

Add working install script for Apple Silicon #4990

Closed
wants to merge 3 commits into from

Conversation

andrewssdd
Copy link

@andrewssdd andrewssdd commented Nov 23, 2022

Will update install instruction in wiki if approved.

Fixes issues:
#4829
#4662

Wiki for mac installation need to be updated. It will resolve
#4743

@andrewssdd
Copy link
Author

@AUTOMATIC1111 , could you please take a look? This addresses install failure for Mac users.

@brkirch
Copy link
Collaborator

brkirch commented Nov 24, 2022

A couple of things:

  • This doesn't fix the script still requiring the Stable Diffusion 1.4 model and not accepting just the 1.5 model
  • I still need to do testing on it to make sure it doesn't create any issues, but we really should have pip install -r requirements.txt in run_webui_mac.sh

Also some things will need to potentially be changed based on whether some currently pending PRs are approved:

We could also potentially use PyTorch 1.13 instead of 1.12.1 so that the newer samplers work, but 1.13 is slower and breaks checkpoint merging and training. A better option is probably to clone the conda environment to install the newer PyTorch and have a second run script for using it.

And also, maybe merge the pip install torchsde line into pip install gdown fastapi psutil to get pip install gdown fastapi psutil torchsde, although if #4961 is approved then we won't need to install torchsde separately anyway as the requirements.txt will do it for us.

All that said, the script doesn't need to be in this repository. If you want to change the currently linked script there is no reason you can't submit a PR to do so.

@0xdevalias
Copy link

All that said, the script doesn't need to be in this repository. If you want to change the currently linked script there is no reason you can't submit a PR to do so.

Doesn't need to, but it would be nice to have everything in the one place IMO.

@andrewssdd
Copy link
Author

@brkirch thanks for your feedback!

I think it is a good practice to put the install script in the same repos so that it can be properly maintained. It has no value as a separate script in another repos.

I am curious why do we want pip install -r requirements.txt in run_webui_mac.sh? We should separate installation and execution. I think we should remove the "git pull" in run_webei_mac.sh

This PR intended to fix installation issue surgically. We can address other issues you mention in separate PRs and see if others agree.

@0xdevalias
Copy link

I am curious why do we want pip install -r requirements.txt in run_webui_mac.sh?

Because as long as the git pull exists, it's required to not break. There was a good 10+ issues on this repo created for basically this reason alone.

We should separate installation and execution. I think we should remove the "git pull" in run_webei_mac.sh

I believe it's currently this way so that newbie users who don't understand how the code/tech works can run the latest updates with minimal steps required.

I have no strong opinion on whether separating it into run and update scripts would be better UX or not.

@andrewssdd
Copy link
Author

Got you. I think it's better to separate them. It's not a good practice to pull and run the latest code every time.

Something could be broken in master and a newbie won't know how to check out a previous version.

We can create an update script if we want better user experience.

@moebis
Copy link

moebis commented Nov 24, 2022

Having a heck of a time trying to install this on a Mac (M1 Ultra). I've completely removed and reinstalled it about 6 times now. I edited the setup_mac.sh to include "torchsde" and still no bueno. Each time it deletes the checkpoints and I have to copy them back (would seem the script could check first before wiping the models directory. I know these should run great on the M1 / Apple silicon because Dream Textures does it inside of Blender and the install is like 2 steps. Any help please? Also will this work with SD 2.0 checkpoints that was just released?

This is one of the errors I see during the install:

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

Got past the torchsde issue, it hangs for a bit at the end (looks like success) and then this:

Traceback (most recent call last):
  File "/Users/moebis/Documents/stable-diffusion-webui/webui.py", line 13, in <module>
  File "/Users/moebis/Documents/stable-diffusion-webui/modules/sd_samplers.py", line 11, in <module>
  File "/Users/moebis/Documents/stable-diffusion-webui/modules/processing.py", line 15, in <module>
    import modules.sd_hijack
  File "/Users/moebis/Documents/stable-diffusion-webui/modules/sd_hijack.py", line 10, in <module>
  File "/Users/moebis/Documents/stable-diffusion-webui/modules/textual_inversion/textual_inversion.py", line 13, in <module>
  File "/Users/moebis/Documents/stable-diffusion-webui/modules/shared.py", line 14, in <module>
    import modules.sd_models
  File "/Users/moebis/Documents/stable-diffusion-webui/modules/sd_models.py", line 12, in <module>
    from modules import shared, modelloader, devices, script_callbacks, sd_vae
ImportError: cannot import name 'sd_vae' from 'modules' (unknown location)

@andrewssdd
Copy link
Author

andrewssdd commented Nov 24, 2022 via email

@johnnymo87
Copy link

This PR intended to fix installation issue surgically. We can address other issues you mention in separate PRs and see if others agree.

I agree with this sentiment. Let's first get approval from @AUTOMATIC1111 on getting the Apple silicon setup scripts merged into this repo as-is, and then separately let's work on making them better.

@RarogCmex
Copy link

It seems this script will no more work with latest git changes (adding SD 2.0 support).

@andrewssdd
Copy link
Author

@RarogCmex thanks for the heads up. Install script fixed.

I notice Euler a sampler is not working now with SD v1. Perhaps its the 2.0 codes. Euler and DIMM works.

And SD 2.0 doesn't work on Mac. We should address in another PR.

@RarogCmex
Copy link

RarogCmex commented Nov 26, 2022 via email

@RarogCmex
Copy link

Checked, Euler a is working with SD1.5 with latest SD2.0 changes.

@andrewssdd
Copy link
Author

andrewssdd commented Nov 26, 2022 via email

@RarogCmex
Copy link

RarogCmex commented Nov 26, 2022 via email

@andrewssdd
Copy link
Author

Thanks for testing. Euler a should be working now.
Also relaxed the check to allow any ckpt models, not just 1.4

@AUTOMATIC1111
Copy link
Owner

What about you host this script somewhere else you have access to and we just add a link to that in the wiki?

@andrewssdd
Copy link
Author

I can do that but then the install script will not be reviewed and can be updated at will. It is opening up the users to malicious attack. Really not a good idea.

@AUTOMATIC1111
Copy link
Owner

I don't want to be the trusted person for the code that I can't run.

@brkirch
Copy link
Collaborator

brkirch commented Nov 28, 2022

I had thought that perhaps the existing scripts already in the repo could get fixed up to work correctly for installing on macOS, but as it turns out even that isn't necessary.

After installing brew (if it is not already installed) then running brew install cmake protobuf rust python git wget, clone this repository with git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui and open webui-user.sh with Xcode and replace its contents with:

Expand
#!/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="--skip-torch-cuda-test --no-half --use-cpu interrogate"

# 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 torchvision==0.13.1 psutil"

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

# Fixed git repos
#export K_DIFFUSION_PACKAGE=""
#export GFPGAN_PACKAGE=""
export K_DIFFUSION_REPO="https://github.com/brkirch/k-diffusion.git"

# Fixed git commits
#export STABLE_DIFFUSION_COMMIT_HASH=""
#export TAMING_TRANSFORMERS_COMMIT_HASH=""
#export CODEFORMER_COMMIT_HASH=""
#export BLIP_COMMIT_HASH=""
export K_DIFFUSION_COMMIT_HASH="51c9778f269cedb55a4d88c79c0246d35bdadb71"

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

# Enable CPU fallback for missing MPS ops
export PYTORCH_ENABLE_MPS_FALLBACK=1

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

Place your Stable Diffusion models into stable-diffusion-webui/models/Stable-diffusion. After that, cd stable-diffusion-webui and ./webui.sh. All the requirements should install successfully, but more importantly you will now be kept up to date with all dependencies whenever you run git stash; git pull; git stash pop and then run the web UI again with ./webui.sh.

Please let me know if there are any problems encountered with this method, but if not then this the wiki should probably be changed to use this instead.

Edit: Added a different fork of k-diffusion (that I created from Birch-san's fork) at https://github.com/brkirch/k-diffusion to fix the black screen with some of the newer samplers. Delete the k-diffusion folder in stable-diffusion-webui/repositories if you already installed using this method before this edit, then replace the contents of webui-user.sh in Xcode again.

Edit 2: Updated webui-user.sh again to add a fix for the DPM fast sampler.

@le-wib
Copy link

le-wib commented Nov 28, 2022

I had thought that perhaps the existing scripts already in the repo could get fixed up to work correctly for installing on macOS, but as it turns out even that isn't necessary.

After installing brew (if it is not already installed) then running brew install cmake protobuf rust python git wget, clone this repository with git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui and open webui-user.sh with Xcode and replace its contents with:

Expand

#!/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="--skip-torch-cuda-test --no-half --use-cpu interrogate"

# 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 torchvision==0.13.1 psutil"

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

# Fixed git repos
#export K_DIFFUSION_PACKAGE=""
#export GFPGAN_PACKAGE=""
export K_DIFFUSION_REPO="https://github.com/Birch-san/k-diffusion.git"

# Fixed git commits
#export STABLE_DIFFUSION_COMMIT_HASH=""
#export TAMING_TRANSFORMERS_COMMIT_HASH=""
#export CODEFORMER_COMMIT_HASH=""
#export BLIP_COMMIT_HASH=""
export K_DIFFUSION_COMMIT_HASH="363386981fee88620709cf8f6f2eea167bd6cd74"

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

# Enable CPU fallback for missing MPS ops
export PYTORCH_ENABLE_MPS_FALLBACK=1

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

Place your Stable Diffusion models into stable-diffusion-webui/models/Stable-diffusion. After that, cd stable-diffusion-webui and ./webui.sh. All the requirements should install successfully, but more importantly you will now be kept up to date with all dependencies whenever you run git pull and then run the web UI again with ./webui.sh.

Please let me know if there are any problems encountered with this method, but if not then this the wiki should probably be changed to use this instead.

I just to test this, and this works like a charm, not a single error in the launching, and eular a works. 1.5 works too and 768-ema too. (only 512-ema.ckpt not working at all)

@0xdevalias
Copy link

I don't want to be the trusted person for the code that I can't run.

@AUTOMATIC1111 While I understand that stance, there are enough macOS users here that would be happy to run/check/etc, and by keeping it together in this main repo, we have the easy opportunity to provide fixes when they need to happen. Currently having it scattered in external places has made it a lot harder than it needs to be IMO. /2c

@brkirch
Copy link
Collaborator

brkirch commented Dec 1, 2022

@AUTOMATIC1111 While I understand that stance, there are enough macOS users here that would be happy to run/check/etc, and by keeping it together in this main repo, we have the easy opportunity to provide fixes when they need to happen. Currently having it scattered in external places has made it a lot harder than it needs to be IMO. /2c

A separate install script is not needed for macOS, with #5286 using webui.sh should be sufficient. @AUTOMATIC1111

@brkirch
Copy link
Collaborator

brkirch commented Jan 4, 2023

Since #5286 was merged and new install instructions added, I'm closing this PR. Go here for the new install instructions and post here if you need any additional support.

@brkirch brkirch closed this Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants