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.
- Install Anaconda for managing python environments and packages https://www.anaconda.com/
- Create a huggingface token which you will need for auto model download: https://huggingface.co/settings/tokens
- 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
- Install git through anaconda:
conda install -c anaconda git -y
- Clone the github repository:
git clone -b local https://github.com/deforum/stable-diffusion.git
- 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
- Install required packages:
python -m pip install -r requirements.txt
- Check your installation by running the .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.
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.
Each time you run this command you will get new images generated on your computer.
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
Modify the prompts in the
Deforum_Stable_Diffusion.py file. Save and run the prompt