본문 바로가기
Data Science/Deep Learning

캐글 GPU 아끼는 방법! (코드 첨부)

by Queen2 2023. 1. 25.
728x90
반응형

캐글이나 코랩을 열심히 쪼개면서 공부하면, 코드가 좀 잘 돌아가네...? 싶을 때 GPU 다 썼다는 알림이 오는데요....

이번에 유용하게 사용했던 GPU 아끼고 비우는 코드를 공유합니다.

 

from GPUtil import showUtilization as gpu_usage
from numba import cuda

def free_gpu_cache():
    print("Initial GPU Usage")
    gpu_usage()                             

    torch.cuda.empty_cache()

    cuda.select_device(0)
    cuda.close()
    cuda.select_device(0)

    print("GPU Usage after emptying the cache")
    gpu_usage()

free_gpu_cache()

이 코드를 사용하면, 사용전에 GPU사용량과 비우고 나서 사용량을 볼 수 있습니다.

 

Initial GPU Usage
| ID | GPU | MEM |
------------------
|  0 |  0% |  0% |
|  1 |  0% |  0% |
GPU Usage after emptying the cache
| ID | GPU | MEM |
------------------
|  0 |  5% |  1% |
|  1 |  0% |  0% |

 

맥북 가지고 싶다~~ GPU 마음껏 쓰면서 실험하고 싶다~~~

728x90
반응형

댓글