From f7b07f71eae37dc3b45a1494cc3b783c1f7127aa Mon Sep 17 00:00:00 2001 From: Alvin Nahabwe Date: Sun, 12 Jul 2026 14:07:21 +0300 Subject: [PATCH] Pin dependencies to a verified stack; align container to Python 3.12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every dependency in the DL service was unpinned, so a fresh install resolved whatever was latest on PyPI. That is the direct cause of the runtime breakage fixed in the pipeline PR: the code had drifted behind transformers 5.x, albumentations 2.x and segmentation-models-pytorch 0.5. A clean `pip install` produced a service that crashed on two of its three segmentation model families and on object detection. This pins requirements.txt to the exact versions verified end-to-end (full train -> evaluate -> save -> inference) for all three tasks and both model families per task, on Python 3.12 / CPU torch: image classification (ViT), object detection (DETR + YOLO), semantic segmentation (SegFormer + SMP U-Net). - torch is pinned by version only; the CUDA base image pulls the matching CUDA build from PyPI. - gradio and wandb are removed: neither is imported anywhere (training sets WANDB_DISABLED=true), and gradio adds a large unused tree. - The pinned stack needs Python >= 3.11 (numpy 2.4 / pandas 3.0), so the Dockerfile base moves from ubuntu22.04/py3.10 to ubuntu24.04/py3.12 and installs into a venv (24.04's system Python is externally managed). Verified: pins run all tasks on CPU/py3.12. NOT yet verified: the CUDA container build itself (needs a GPU host) — torch==2.13.0 and the ubuntu24.04 CUDA base tag were confirmed to exist, but the image has not been built here. Co-Authored-By: Claude Opus 4.8 --- .gitignore | 3 ++ Dockerfile | 25 ++++++++++------ requirements.txt | 74 ++++++++++++++++++++++++++++-------------------- 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 340160b..aeb8d88 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ runs/* *.pt __pycache__/ __pycache__/* + +# Local dependency-verification artifact (CPU freeze); not for the repo +.verified-freeze-cpu.txt diff --git a/Dockerfile b/Dockerfile index 529f442..e3926d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,16 @@ # no-code-deeplearning-prod/Dockerfile -# Use NVIDIA's official CUDA base image -FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu22.04 +# NVIDIA CUDA base. Ubuntu 24.04 ships Python 3.12, which the pinned stack in +# requirements.txt requires (numpy 2.4 / pandas 3.0 need Python >= 3.11). +FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04 ENV DEBIAN_FRONTEND=noninteractive -# Install Python 3.10 and pip +# Python 3.12 + the OpenCV/rendering shared libs pulled in by opencv/albumentations. RUN apt-get update && \ apt-get install -y \ - python3.10 \ + python3.12 \ + python3.12-venv \ python3-pip \ libgl1 \ libglib2.0-0 \ @@ -18,16 +20,21 @@ RUN apt-get update && \ libfontconfig1 \ && rm -rf /var/lib/apt/lists/* -RUN ln -sf /usr/bin/python3.10 /usr/bin/python && \ - ln -sf /usr/bin/pip3 /usr/bin/pip +# Use an isolated virtualenv. On Ubuntu 24.04 the system Python is +# externally-managed (PEP 668), so installing into it needs a venv (or +# --break-system-packages); a venv is cleaner and keeps the image reproducible. +RUN python3.12 -m venv /opt/venv +ENV PATH="/opt/venv/bin:$PATH" WORKDIR /app # Copy requirements first for layer caching COPY requirements.txt . -# Install Python dependencies (with CUDA torch) -RUN pip install --no-cache-dir -r requirements.txt +# Install the pinned dependencies. On this CUDA base image, PyPI serves the +# CUDA build of the pinned torch version. +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir -r requirements.txt # Copy the entire DL service codebase -COPY . . \ No newline at end of file +COPY . . diff --git a/requirements.txt b/requirements.txt index 7f9995a..7b7ee79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,40 +1,54 @@ +# Pinned to a verified-working stack. +# +# Every version below was confirmed by running the full train -> evaluate -> +# save -> inference cycle for all three tasks and both model families per task +# (image classification, object detection via DETR and YOLO, semantic +# segmentation via SegFormer and SMP U-Net) on Python 3.12 / CPU torch. +# +# Torch is pinned by version only (no +cpu local tag): on the CUDA base image in +# the Dockerfile, PyPI serves the matching CUDA build of the same version. +# +# To refresh: bump a pin, re-run the smoke tests for all tasks, then commit. + # --- Core ML/DL --- -torch -torchvision -torchaudio -accelerate +torch==2.13.0 +torchvision==0.28.0 +torchaudio==2.11.0 +accelerate==1.14.0 # --- Hugging Face --- -transformers -datasets -evaluate -huggingface_hub +transformers==5.13.1 +datasets==5.0.0 +evaluate==0.4.6 +huggingface_hub==1.23.0 # --- Task-Specific --- -albumentations -torchmetrics -timm -pycocotools -ultralytics -faster-coco-eval -segmentation-models-pytorch +albumentations==2.0.8 +torchmetrics==1.9.0 +timm==1.0.28 +pycocotools==2.0.11 +ultralytics==8.4.92 +faster-coco-eval==1.7.2 +segmentation-models-pytorch==0.5.0 -# --- API & UI --- -fastapi -uvicorn[standard] -python-multipart -gradio +# --- API --- +fastapi==0.139.0 +uvicorn[standard]==0.51.0 +python-multipart==0.0.32 # --- Utilities --- -numpy -pandas -scipy -Pillow -wandb -psutil -scikit-learn +numpy==2.4.4 +pandas==3.0.3 +scipy==1.18.0 +Pillow==12.2.0 +psutil==7.2.2 +scikit-learn==1.9.0 # --- Job Persistence & Queuing --- -sqlalchemy -celery -redis \ No newline at end of file +sqlalchemy==2.0.51 +celery==5.6.3 +redis==8.0.1 + +# Removed (2026-07): gradio and wandb — neither is imported anywhere in the +# codebase (training sets WANDB_DISABLED=true), and gradio pulls a large, +# unused dependency tree. Re-add with a pin if a demo UI / W&B logging is built.