반응형

RuntimeError: CUDA out of memory. Tried to allocate 192.00 MiB (GPU 0; 15.90 GiB total capacity; 14.92 GiB already allocated; 3.75 MiB free; 15.02 GiB reserved in total by PyTorch)

 

이런 에러가 발생하는 이유는 batch size가 너무 크거나, 코드 상에서 메모리 누수가 발생했기 때문이라고 한다.

batch size 크기를 줄여가면서 gpu 캐시를 비워주는 아래 코드를 실행해보니 해결이 되었다.

import gc
import torch

gc.collect()
torch.cuda.empty_cache()

 

 

 

반응형

+ Recent posts