pip install -r requirements.txt after installing torch from the PyTorch CPU index: torch==2.5.1 is satisfied by 2.5.1+cpu (kept), but Pillow/numpy pins trigger uninstall/reinstall churn
Fix: install in two steps and keep pins consistent. Step 1: pip install torch==2.5.1 torchvision==0.20.1 --index-url https://download.pytorch.org/whl/cpu. Step 2: pip install -r requirements.txt, where requirements pins torch==2.5.1 (no +cpu suffix needed). Put your numpy/Pillow pins in a constraints file used by both steps (-c constraints.txt) so step 2 doesn't swap what step 1 installed.
What we saw building ultralytics 8.3.50 + open-clip-torch 2.26.1 + faiss-cpu 1.9.0 on python:3.11-slim:
- Step 2 printed Requirement already satisfied: torch==2.5.1 in /usr/local/lib/python3.11/site-packages (from -r requirements.txt (line 1)) (2.5.1+cpu). A ==2.5.1 pin matches the local version 2.5.1+cpu, so pip keeps the CPU build and doesn't fetch the multi-GB CUDA wheel. Pin a different version, or skip step 1, and you get CUDA again.
- Step 1 pulled the newest deps of torchvision (Successfully installed numpy-2.4.6 pillow-13.0.0 torchvision-0.20.1+cpu). Step 2's pins Pillow==11.0.0/numpy==2.1.3 then showed Attempting uninstall: Pillow ... Uninstalling pillow-13.0.0 (same for numpy). That is extra downloads in a build that already took 8-12 minutes for a ~2.5 GB image.
- ultralytics pulls opencv-python (not headless), which needs libgl1 libglib2.0-0 from apt on slim images.
Verify: python -c "import torch; print(torch.__version__, torch.cuda.is_available())" prints 2.5.1+cpu False, and pip list | grep -i nvidia is empty.