Skip to content

fix: install CPU-only torch so the image can actually be deployed - #137

Merged
saqibmanan merged 1 commit into
devfrom
fix/cpu-only-torch-image-size
Sep 3, 2026
Merged

fix: install CPU-only torch so the image can actually be deployed#137
saqibmanan merged 1 commit into
devfrom
fix/cpu-only-torch-image-size

Conversation

@saqibmanan

Copy link
Copy Markdown
Contributor

Blocking. Deploys are currently failing and this is why.

The problem

The image is 14.1GB. docker pull now runs past the deploy step's 40 minute command_timeout, so Deploy to EC2 fails with Run Command Timeout. That is what stopped #136 (the row-lock fix) from reaching dev — it merged green and then could not be deployed. I confirmed the interrupted pull left nothing cached, so a re-run just restarts the same doomed download.

Where the size comes from

Measured in the running container:

Layer / package Size
pip install -r requirements.txt 12.1GB
site-packages/nvidia 4.3GB
site-packages/torch 1.7GB
site-packages/triton 592MB

That is ~6.6GB of CUDA runtime on a 2-CPU EC2 instance with no GPU, which cannot execute any of it.

The change

Install CPU-only torch before requirements.txt, so the pinned torch==2.9.0 is already satisfied and pip never reaches for the default CUDA build.

PEP 440 treats the local version segment as compatible, so 2.9.0+cpu satisfies ==2.9.0 and requirements.txt needs no change. I confirmed the wheel exists for this exact version and platform: torch-2.9.0+cpu-cp310-cp310-manylinux_2_28_x86_64.whl. This changes the build of torch, not the version.

--no-cache-dir on both installs drops the pip wheel cache from the layer.

Worth checking at review

If anything in the codebase assumes CUDA is available it will now find none — though on this box it never had a GPU, so runtime behaviour there should be unchanged. Inference via transformers/torch will run on CPU, as it already effectively did.

Effect

Once merged, the next build from dev carries both this and the #136 row-lock fix, so a single successful deploy lands both. Verification of the row-lock fix follows on #136 once it is actually running.

The image is 14.1GB and `docker pull` now runs past the deploy step's
40 minute command_timeout, so deploys fail outright. That is what
stopped the row-lock fix in #136 from reaching dev - it merged green and
then could not be deployed.

Where the size comes from, measured in the running container:

    12.1GB  RUN pip install -r requirements.txt
     4.3GB  site-packages/nvidia
     1.7GB  site-packages/torch
     592MB  site-packages/triton

That is roughly 6.6GB of CUDA runtime on a 2-CPU EC2 instance with no
GPU, which cannot execute any of it.

Installing CPU-only torch first means the pinned torch==2.9.0 is already
satisfied and pip never reaches for the CUDA build. PEP 440 treats the
local version segment as compatible, so 2.9.0+cpu satisfies ==2.9.0 and
requirements.txt needs no change. The wheel was confirmed to exist for
this exact version and platform
(torch-2.9.0+cpu-cp310-cp310-manylinux_2_28_x86_64.whl), so this changes
the build of torch, not the version.

--no-cache-dir on both installs drops the pip wheel cache from the layer.

This is a prerequisite now rather than an optimisation: nothing else can
deploy until the pull fits inside the timeout.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

2 participants