Use CPU-only torch for Docker builds to reduce image size#2946
Merged
adamtheturtle merged 4 commits intomainfrom Feb 18, 2026
Merged
Use CPU-only torch for Docker builds to reduce image size#2946adamtheturtle merged 4 commits intomainfrom
adamtheturtle merged 4 commits intomainfrom
Conversation
Configure uv to install CPU-only torch from PyTorch's dedicated index via [tool.uv.sources] in pyproject.toml. Update Dockerfile to use uv sync (which respects uv.sources) instead of uv pip install, and upgrade uv from 0.1.44 to 0.5.0 for [tool.uv.sources] support. This reduces the Docker image by ~3GB (CUDA libraries are unnecessary for the CPU-only Flask server). Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Add torchvision to [tool.uv.sources] so it also comes from the CPU index (piq depends on torchvision, which crashes on import with CPU-only torch when installed from PyPI). Restore python3 -m venv in the Dockerfile so pip install uv puts the uv binary into the venv's bin directory (which is on PATH), rather than ~/.local/bin (which is not). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
tool.uv.sources only applies to direct dependencies; torchvision was only a transitive dependency via piq, so sources.torchvision was silently ignored and PyPI's torchvision was installed instead. PyPI's torchvision registers torchvision::nms operators that don't exist in CPU-only torch, causing RuntimeError on import. Making torchvision a direct dependency causes uv to route it through the CPU index. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Configure uv to install CPU-only torch from PyTorch's dedicated index via
[tool.uv]configuration inpyproject.toml. Update the Dockerfile to useuv sync(which respectstool.uvsources) instead ofuv pip install, and upgrade uv from 0.1.44 to 0.5.0 for source configuration support. This reduces the Docker image size by ~3GB by removing unnecessary CUDA dependencies.Changes
[tool.uv]with index configuration for CPU-only torch fromhttps://download.pytorch.org/whl/cpuuv pip install --editable .touv sync --no-cacheUV_PROJECT_ENVIRONMENTto direct uv to the container's venv locationImpact
🤖 Generated with Claude Code
Note
Medium Risk
Changes dependency resolution and Docker build/install flow for
torch/torchvision, which could cause build failures or runtime incompatibilities if the CPU wheels or uv config behave differently across environments.Overview
Configures uv to install
torchandtorchvisionfrom PyTorch’s CPU-only wheel index via new[tool.uv]entries inpyproject.toml, and addstorchvisionas an explicit dependency (with adeptryignore) so it can be routed to that index.Updates the Flask server Docker build to set
UV_PROJECT_ENVIRONMENTand useuv sync --no-cache(instead ofuv pip install --editable .) when installing into the container venv.Written by Cursor Bugbot for commit 9f484ea. This will update automatically on new commits. Configure here.