why Heroku: slug size so large after installing Pytorch?
I'm trying to deploy python to heroku, but it's too big to deploy.
I've been getting the slug size too large warning (Compiled slug size: 789.8M is too large (max is 500M)) from Heroku
Compiled slug size: 826.6M is too large (max is 500M).
remote:  !     See: http://devcenter.heroku.com/articles/slug-size
remote:
remote:  !     Push failed
remote: Verifying deploy....
remote:
fastapi==0.78.0
gunicorn==20.1.0
numpy==1.22.4
opencv-python==4.5.4.58
Pillow==8.4.0
retina-face==0.0.12
uvicorn==0.17.6
--find-links https://download.pytorch.org/whl/torch_stable.html
torch==1.11.0+cpu; python_full_version &gt;= &quot;3.6.2&quot;
torchvision==0.12.0+cpu
tensorflow-cpu == 2.8.0

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----&gt; Building on the Heroku-20 stack
remote: -----&gt; Determining which buildpack to use for this app
remote: -----&gt; Python app detected
remote: -----&gt; No Python version was specified. Using the buildpack default: python-3.10.5
remote:        To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
remote: -----&gt; Installing python-3.10.5
remote: -----&gt; Installing pip 22.1.2, setuptools 60.10.0 and wheel 0.37.1
remote: -----&gt; Installing SQLite3
remote: -----&gt; Installing requirements with pip
remote:        Looking in links: https://download.pytorch.org/whl/torch_stable.html
remote:        Collecting fastapi==0.78.0
remote:          Downloading fastapi-0.78.0-py3-none-any.whl (54 kB)
remote:        Collecting gunicorn==20.1.0
remote:          Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
remote:        Collecting numpy==1.22.4
remote:          Downloading numpy-1.22.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.8 MB)
remote:        Collecting opencv-python==4.5.4.58
remote:          Downloading opencv_python-4.5.4.58-cp310-cp310-manylinux2014_x86_64.whl (60.3 MB)
remote:        Collecting Pillow==8.4.0
remote:          Downloading Pillow-8.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.1 MB)
remote:        Collecting retina-face==0.0.12
remote:          Downloading retina_face-0.0.12-py3-none-any.whl (15 kB)
remote:        Collecting uvicorn==0.17.6
remote:          Downloading uvicorn-0.17.6-py3-none-any.whl (53 kB)
remote:        Collecting torch==1.11.0+cpu
remote:          Downloading https://download.pytorch.org/whl/cpu/torch-1.11.0%2Bcpu-cp310-cp310-linux_x86_64.whl (169.2 MB)
remote:        Collecting torchvision==0.12.0+cpu
remote:          Downloading https://download.pytorch.org/whl/cpu/torchvision-0.12.0%2Bcpu-cp310-cp310-linux_x86_64.whl (14.7 MB)
remote:        Collecting tensorflow-cpu==2.8.0
remote:          Downloading tensorflow_cpu-2.8.0-cp310-cp310-manylinux2010_x86_64.whl (190.6 MB)
remote:        Collecting pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,&lt;2.0.0,&gt;=1.6.2
remote:          Downloading pydantic-1.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.0 MB)
remote:        Collecting starlette==0.19.1
remote:          Downloading starlette-0.19.1-py3-none-any.whl (63 kB)
remote:        Collecting gdown&gt;=3.10.1
remote:          Downloading gdown-4.4.0.tar.gz (14 kB)
remote:          Installing build dependencies: started
remote:          Installing build dependencies: finished with status 'done'
remote:          Getting requirements to build wheel: started
remote:          Getting requirements to build wheel: finished with status 'done'
remote:          Preparing metadata (pyproject.toml): started
remote:          Preparing metadata (pyproject.toml): finished with status 'done'
remote:        Collecting tensorflow&gt;=1.9.0
remote:          Downloading tensorflow-2.9.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (511.7 MB)
remote:        Collecting h11&gt;=0.8
remote:          Downloading h11-0.13.0-py3-none-any.whl (58 kB)
remote:        Collecting click&gt;=7.0
remote:          Downloading click-8.1.3-py3-none-any.whl (96 kB)
remote:        Collecting asgiref&gt;=3.4.0
remote:          Downloading asgiref-3.5.2-py3-none-any.whl (22 kB)
remote:        Collecting typing-extensions
remote:          Downloading typing_extensions-4.2.0-py3-none-any.whl (24 kB)
remote:        Collecting requests
remote:          Downloading requests-2.28.0-py3-none-any.whl (62 kB)
remote:        Collecting opt-einsum&gt;=2.3.2
remote:          Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB)
remote:        Collecting flatbuffers&gt;=1.12
remote:          Downloading flatbuffers-2.0-py2.py3-none-any.whl (26 kB)
remote:        Collecting gast&gt;=0.2.1
remote:          Downloading gast-0.5.3-py3-none-any.whl (19 kB)
remote:        Collecting keras-preprocessing&gt;=1.1.1
remote:          Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
remote:        Collecting libclang&gt;=9.0.1
remote:          Downloading libclang-14.0.1-py2.py3-none-manylinux1_x86_64.whl (14.5 MB)
remote:        Collecting grpcio&lt;2.0,&gt;=1.24.3
remote:          Downloading grpcio-1.46.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB)
remote:        Collecting tensorboard&lt;2.9,&gt;=2.8
remote:          Downloading tensorboard-2.8.0-py3-none-any.whl (5.8 MB)
remote:        Collecting astunparse&gt;=1.6.0
remote:          Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
remote:        Collecting protobuf&gt;=3.9.2
remote:          Downloading protobuf-4.21.1-cp37-abi3-manylinux2014_x86_64.whl (407 kB)
remote:        Collecting keras&lt;2.9,&gt;=2.8.0rc0
remote:          Downloading keras-2.8.0-py2.py3-none-any.whl (1.4 MB)
remote:        Collecting six&gt;=1.12.0
remote:          Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
remote:        Collecting termcolor&gt;=1.1.0
remote:          Downloading termcolor-1.1.0.tar.gz (3.9 kB)
remote:          Preparing metadata (setup.py): started
remote:          Preparing metadata (setup.py): finished with status 'done'
remote:        Collecting absl-py&gt;=0.4.0
remote:          Downloading absl_py-1.1.0-py3-none-any.whl (123 kB)
remote:        Collecting google-pasta&gt;=0.1.1
remote:          Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
remote:        Collecting tensorflow-io-gcs-filesystem&gt;=0.23.1
remote:          Downloading tensorflow_io_gcs_filesystem-0.26.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.4 MB)
remote:        Collecting h5py&gt;=2.9.0
remote:          Downloading h5py-3.7.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (4.5 MB)
remote:        Collecting tf-estimator-nightly==2.8.0.dev2021122109
remote:          Downloading tf_estimator_nightly-2.8.0.dev2021122109-py2.py3-none-any.whl (462 kB)
remote:        Collecting wrapt&gt;=1.11.0
remote:          Downloading wrapt-1.14.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (77 kB)
remote:        Collecting anyio&lt;5,&gt;=3.4.0
remote:          Downloading anyio-3.6.1-py3-none-any.whl (80 kB)
remote:        Collecting tqdm
remote:          Downloading tqdm-4.64.0-py2.py3-none-any.whl (78 kB)
remote:        Collecting filelock
remote:          Downloading filelock-3.7.1-py3-none-any.whl (10 kB)
remote:        Collecting beautifulsoup4
remote:          Downloading beautifulsoup4-4.11.1-py3-none-any.whl (128 kB)
remote:        Collecting werkzeug&gt;=0.11.15
remote:          Downloading Werkzeug-2.1.2-py3-none-any.whl (224 kB)
remote:        Collecting google-auth-oauthlib&lt;0.5,&gt;=0.4.1
remote:          Downloading google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
remote:        Collecting markdown&gt;=2.6.8
remote:          Downloading Markdown-3.3.7-py3-none-any.whl (97 kB)
remote:        Collecting google-auth&lt;3,&gt;=1.6.3
remote:          Downloading google_auth-2.7.0-py2.py3-none-any.whl (160 kB)
remote:        Collecting tensorboard-data-server&lt;0.7.0,&gt;=0.6.0
remote:          Downloading tensorboard_data_server-0.6.1-py3-none-manylinux2010_x86_64.whl (4.9 MB)
remote:        Collecting tensorboard-plugin-wit&gt;=1.6.0
remote:          Downloading tensorboard_plugin_wit-1.8.1-py3-none-any.whl (781 kB)
remote:        Collecting charset-normalizer~=2.0.0
remote:          Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
remote:        Collecting urllib3&lt;1.27,&gt;=1.21.1
remote:          Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
remote:        Collecting idna&lt;4,&gt;=2.5
remote:          Downloading idna-3.3-py3-none-any.whl (61 kB)
remote:        Collecting certifi&gt;=2017.4.17
remote:          Downloading certifi-2022.5.18.1-py3-none-any.whl (155 kB)
remote:        Collecting gast&gt;=0.2.1
remote:          Downloading gast-0.4.0-py3-none-any.whl (9.8 kB)
remote:        Collecting tensorflow-estimator&lt;2.10.0,&gt;=2.9.0rc0
remote:          Downloading tensorflow_estimator-2.9.0-py2.py3-none-any.whl (438 kB)
remote:        Collecting tensorflow&gt;=1.9.0
remote:          Downloading tensorflow-2.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (511.7 MB)
remote:          Downloading tensorflow-2.8.2-cp310-cp310-manylinux2010_x86_64.whl (498.0 MB)
remote:        Collecting tensorflow-estimator&lt;2.9,&gt;=2.8
remote:          Downloading tensorflow_estimator-2.8.0-py2.py3-none-any.whl (462 kB)
remote:        Collecting protobuf&gt;=3.9.2
remote:          Downloading protobuf-3.19.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB)
remote:        Collecting sniffio&gt;=1.1
remote:          Downloading sniffio-1.2.0-py3-none-any.whl (10 kB)
remote:        Collecting rsa&lt;5,&gt;=3.1.4
remote:          Downloading rsa-4.8-py3-none-any.whl (39 kB)
remote:        Collecting cachetools&lt;6.0,&gt;=2.0.0
remote:          Downloading cachetools-5.2.0-py3-none-any.whl (9.3 kB)
remote:        Collecting pyasn1-modules&gt;=0.2.1
remote:          Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
remote:        Collecting requests-oauthlib&gt;=0.7.0
remote:          Downloading requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)
remote:        Collecting soupsieve&gt;1.2
remote:          Downloading soupsieve-2.3.2.post1-py3-none-any.whl (37 kB)
remote:        Collecting PySocks!=1.5.7,&gt;=1.5.6
remote:          Downloading PySocks-1.7.1-py3-none-any.whl (16 kB)
remote:        Collecting pyasn1&lt;0.5.0,&gt;=0.4.6
remote:          Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
remote:        Collecting oauthlib&gt;=3.0.0
remote:          Downloading oauthlib-3.2.0-py3-none-any.whl (151 kB)
remote:        Building wheels for collected packages: gdown, termcolor
remote:          Building wheel for gdown (pyproject.toml): started
remote:          Building wheel for gdown (pyproject.toml): finished with status 'done'
remote:          Created wheel for gdown: filename=gdown-4.4.0-py3-none-any.whl size=14759 sha256=7708c4f7156a089f3fc5fc4488a952096a5a55641ba3eb077fbe30557bad88b9
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-gs7e9o2q/wheels/03/0b/3f/6ddf67a417a5b400b213b0bb772a50276c199a386b12c06bfc
remote:          Building wheel for termcolor (setup.py): started
remote:          Building wheel for termcolor (setup.py): finished with status 'done'
remote:          Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4848 sha256=1d47aa236c647ae87a51f34c01fb6c879088c2d0af3e04cd7a949a4b8b0ae977
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-gs7e9o2q/wheels/a1/49/46/1b13a65d8da11238af9616b00fdde6d45b0f95d9291bac8452
remote:        Successfully built gdown termcolor
remote:        Installing collected packages: tf-estimator-nightly, termcolor, tensorflow-estimator, tensorboard-plugin-wit, pyasn1, libclang, keras, flatbuffers, wrapt, werkzeug, urllib3, typing-extensions, tqdm, tensorflow-io-gcs-filesystem, tensorboard-data-server, soupsieve, sniffio, six, rsa, PySocks, pyasn1-modules, protobuf, Pillow, oauthlib, numpy, markdown, idna, h11, gunicorn, gast, filelock, click, charset-normalizer, certifi, cachetools, asgiref, absl-py, uvicorn, torch, requests, pydantic, opt-einsum, opencv-python, keras-preprocessing, h5py, grpcio, google-pasta, google-auth, beautifulsoup4, astunparse, anyio, torchvision, starlette, requests-oauthlib, google-auth-oauthlib, gdown, fastapi, tensorboard, tensorflow-cpu, tensorflow, retina-face
remote:        Successfully installed Pillow-8.4.0 PySocks-1.7.1 absl-py-1.1.0 anyio-3.6.1 asgiref-3.5.2 astunparse-1.6.3 beautifulsoup4-4.11.1 cachetools-5.2.0 certifi-2022.5.18.1 charset-normalizer-2.0.12 click-8.1.3 fastapi-0.78.0 filelock-3.7.1 flatbuffers-2.0 gast-0.5.3 gdown-4.4.0 google-auth-2.7.0 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.46.3 gunicorn-20.1.0 h11-0.13.0 h5py-3.7.0 idna-3.3 keras-2.8.0 keras-preprocessing-1.1.2 libclang-14.0.1 markdown-3.3.7 numpy-1.22.4 oauthlib-3.2.0 opencv-python-4.5.4.58 opt-einsum-3.3.0 protobuf-3.19.4 pyasn1-0.4.8 pyasn1-modules-0.2.8 pydantic-1.9.1 requests-2.28.0 requests-oauthlib-1.3.1 retina-face-0.0.12 rsa-4.8 six-1.16.0 sniffio-1.2.0 soupsieve-2.3.2.post1 starlette-0.19.1 tensorboard-2.8.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-2.8.2 tensorflow-cpu-2.8.0 tensorflow-estimator-2.8.0 tensorflow-io-gcs-filesystem-0.26.0 termcolor-1.1.0 tf-estimator-nightly-2.8.0.dev2021122109 torch-1.11.0+cpu torchvision-0.12.0+cpu tqdm-4.64.0 typing-extensions-4.2.0 urllib3-1.26.9 uvicorn-0.17.6 werkzeug-2.1.2 wrapt-1.14.1
remote: -----&gt; Discovering process types
remote:        Procfile declares types -&gt; web
remote:
remote: -----&gt; Compressing...
remote:  !     Compiled slug size: 826.6M is too large (max is 500M).
remote:  !     See: http://devcenter.heroku.com/articles/slug-size
remote:
remote:  !     Push failed
remote: Verifying deploy....
remote:
remote: !       Push rejected to lit-castle-78959.
remote:


You are installing both pytorch and tensorflow in the same slug.
Both libraries are known to be large and they are rarely deployed in the same slug.
Since they both aim to solve the same problem (neural networks/tensor computation), do you really need both? If yes, try to split your application and create two different slugs.
I am used to deploy slugs with either torch==1.11.0+cpu or tensorflow-cpu==2.1.0.
