A Stable Diffusion-based command-line image generator for *nix.
-
NVIDIA GPU with CUDA Compute Capability 6.1 or higher and minimum 6 GB VRAM.
-
We are assuming that we are working in an operating system with a POSIX-compliant shell
shin thePATHenvironment variable. -
Install a suitable NVIDIA driver for your GPU.
-
Install Git and add it to
PATH. -
Install Docker and add it to
PATH. -
Install the NVIDIA Container Toolkit.
-
Clone this repository and
cdto the (root of the) cloned directory:
$ git clone https://github.com/8vasu/sg-diffusion.git
$ cd sg-diffusion
- Run
build.shto build the Docker image:
$ ./build.sh
- After Docker has successfully built the
sg-diffusionimage, download a Stable Diffusion checkpoint model, say, from Hugging Face. For example, for low VRAM graphics cards like mine, Stable Diffusion 1.4 is good. Create a directory namedmodelsin the root of the cloned directorysg-diffusion, and place the model there so that the directory structure ofmodelsis this:
models
└── stable-diffusion-v1-4
├── feature_extractor
│ └── preprocessor_config.json
├── model_index.json
├── safety_checker
│ ├── config.json
│ └── model.fp16.safetensors
├── scheduler
│ └── scheduler_config.json
├── text_encoder
│ ├── config.json
│ └── model.fp16.safetensors
├── tokenizer
│ ├── merges.txt
│ ├── special_tokens_map.json
│ ├── tokenizer_config.json
│ └── vocab.json
├── unet
│ ├── config.json
│ └── diffusion_pytorch_model.fp16.safetensors
└── vae
├── config.json
└── diffusion_pytorch_model.fp16.safetensors
- Run
test.shto test:
$ ./test.sh
- Add the following alias to the shell profile
~/.profileof your POSIX-compliant shell (or some similar shell such asbash):
alias sgimg='docker run -it --rm --gpus=all --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 -v /home/8vasu/sg-diffusion:/app -v "$PWD":/work sg-diffusion python /app/sg-diffusion.py'
Replace /home/8vasu/sg-diffusion with the path to the (root of the) cloned directory.
- Test the above alias:
$ sgimg -o garden.png "a beautiful garden"
- Check the help message for more options:
sgimg -h