zdd

zdd

How to make the most of stable-diffusion on Apple M1

Being repeatedly hit by the wave of AIGC, the free 25 Midjourney images haven't taught me the "magic spell" yet. Without a credit card with foreign currency settlement, recharging is too troublesome. So it's time to thank open source again and continue practicing the magic spell of stable diffusion. Apple's M-series chips have powerful computing power. Combined with unified memory technology, we can master SD on M-series Macs. Of course, the prerequisite is at least 16GB of memory!

https://oss.productnose.com/assets/stable-diffusion-demo-2.jpg|inline

Following the principle of avoiding command line usage if possible, I chose https://github.com/AUTOMATIC1111/stable-diffusion-webui open source project to tinker with, and the entire setup process is highly automated. It provides an automatic installation script for Apple's ARM chips.

Preparation of Basic Environment#

You need to have basic runtime environments such as Python and Rust. If you have already installed Homebrew, you can use the following command to install:

brew install cmake protobuf rust [email protected] git wget

Download the Project#

First, go to this project address: https://github.com/AUTOMATIC1111/stable-diffusion-webui

If you know how to use git, you can directly clone the project:

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui

If you don't know how to use git, you can directly download the compressed package of the project code:

[https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/heads/master.zip](https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/heads/master.zip)

Download the Models#

The project code does not include the models. You need to download the well-trained models from the official model library or Hugging Face. The size of image generation models is usually quite large, so it may take some time to download if your network is slow.

Some popular official stable models:

In Hugging Face, you can search for popular models under Text-to-Image.

https://oss.productnose.com/assets/huggingface.png|inline

Finally, place the downloaded models in the following directory of the project:

stable-diffusion-webui/models/Stable-diffusion

Let's Begin#

Go to the terminal in the root directory of the project and execute the following code. Wait for the running prompt to complete, and then you can start the magic by accessing 127.0.0.1:7860 in your browser.

./webui.sh

Under the txt2img menu, enter your magic spell to get started. The following attributes can be adjusted to generate images with different resolutions, quantities, etc. We will learn how to play with them in the following articles (I also need to learn, it's a bit complicated, hahaha).

https://oss.productnose.com/assets/20230323160108.png|inline

About the Experience#

Regarding the speed of generating images, based on my experience with MacBook Pro M1 Pro 32GB, the speed of 512 resolution images is quite fast, usually within 15 seconds. Of course, as you increase the sampling steps and the number of batch generations, the time will also increase. After playing for about half an hour, I can feel the temperature of the MBP rising.

There are some explanations about the use of official Apple ARM in the web UI; I haven't encountered them yet in my usage (mainly because I haven't used some advanced techniques).

Currently most functionality in the web UI works correctly on macOS, with the most notable exceptions being CLIP interrogator and training. Although training does seem to work, it is incredibly slow and consumes an excessive amount of memory. CLIP interrogator can be used but it doesn't work correctly with the GPU acceleration macOS uses so the default configuration will run it entirely via CPU (which is slow).

Most samplers are known to work with the only exception being the PLMS sampler when using the Stable Diffusion 2.0 model. Generated images with GPU acceleration on macOS should usually match or almost match generated images on CPU with the same settings and seed.

Currently, most functionality in the web UI works correctly on macOS, with the most notable exceptions being CLIP interrogator and training. Although training does seem to work, it is incredibly slow and consumes an excessive amount of memory. CLIP interrogator can be used but it doesn't work correctly with the GPU acceleration macOS uses so the default configuration will run it entirely via CPU (which is slow).

Most samplers are known to work, with the only exception being the PLMS sampler when using the Stable Diffusion 2.0 model. Generated images with GPU acceleration on macOS should usually match or almost match generated images on CPU with the same settings and seed.

Next Steps#

Recently, I want to use AIGC to generate beautiful logos for me. Logos drawn without a background in art design are really embarrassing. I will also organize and share tutorials on how to use it based on what I have learned in the practical process. See you later!

References:

https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon#downloading-stable-diffusion-models

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.