Skip to content

Instantly share code, notes, and snippets.

@cuibonobo
Last active October 2, 2022 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuibonobo/b331ce1dcdfeef2c3f5933a9d6d0fc3d to your computer and use it in GitHub Desktop.
Save cuibonobo/b331ce1dcdfeef2c3f5933a9d6d0fc3d to your computer and use it in GitHub Desktop.
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.

stable-diffusion (optimized)

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.

Pre-requisites

  • 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's condabin directory is in your PATH system environment variable.

Setting up the environment

  1. Download the .zip of the optimized Stable Diffusion code: https://github.com/basujindal/stable-diffusion/archive/refs/heads/main.zip
  2. Extract the .zip file
  3. Open a terminal and cd into the stable-diffusion-main directory that was just extracted
    • We'll refer to this directory as <sd-directory> for the rest of these instructions
  4. 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
  5. 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
  6. 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
  7. Create a new stable-diffusion-v1 directory at <sd-directory>/models/ldm/
  8. Move the sd-v1-1-full-ema.ckpt to this new directory and rename it model.ckpt

Running txt2img commands

  1. In a terminal window, cd to <sd-directory>
  2. Run conda activate ldm to enable the environment
  3. 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>/

Running txt2img in the Gradio GUI

  1. In a terminal window, cd to <sd-directory>
  2. Run conda activate ldm to enable the environment
  3. 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
  4. Run python optimizedSD/txt2img_gradio.py
  5. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment