Skip to content

[Docker support] enabling docker, adding description to readme#134

Open
JustinGuese wants to merge 12 commits intoCompVis:mainfrom
JustinGuese:docker
Open

[Docker support] enabling docker, adding description to readme#134
JustinGuese wants to merge 12 commits intoCompVis:mainfrom
JustinGuese:docker

Conversation

@JustinGuese
Copy link
Copy Markdown

adding docker support and a proposal for usage in the readme

Comment thread Dockerfile Outdated
Comment on lines +26 to +28
# 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've been wondering how to do this, is there really no better way to download the deps?

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 it must be simple code somewhere, didn't find it so far though
must be some tqdm part, maybe:

for zd in tqdm(samples, desc=desc):
?

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread Dockerfile Outdated
JustinGuese and others added 3 commits September 1, 2022 09:50
Co-authored-by: eggplants <w10776e8w@yahoo.co.jp>
Co-authored-by: eggplants <w10776e8w@yahoo.co.jp>
Co-authored-by: eggplants <w10776e8w@yahoo.co.jp>
@JustinGuese
Copy link
Copy Markdown
Author

thx @eggplants the weight(th)s gets me every time

@JustinGuese
Copy link
Copy Markdown
Author

JustinGuese commented Sep 1, 2022

okay the part that does not get initialized yet is
Downloading: "https://github.com/DagnyT/hardnet/raw/master/pretrained/train_liberty_with_aug/checkpoint_liberty_with_aug.pth" to /root/.cache/torch/hub/checkpoints/checkpoint_liberty_with_aug.pth

so I will try to add that to the docker image as well...
and it gets really huge anyways, so I thought about just including the weights? what do you think?

it's already like 10 GB, so 14 GB wouldn't be to different neither :D it's absurd yes

Comment thread docker-compose.yaml
Co-authored-by: Harrison Kiang <hkiang01@gmail.com>
Copy link
Copy Markdown

@hkiang01 hkiang01 left a comment

Choose a reason for hiding this comment

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

Optimizations re: Docker's build cache

Comment thread Dockerfile
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/
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

Comment thread Dockerfile
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/checkpoint_liberty_with_aug.pth
# 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 -P 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", \

@magnusviri
Copy link
Copy Markdown

@JustinGuese, would you be willing to add this to https://github.com/lstein/stable-diffusion?

@JustinGuese
Copy link
Copy Markdown
Author

@magnusviri can do

@JustinGuese
Copy link
Copy Markdown
Author

@magnusviri i added it to lstein's version: invoke-ai/InvokeAI#560

Comment thread Dockerfile
Comment on lines +23 to +24
RUN rm /usr/local/bin/python
RUN ln -s /root/miniconda3/envs/ldm/bin/python /usr/local/bin/python
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

Comment thread Dockerfile
Comment on lines +1 to +14
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
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...?

Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
@krainboltgreene
Copy link
Copy Markdown

Fun fact: 3 of the dependencies that you install store files in stable-diffusion/src/ and if you don't cache those files you have to reinstall every time.

JustinGuese and others added 4 commits September 23, 2022 12:01
Co-authored-by: Helio Machado <0x2b3bfa0+git@googlemail.com>
Co-authored-by: Shenghang Tsai <jackalcooper@gmail.com>
Co-authored-by: Shenghang Tsai <jackalcooper@gmail.com>
Co-authored-by: Shenghang Tsai <jackalcooper@gmail.com>
@JustinGuese
Copy link
Copy Markdown
Author

JustinGuese commented Sep 23, 2022

@krainboltgreene

Fun fact: 3 of the dependencies that you install store files in stable-diffusion/src/ and if you don't cache those files you have to reinstall every time.

feel free to edit the dockerfile, or you can name me the URLs of them and the paths where they are supposed to be and I will add it ;)

@krainboltgreene
Copy link
Copy Markdown

@JustinGuese Will do when I have time. It's the CLIP and taming-transform dependency that make files in src/.

@krainboltgreene
Copy link
Copy Markdown

Oh also, don't run conda env update because it will update libraries past what works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants