|
| 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 | + |
0 commit comments