migrate to uv + pyproject.toml

- root pyproject.toml replaces requirements.txt and requirements-worker.txt
  (worker = root + ffmpeg-python which root already had); test deps moved
  to [dependency-groups] dev
- core/gpu/pyproject.toml replaces core/gpu/requirements.txt; uses
  [tool.uv.sources] to pin torch/torchvision and paddlepaddle-gpu to their
  CUDA index URLs, replacing the manual reinstall dance from old comments
- Dockerfiles use uv sync --frozen against uv.lock for reproducible builds;
  PATH includes /app/.venv/bin so k8s manifests' bare uvicorn/celery
  commands resolve without wrapping in uv run
- core/gpu/run.sh local mode now does uv sync + uv run python server.py;
  errors out cleanly if uv is missing
This commit is contained in:
2026-04-29 07:32:56 -03:00
parent d9e0794b83
commit f66d3a273f
10 changed files with 3132 additions and 93 deletions

View File

@@ -8,8 +8,11 @@ RUN apt-get update && apt-get install -y \
WORKDIR /app
COPY requirements.txt .
RUN uv pip install --system --no-cache -r requirements.txt
ENV PATH="/app/.venv/bin:$PATH"
# uv.lock is generated on first build (dev box can't reach paddlepaddle's index)
COPY pyproject.toml ./
RUN uv sync --no-install-project --no-dev
COPY . .

42
core/gpu/pyproject.toml Normal file
View File

@@ -0,0 +1,42 @@
[project]
name = "mpr-gpu"
version = "0.1.0"
description = "MPR remote inference server (GPU)"
requires-python = ">=3.11"
dependencies = [
"fastapi>=0.109.0",
"uvicorn[standard]>=0.27.0",
"rapidfuzz>=3.0.0",
"Pillow>=10.0.0",
"redis>=5.0.0",
"ultralytics>=8.0.0",
"paddleocr>=3.0.0",
"paddlepaddle-gpu==3.0.0",
"transformers>=4.40.0,<5",
"accelerate>=0.27.0",
"torch",
"torchvision",
"opencv-python-headless>=4.8.0",
]
# RTX 3080 / CUDA toolkit 12.8 — cu126 wheels are forward-compatible
# (no cu128 wheels yet on either index). Mixing PyPI torch with CUDA 12.8
# causes NCCL symbol errors, so the explicit index pins prevent uv from
# pulling torch transitively from PyPI via ultralytics.
[tool.uv.sources]
torch = { index = "pytorch-cu126" }
torchvision = { index = "pytorch-cu126" }
paddlepaddle-gpu = { index = "paddle-cu126" }
[[tool.uv.index]]
name = "pytorch-cu126"
url = "https://download.pytorch.org/whl/cu126"
explicit = true
[[tool.uv.index]]
name = "paddle-cu126"
url = "https://www.paddlepaddle.org.cn/packages/stable/cu126/"
explicit = true
[tool.uv]
package = false

View File

@@ -1,31 +0,0 @@
fastapi>=0.109.0
uvicorn[standard]>=0.27.0
rapidfuzz>=3.0.0
Pillow>=10.0.0
redis>=5.0.0
# --- GPU-specific installs (mcrn: RTX 3080, CUDA toolkit 12.8) ---
#
# torch: must be installed from the PyTorch index, NOT from PyPI.
# cu126 is the closest build to CUDA 12.8 (no cu128 wheel yet; cu126 is forward-compatible).
# Install with:
# uv pip install --reinstall torch torchvision --index-url https://download.pytorch.org/whl/cu126
#
# ultralytics pulls torch as a dependency — reinstall torch after ultralytics to ensure
# the correct CUDA build. Mixing the PyPI torch with CUDA 12.8 causes NCCL symbol errors.
ultralytics>=8.0.0
# paddlepaddle-gpu: NOT available on PyPI. Install from PaddlePaddle's package index.
# cu126 build works on CUDA 12.8.
# Install with:
# uv pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
paddleocr>=3.0.0
# VLM (moondream2) — uses torch (already installed above)
# Pinned <5: transformers 5.x broke moondream2's custom model code
# (all_tied_weights_keys API change). Also needs accelerate for device_map.
transformers>=4.40.0,<5
accelerate>=0.27.0
# Preprocessing (phase 12)
opencv-python-headless>=4.8.0

View File

@@ -2,7 +2,7 @@
# Run the inference server
#
# Usage:
# ./run.sh # Local (pip install -r requirements.txt first)
# ./run.sh # Local: uv sync + run server.py (auto-installs/activates .venv)
# ./run.sh docker # Docker (CPU)
# ./run.sh docker-gpu # Docker with GPU
# ./run.sh stop # Stop Docker container
@@ -26,7 +26,12 @@ fi
case "${1:-local}" in
local)
python server.py
if ! command -v uv >/dev/null 2>&1; then
echo "uv not found. Install: curl -LsSf https://astral.sh/uv/install.sh | sh"
exit 1
fi
uv sync
uv run python server.py
;;
docker)
docker build -t mpr-inference .