The first thing you can try is wrapping your model with torch.no_grad().
If you have already wrapped your model with torch.no_grad() and are still experiencing the GPU memory leakage issue,
then you can do the garbage collection as well as the memory cache deletion as follows:
import gc
gc.collect()
torch.cuda.empty_cache()
evaluation mode에서 gpu memory leakage를 경험할 경우 모델을 torch.no_grad()로 감쌌는지 확인해본다. 감쌌는데도 여전히 동일한 문제가 발생할 경우,
import gc
gc.collect()
torch.cuda.empty_cache()
를 해주어 garbage collection과 메모리 캐시 삭제를 해주면 된다. 다만 이 경우 코드의 실행 속도가 느려진다.