Heroku:安装 Pytorch 后 slug 尺寸太大

gal*_*xea 22 python heroku pytorch

我一直Compiled slug size: 789.8M is too large (max is 500M)从 Heroku收到 slug size too large 警告 ( ),我不知道为什么,因为我的模型大小(下面的 cnn.pth)相当小,我的文件目录总共只有 1.1mb:截图目录。

大小增加似乎是由运行引起的pipenv install torch,因为安装前的 slug 大小为 89.1mb,安装torch后为 798.8mb 。

我的 Pipfile 目前安装了这些软件包:

[packages]
flask = "*"
flask-sqlalchemy = "*"
psycopg2 = "*"
psycopg2-binary = "*"
requests = "*"
numpy = "*"
gunicorn = "*"
pillow = "*"
torch = "*"
Run Code Online (Sandbox Code Playgroud)

有什么解决方法吗?

编辑:我正在运行 Mac OSX 10.10.5,使用Flaskpipenv

kHa*_*hit 17

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
Run Code Online (Sandbox Code Playgroud)

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.


小智 12

  1. 转到PyTorch 入门页面。选择稳定版、Linux、pip、python、cpu,可以看到:
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
Run Code Online (Sandbox Code Playgroud)
  1. 将版本复制到您的requirements.txt.
torch==1.8.1+cpu 
torchvision==0.9.1+cpu
Run Code Online (Sandbox Code Playgroud)
  1. 并添加到requirements.txtthis的开头:
-f https://download.pytorch.org/whl/torch_stable.html
Run Code Online (Sandbox Code Playgroud)

之后,所有软件包都将安装在 Heroku 上。

供参考: torch==1.8.1+cpu (169.1 MB); torchvision==0.9.1+cpu(13.3 MB)

  • 只是一个提示:我用 `torch>=1.8.1+cpu` 尝试过,但没有成功;弹头尺寸仍然太大。在需求中使用“==”而不是“>=”似乎很重要。 (2认同)