|
1 |
| -FROM nvidia/cuda:12.6.0-devel-ubuntu22.04 |
| 1 | +FROM nvidia/cuda:12.6.0-devel-ubuntu22.04 AS base |
2 | 2 |
|
3 | 3 | # Set user/group IDs to match host user (default 1000 for first user)
|
4 | 4 | ARG UID=1000
|
5 | 5 | ARG GID=1000
|
| 6 | +# Control compilation parallelism (4 jobs ~16GB RAM, 8 jobs ~32GB RAM, 64 jobs ~500GB RAM) |
| 7 | +ARG MAX_JOBS=4 |
6 | 8 |
|
7 | 9 | ENV DEBIAN_FRONTEND=noninteractive \
|
8 | 10 | PYTHONUNBUFFERED=1 \
|
9 | 11 | PYTHONDONTWRITEBYTECODE=1 \
|
10 | 12 | VIRTUAL_ENV=/app/venv \
|
11 | 13 | PATH="/app/venv/bin:$PATH" \
|
12 |
| - USER=appuser |
| 14 | + USER=appuser \ |
| 15 | + MAX_JOBS=$MAX_JOBS |
13 | 16 |
|
14 |
| -# Create system user and group |
15 |
| -RUN groupadd -g $GID appuser && \ |
16 |
| - useradd -u $UID -g $GID -m -s /bin/bash appuser |
17 |
| - |
18 |
| -# Install dependencies as root first |
| 17 | +# Layer 1: Install system dependencies (most stable, cached longest) |
19 | 18 | RUN apt-get update && apt-get install -y --no-install-recommends \
|
20 | 19 | git \
|
21 | 20 | python3.10 \
|
22 | 21 | python3.10-venv \
|
23 | 22 | python3.10-dev \
|
| 23 | + python3-pip \ |
24 | 24 | libgl1 \
|
25 | 25 | libglib2.0-0 \
|
26 | 26 | libsm6 \
|
27 | 27 | libxrender1 \
|
28 | 28 | libxext6 \
|
29 | 29 | ninja-build \
|
30 | 30 | sudo \
|
31 |
| - && rm -rf /var/lib/apt/lists/* \ |
32 |
| - && echo "appuser ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers |
| 31 | + curl \ |
| 32 | + wget \ |
| 33 | + && rm -rf /var/lib/apt/lists/* |
33 | 34 |
|
34 |
| -# Create and configure directories before switching user |
35 |
| -RUN mkdir -p /app && \ |
| 35 | +# Layer 2: Create user and basic directory structure early |
| 36 | +RUN groupadd -g $GID appuser && \ |
| 37 | + useradd -u $UID -g $GID -m -s /bin/bash appuser && \ |
| 38 | + echo "appuser ALL=(ALL) NOPASSWD: /bin/chown" >> /etc/sudoers && \ |
| 39 | + mkdir -p /app /app/outputs /app/hf_download && \ |
36 | 40 | chown -R $UID:$GID /app
|
37 | 41 |
|
38 |
| -# Switch to non-root user |
| 42 | +# Layer 3: Setup Python environment and clone repository (stable) |
39 | 43 | USER $UID:$GID
|
40 |
| - |
41 |
| -# Clone repository |
42 |
| -RUN git clone https://github.com/lllyasviel/FramePack /app |
43 | 44 | WORKDIR /app
|
| 45 | +RUN python3.10 -m venv $VIRTUAL_ENV && \ |
| 46 | + python -m pip install --upgrade pip wheel setuptools && \ |
| 47 | + git clone https://github.com/lllyasviel/FramePack /tmp/framepack && \ |
| 48 | + cp -r /tmp/framepack/* /app/ && \ |
| 49 | + rm -rf /tmp/framepack |
44 | 50 |
|
45 |
| -# Create virtual environment as user |
46 |
| -RUN python3.10 -m venv $VIRTUAL_ENV |
47 |
| - |
48 |
| -# Install Python dependencies |
| 51 | +# Layer 4: Install PyTorch ecosystem with specific CUDA version |
49 | 52 | RUN pip install --no-cache-dir \
|
50 | 53 | torch==2.6.0 \
|
51 |
| - torchvision \ |
52 |
| - torchaudio \ |
| 54 | + torchvision==0.21.0 \ |
| 55 | + torchaudio==2.6.0 \ |
53 | 56 | --index-url https://download.pytorch.org/whl/cu124
|
54 | 57 |
|
55 |
| -# Install requirements |
| 58 | +# Layer 5: Install FramePack requirements (from the official requirements.txt) |
56 | 59 | RUN pip install --no-cache-dir -r requirements.txt
|
57 |
| -RUN pip install --no-cache-dir triton sageattention |
58 | 60 |
|
59 |
| -# Install additional dependencies |
60 |
| -RUN pip install --no-cache-dir \ |
61 |
| - triton==3.0.0 \ |
62 |
| - sageattention==1.0.6 |
63 |
| - |
64 |
| -# Create and configure directories before switching user |
65 |
| -RUN mkdir -p /app/outputs && \ |
66 |
| - chown -R $UID:$GID /app/outputs && \ |
67 |
| - mkdir -p $VIRTUAL_ENV && \ |
68 |
| - chown -R $UID:$GID $VIRTUAL_ENV && \ |
69 |
| - mkdir -p /app/hf_download && \ |
70 |
| - chown -R $UID:$GID /app/hf_download |
71 |
| - |
72 |
| -# Copy entrypoint script |
| 61 | +# Layer 6: Install performance enhancements - triton and xformers |
| 62 | +RUN pip install --no-cache-dir triton==3.2.0 xformers |
| 63 | + |
| 64 | +# Layer 7: Install sageattention (needs compilation from source) |
| 65 | +RUN python -m pip install --no-cache-dir sageattention==1.0.6 |
| 66 | + |
| 67 | +# Layer 8: Install flash-attn (needs special compilation) |
| 68 | +RUN python -m pip -v install --no-cache-dir flash-attn --no-build-isolation |
| 69 | + |
| 70 | +# Verify PyTorch installation works correctly and check operator availability |
| 71 | +RUN python -c "import torch; import torchvision; import torchaudio; print(f'PyTorch: {torch.__version__}, TorchVision: {torchvision.__version__}, TorchAudio: {torchaudio.__version__}'); print('CUDA available:', torch.cuda.is_available()); import torchvision.ops; print('torchvision.ops loaded successfully')" |
| 72 | + |
| 73 | +# ===== APPLICATION STAGE ===== |
| 74 | +FROM base AS application |
| 75 | + |
| 76 | +ARG UID=1000 |
| 77 | +ARG GID=1000 |
| 78 | + |
| 79 | +# Layer 9: Copy entrypoint script (changes occasionally) |
| 80 | +USER root |
73 | 81 | COPY entrypoint.sh /entrypoint.sh
|
74 | 82 | RUN chmod +x /entrypoint.sh && \
|
75 | 83 | chown $UID:$GID /entrypoint.sh
|
76 | 84 |
|
| 85 | +# Final configuration |
| 86 | +USER $UID:$GID |
| 87 | +WORKDIR /app |
77 | 88 | EXPOSE 7860
|
78 | 89 |
|
79 | 90 | # Configure volumes
|
80 | 91 | VOLUME /app/hf_download
|
81 | 92 | VOLUME /app/outputs
|
82 | 93 |
|
83 | 94 | ENTRYPOINT ["/entrypoint.sh"]
|
84 |
| -CMD ["python", "demo_gradio.py", "--share", "--server-name", "0.0.0.0"] |
| 95 | +CMD ["python", "demo_gradio.py", "--share", "--server", "0.0.0.0"] |
0 commit comments