Using PyTorch on Heroku

I wanted to share a problem I ran into whilst trying to run a Python app with the torch library on Heroku. If you see a message like this in your Heroku deployment logs:

Compiled slug size: 504MB is too large (max is 500MB).

Its probably because the torch library is being included in its entirety including all the CUDA libraries. At time of writing, none of the Heroku Dyno instances support CUDA, so there is no need to include all those libraries. You need to specify the cpu only version to fix it. In your requirements.txt, add the following at the top:

-f https://download.pytorch.org/whl/cpu/torch_stable.html

And then update your torch dependency to add the "+cpu" suffix:

torch==2.3.1+cpu

Note, the latest version of torch may not have a CPU-only build, so you may need to check the CPU build releases here to find the latest version: https://download.pytorch.org/whl/cpu/torch_stable.html


Comments

Popular posts from this blog

Getting code highlighting working on Blogger

Problem deploying app to heroku using GitHub Actions