File size: 3,814 Bytes
2297318
 
feb02ea
3452715
feb02ea
 
51543d6
2297318
 
 
 
 
 
623f25e
feb02ea
 
51543d6
a1c5982
feb02ea
51543d6
feb02ea
 
2297318
feb02ea
 
57d9a71
51543d6
 
a9c4781
 
 
 
46cdd84
51543d6
 
feb02ea
 
 
2297318
 
feb02ea
40f6ef3
51543d6
c7b009b
40f6ef3
 
95f3856
51543d6
 
46cdd84
51543d6
 
 
 
 
 
40f6ef3
b7b9eee
51543d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
feb02ea
 
51543d6
feb02ea
 
 
0c6ad14
 
3452715
feb02ea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 1. Use NVIDIA's stable Ubuntu 22.04 image (Natively provides Python 3.10)
FROM nvidia/cuda:12.5.1-devel-ubuntu22.04

# Prevent interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# 2. Install Python 3.10, system dependencies, and ninja-build
RUN apt-get update && apt-get install -y software-properties-common && \
    add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
    apt-get update && apt-get install -y \
    python3 \
    python3-venv \
    python3-dev \
    python3-pip \
    git \
    wget \
    ninja-build \
    libgl1 \
    libglib2.0-0 \
    libstdc++6 \
    && rm -rf /var/lib/apt/lists/*

# 3. Create user (Standard UID 1000)
RUN useradd -m -u 1000 user
USER user

# 4. Set Architecture for L40S (8.9) and CUDA paths
# MAX_JOBS=2 limits compilation threads so the build server doesn't run out of RAM!
ENV HOME=/home/user \
    PATH=/home/user/venv/bin:/usr/local/cuda/bin:$PATH \
    LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH \
    PYTHONWARNINGS="ignore::SyntaxWarning" \
    TORCH_CUDA_ARCH_LIST="8.9" \
    CUDA_HOME=/usr/local/cuda \
    MAX_JOBS=2

WORKDIR $HOME/app

# 5. Set up Virtual Environment (This creates a Python 3.10 virtual environment)
RUN python3 -m venv $HOME/venv

# 6. Install PyTorch 2.6.0, Hugging Face spaces, and the matched pre-compiled FlashAttention-2 wheel 
RUN pip install --no-cache-dir --upgrade pip wheel setuptools ninja packaging && \
    pip install --no-cache-dir torch==2.6.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 && \
    pip install --no-cache-dir spaces && \
    pip install --no-cache-dir https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.4.post1/flash_attn-2.7.4.post1+cu12torch2.6cxx11abiFALSE-cp310-cp310-linux_x86_64.whl

# 7. Clean up requirements_th26_cu124.txt
# We delete their precompiled wheels so they don't overwrite our compilation
COPY --chown=user requirements_th26_cu124.txt ./requirements.txt
RUN sed -i '/cumesh/d' requirements.txt && \
    sed -i '/o-voxel/d' requirements.txt && \
    sed -i '/flex-gemm/d' requirements.txt && \
    sed -i '/nvdiffrast/d' requirements.txt && \
    sed -i '/nvdiffrec-render/d' requirements.txt && \
    sed -i '/flash_attn_3/d' requirements.txt && \
    pip install --no-cache-dir -r requirements.txt

# 8. Compile the 3D CUDA extensions from source for Compute 8.9 (L40S)
# By splitting these, Docker will cache each successful build.

# Build CuMesh
RUN git clone https://github.com/JeffreyXiang/CuMesh.git && \
    cd CuMesh && \
    pip install --no-cache-dir . --no-build-isolation && \
    cd .. && rm -rf CuMesh

# Build FlexGEMM
RUN git clone https://github.com/JeffreyXiang/FlexGEMM.git && \
    cd FlexGEMM && \
    pip install --no-cache-dir . --no-build-isolation && \
    cd .. && rm -rf FlexGEMM

# Build o-voxel (cloning and manually embedding PX4/eigen)
RUN git clone https://github.com/microsoft/TRELLIS.2.git && \
    cd TRELLIS.2/o-voxel && \
    mkdir -p third_party && \
    git clone https://github.com/PX4/eigen.git third_party/eigen && \
    pip install --no-cache-dir . --no-build-isolation && \
    cd ../.. && rm -rf TRELLIS.2

# Build nvdiffrast
RUN git clone https://github.com/NVlabs/nvdiffrast.git && \
    cd nvdiffrast && \
    pip install --no-cache-dir . --no-build-isolation && \
    cd .. && rm -rf nvdiffrast

# Build nvdiffrec-render
RUN git clone https://github.com/JeffreyXiang/nvdiffrec.git && \
    cd nvdiffrec && \
    git checkout renderutils && \
    pip install --no-cache-dir . --no-build-isolation && \
    cd .. && rm -rf nvdiffrec

# 9. Copy application files
COPY --chown=user . .

# 10. App settings
EXPOSE 7860
ENV GRADIO_SERVER_NAME="0.0.0.0"
ENV GRADIO_SERVER_PORT="7860"
ENV PYTORCH_CUDA_ALLOC_CONF="expandable_segments:True"

# Run the app
CMD ["python", "app.py"]