回心誌

日々是回心

"Including non-PyTorch memory, this process has 17179869184.00 GiB memory in use"

ResNetの学習がなんかうまくいかない。

OutOfMemoryError: CUDA out of memory. Tried to allocate 2.00 MiB. GPU 0 has a total capacity of 11.99 GiB of which 0 bytes is free. Including non-PyTorch memory, this process has 17179869184.00 GiB memory in use. Of the allocated memory 26.34 GiB is allocated by PyTorch, and 67.78 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)

17179869184.00 GiB memory in use.ってありえないでしょ・・・。まあ、それは単位の間違いの可能性はあるが。

ググったら以下のような情報があり。
Mistral works on (2.0.1+cu117) but "CUDA out of memory" on (2.1.2+cu121) · Issue #116928 · pytorch/pytorch · GitHub

PyTorchのバージョンを2.1.2にしていた発生したが2.0.1に切り戻したら解消されたとのこと。

自分のバージョンを確認したところ
Version: 2.2.0+cu118
だったので、2.0.1に戻したら直る可能性がある。

ということで

pip uninstall torch torchvision torchaudio
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118

ん-。結局直らず。
同じようなCUDA メモリエラーが発生する。



色々ググり、結局以下のwithブロックに予測処理を入れるようにして勾配計算を停止すればメモリ不足が解消された。
学習のときは使えないが、今回エラーが発生していたのが検証のタイミングなので、これでいける。

with torch.set_grad_enabled(False):