Fastai library too large for heroku

Hello everyone, I encounter a problem today when deploying an application with fastai v2 to heroku free server.
The problem is the slug size too large which exceeds 500MB. Most of it comes from fastai and its dependencies.

What should I do to reduce the slug size? Thanks in advance.

You should use the pytorch-cpu package when deploying to heroku, this significantly reduces the deployment size. Here’s a related StackOverflow thread

2 Likes

I come back to confirm for anyone encounter. This approach works. Thank you Raphi.

1 Like

I spent a while fiddling around with different package versions. I got things working so I figured I’d share my requirements.txt.

https://download.pytorch.org/whl/cpu/torch-1.7.1%2Bcpu-cp38-cp38-linux_x86_64.whl
fastai==2.2.5
voila==0.2.6
ipywidgets==7.6.3

This works on Heroku-20 stack on python 3.8.

It produces a slug of 366 MB which is still pretty large – I wish there was a good way to trim down some of the dependencies for fastai for a smaller serving library.