[코랩/파이토치] 오류 : cuda out of memory

[오류]

RuntimeError: CUDA out of memory.  Tried to allocate 60.00 MiB (GPU 0; 11.17 GiB total capacity; 10.15 GiB already allocated; 
7.81 MiB free; 10.56 GiB reserved in total by PyTorch) 

 

이 오류에 대한 해결방법은 다양하다. 

하지만 대부분의 경우는 두가지 방법 안에서 해결된다.

 

[해결방법]

1) 배치 사이즈 줄이기

보통 배치사이즈가 큰 경우 오류가 발생한다.

나는 원래 사이즈인 64에서 16까지 줄여 해결했다..

 

 

2) GPU 캐시 비워주기

import gc
gc.collect()
torch.cuda.empty_cache()
320x100