Research Notes

[Solved] 'RuntimeError: CUDA out of memory.' 본문

Programming Language/Python

[Solved] 'RuntimeError: CUDA out of memory.'

jiachoi 2022. 4. 27. 13:14

- 문제 : 'RuntimeError: CUDA out of memory.' -> 모델이 계산량이 많고, 데이터 배치 사이즈가 커서, 에러가 남. 

 보통  batch  size를 줄이라고 하던데, 8까지 줄여봐도 효과 없었음 (아래 링크 참고) 

https://github.com/pytorch/pytorch/issues/16417 

 

RuntimeError: CUDA out of memory. Tried to allocate 12.50 MiB (GPU 0; 10.92 GiB total capacity; 8.57 MiB already allocated; 9.28

CUDA Out of Memory error but CUDA memory is almost empty I am currently training a lightweight model on very large amount of textual data (about 70GiB of text). For that I am using a machine on a c...

github.com

 

- 해결 : GPU 메모리를 reset 해주는 코드를 에러나는 코드 위에 넣어서 돌림. 배치 사이즈도 줄여줬음! 

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