How to install and run Stable Diffusion on Apple Silicon M1/M2 Macs

Updated Categorized as Tutorial Tagged 65 Comments on How to install and run Stable Diffusion on Apple Silicon M1/M2 Macs
Install Stable diffusion on Mac

Stable Diffusion is a text-to-image AI that can be run on personal computers like Mac M1 or M2. In this article, you will find a step-by-step guide for installing and running Stable Diffusion on Mac.

You will need a Mac with Apple Silicon (M1 or M2) for reasonable speed. Ideally, your machine will have 16 GB of memory or more. You will need to wait longer for an image compared to using a similarly priced Windows PC with a discrete graphics card.

Here are the install options I will go through in this article.

  1. Draw Things – Easiest to install with a good set of features.
  2. Diffusers – Easiest to install but with not many features.
  3. DiffusionBee – Easy to install but with a smaller set of functions.
  4. AUTOMATIC1111 – Best features but a bit harder to install.

Alternatively, you can run Stable Diffusion in Google Colab which uses AUTOMATIC1111 (This is what I use and I am a Mac user). Check the Quick Start Guide for details.

Read this install guide if you want to install Stable Diffusion on a Windows PC.

Draw Things App

Install Instructions

Draw Things

Draw Things is an Apple App that can be installed on iPhones, iPad, and Macs. Installing it is no different from installing any other App.

App Product Page

It supports a pretty extensive list of models out of the box and a reasonable set of customizations you can make. It also supports inpainting.

Pros and Cons of Draw Things App

Pros

  • Easy to install
  • A good set of features

Cons

  • Features are not as extensive as AUTOMATIC1111

Diffusers App

Install Instructions

Diffusers is a Mac app made by Hugging Face, the place where many Stable Diffusion models are hosted. You can install the app using the link below.

Link to Diffusers app page

Customizations and available models are pretty limited.

Pros and Cons of Diffusers App

Pros:

  • Easy to install.

Cons:

  • Very limited models and features.

DiffusionBee

In this section, you will learn how to install and run DiffusionBee on Mac step-by-step.

Install DiffusionBee on Mac

DiffusionBee is one of the easiest ways to run Stable Diffusion on Mac. Its installation process is no different from any other app.

Step 1: Go to DiffusionBee’s download page and download the installer for MacOS – Apple Silicon. A dmg file should be downloaded.

Step 2: Double-click to run the downloaded dmg file in Finder. The following windows will show up.

Step 3: Drag the DiffusionBee icon on the left to the Applications folder on the right. Installation is now complete!

Run DiffusionBee on Mac

You can use the spotlight search bar to start StableBee. Press command + spacebar to bring up spotlight search. Type “DiffusionBee” and press return to start DiffusionBee.

It will download some models when it starts for the very first time.

After it is done, you can start using Stable Diffusion! Let’s try putting the prompt “a cat” in the prompt box and hit Generate.

Works pretty well! You can click the option button to customize your images such as image size and CFG scale.

Go to the Next Step section to see what to do next.

Pros and Cons of DiffusionBee

Pros

  • Installation is relatively easy

Cons

  • Features are a bit lacking.

AUTOMATIC1111

This section shows you how to install and run AUTOMATIC1111 on Mac step-by-step.

DiffusionBee is easy to install but the functionality is pretty limited. If you are (or aspired to be) an advanced user, you will want to use an advanced GUI like AUTOMATIC1111. You will need this GUI if you want to follow my tutorials.

Install AUTOMATIC1111 on Mac

Step 1: Install Homebrew, a package manager for Mac, if you haven’t already. Open the Terminal app, type the following command, and press return.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install a few required packages. Open a new terminal and run the following command

brew install cmake protobuf rust [email protected] git wget

Step 3: Clone the AUTOMATIC1111 repository by running the following command in the terminal

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

A new folder stable-diffusion-webui should be created under your home directory.

Step 5: You will need a model to run Stable Diffusion. Use the following link to download the v1.5 model.

Download link

Put the file in the folder stable-diffusion-webui/models/Stable-diffusion. You can get there in the Finder app. In the top menu, click Go and then Home. Double Click to go to the folder stable-diffusion-webui, and then models, and then Stable-diffusion.

When you are done with this step, the Stable-diffusion folder should have two files like below.

Run AUTOMATIC1111 on Mac

Follow the steps in this section to start AUTOMATIC1111 GUI for Stable Diffusion.

In the terminal, run the following command.

cd ~/stable-diffusion-webui;./webui.sh 

It will take a while when you run it for the very first time.

Open a web browser and click the following URL to start Stable Diffusion.

http://127.0.0.1:7860/

You should see the AUTOMATIC1111 GUI. Put in a prompt “a cat” and press Generate to test using the GUI.

Close the terminal when you are done. Follow the steps in this section the next time when you want to run Stable Diffusion.

Pros and Cons of AUTOMATIC1111

Pros

  • Best features among all apps

Cons

  • Difficult to install if you are not tech-savvy.

Common issues when installing AUTOMATIC1111 on Mac

I got “RuntimeError: Cannot add middleware after an application has started”

If you get the following error:

File “/Users/XXXXX/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/applications.py”, line 139, in add_middleware
raise RuntimeError(“Cannot add middleware after an application has started”)
RuntimeError: Cannot add middleware after an application has started

This is caused by an outdated fastapi package. Run the following command in the webui folder.

./venv/bin/python -m pip install --upgrade fastapi==0.90.1

I got RuntimeError: “LayerNormKernelImpl” not implemented for ‘Half’

Start the webUI with the following command.

./webui.sh --precision full --no-half

Next Steps

Now you can run Stable Diffusion; below are some suggestions on what to learn next.


Buy Me A Coffee

65 comments

  1. Hi I’m using Python 3.10.0, but still got this problem. Below is the error message:
    Error completing request
    Arguments: (‘task(es1qnibtjns5d1h)’, ‘cat’, ”, [], 20, 0, False, False, 1, 1, 7, -1.0, -1.0, 0, 0, 0, False, 512, 512, False, 0.7, 2, ‘Latent’, 0, 0, 0, [], 0, , False, False, ‘positive’, ‘comma’, 0, False, False, ”, 1, ”, [], 0, ”, [], 0, ”, [], True, False, False, False, 0, None, False, 50) {}
    Traceback (most recent call last):
    File “/Users/p1323593/stable-diffusion-webui/modules/call_queue.py”, line 57, in f
    res = list(func(*args, **kwargs))
    File “/Users/p1323593/stable-diffusion-webui/modules/call_queue.py”, line 37, in f
    res = func(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/modules/txt2img.py”, line 56, in txt2img
    processed = process_images(p)
    File “/Users/p1323593/stable-diffusion-webui/modules/processing.py”, line 526, in process_images
    res = process_images_inner(p)
    File “/Users/p1323593/stable-diffusion-webui/extensions/sd-webui-controlnet/scripts/batch_hijack.py”, line 42, in processing_process_images_hijack
    return getattr(processing, ‘__controlnet_original_process_images_inner’)(p, *args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/modules/processing.py”, line 680, in process_images_inner
    samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength, prompts=prompts)
    File “/Users/p1323593/stable-diffusion-webui/modules/processing.py”, line 907, in sample
    samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning, image_conditioning=self.txt2img_image_conditioning(x))
    File “/Users/p1323593/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py”, line 377, in sample
    samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={
    File “/Users/p1323593/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py”, line 251, in launch_sampling
    return func()
    File “/Users/p1323593/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py”, line 377, in
    samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args={
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py”, line 115, in decorate_context
    return func(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/sampling.py”, line 145, in sample_euler_ancestral
    denoised = model(x, sigmas[i] * s_in, **extra_args)
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/modules/sd_samplers_kdiffusion.py”, line 135, in forward
    x_out = self.inner_model(x_in, sigma_in, cond=make_condition_dict([cond_in], image_cond_in))
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/external.py”, line 114, in forward
    eps = self.get_eps(input * c_in, self.sigma_to_t(sigma), **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/repositories/k-diffusion/k_diffusion/external.py”, line 140, in get_eps
    return self.inner_model.apply_model(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/modules/sd_hijack_utils.py”, line 17, in
    setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs))
    File “/Users/p1323593/stable-diffusion-webui/modules/sd_hijack_utils.py”, line 26, in __call__
    return self.__sub_func(self.__orig_func, *args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/modules/sd_hijack_unet.py”, line 45, in apply_model
    return orig_func(self, x_noisy.to(devices.dtype_unet), t.to(devices.dtype_unet), cond, **kwargs).float()
    File “/Users/p1323593/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py”, line 858, in apply_model
    x_recon = self.model(x_noisy, t, **cond)
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py”, line 1335, in forward
    out = self.diffusion_model(x, t, context=cc)
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/diffusionmodules/openaimodel.py”, line 802, in forward
    h = module(h, emb, context)
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/diffusionmodules/openaimodel.py”, line 86, in forward
    x = layer(x)
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/p1323593/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/diffusionmodules/openaimodel.py”, line 115, in forward
    x = F.interpolate(x, scale_factor=2, mode=”nearest”)
    File “/Users/p1323593/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/functional.py”, line 3931, in interpolate
    return torch._C._nn.upsample_nearest2d(input, output_size, scale_factors)
    RuntimeError: “upsample_nearest2d_channels_last” not implemented for ‘Half’

  2. Help?

    RuntimeError: “LayerNormKernelImpl” not implemented for ‘Half’

    Python 3.10.11 (main, Apr 7 2023, 07:31:31) [Clang 14.0.0 (clang-1400.0.29.202)]
    Version: v1.2.1
    Commit hash: 89f9faa63388756314e8a1d96cf86bf5e0663045
    Installing requirements
    Launching Web UI with arguments: –skip-torch-cuda-test –upcast-sampling –no-half-vae –use-cpu interrogate
    No module ‘xformers’. Proceeding without it.
    Warning: caught exception ‘Torch not compiled with CUDA enabled’, memory monitor disabled
    Loading weights [cc6cb27103] from /Users/harrison/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.ckpt
    Running on local URL: http://127.0.0.1:7860

    To create a public link, set `share=True` in `launch()`.
    Startup time: 7.9s (import torch: 2.3s, import gradio: 2.0s, import ldm: 0.6s, other imports: 1.5s, setup codeformer: 0.1s, load scripts: 0.7s, create ui: 0.6s, gradio launch: 0.1s).
    Creating model from config: /Users/harrison/stable-diffusion-webui/configs/v1-inference.yaml
    LatentDiffusion: Running in eps-prediction mode
    DiffusionWrapper has 859.52 M params.
    Applying cross attention optimization (InvokeAI).
    Textual inversion embeddings loaded(0):
    Model loaded in 12.7s (load weights from disk: 4.2s, create model: 0.9s, apply weights to model: 5.3s, apply half(): 2.2s).
    Error completing request
    Arguments: (‘task(fj7zyha6pm7lx3f)’, ‘sun\n’, ”, [], 20, 0, False, False, 1, 1, 7, -1.0, -1.0, 0, 0, 0, False, 512, 512, False, 0.7, 2, ‘Latent’, 0, 0, 0, [], 0, False, False, ‘positive’, ‘comma’, 0, False, False, ”, 1, ”, [], 0, ”, [], 0, ”, [], True, False, False, False, 0) {}
    Traceback (most recent call last):
    File “/Users/harrison/stable-diffusion-webui/modules/call_queue.py”, line 57, in f
    res = list(func(*args, **kwargs))
    File “/Users/harrison/stable-diffusion-webui/modules/call_queue.py”, line 37, in f
    res = func(*args, **kwargs)
    File “/Users/harrison/stable-diffusion-webui/modules/txt2img.py”, line 56, in txt2img
    processed = process_images(p)
    File “/Users/harrison/stable-diffusion-webui/modules/processing.py”, line 526, in process_images
    res = process_images_inner(p)
    File “/Users/harrison/stable-diffusion-webui/modules/processing.py”, line 669, in process_images_inner
    uc = get_conds_with_caching(prompt_parser.get_learned_conditioning, negative_prompts, p.steps * step_multiplier, cached_uc)
    File “/Users/harrison/stable-diffusion-webui/modules/processing.py”, line 608, in get_conds_with_caching
    cache[1] = function(shared.sd_model, required_prompts, steps)
    File “/Users/harrison/stable-diffusion-webui/modules/prompt_parser.py”, line 140, in get_learned_conditioning
    conds = model.get_learned_conditioning(texts)
    File “/Users/harrison/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py”, line 669, in get_learned_conditioning
    c = self.cond_stage_model(c)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/harrison/stable-diffusion-webui/modules/sd_hijack_clip.py”, line 229, in forward
    z = self.process_tokens(tokens, multipliers)
    File “/Users/harrison/stable-diffusion-webui/modules/sd_hijack_clip.py”, line 254, in process_tokens
    z = self.encode_with_transformers(tokens)
    File “/Users/harrison/stable-diffusion-webui/modules/sd_hijack_clip.py”, line 302, in encode_with_transformers
    outputs = self.wrapped.transformer(input_ids=tokens, output_hidden_states=-opts.CLIP_stop_at_last_layers)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/models/clip/modeling_clip.py”, line 811, in forward
    return self.text_model(
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/models/clip/modeling_clip.py”, line 721, in forward
    encoder_outputs = self.encoder(
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/models/clip/modeling_clip.py”, line 650, in forward
    layer_outputs = encoder_layer(
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/transformers/models/clip/modeling_clip.py”, line 378, in forward
    hidden_states = self.layer_norm1(hidden_states)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py”, line 1501, in _call_impl
    return forward_call(*args, **kwargs)
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/normalization.py”, line 190, in forward
    return F.layer_norm(
    File “/Users/harrison/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/functional.py”, line 2515, in layer_norm
    return torch.layer_norm(input, normalized_shape, weight, bias, eps, torch.backends.cudnn.enabled)
    RuntimeError: “LayerNormKernelImpl” not implemented for ‘Half’

  3. I’m getting same error and I’m running web.sh on terminal. Is there anything else needed to install to get rid of this RuntimeError: “LayerNormKernelImpl” not implemented for ‘Half’

    1. It seems that you were not using webui.sh because it should set the --no-half argument to avoid this error. By any chance you have run another file?

  4. After installing Homebrew you need the environment variable PATH by using these commands:
    (echo; echo ‘eval “$(/opt/homebrew/bin/brew shellenv)”‘) >> /Users/bobpuffer/.zprofile
    and
    eval “$(/opt/homebrew/bin/brew shellenv)”

  5. the strange thing is, I did update to 3.10 and i double checked in terminal, and it is still showing v3.9 in the error message. Thanks for taking a look, either way — I appreciate it.

Leave a Reply