Skip to content

fix: pull torch from CPU-only index to shrink backend image (3.3GB → ~588MB)#4686

Merged
marcoacierno merged 1 commit into
mainfrom
fix/torch-cpu-only-backend-image
Jun 20, 2026
Merged

fix: pull torch from CPU-only index to shrink backend image (3.3GB → ~588MB)#4686
marcoacierno merged 1 commit into
mainfrom
fix/torch-cpu-only-backend-image

Conversation

@marcoacierno

Copy link
Copy Markdown
Member

Problem

The arm64 backend image jumped from ~588MB to ~3.31GB compressed starting 2026-06-19.

Root cause: the uv group bump in #4672 upgraded torch transitively 2.10.0 → 2.12.1. torch 2.12 changed its CUDA dependency markers:

torch 2.10.0 torch 2.12.1
CUDA marker platform_machine == 'x86_64' and sys_platform == 'linux' platform_system == 'Linux'

The backend image is arm64. Under the old marker, the x86_64 guard excluded CUDA on arm. Under the new marker, arm64 Linux now pulls the full NVIDIA CUDA stack — cuda-toolkit + 15 nvidia-* wheels + triton — ~2.7GB of GPU libraries the host can never use (no GPU).

torch reaches the tree via sentence-transformers.

Fix

Bind torch to the PyTorch CPU-only index. The +cpu wheels declare no nvidia dependencies.

torch is declared as a direct dependency because [tool.uv.sources] only binds direct deps, not transitive ones.

Verification

  • Relock removes 19 packages (all CUDA/nvidia/triton), pure removals, no additions.
  • torch resolves to 2.12.1+cpu from download.pytorch.org/whl/cpu.
  • Installed venv: 0 nvidia/cuda/triton dirs; site-packages 2.1G uncompressed (was ~5–6G) → compresses back to the ~588MB baseline.
  • aarch64 + macOS arm64 +cpu/cpu wheels confirmed present on the index → CI and dev machines covered.
  • Lock stays format version = 1 → compatible with the Dockerfile's pinned uv==0.5.5. uv lock --locked passes.

Note: verified at install/lock level; the actual ECR image size is produced by CI on this branch.

🤖 Generated with Claude Code

torch 2.12 (bumped transitively via #4672) changed its CUDA dependency
markers from `platform_machine == 'x86_64'` to `platform_system == 'Linux'`,
so the arm64 backend image started pulling the full NVIDIA CUDA stack
(cuda-toolkit + 15 nvidia-* wheels + triton). Compressed image jumped from
~588MB to ~3.31GB — none of it usable, the host has no GPU.

Bind torch to the PyTorch CPU index. torch is declared as a direct
dependency because [tool.uv.sources] only applies to direct deps, not
transitive ones (it's otherwise pulled in by sentence-transformers).

Relock removes 19 packages (all CUDA/nvidia/triton); torch resolves to
2.12.1+cpu. Lock stays format version 1 (compatible with the Dockerfile's
pinned uv==0.5.5).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pycon Ready Ready Preview Jun 20, 2026 8:15pm

@claude

claude Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Pins torch to PyTorch's CPU-only wheel index to fix the arm64 Docker image size regression (~3.3GB → ~588MB) introduced when torch 2.12 changed its CUDA platform markers.

Potential issue: macOS arm64 installs may break

The new lock file drops all macOS wheels — previously the lock included macosx_14_0_arm64 wheels from PyPI, but after switching to the CPU index with explicit = true, only Linux and Windows wheels are present in the lock.

With explicit = true, uv will only look in the pytorch-cpu index for torch and will not fall back to PyPI. If PyTorch's CPU index doesn't publish macOS wheels for the +cpu variant, uv sync on macOS arm64 dev machines would fail with no fallback.

Before merging, verify uv sync works on macOS arm64, or confirm that all developers and CI exclusively run Linux.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.43%. Comparing base (e13f471) to head (f898369).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4686   +/-   ##
=======================================
  Coverage   92.43%   92.43%           
=======================================
  Files         355      355           
  Lines       10719    10719           
  Branches      818      818           
=======================================
  Hits         9908     9908           
  Misses        698      698           
  Partials      113      113           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marcoacierno marcoacierno merged commit 683dae6 into main Jun 20, 2026
8 checks passed
@marcoacierno marcoacierno deleted the fix/torch-cpu-only-backend-image branch June 20, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant