I am trying to deploy a web app to Heroku. The free tier is limited to 500 MB.

I am using my resnet34 model as a .pkl file.

I create model with it using the fastai library.

This project requires torch and torchvision as dependencies.

But not specifying the dependency will download the latest version of torch which alone is 750 MB and exceeds the memory limit.

So, I specify torchvision version as 0.2.2 and specify the wheel for torch for v1.1.0 in the requirements.txt file. Now, this gives rise to other problems.

For example, I got this error message from Heroku build log-

ERROR: torchvision 0.2.2 has requirement tqdm==4.19.9, but you'll have tqdm 4.48.0 which is incompatible.

But if I specify tqdm's version to 4.19.9, some library called spacey becomes incompatible and the app fails. If I install more recent version of torchvision, the app size will exceed permitted limits.

How do I get around this problem? How do I find out which dependency versions are compatible with each other, and the total size doesn't exceed 500 MB? Is there an easy way to do that?

  • $\begingroup$ avoid fastai as it has many dependencies; you are good to use the raw libs due to space restrictions! $\endgroup$
    – Aditya
    Aug 1 '20 at 19:08
  • $\begingroup$ @Aditya , using fastai makes the source code small and it is easy to use. That's why I use it. And I cannot really use the latest versions, because they exceed permitted limit. $\endgroup$
    – truth
    Aug 2 '20 at 5:48
  • $\begingroup$ Yep! I know what fastAI is but as I said, the requirements are little high for it. Why don't you try a smaller model? $\endgroup$
    – Aditya
    Aug 2 '20 at 6:18
  • $\begingroup$ @Aditya Model is not a bottleneck. It's less than 90 MB. $\endgroup$
    – truth
    Aug 2 '20 at 6:28
  • 1
    $\begingroup$ Cool! Can you attach a sample as an answer as well? $\endgroup$
    – Aditya
    Aug 13 '20 at 6:27

Till now, what I have learned is that it is a trial and error process.

And the best solution is to look for projects that have already done this using a working combination of libraries.

I used this requirements.txt file, which works fine:


The web app works perfectly and the permitted size is not exceeded.

Although Heroku's size limit is 500 MB, they have a soft limit of 300 MB. These libraries, their dependencies, and the model file together exceed that resulting in a slightly longer response time.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.