에러메시지
OutOfMemoryError: CUDA out of memory. Tried to allocate 48.00 MiB. GPU 0 has a total capacty of 23.69 GiB of which 20.81 MiB is free. Process 2921978 has 23.66 GiB memory in use. Of the allocated memory 23.18 GiB is allocated by PyTorch, and 177.60 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
아래 남은 메모리가 가운데 보이는 24526Mib / 24526Mib 입니다.

아래와 같이 코딩하고 실행합니다..

코드 설명
gc.collect():
torch.cuda.empty_cache():
사용 시기
이 코드를 사용하면 CPU와 GPU 메모리 사용량을 줄일 수 있습니다. 다음과 같은 경우에 유용합니다.
주의 사항

이 코드들을 적절히 사용하면 메모리 관리와 최적화에 도움이 됩니다.