공포의 단어 OOM (Out Of Memory)
OOM은 왜 어려운가?
그 외에 발생할 수 있는 문제들
!pip install GPUtil
import GPUtil
GPUtil.showUtilization()

import torch
from GPUtil import showUtilization as gpu_usage
print("Initial GPU Usage")
gpu_usage()
tensorList = []
for x in range(10):
tensorList.append(torch.randn(10000000,10).cuda())
print("GPU Usage after allcoating a bunch of Tensors")
gpu_usage()
del tensorList
print("GPU Usage after deleting the Tensors")
gpu_usage()
print("GPU Usage after emptying the cache")
torch.cuda.empty_cache()
gpu_usage()

total_loss = 0
for i in range(10000):
optimizer.zero_grad()
output = model(input)
loss = criterion(output)
loss.backward()
optimizer.step()
total_loss += loss
oom = False
try:
run_model(batch_size)
except RuntimeError: # out of memory
oom = True
if oom:
for _ in range(batch_size):
run_model(1)
with torch.no_grad() :
for data, target in test_loader:
output = network(data)
test_loss += F.nll_loss(output, target, size_average=False).item()
pred = output.data.max( 1 , keepdim=True)[1]
correct += pred.eq(target.data.view_as(pred)).sum()
| 강의 복습내용 [week2-7] Multi-GPU 학습 (0) | 2023.03.16 |
|---|---|
| 강의 복습내용 [week2-5] 모델 불러오기 (0) | 2023.03.14 |
| 강의 복습내용 [week2-4] PyTorch Datasets & Dataloaders (0) | 2023.03.13 |
| 강의 복습내용 [week2-3] AutoGrad & Optimizer (0) | 2023.03.13 |
| 강의 복습내용 [week2-1] 파이토치 기초 (0) | 2023.03.13 |
댓글 영역