Skip to content

Commit 3f7fc6c

Browse files
committed
add Dockerfile, an onstart.sh for vast.ai
Add a post-build script that runs the first time you execute it on a machine with a GPU, since some stuff won't build in the builder
1 parent ab1b84a commit 3f7fc6c

5 files changed

Lines changed: 120 additions & 1 deletion

File tree

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
.env
3+
*.pyc
4+
Dockerfile

Dockerfile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
FROM pytorch/pytorch:2.4.0-cuda12.4-cudnn9-devel AS builder
2+
3+
# Install build dependencies
4+
RUN apt-get update && \
5+
apt-get install -y ffmpeg build-essential htop git python3-onnx rdfind
6+
7+
WORKDIR /app
8+
ADD trellis /app/trellis
9+
ADD setup.sh /app/setup.sh
10+
ADD app.py /app/app.py
11+
ADD example.py /app/example.py
12+
ADD extensions /app/extensions
13+
ADD assets /app/assets
14+
15+
# Setup conda
16+
RUN conda config --set always_yes true && conda init
17+
18+
# Use bash shell so we can source activate
19+
SHELL ["/bin/bash", "-c"]
20+
21+
RUN conda install cuda=12.4 pytorch==2.4.0 torchvision==0.19.0 pytorch-cuda=12.4 -c pytorch -c nvidia
22+
23+
# Create a g++ wrapper for JIT, since the include dirs are passed with -i rather than -I for some reason
24+
RUN printf '#!/usr/bin/env bash\nexec /usr/bin/g++ -I/usr/local/cuda/include -I/usr/local/cuda/include/crt "$@"\n' > /usr/local/bin/gxx-wrapper && \
25+
chmod +x /usr/local/bin/gxx-wrapper
26+
ENV CXX=/usr/local/bin/gxx-wrapper
27+
28+
# Run setup.sh - this won't install all the things, we'll need to install some later
29+
RUN conda run -n base ./setup.sh --basic --xformers --flash-attn --diffoctreerast --vox2seq --spconv --mipgaussian --kaolin --nvdiffrast --demo
30+
31+
# Now install additional Python packages
32+
# These ones work inside the builder
33+
RUN conda run -n base pip install diso
34+
RUN conda run -n base pip install plyfile utils3d flash_attn spconv-cu120 xformers
35+
RUN conda run -n base pip install kaolin -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.4.0_cu121.html
36+
RUN conda run -n base pip install git+https://github.com/NVlabs/nvdiffrast.git
37+
38+
# Cleanup after builds are done
39+
RUN apt-get remove -y ffmpeg build-essential htop git python3-onnx && \
40+
apt-get autoremove -y && \
41+
apt-get clean && \
42+
rm -rf /var/lib/apt/lists/*
43+
44+
RUN conda clean --all -f -y
45+
46+
# Deduplicate with rdfind
47+
# This reduces the size of the image by a few hundred megs. Not great, but it's a start.
48+
RUN rdfind -makesymlinks true /opt/conda
49+
50+
# Final stage
51+
FROM pytorch/pytorch:2.4.0-cuda12.4-cudnn9-devel AS final
52+
53+
WORKDIR /app
54+
COPY --from=builder /usr/local/bin/gxx-wrapper /usr/local/bin/gxx-wrapper
55+
COPY --from=builder /opt/conda /opt/conda
56+
COPY --from=builder /root /root
57+
COPY --from=builder /app /app
58+
59+
# Reinstall any runtime tools needed
60+
# git and build-essential are needed for post_install.sh script. vim and strace are
61+
# useful for debugging the image size.
62+
RUN apt-get update && \
63+
apt-get install -y build-essential \
64+
git \
65+
strace \
66+
vim && \
67+
rm -rf /var/lib/apt/lists/*
68+
69+
# install these last so we don't need to rebuild the whole image every time we mess
70+
# with the way it runs.
71+
COPY onstart.sh /app/onstart.sh
72+
COPY post_install.sh /app/post_install.sh
73+
74+
ENV PATH=/opt/conda/bin:$PATH
75+
76+
# This script runs the post_install steps
77+
CMD ["/app/onstart.sh"]
78+

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,4 @@ def deactivate_button() -> gr.Button:
245245
if __name__ == "__main__":
246246
pipeline = TrellisImageTo3DPipeline.from_pretrained("JeffreyXiang/TRELLIS-image-large")
247247
pipeline.cuda()
248-
demo.launch()
248+
demo.launch(server_name='0.0.0.0', server_port=8080)

onstart.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
cd /app
4+
5+
echo "doing post install steps"
6+
./post_install.sh
7+
8+
export CXX=/usr/local/bin/gxx-wrapper
9+
10+
echo "launching app"
11+
python3 app.py
12+

post_install.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Check if post-install steps have already been run
5+
if [ -f /app/.post_install_done ]; then
6+
echo "Post-install steps already completed."
7+
exit 0
8+
fi
9+
10+
cd /app
11+
12+
echo "Install stuff that couldn't be installed without GPU"
13+
# Run the demo setup
14+
conda run -n base ./setup.sh --mipgaussian --diffoctreerast
15+
16+
echo "Proving it actually works..."
17+
18+
export CXX=/usr/local/bin/gxx-wrapper
19+
python example.py
20+
21+
# Mark completion
22+
touch /app/.post_install_done
23+
24+
echo "Post-install steps completed successfully."
25+

0 commit comments

Comments
 (0)