Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
python-version: "3.11"
cache: pip
cache-dependency-path: |
apps/backend/requirements.txt
apps/backend/requirements-core.txt
apps/backend/requirements-dev.txt

- name: Install dependencies
Expand All @@ -62,13 +62,14 @@ jobs:
python-version: "3.11"
cache: pip
cache-dependency-path: |
apps/backend/requirements.txt
apps/backend/requirements-core.txt
apps/backend/requirements-dev.txt

- name: Install backend dependencies
run: |
python -m pip install --upgrade pip
python -m pip install torch==2.9.1 torchvision==0.24.1 --index-url https://download.pytorch.org/whl/cpu
python -m pip install -r apps/backend/requirements-core.txt
python -m pip install -r apps/backend/requirements-dev.txt

- name: Run backend tests
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ cd apps/backend
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install torch==2.9.1 torchvision==0.24.1 --index-url https://download.pytorch.org/whl/cpu
python3 -m pip install -r requirements-dev.txt
cp .env.example .env
set -a
Expand Down
7 changes: 5 additions & 2 deletions apps/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ RUN useradd --create-home --shell /bin/bash appuser

WORKDIR ${APP_HOME}

COPY requirements.txt ./requirements.txt
RUN python -m pip install --upgrade pip && python -m pip install -r requirements.txt
COPY requirements-core.txt ./requirements-core.txt
RUN python -m pip install --upgrade pip && \
python -m pip install torch==2.9.1 torchvision==0.24.1 \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Install order looks correct: CPU wheels first, then requirements-core.txt. That prevents transformers from dragging in the ~9 GB CUDA build during the same layer.

--index-url https://download.pytorch.org/whl/cpu && \
python -m pip install -r requirements-core.txt

COPY app ./app
COPY migrations ./migrations
Expand Down
4 changes: 4 additions & 0 deletions apps/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ app/
tests/
sql/manual/ optional manual seeds (calendar demo); not executed automatically
requirements.txt
requirements-core.txt
requirements-dev.txt
Dockerfile
```
Expand All @@ -55,6 +56,7 @@ Dockerfile
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install torch==2.9.1 torchvision==0.24.1 --index-url https://download.pytorch.org/whl/cpu
python3 -m pip install -r requirements-dev.txt
cp .env.example .env
set -a
Expand Down Expand Up @@ -119,6 +121,8 @@ Important settings:

## Docker

The production image installs CPU-only PyTorch wheels (not the default CUDA build from PyPI), keeping the image around **2–3 GB** instead of ~9 GB. Inference remains CPU-only (`DEVICE=cpu`).

### Build

```bash
Expand Down
17 changes: 17 additions & 0 deletions apps/backend/requirements-core.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Install CPU torch first — see Dockerfile and apps/backend/README.md
# pip install torch==2.9.1 torchvision==0.24.1 --index-url https://download.pytorch.org/whl/cpu
fastapi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider a header comment here noting that torch/torchvision must be installed separately from the CPU wheel index before this file (see Dockerfile / CI). Without that, pip install -r requirements-core.txt alone will let transformers pull the default (CUDA) PyPI torch.

python-multipart
Pillow
requests
sqlalchemy
alembic
psycopg[binary]
boto3
numpy
joblib
scikit-learn
huggingface_hub
transformers
uvicorn[standard]
prometheus-fastapi-instrumentator
3 changes: 1 addition & 2 deletions apps/backend/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-r requirements.txt
-r requirements-core.txt

httpx
pytest

22 changes: 4 additions & 18 deletions apps/backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
fastapi
python-multipart
Pillow
requests
sqlalchemy
alembic
psycopg[binary]
boto3
numpy
joblib
scikit-learn
huggingface_hub
transformers
torch==2.9.1
torchvision==0.24.1
uvicorn[standard]
prometheus-fastapi-instrumentator

# PyTorch is installed separately from the CPU wheel index.
# Docker: see Dockerfile
# Local / CI: pip install torch==2.9.1 torchvision==0.24.1 --index-url https://download.pytorch.org/whl/cpu
-r requirements-core.txt
Loading