Instructions for installing an optimized version of Stable Diffusion. Use this guide if your GPU has less than the recommended 10GB of VRAM for the 'full' version.
The optimized version is from basujindal/stable-diffusion. See that repo for additional img2img
and inpaint
commands, plus an explanation of the arguments supplied to each command.
- A graphics card that supports NVIDIA CUDA
- The CUDA Toolkit has been installed
- Miniconda has been installed for all users
- The
conda
command is available on the command line. Usually this means that Miniconda'scondabin
directory is in yourPATH
system environment variable.
- Download the .zip of the optimized Stable Diffusion code: https://github.com/basujindal/stable-diffusion/archive/refs/heads/main.zip
- Extract the .zip file
- Open a terminal and
cd
into thestable-diffusion-main
directory that was just extracted- We'll refer to this directory as
<sd-directory>
for the rest of these instructions
- We'll refer to this directory as
- Run
conda env create -f ./environment.yaml
to install the project dependencies- This process takes 5 - 10 minutes
- On Windows, you should also run
conda init powershell
to enable Anaconda in PowerShell
- Visit https://huggingface.co/CompVis/stable-diffusion-v-1-1-original, agree to the license terms, and click the "Access Repository" button to download the model
- You will need to sign up for a free account on the Hugging Face site to enable the download
- On the next page, download the sd-v1-1-full-ema.ckpt model
- This file is 7.2GB, so be sure you have enough space
- Create a new
stable-diffusion-v1
directory at<sd-directory>/models/ldm/
- Move the
sd-v1-1-full-ema.ckpt
to this new directory and rename itmodel.ckpt
- In a terminal window,
cd
to<sd-directory>
- Run
conda activate ldm
to enable the environment - Run
python optimizedSD/optimized_txt2img.py --prompt "<your prompt here>" --H 512 --W 512 --n_samples 5
to generate 5 images with 512px x 512px dimensions- Replace
<your prompt here>
with the prompt you'd like to generate - The generated files are saved in
<sd_directory>/outputs/text2img-samples/<your_prompt_here>/
- Replace
- In a terminal window,
cd
to<sd-directory>
- Run
conda activate ldm
to enable the environment - Run
pip install gradio==3.1.7
to install the dependencies for Gradio- Once the Gradio dependencies are installed, you can skip this step for subsequent runs
- Run
python optimizedSD/txt2img_gradio.py
- Open your browser and go to http://127.0.0.1:7860/ to use the Gradio GUI
- If some other process is using port
7860
the URL may be slightly different. Check the output of the command for the correct local URL.
- If some other process is using port