Use CPU-only PyTorch build to reduce image size#5
Open
PerinbaBuilds wants to merge 2 commits into
Open
Conversation
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.
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
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
torch==2.12.0+cputo ensure the CPU-only variant is installedDetails
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