Thanks to latest billing model with Google Colab, more and more people are switching to running Stable Diffusion and other models locally on their PC. This post is covering how to setup and run Stable Diffusion locally and the installation steps have been gathered from a GitHub repository and video tutorial by Rikkar which is quite extensive but here we focus on only local execution of Stable Diffusion.

Getting Started

  1. Install Anaconda for managing python environments and packages https://www.anaconda.com/
  2. Create a huggingface token which you will need for auto model download: https://huggingface.co/settings/tokens
  3. Open a anaconda powershell (on Windows) or terminal (Linux). Change directory if you want to install in different location then the default eg. C:\AI
  4. Install git through anaconda: conda install -c anaconda git -y
  5. Clone the github repository:
    git clone -b local https://github.com/deforum/stable-diffusion.git
    cd stable-diffusion
  6. Create Anaconda environment:
    conda create -n dsd python=3.9 -y
    conda activate dsd
    conda install pytorch cudatoolkit=11.6 torchvision torchaudio -c pytorch -c conda-forge -y
  7. Install required packages:
    python -m pip install -r requirements.txt
  8. Check your installation by running the .py
    python Deforum_Stable_Diffusion.py

Running Deforum Stable Diffusion

There are four ways to run Deforum Stable Diffusion: locally with the .py file, locally with jupyter, locally through colab, and on colab severs.

Running Locally

Make sure the dsd conda environment is active:
conda activate dsd

Navigate to the stable-diffusion folder and run either the Deforum_Stable_Diffusion.py or the Deforum_Stable_Diffusion.ipynb. running the .py is the quickest and easiest way to check that your installation is working, however, it is not the best environment for tinkering with prompts and settings.

If you have already downloaded the sd-v1-4.ckpt then copy it into the stable-diffusion\models folder on your computer, otherwise the next step will ask for huggingface token each time. Save time and download the checkpoint file before hand.

python Deforum_Stable_Diffusion.py

Each time you run this command you will get new images generated on your computer.

Screenshot of SD running locally (Credit Rikkar)
Screenshot of resulting Images (Credit Rikkar)

You can now modify the prompts by editing the Deforum_Stable_Diffusion.py file and run the python Deforum_Stable_Diffusion.py to create new image. Prompts are defined in the prompts = [] section, which should be familiar for Google Colab users.

Tip: You should also modify line which as hash check enabled to false (at line 151 at the time of writing this post). Change check_sha256 = True to check_sha256 = False

Screenshot of prompts in Deforum_Stable_Diffusion.py file

Modify the prompts in the Deforum_Stable_Diffusion.py file. Save and run the prompt python Deforum_Stable_Diffusion.py

If you'd like to support our site please consider buying us a Ko-fi, grab a product or subscribe.