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

[Bug]: Segmentation Fault in webui.py on M1 Mac #5167

Closed
1 task done
rworne opened this issue Nov 28, 2022 · 3 comments
Closed
1 task done

[Bug]: Segmentation Fault in webui.py on M1 Mac #5167

rworne opened this issue Nov 28, 2022 · 3 comments
Labels
bug-report Report of a bug, yet to be confirmed

Comments

@rworne
Copy link

rworne commented Nov 28, 2022

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What happened?

Segmentation faults on M1 mac in webui.py.

When doing a fresh install, webui.py may or may not start up correctly. When it fails (as it does most of the time) it gets a segmentation fault:

Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled No module 'xformers'. Proceeding without it. LatentDiffusion: Running in eps-prediction mode DiffusionWrapper has 859.52 M params. Loading weights [6b508e59] from /Volumes/Mac Data SSD/Developer/stable-diffusion-webui/models/Stable-diffusion/Elysium_Anime_V2.ckpt Loading VAE weights from: /Volumes/Mac Data SSD/Developer/stable-diffusion-webui/models/VAE/kl-f8-anime2.ckpt ./run_webui_mac.sh: line 15: 4213 Segmentation fault: 11 python webui.py --precision full --no-half --use-cpu Interrogate GFPGAN CodeFormer $@

Steps to reproduce the problem

  1. Install Automatic1111
  2. Copy your models back in
  3. Start the WebUI
  4. Exit app
  5. Start WebUI again

On the first run it usually will run OK. Afterwards, when exiting and restarting it will stubbornly get segmentation faults - nondeterministically. Sometimes no, but most of the time yes. To get it working again, I need to nuke it and reinstall.

What should have happened?

Should run without crashing. Stability has gone down a lot over the past few weeks.

Commit where the problem happens

0b5dcb3

What platforms do you use to access UI ?

MacOS

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

python webui.py --precision full --no-half --use-cpu Interrogate GFPGAN CodeFormer $@

Additional information, context and logs

As you can see from the log below, it successfully ran once (as the default model has changed). It refuses to run a second time.

Robert@Mac-Studio stable-diffusion-webui % ./run_webui_mac.sh
To make your changes take effect please reactivate your environment
WARNING: overwriting environment variables set in the machine
overwriting variable {'PYTORCH_ENABLE_MPS_FALLBACK'}
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 10 (delta 6), reused 6 (delta 6), pack-reused 0
Unpacking objects: 100% (10/10), 5.28 KiB | 676.00 KiB/s, done.
From https://github.com/AUTOMATIC1111/stable-diffusion-webui
   bb11bee..0b5dcb3  master     -> origin/master
Updating bb11bee..0b5dcb3
Fast-forward
 modules/call_queue.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++
 modules/sd_models.py  |  4 +--
 modules/ui.py         | 67 ++---------------------------------
 webui.py              | 30 ++--------------
 4 files changed, 106 insertions(+), 93 deletions(-)
 create mode 100644 modules/call_queue.py
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
No module 'xformers'. Proceeding without it.
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading weights [6b508e59] from /Volumes/Mac Data SSD/Developer/stable-diffusion-webui/models/Stable-diffusion/Elysium_Anime_V2.ckpt
Loading VAE weights from: /Volumes/Mac Data SSD/Developer/stable-diffusion-webui/models/VAE/kl-f8-anime2.ckpt
./run_webui_mac.sh: line 15:  4213 Segmentation fault: 11  python webui.py --precision full --no-half --use-cpu Interrogate GFPGAN CodeFormer $@

Adding: pip install -r requirements.txt to the startup script tends to bring it back (cut for brevity):

Installing collected packages: fairscale, timm, pytorch_lightning
  Attempting uninstall: fairscale
    Found existing installation: fairscale 0.4.9
    Uninstalling fairscale-0.4.9:
      Successfully uninstalled fairscale-0.4.9
  Attempting uninstall: timm
    Found existing installation: timm 0.6.7
    Uninstalling timm-0.6.7:
      Successfully uninstalled timm-0.6.7
  Attempting uninstall: pytorch_lightning
    Found existing installation: pytorch-lightning 1.7.6
    Uninstalling pytorch-lightning-1.7.6:
      Successfully uninstalled pytorch-lightning-1.7.6
Successfully installed fairscale-0.4.4 pytorch_lightning-1.7.7 timm-0.4.12
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
No module 'xformers'. Proceeding without it.
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading weights [6b508e59] from /Volumes/Mac Data SSD/Developer/stable-diffusion-webui/models/Stable-diffusion/Elysium_Anime_V2.ckpt
Loading VAE weights from: /Volumes/Mac Data SSD/Developer/stable-diffusion-webui/models/VAE/kl-f8-anime2.ckpt
Applying cross attention optimization (InvokeAI).
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Embeddings: 
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.

@rworne rworne added the bug-report Report of a bug, yet to be confirmed label Nov 28, 2022
@cooperdk
Copy link

cooperdk commented Nov 29, 2022

It doesn't seem like it actually did run once.

You get a pretty clear error: Torch is not compiled with CUDA enabled.

Generally, using Mac means disabling yourself from a lot of stuff, especially stuff like this, and even more so when using M1/M2 which is ARM-based specialized architecture and the GPU is proprietary (and non-CUDA) as well...
That means you need to disable GPU computing in the settings. Your GPU, while having neural capability, doesn't have CUDA capability, leaving you able to only compute images with your CPU.

Choosing Mac often means choosing non-compatability. I am sure that Applie didn't inform you of that, but that's how it is.

Still, some people made general SD work:
https://replicate.com/blog/run-stable-diffusion-on-m1-mac

(They didn't report compute times, however. Since you basically need a supported card to run this GPU-accellerated, and only Nvidia and AMD are supported, you're in for a wait).

IF you're gonna make it WebUI work, it probably means not using venv, but conda, unless you're able to take something from the first link and apply it to the WebUI installation.

https://towardsdatascience.com/installing-pytorch-on-apple-m1-chip-with-gpu-acceleration-3351dc44d67c

What you CAN maybe do is run SD on CPU only. As a command-line argument, add "--use-cpu all". But again, it will take you at least ten times longer to compute an image.

@rworne
Copy link
Author

rworne commented Nov 29, 2022

It is running on my system. I've been running it for about a month now, and it uses my GPU. Over the past few weeks, stability has gotten pretty bad. I don't know if it was due to the OS update or SD. Both happened about the same time.

No idea why I can try to launch it a half dozen times and get the fault, then suddenly it loads as if there's no problem. It's not memory, as a fresh reboot is no guarantee it'll run either.

@rworne
Copy link
Author

rworne commented Dec 2, 2022

Followed these instructions HERE and the issue cleared up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report Report of a bug, yet to be confirmed
Projects
None yet
Development

No branches or pull requests

4 participants