Spaces:
Sleeping
Sleeping
Commit ·
c7efece
1
Parent(s): 4aa9277
fix: split nnunetv2 install to preserve CUDA PyTorch in Docker
Browse files- Install all deps except nnunetv2 first (keeps base image CUDA torch)
- Install nnunetv2 deps separately, then nnunetv2 with --no-deps
- Add system dev packages for C compilation (SimpleITK, blosc2, etc.)
- Add build verification step to fail loudly if nnunetv2 missing
- Dockerfile +27 -3
Dockerfile
CHANGED
|
@@ -5,11 +5,18 @@
|
|
| 5 |
|
| 6 |
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
|
| 7 |
|
| 8 |
-
# Install system dependencies
|
|
|
|
| 9 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 10 |
build-essential \
|
| 11 |
curl \
|
| 12 |
git \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
# Create non-root user (HF Spaces requirement)
|
|
@@ -20,10 +27,27 @@ ENV HOME=/home/user \
|
|
| 20 |
|
| 21 |
WORKDIR /home/user/app
|
| 22 |
|
| 23 |
-
# Copy requirements
|
| 24 |
COPY --chown=user:user requirements.txt .
|
|
|
|
|
|
|
| 25 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 26 |
-
pip install --no-cache-dir -r
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Copy application code
|
| 29 |
COPY --chown=user:user . .
|
|
|
|
| 5 |
|
| 6 |
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
|
| 7 |
|
| 8 |
+
# Install system dependencies required for nnunetv2 and its transitive deps
|
| 9 |
+
# (SimpleITK, blosc2, imagecodecs need C compilation toolchains)
|
| 10 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 11 |
build-essential \
|
| 12 |
curl \
|
| 13 |
git \
|
| 14 |
+
pkg-config \
|
| 15 |
+
libjpeg-dev \
|
| 16 |
+
libpng-dev \
|
| 17 |
+
libtiff-dev \
|
| 18 |
+
libopenblas-dev \
|
| 19 |
+
graphviz \
|
| 20 |
&& rm -rf /var/lib/apt/lists/*
|
| 21 |
|
| 22 |
# Create non-root user (HF Spaces requirement)
|
|
|
|
| 27 |
|
| 28 |
WORKDIR /home/user/app
|
| 29 |
|
| 30 |
+
# Copy requirements first for Docker cache
|
| 31 |
COPY --chown=user:user requirements.txt .
|
| 32 |
+
|
| 33 |
+
# Step 1: Install all deps EXCEPT nnunetv2 (keep base image's CUDA torch)
|
| 34 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 35 |
+
grep -v nnunetv2 requirements.txt | pip install --no-cache-dir -r /dev/stdin
|
| 36 |
+
|
| 37 |
+
# Step 2: Install nnunetv2's non-torch dependencies, then nnunetv2 itself
|
| 38 |
+
# with --no-deps so it does NOT overwrite the CUDA PyTorch
|
| 39 |
+
RUN pip install --no-cache-dir \
|
| 40 |
+
acvl-utils batchgenerators batchgeneratorsv2 blosc2 \
|
| 41 |
+
dynamic-network-architectures graphviz imagecodecs \
|
| 42 |
+
pandas requests scikit-image scikit-learn seaborn \
|
| 43 |
+
SimpleITK tifffile tqdm yacs && \
|
| 44 |
+
pip install --no-cache-dir --no-deps nnunetv2>=2.2
|
| 45 |
+
|
| 46 |
+
# Verify critical packages installed (fail build early if not)
|
| 47 |
+
RUN python -c "import nnunetv2; print('nnunetv2 OK')" && \
|
| 48 |
+
python -c "import torch; print('torch', torch.__version__); assert 'cu' in torch.__version__ or torch.cuda.is_available(), 'CUDA torch missing!'" && \
|
| 49 |
+
python -c "import fastapi; print('fastapi OK')" && \
|
| 50 |
+
python -c "import monai; print('monai OK')"
|
| 51 |
|
| 52 |
# Copy application code
|
| 53 |
COPY --chown=user:user . .
|