기록용.
1. Model GPU 사용량 체크
print('Memory Usage:')
print('Max Alloc:', round(torch.cuda.max_memory_allocated(0)/1024**3, 1), 'GB')
print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
# MB 단위 : print(torch.cuda.memory_allocated() / 1024 /1024)
print('Cached: ', round(torch.cuda.memory_cached(0)/1024**3,1), 'GB')
⚠️nvidia-smi는 reserved memory를 포함한 값이기 때문에 실제 모델의 GPU 사용량을 보여주는 것이라 보기 힘들다.
(관련 stackoverflow)
=> 참고 자료 추가 (https://pytorch.org/blog/understanding-gpu-memory-1/)
2. Inference time
딥러닝 모델의 GPU 연산이 비동기적으로 수행되기 때문에 time.time()을 쓰면 실제 GPU 작업이 끝나기도 전에 CPU 내에서 측정을 종료할 수 있음.
따라서 정확한 시간 측정을 위해서는torch.cuda에서 제공하는 Event 클래스를 활용.
import torch
model.eval()
model = model.cuda()
starter = torch.cuda.Event(enable_timing=True)
ender = torch.cuda.Event(enable_timing=True)
with torch.no_grad(): # Gradient 연산 비활성화
starter.record()
output = model(input_tensor.cuda())
ender.record()
torch.cuda.synchronize() # Gpu 연산이 완료될 때까지 대기
infer_time = starter.elapsed_time(ender)
print("Elapsed time: {} s".format(infer_time * 1e-3)) # milliseconds to second
Deep Learning Model Inference time 정확히 측정하는 방법
Deep learning model inference time을 정확히 측정하는 법 요즘 ChatGPT, DALL-E 등 딥러닝 모델들이 많은 주목을 받고, 이에 따라 사용량 또한 급증하면서 모델을 사용할 때의 적은 inference time이 더욱 중요해
seungseop.tistory.com
Pytorch Inference time 측정
요즘 딥러닝의 수요가 증가하는 만큼 현업에서는 굉장히 빠른 인퍼런스 속도를 요구합니다. 때문에 밀리초 단위로 평가가 나뉘며 그 속도를 재는 방법이 중요합니다. 하지만 정확한 속도측정을
velog.io
'머신러닝' 카테고리의 다른 글
[mmdetection/ mmrotate] Loss Nan (0) | 2023.03.28 |
---|---|
자연어 처리 도움되는 사이트 (1) | 2020.07.20 |
YOLO (0) | 2019.04.25 |
기록용.
1. Model GPU 사용량 체크
print('Memory Usage:')
print('Max Alloc:', round(torch.cuda.max_memory_allocated(0)/1024**3, 1), 'GB')
print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
# MB 단위 : print(torch.cuda.memory_allocated() / 1024 /1024)
print('Cached: ', round(torch.cuda.memory_cached(0)/1024**3,1), 'GB')
⚠️nvidia-smi는 reserved memory를 포함한 값이기 때문에 실제 모델의 GPU 사용량을 보여주는 것이라 보기 힘들다.
(관련 stackoverflow)
=> 참고 자료 추가 (https://pytorch.org/blog/understanding-gpu-memory-1/)
2. Inference time
딥러닝 모델의 GPU 연산이 비동기적으로 수행되기 때문에 time.time()을 쓰면 실제 GPU 작업이 끝나기도 전에 CPU 내에서 측정을 종료할 수 있음.
따라서 정확한 시간 측정을 위해서는torch.cuda에서 제공하는 Event 클래스를 활용.
import torch
model.eval()
model = model.cuda()
starter = torch.cuda.Event(enable_timing=True)
ender = torch.cuda.Event(enable_timing=True)
with torch.no_grad(): # Gradient 연산 비활성화
starter.record()
output = model(input_tensor.cuda())
ender.record()
torch.cuda.synchronize() # Gpu 연산이 완료될 때까지 대기
infer_time = starter.elapsed_time(ender)
print("Elapsed time: {} s".format(infer_time * 1e-3)) # milliseconds to second
Deep Learning Model Inference time 정확히 측정하는 방법
Deep learning model inference time을 정확히 측정하는 법 요즘 ChatGPT, DALL-E 등 딥러닝 모델들이 많은 주목을 받고, 이에 따라 사용량 또한 급증하면서 모델을 사용할 때의 적은 inference time이 더욱 중요해
seungseop.tistory.com
Pytorch Inference time 측정
요즘 딥러닝의 수요가 증가하는 만큼 현업에서는 굉장히 빠른 인퍼런스 속도를 요구합니다. 때문에 밀리초 단위로 평가가 나뉘며 그 속도를 재는 방법이 중요합니다. 하지만 정확한 속도측정을
velog.io
'머신러닝' 카테고리의 다른 글
[mmdetection/ mmrotate] Loss Nan (0) | 2023.03.28 |
---|---|
자연어 처리 도움되는 사이트 (1) | 2020.07.20 |
YOLO (0) | 2019.04.25 |