App deployment on heroku platform

So, on heroku i am only interested in deploying the app, similar to what Jeremy showed with binder. so i have trained the model, exported to .pkl file. now i want to deploy the app to heroku using streamlit. the issue i have is that heroku limits build size to 500MB. When i put fastai2 in requirements.txt, heroku will build it with pip install fastai2. Which installs everyting fastai2 has (nlp, tabular, collabe, vision) and all dependencies which is more than 500MB. I found the way to install torch for cpu only which was just below the limit, but when i uploaded export.pkl file it went up above limit again :frowning:

What i want to find out - if it’s possible to do something like pip install --no-deps on heroku, but so far i haven’t managed to find that, or any other method really to install only required bits from fastai2 on heroku platform.

This is re-post from the beginner forums, but as this wasn’t discussed in the lecture i think it’s better suited for the non-beginner


Try saving the PyTorch model file (ex: learn.pth), and performing inference with PyTorch (CPU version). Also, some models (like ResNet50) will still likely not fit under the 500 MB requirement. Try training with smaller models. Some of the smaller models included in torchvision include SqueezeNets and MobileNetV2.

1 Like

EfficientNet’s are a good alternative too for smaller but powerful models, last week I was training an EfficientNet b5 that was 466mb when exported, it should outperform a vanilla ResNet50.

1 Like

Hi! I am also having troubles, deploying to heroku. It worked fine with fastaiv1 but it doesn’t work with v2.
This is my requirements.txt:

fastai2>=0.0.11> linux_x86_64.whl

When I deploy, this error occures:

-----> Deleting 4 files matching .slugignore patterns.
-----> Python app detected
cp: cannot create regular file '/app/tmp/cache/.heroku/requirements.txt': No such file or directory
-----> Installing python-3.8.2
-----> Installing pip
-----> Installing dependencies with Pipenv 2018.5.18…
       Installing -e git+…
       Obtaining fastai2 from git+
         Cloning (to 4ac2d8913a5094fb15489f4b80296b9429330b8e) to ./src/fastai2
       Collecting fastcore (from fastai2)
       Collecting torch<1.4.0,>=1.2.0 (from fastai2)
       Error:  An error occurred while installing -e git+!
         Could not find a tag or branch '4ac2d8913a5094fb15489f4b80296b9429330b8e', assuming commit.
         Could not find a version that satisfies the requirement torch<1.4.0,>=1.2.0 (from fastai2) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2, 1.4.0)
       No matching distribution found for torch<1.4.0,>=1.2.0 (from fastai2)
       You are using pip version 9.0.2, however version 20.0.2 is available.
       You should consider upgrading via the 'pip install --upgrade pip' command.
 !     Push rejected, failed to compile Python app.
 !     Push failed
1 Like

Just signed up to Heroku and then saw this…

Can you share how you installed torch for cpu only, how much disk space that took up, and how much was left?

Also, why do you want to do pip install --no-deps? Wouldn’t you still need pytorch sooner or later?

Have you looked other services, such as Pythonanywhere?

i put the below in the requirements.txt file


nut sure if i need torchvision though, can experiment with it

i wanted to install fastai2 but without all the dependencies i don’t need for CV problem, like spacy, pandas, etc. but couldn’t find a way to do it. i wrote to heroku support but they replied that they don’t know --no-deps but insted they gave me more space for this container 650MB isntead of 500MB and it worked.

i haven’t looked at other services so far.

Thanks. Streamlit looks pretty cool!