diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..68ac04fceb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM python:3.8-slim +RUN apt update && apt install -y wget git libglib2.0-0 libsm6 libxext6 libxrender-dev +RUN apt clean && rm -rf /var/lib/apt/lists/* +# RUN useradd -ms /bin/bash stablediff +# install conda +RUN wget \ + https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ + && mkdir /root/.conda \ + && bash Miniconda3-latest-Linux-x86_64.sh -b \ + && rm -f Miniconda3-latest-Linux-x86_64.sh \ + && echo PATH="/root/miniconda3/bin":$PATH >> .bashrc +RUN chmod +x /root/miniconda3/bin/conda +RUN ln -s /root/miniconda3/bin/conda /usr/local/bin/conda +RUN conda update -y conda +# i am using git clone instead during development of this dockerfile +COPY . /app/ +RUN mkdir /app/outputs/ +RUN mkdir /app/weights/ +# RUN git clone https://github.com/CompVis/stable-diffusion.git /app/ +WORKDIR /app/ +RUN conda env create -f environment.yaml -n ldm +# conda env trick +RUN rm /usr/local/bin/python +RUN ln -s /root/miniconda3/envs/ldm/bin/python /usr/local/bin/python +ENV PROMPT="a drawing of a giraffe riding a motorcycle in space" +# trigger first download to prevent re-downloading in the future +# the script will fail as we do not have the weights yet, therefore the exit 0 +# RUN python scripts/txt2img.py; exit 0 +# there are even more post install downloads. the image is really big anyways already, +# so i was thinking about just including the weights as well... open to your ideas! +RUN wget https://github.com/DagnyT/hardnet/raw/master/pretrained/train_liberty_with_aug/checkpoint_liberty_with_aug.pth -P /root/.cache/torch/hub/checkpoints +# and now just grab the weights as well +RUN wget https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media -O weights/sd-v1-4.ckpt +CMD [ "python", "scripts/txt2img.py", \ + "--prompt", "'$PROMPT'", "--plms", "--ckpt", "./weights/sd-v1-4.ckpt", "--skip_grid", \ + "--n_samples", "1", "--n_iter", "1"] \ No newline at end of file diff --git a/README.md b/README.md index c9e6c3bb13..1a4094ffae 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,34 @@ Values that approach 1.0 allow for lots of variations but will also produce imag This procedure can, for example, also be used to upscale samples from the base model. +## Docker + +First you will need the `nvidia-docker` to be set up. If you are using Windows Docker Desktop you are in luck, as it is already working by default, otherwise follow [the NVIDIA guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html). + +After that, assuming you have downloaded the weights into the "weights" folder (see above, or `curl https://www.googleapis.com/storage/v1/b/aai-blog-files/o/sd-v1-4.ckpt?alt=media > weights/sd-v1-4.ckpt`), you can start it in three different modes: + +### 1. simple docker-compose up + +change the prompt located in [docker-compose.yaml](docker-compose.yaml), located under "environment" and execute: + +``` +docker-compose up +``` + +### 2. simple docker run + +edit the last part of the command and hit enter + +``` +docker run --it guestros/stable-diffusion:latest --gpus all -v $PWD/weights/:/app/weights/ -v $PWD/outputs/:/app/outputs/ -e 'PROMPT="a dinosaur looking at a meteor"' +``` + +### 3. interactive session + +An interactive session where you can type in your own commands and arguments +``` +docker run --it guestros/stable-diffusion:latest --gpus all -v $PWD/weights/:/app/weights/ -v $PWD/outputs/:/app/outputs/ +``` ## Comments diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000000..5937a1f055 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,18 @@ +version: "3" +services: + stable-diffusor: + # TODO: exchange this image with an image of CompVis + image: guestros/stable-diffusion:latest + build: . + platform: linux/amd64 + volumes: + - ./weights/:/app/weights/ + - ./outputs/:/app/outputs/ + environment: + - PROMPT="a drawing of a giraffe riding a bicycle in space" + # to make sure all gpus are passed + deploy: + resources: + reservations: + devices: + - capabilities: [gpu] \ No newline at end of file