From 39190f5f448887190fe138f804fc8214dfe1a337 Mon Sep 17 00:00:00 2001 From: Hoan Nguyen Date: Mon, 17 Oct 2022 10:41:21 +0200 Subject: [PATCH] Remove inplace operators when calculating the loss Remove inplace operators to overcome the following error when using `asymmetric_loss` ``` RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation ``` --- timm/loss/asymmetric_loss.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timm/loss/asymmetric_loss.py b/timm/loss/asymmetric_loss.py index 96a97788..ca7e0b7f 100644 --- a/timm/loss/asymmetric_loss.py +++ b/timm/loss/asymmetric_loss.py @@ -85,7 +85,7 @@ class AsymmetricLossSingleLabel(nn.Module): log_preds = log_preds * asymmetric_w if self.eps > 0: # label smoothing - self.targets_classes.mul_(1 - self.eps).add_(self.eps / num_classes) + self.targets_classes = self.targets_classes.mul(1 - self.eps).add(self.eps / num_classes) # loss calculation loss = - self.targets_classes.mul(log_preds)