From 5c70d06da23170599f02716218b59bb236f46474 Mon Sep 17 00:00:00 2001 From: Kaled Dahleh Date: Sat, 15 Jun 2024 11:32:49 -0500 Subject: [PATCH 1/5] asynch=True argument removed from Pytorch 1.0.0. --- cifar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cifar.py b/cifar.py index 9572cf81..9be2f591 100644 --- a/cifar.py +++ b/cifar.py @@ -245,7 +245,7 @@ def train(trainloader, model, criterion, optimizer, epoch, use_cuda): data_time.update(time.time() - end) if use_cuda: - inputs, targets = inputs.cuda(), targets.cuda(async=True) + inputs, targets = inputs.cuda(), targets.cuda() inputs, targets = torch.autograd.Variable(inputs), torch.autograd.Variable(targets) # compute output From d378d87ec1d56da4321cd66da5151033c0a0e2dd Mon Sep 17 00:00:00 2001 From: Kaled Dahleh Date: Sat, 15 Jun 2024 11:47:13 -0500 Subject: [PATCH 2/5] Fix tensor reshaping: replace view with reshape in accuracy function --- utils/eval.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/eval.py b/utils/eval.py index 50513501..d6f11c66 100644 --- a/utils/eval.py +++ b/utils/eval.py @@ -9,10 +9,10 @@ def accuracy(output, target, topk=(1,)): _, pred = output.topk(maxk, 1, True, True) pred = pred.t() - correct = pred.eq(target.view(1, -1).expand_as(pred)) + correct = pred.eq(target.reshape(1, -1).expand_as(pred)) res = [] for k in topk: - correct_k = correct[:k].view(-1).float().sum(0) + correct_k = correct[:k].reshape(-1).float().sum(0) res.append(correct_k.mul_(100.0 / batch_size)) return res \ No newline at end of file From c570bd6d428bc0c7b8054abefe10b587ed3dc11b Mon Sep 17 00:00:00 2001 From: Kaled Dahleh Date: Sat, 15 Jun 2024 11:55:22 -0500 Subject: [PATCH 3/5] fixed index error accessing 0-dim tensors in training metrics update --- cifar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cifar.py b/cifar.py index 9be2f591..9e6afd5a 100644 --- a/cifar.py +++ b/cifar.py @@ -254,9 +254,9 @@ def train(trainloader, model, criterion, optimizer, epoch, use_cuda): # measure accuracy and record loss prec1, prec5 = accuracy(outputs.data, targets.data, topk=(1, 5)) - losses.update(loss.data[0], inputs.size(0)) - top1.update(prec1[0], inputs.size(0)) - top5.update(prec5[0], inputs.size(0)) + losses.update(loss.item(), inputs.size(0)) + top1.update(prec1.item(), inputs.size(0)) + top5.update(prec5.item(), inputs.size(0)) # compute gradient and do SGD step optimizer.zero_grad() From 29355786e4c85c7c94c7f4bf2c165ea2d95ae271 Mon Sep 17 00:00:00 2001 From: Kaled Dahleh Date: Sat, 15 Jun 2024 12:10:24 -0500 Subject: [PATCH 4/5] fixed remaining index errors accessing 0-dim tensors --- cifar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cifar.py b/cifar.py index 9e6afd5a..65f251b6 100644 --- a/cifar.py +++ b/cifar.py @@ -311,9 +311,9 @@ def test(testloader, model, criterion, epoch, use_cuda): # measure accuracy and record loss prec1, prec5 = accuracy(outputs.data, targets.data, topk=(1, 5)) - losses.update(loss.data[0], inputs.size(0)) - top1.update(prec1[0], inputs.size(0)) - top5.update(prec5[0], inputs.size(0)) + losses.update(loss.item(), inputs.size(0)) + top1.update(prec1.item(), inputs.size(0)) + top5.update(prec5.item(), inputs.size(0)) # measure elapsed time batch_time.update(time.time() - end) From 4d393ff186d3af988a99a91a39d23aa288f04c6f Mon Sep 17 00:00:00 2001 From: Kaled Dahleh Date: Sat, 15 Jun 2024 12:32:12 -0500 Subject: [PATCH 5/5] refactor deprecated volatile=true to torch.no_grad() for better compatibility --- cifar.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cifar.py b/cifar.py index 65f251b6..9dfe0016 100644 --- a/cifar.py +++ b/cifar.py @@ -303,7 +303,9 @@ def test(testloader, model, criterion, epoch, use_cuda): if use_cuda: inputs, targets = inputs.cuda(), targets.cuda() - inputs, targets = torch.autograd.Variable(inputs, volatile=True), torch.autograd.Variable(targets) + with torch.no_grad(): + inputs, targets = torch.autograd.Variable(inputs), torch.autograd.Variable(targets) + # compute output outputs = model(inputs)