Pytorch RunTimeError: one of the variables needed for gradient computation has been modified by an inplace operation

95 views Asked by At

I am currently working on a project that involves the implementation of Bayesian GAN. I am following the Pytorch implementation, and this seems to follow the style of the official tutorial of DCGAN. But when I run the iPython notebook, I get the following error after executing the cell containing the main training loop:

RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [128, 3, 4, 4]] is at version 30; expected version 29 instead.

I have searched online for possible solutions, and most of them point to the concurrent updating of weights of generator and discriminator. But the gradient computation of generator and discriminator shouldn’t be an issue here because the gradients were set to zero before calculation. I have tried replacing all the a+=b operations with a=a+b, but the error persists. I have also tried pushing all the .step() updates after completing all the .backward() operations, but this didn't help either. Setting retain_graph=True inside .backward() doesn't change anything. I have also tried setting False to LeakyReLU, but that didn't change anything either. I am not sure what the problem is.

0

There are 0 answers