Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +1 to +14
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official continuumio/miniconda3 container images would spare a few lines

Suggested change
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
FROM continuumio/miniconda3

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was hesitant about that because it was last updated 3 months ago... but yeah maybe using that and just do a apt update upgrade...?

# i am using git clone instead during development of this dockerfile
COPY . /app/
Copy link
Copy Markdown

@hkiang01 hkiang01 Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as to take advantage of Docker's build cache, COPYs should be towards the bottom of the Dockerfile as possible. In this case, the only files required before the RUN conda env create... layer is the environment.yml and setup.py.

Suggested change
COPY . /app/
COPY environment.yml setup.py ./

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check if really only the environment.yml is needed, I think the .yml uses the setup.py to build the local package as well, that is why I thought it's needed as well. will check it out though

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
Comment on lines +23 to +24
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered this simpler alternative?

Suggested change
RUN rm /usr/local/bin/python
RUN ln -s /root/miniconda3/envs/ldm/bin/python /usr/local/bin/python
ENV PATH /root/miniconda3/envs/ldm/bin:$PATH

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah at least for me it didn't work when calling python later on... but feel free to try it out

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also look at PYTHONPATH

Suggested change
RUN rm /usr/local/bin/python
RUN ln -s /root/miniconda3/envs/ldm/bin/python /usr/local/bin/python
ENV PYTHONPATH=/root/miniconda3/envs/ldm

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", \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with the other suggestion for COPY, to make sure the files are still available, we can move the original COPY towards the bottom, here

Suggested change
CMD [ "python", "scripts/txt2img.py", \
COPY . /app/
CMD [ "python", "scripts/txt2img.py", \

"--prompt", "'$PROMPT'", "--plms", "--ckpt", "./weights/sd-v1-4.ckpt", "--skip_grid", \
"--n_samples", "1", "--n_iter", "1"]
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"
services:
stable-diffusor:
# TODO: exchange this image with an image of CompVis
image: guestros/stable-diffusion:latest
build: .
Comment thread
JustinGuese marked this conversation as resolved.
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]