0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Herokuでアプリをデプロイしたらslug sizeがとデカすぎた話

Posted at

起きたこと

あるpythonアプリをherokuにデプロイしようとしたら...

-----> Building on the Heroku-24 stack
-----> Determining which buildpack to use for this app
-----> Python app detected
-----> Using Python 3.10.12 specified in runtime.txt
-----> Installing Python 3.10.12
-----> Installing pip 24.3.1, setuptools 70.3.0 and wheel 0.45.1
-----> Installing SQLite3
-----> Installing dependencies using 'pip install -r requirements.txt'
#長くなるので省略
       Successfully installed Flask-2.0.1 Jinja2-3.1.5 MarkupSafe-3.0.2 PyYAML-6.0.2 Werkzeug-3.1.3 aiohappyeyeballs-2.4.4 aiohttp-3.11.11 aiosignal-1.3.2 annotated-types-0.7.0 anyio-4.8.0 async-timeout-5.0.1 attrs-24.3.0 certifi-2024.12.14 cffi-1.17.1 charset-normalizer-3.4.1 click-8.1.8 datasets-3.2.0 dill-0.3.8 distro-1.9.0 exceptiongroup-1.2.2 filelock-3.16.1 frozenlist-1.5.0 fsspec-2024.9.0 gunicorn-20.1.0 h11-0.14.0 httpcore-1.0.7 httpx-0.28.1 huggingface-hub-0.27.1 idna-3.10 itsdangerous-2.2.0 jiter-0.8.2 joblib-1.4.2 llvmlite-0.43.0 more-itertools-10.6.0 mpmath-1.3.0 multidict-6.1.0 multiprocess-0.70.16 networkx-3.4.2 numba-0.60.0 numpy-2.0.2 nvidia-cublas-cu12-12.4.5.8 nvidia-cuda-cupti-cu12-12.4.127 nvidia-cuda-nvrtc-cu12-12.4.127 nvidia-cuda-runtime-cu12-12.4.127 nvidia-cudnn-cu12-9.1.0.70 nvidia-cufft-cu12-11.2.1.3 nvidia-curand-cu12-10.3.5.147 nvidia-cusolver-cu12-11.6.1.9 nvidia-cusparse-cu12-12.3.1.170 nvidia-nccl-cu12-2.21.5 nvidia-nvjitlink-cu12-12.4.127 nvidia-nvtx-cu12-12.4.127 openai-whisper-20240930 packaging-24.2 pandas-2.2.3 pillow-11.1.0 propcache-0.2.1 pyarrow-19.0.0 pycparser-2.22 pydantic-2.10.5 pydantic_core-2.27.2 python-dateutil-2.9.0.post0 pytz-2024.2 pyxel-2.2.11 regex-2024.11.6 requests-2.32.3 safetensors-0.5.2 scikit-learn-1.6.1 scipy-1.15.1 semantic-version-2.10.0 sentence-transformers-3.3.1 setuptools-rust-1.10.2 six-1.17.0 sniffio-1.3.1 sounddevice-0.5.1 sympy-1.13.1 threadpoolctl-3.5.0 tiktoken-0.8.0 tokenizers-0.21.0 torch-2.5.1 tqdm-4.67.1 transformers-4.48.0 triton-3.1.0 typing_extensions-4.12.2 tzdata-2024.2 urllib3-2.3.0 xxhash-3.5.0 yarl-1.18.3
-----> Discovering process types
       Procfile declares types -> web
-----> Compressing...
 !     Compiled slug size: 3.1G is too large (max is 500M).
 !     See: http://devcenter.heroku.com/articles/slug-size
 !     Push failed

なんとslug sizeが3.1Gというとんでもなく大きいサイズになってしまっていました。
こんなにサイズが大きくなるのかとびっくりしました。
まず頭の中に一つの疑問が...

そもそもslug sizeとはなんぞや?

slug sizeについてherokuのドキュメントを見てみると

slug は、dyno マネージャ​への配布に最適化された、圧縮および事前パッケージ化されたアプリケーションのコピーです。Heroku に対して git push​ を実行すると、slug コンパイラがコードを受け取り、リポジトリを slug に変換します。その後、アプリケーションのスケーリングによって >slug が dyno にダウンロードされ、展開されて実行されます。

Herokuのアプリケーションはすべてdynoで実行されるので、それ用に最適化されて圧縮されたファイルといったところでしょうか?
ではなぜ3.1Gという大きさになっていたのか?

エラー解決のために行ったこと

heroku-repoを使う

一番良く見つかる解決方法ですが、私の場合は最初にデプロイが失敗していたので使えませんでした。

Herokuのシェルに入って大きさを確認

teratailで質問させていただき、heroku run bashでシェルの中に入ってサイズを確認するようご教授いただきました。しかし、こちらも最初にデプロイが失敗していたのでうまくいきません。

解決方法

先ほどのログにあったnvidia関連のパッケージの容量がかなり大きいことに気づき調べてみたところ、herokuではGPUは使えないとのことでした。そして、pytorchを使用していたことからそれでGPUが使われてしまっているのではないかと気づきました。

すると私と似た境遇の以下の記事を発見...

これでCPUバージョンをインストールすれば良さそうです。

#requiremnents.txt
#以下を追記
// requirements.txt
--extra-index-url https://download.pytorch.org/whl/cpu
torch==2.1.2+cpu  #バージョンは各自で合わせてください

これで解決できました!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?