Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku: slug size too large after installing Pytorch

Tags:

I've been getting the slug size too large warning (Compiled slug size: 789.8M is too large (max is 500M)) from Heroku and I can't figure out why, as my model size (cnn.pth below) is fairly small and my file directory is only 1.1mb in total: screenshot of directory.

It seems like the size increase is caused by running pipenv install torch, as the slug size was 89.1mb before installing torch and 798.8mb after.

My Pipfile currently has these packages installed:

[packages] flask = "*" flask-sqlalchemy = "*" psycopg2 = "*" psycopg2-binary = "*" requests = "*" numpy = "*" gunicorn = "*" pillow = "*" torch = "*" 

Is there any workaround for this?

Edit: I'm running Mac OSX 10.10.5, using Flask and pipenv.

like image 455
galaxea Avatar asked Dec 01 '19 03:12

galaxea


People also ask

How do you reduce a large slug size in Heroku?

The easiest is to add a . slugignore file to your application to tell the slug compiler to ignore any unnecessary files in your application, such as static assets. This can be helpful in determining where large files are. You may also find that clearing the build cache helps reduce the size of the slug.

How do I know my heroku slug size?

Your slug size is displayed at the end of a successful compile after the Compressing message. The maximum allowed slug size (after compression) is 500 MB. You can inspect the extracted contents of your slug with heroku run bash and by using commands such as ls and du .


2 Answers

The pytorch package that you're installing comes with both cpu and gpu support, thus has a large size. It seems you're using the free version of heroku, and only require the cpu support. The solution is to install the pytorch package for cpu only i.e.

In requirements.txt, write the wheel file path corresponding to the version of pytorch (cpu) that you're interested in. You can find the list of wheel files, which can be installed with pip. For example, for PyTorch 1.3.1, torchvision 0.4.2, Python 3.7, Linux, you can write the following for pytorch and torchvision respectively:

https://download.pytorch.org/whl/cpu/torch-1.3.1%2Bcpu-cp37-cp37m-linux_x86_64.whl https://download.pytorch.org/whl/cpu/torchvision-0.4.2%2Bcpu-cp37-cp37m-linux_x86_64.whl 

The above will download torch-1.3.1+cpu-cp37-cp37m-linux_x86_64.whl (107MB) torchvision-0.4.2+cpu-cp37-cp37m-linux_x86_64.whl (13MB) respectively.

like image 148
kHarshit Avatar answered Sep 22 '22 14:09

kHarshit


  1. Go to PyTorch Get Started page. Choose Stable version, Linux, pip, python, cpu and you can see:
pip install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html 
  1. Copy versions to your requirements.txt.
torch==1.8.1+cpu  torchvision==0.9.1+cpu 
  1. And add to the beginning of the requirements.txt this:
-f https://download.pytorch.org/whl/torch_stable.html 

After that, all packages will be installed on Heroku.

For reference: torch==1.8.1+cpu (169.1 MB); torchvision==0.9.1+cpu (13.3 MB)

like image 22
ShtanyNaStol Avatar answered Sep 21 '22 14:09

ShtanyNaStol