TinyZeaMays / CircleLoss

Pytorch implementation of the paper "Circle Loss: A Unified Perspective of Pair Similarity Optimization"

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

softplus failed to compute its gradient

LiuJMzzZ opened this issue · comments

i use your version of circle loss to do a image classification
when loss.backward() an error occured

in your code loss -> forward
loss_temp = torch.logsumexp(logit_n, dim=0) + torch.logsumexp(logit_p, dim=0) loss = self.soft_plus(loss_temp)
there is an error that softplus cannot compute its gradient, maybe the F.softplus take an inplace operation?

my version is python 3.7 and torch 1.5.0

Warning: Error detected in SoftplusBackward. Traceback of forward call that caused the error: File "train.py", line 473, in <module> train_fun(args, train_loader, feat_loader, i) File "train.py", line 221, in train_fun loss = criterion(embed_feat, labels) File "/home/anaconda3/envs/ljm/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in __call__ result = self.forward(*input, **kwargs) File "/home/Project/SDC-IL/SDC-IL/losses/circle_loss.py", line 51, in forward loss = F.softplus(loss_temp) (print_stack at /opt/conda/conda-bld/pytorch_1587428266983/work/torch/csrc/autograd/python_anomaly_mode.cpp:60) iter 0Traceback (most recent call last): File "train.py", line 473, in <module> train_fun(args, train_loader, feat_loader, i) File "train.py", line 230, in train_fun loss.backward() File "/home/anaconda3/envs/ljm/lib/python3.7/site-packages/torch/tensor.py", line 198, in backward torch.autogr ad.backward(self, gradient, retain_graph, create_graph) File "/home/anaconda3/envs/ljm/lib/python3.7/site-packages/torch/autograd/__init__.py", line 100, in backward allow_unreachable=True) # allow_unreachable flag RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor []], which is output 0 of SoftplusBackward, is at version 1; expected version 0 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!

Sorry, it is something on my own code, not this circleloss.
i replace loss += loss_aug by loss = loss + loss_aug that's cause by inplace operation