Run time error with backward() after upgrading to pytorch 1.2.0

The following error occurs after I upgrade to Pytorch 1.2.0. No errors when running in 1.1.0

one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [3]], which is output 0 of AddBackward0, is at version 1; expected version 0 instead.


import torch

b0 = torch.tensor(5.0, requires_grad = True)
a = torch.Tensor([1,0,0])
b = torch.zeros(3, requires_grad = True)
c = torch.ones(3, requires_grad = True)

bb = b+1

bb[a!=0] = torch.min(bb[a!=0], c[a!=0])

d = torch.sum(bb)

Is there a way to make it work in 1.2.0? I tried adding clone() at a couple of locations, but still didn’t work.

It’s being followed up here.