Introduction

What is Stable Diffusion?

Acording to the Wikipedia, Stable Diffusion is a form of diffusion model (DM). Introduced in 2015, diffusion models are trained with the objective of removing successive applications of Gaussian noise to training images, and can be thought of as a sequence of denoising autoencoders. Stable Diffusion uses a variant known as a “latent diffusion model” (LDM).

How to install Stable Diffusion?

There are 2 ways to play with Stable Diffusion.

  • Install Stable Diffusion on your local computer
  • Play Stable Diffusion on Colab or other online services

In this article, we will focus on install Stable Diffusion on your local computer.


For Apple Silicon Mac User

There are two main ways to let you play with Stable Diffusion.

Method1: Normal way in terminal

Requirements:

  • A Mac with an M1,M1 Pro,M1 Max,M1 ULTRA M2 chip
  • 16GB RAM or more.
  • macOS 12.3 or higher

Step1

You need to install Python on your Mac

Enter python3 -V to check the version

1
2
python3 -V  
Python 3.10.0
1
2
which python3
/usr/bin/python3
1
2
pip3 --version
pip 22.X.X from XXX

If you need to install Python the eastest way to install that will be use Homebrew. Chick https://brew.sh to know more.

Install the latest version of Python by using the Homebrew

1
2
brew update
brew install python3
Step2

Clone the repository and install the dependencies.

If you haven’t install git, you can install that by typing:

1
2
brew update
brew install git
1
2
3
git clone -b apple-silicon-mps-support https://github.com/bfirsh/stable-diffusion.git
cd stable-diffusion
mkdir -p models/ldm/stable-diffusion-v1/
Step3

Install a vertual environment to install the dependencies:

1
2
python3 -m pip install virtualenv
python3 -m virtualenv venv

Activate vertual environment:

1
source venv/bin/activate

Dectivate vertual environment:

1
deactive

Note: all steps should under the path of the stable-diffusion-v1

Step4

Install necessary packages again

1
brew install Cmake rust protobuf
Step5

Install the dependencies in the list:

1
pip install -r requirements.txt
Step6

Download the weights

Go to the Hugging Face repository, have a read and understand the license, then click “Access repository”.

Download sd-v1-4.ckpt (~4 GB) on that page and save it as models/ldm/stable-diffusion-v1/model.ckpt in the directory you created above.

Step7

Start

1
2
3
python scripts/txt2img.py \
--prompt "a red juicy apple floating in outer space, like a planet" \
--n_samples 1 --n_iter 1 --plms

Note: Step6 and Step7 sources from Replicate


Method2: GUI

  • GUI software called Diffusionbee<—Chick here to start

    Requirements:

    • A Mac with an M1,M1 Pro,M1 Max,M1 ULTRA M2 chip
    • 16GB RAM or more.
    • macOS 12.3 or higher

For Linux User(Debian or Ubuntu)

Method

Step1

Install Python,git,virtualenv

1
sudo apt install python3 git virtualenv
Step2

Clone the repository and install the dependencies.

1
2
git clone https://github.com/CompVis/stable-diffusion.git
cd stable-diffusion/

Read and accept the Licence

Step3

Go to a vertual environment

Activate vertual environment

1
source venv/bin/activate

Dectivate vertual environment

1
deactive
Step4

Download the weights

Go to the Hugging Face repository, have a read and understand the license, then click “Access repository”.

1
curl https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media > sd-v1-4.ckpt
Step5

Play

1
python scripts/txt2img.py --prompt "YOUR-PROMPT-HERE" --plms --ckpt sd-v1-4.ckpt --skip_grid --n_samples 1

Reference

Run. Replicate. (n.d.). Retrieved October 11, 2022, from https://replicate.com/blog/run-stable-diffusion-on-m1-mac

Divamgupta. (n.d.). Divamgupta/diffusionbee-stable-diffusion-ui: Diffusion Bee is the easiest way to run stable diffusion locally on your M1 mac. comes with a one-click installer. no dependencies or technical knowledge needed. GitHub. Retrieved October 11, 2022, from https://github.com/divamgupta/diffusionbee-stable-diffusion-ui