Skip to content

Use CPU-only PyTorch build to reduce image size#5

Open
PerinbaBuilds wants to merge 2 commits into
mainfrom
fix/slim-cpu-image
Open

Use CPU-only PyTorch build to reduce image size#5
PerinbaBuilds wants to merge 2 commits into
mainfrom
fix/slim-cpu-image

Conversation

@PerinbaBuilds

Copy link
Copy Markdown
Owner

Summary

Optimize the Docker image size by using PyTorch's CPU-only wheel distribution instead of the default CUDA build, which includes unnecessary GPU libraries (~2.5 GB).

Changes

  • Added PyTorch CPU wheel index to pip configuration to pull CPU-only builds
  • Explicitly pinned torch==2.12.0+cpu to ensure the CPU-only variant is installed
  • Added explanatory comments documenting the rationale for these changes

Details

The default PyTorch distribution includes CUDA libraries (cublas, cudnn, nccl, cufft, etc.) that are not needed in CPU-only environments. On resource-constrained platforms like Hugging Face Spaces, this bloat can cause scheduling failures and slow cold starts. By explicitly using the CPU-only wheel distribution, we reduce the image footprint while maintaining the same torch version that was already being resolved.

https://claude.ai/code/session_012WxvcLFdwVfcPFkCmqPVEu

PerinbaBuilds added 2 commits July 8, 2026 19:48
The unpinned torch dependency resolved to the CUDA build, pulling ~2.5GB
of unused NVIDIA GPU libraries (cublas, cudnn, nccl, cufft, cusolver,
triton, ...). On a CPU-only Space this bloats the image enough that the
platform cannot schedule the container ('Scheduling failure: unable to
schedule') and cold starts are slow.

Pin torch to the CPU wheel (same version, via the PyTorch CPU index) so
no CUDA packages are installed. Image shrinks by ~2.5GB.
Uptime monitors (UptimeRobot free tier) probe with HEAD by default. The
GET-only /health route answered HEAD with 405 Method Not Allowed, so the
monitor reported the Space as down even though it was healthy. Accept both
GET and HEAD.
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