scenegen / Dockerfile
bitsinthesky's picture
Replace gradio with FastAPI to fix transitive dep crashes
7480796 verified
FROM nvidia/cuda:12.1.1-devel-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive
ENV TORCH_CUDA_ARCH_LIST="7.5"
ENV PYTHONUNBUFFERED=1
# ──────────────────────────────────────────────
# 1. System dependencies + Python 3.10
# ──────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
software-properties-common \
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt-get update && apt-get install -y --no-install-recommends \
python3.10 python3.10-dev python3.10-venv python3.10-distutils \
git wget curl build-essential cmake \
libgl1-mesa-glx libglib2.0-0 libsm6 libxrender1 libxext6 \
libgomp1 libglu1-mesa libxi6 libxmu6 \
&& rm -rf /var/lib/apt/lists/*
# Make python3.10 the default
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1 \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1 \
&& curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
# ──────────────────────────────────────────────
# 2. PyTorch 2.4.0+cu121 (pin FIRST)
# ──────────────────────────────────────────────
RUN pip install --no-cache-dir \
torch==2.4.0 torchvision==0.19.0 \
--index-url https://download.pytorch.org/whl/cu121
# ──────────────────────────────────────────────
# 3. setup.sh --basic deps
# ──────────────────────────────────────────────
# Remove system-installed blinker (distutils) that blocks pip upgrades
RUN pip install --no-cache-dir --ignore-installed blinker \
&& pip install --no-cache-dir \
pillow imageio imageio-ffmpeg tqdm easydict \
opencv-python-headless scipy ninja \
rembg onnxruntime trimesh open3d xatlas \
pyvista pymeshfix igraph \
transformers scikit-image einops safetensors \
huggingface-hub
# ──────────────────────────────────────────────
# 4. utils3d (pinned commit)
# ──────────────────────────────────────────────
RUN pip install --no-cache-dir \
git+https://github.com/EasternJournalist/utils3d.git@9a4eb15e4021b67b12c460c7057d642626897ec8
# ──────────────────────────────────────────────
# 5. spconv-cu120
# ──────────────────────────────────────────────
RUN pip install --no-cache-dir spconv-cu120
# ──────────────────────────────────────────────
# 6. xformers 0.0.27.post2 (cu121)
# ──────────────────────────────────────────────
RUN pip install --no-cache-dir \
xformers==0.0.27.post2 \
--index-url https://download.pytorch.org/whl/cu121
# ──────────────────────────────────────────────
# 7. kaolin (torch-2.4.0 cu121)
# ──────────────────────────────────────────────
RUN pip install --no-cache-dir kaolin \
--find-links https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.4.0_cu121.html
# ──────────────────────────────────────────────
# 8. Pre-built CUDA wheels (built on Colab to avoid OOM on HF build machine)
# Requires: nvdiffrast, diffoctreerast, diff_gaussian_rasterization
# See scene_generation/03_build_wheels.ipynb to rebuild
# ──────────────────────────────────────────────
COPY wheels/*.whl /tmp/wheels/
RUN pip install --no-cache-dir /tmp/wheels/*.whl && rm -rf /tmp/wheels
# ──────────────────────────────────────────────
# 9. numpy pin + FastAPI (replaces gradio to avoid transitive dep hell)
# ──────────────────────────────────────────────
RUN pip install --no-cache-dir \
numpy==1.26.4 \
fastapi uvicorn python-multipart
# ──────────────────────────────────────────────
# 10. Clone SceneGen repo
# ──────────────────────────────────────────────
RUN git clone https://github.com/Mengmouxu/SceneGen.git /opt/SceneGen
# ──────────────────────────────────────────────
# 11. Download checkpoints (baked into image)
# ──────────────────────────────────────────────
RUN python -c "\
from huggingface_hub import snapshot_download; \
snapshot_download(repo_id='facebook/VGGT-1B', local_dir='/opt/SceneGen/checkpoints/VGGT-1B'); \
snapshot_download(repo_id='haoningwu/SceneGen', local_dir='/opt/SceneGen/checkpoints/scenegen'); \
"
# ──────────────────────────────────────────────
# 12. HF Space user setup
# ──────────────────────────────────────────────
RUN useradd -m -u 1000 user \
&& chown -R user:user /opt/SceneGen
USER user
ENV HOME=/home/user
WORKDIR /home/user/app
COPY --chown=user:user app.py .
CMD ["python", "app.py"]