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

2 Likes

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:

aiofiles==0.4.0
aiohttp==3.5.4
asyncio==3.4.3
fastai2>=0.0.11
https://download.pytorch.org/whl/cpu/torch-1.1.0-cp37-cp37m-linux_x86_64.whl
https://download.pytorch.org/whl/cpu/torchvision-0.3.0-cp37-cp37m-> linux_x86_64.whl
pillow<7
starlette==0.12.0
uvicorn==0.7.1
nest_asyncio
Jinja2==2.11.1
gunicorn==20.0.4
python-multipart==0.0.5

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+https://github.com/fastai/fastai2@4ac2d8913a5094fb15489f4b80296b9429330b8e#egg=fastai2…
       Obtaining fastai2 from git+https://github.com/fastai/fastai2@4ac2d8913a5094fb15489f4b80296b9429330b8e#egg=fastai2
         Cloning https://github.com/fastai/fastai2 (to 4ac2d8913a5094fb15489f4b80296b9429330b8e) to ./src/fastai2
       Collecting fastcore (from fastai2)
         Downloading https://files.pythonhosted.org/packages/3b/b5/aed836ce5b16ea1088a5d1a41d400bc051abf90bbef58bb74d8fd01a76af/fastcore-0.1.16-py3-none-any.whl
       Collecting torch<1.4.0,>=1.2.0 (from fastai2)
       
       Error:  An error occurred while installing -e git+https://github.com/fastai/fastai2@4ac2d8913a5094fb15489f4b80296b9429330b8e#egg=fastai2!
         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

streamlit
https://download.pytorch.org/whl/cpu/torch-1.4.0%2Bcpu-cp36-cp36m-linux_x86_64.whl
https://download.pytorch.org/whl/cpu/torchvision-0.5.0%2Bcpu-cp36-cp36m-linux_x86_64.whl
fastai2

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!