I am getting this error because of the following code.
"RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [8, 16, 240, 427]], which is output 0 of AddBackward0, is at version 3; expected version 2 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True)."
    def forward(self, x):
        x = self.activation(self.in_conv(x))
        for i, conv in enumerate(self.mid_conv):
            x += self.activation(conv(x))
        return self.out_conv(x)

if I change the code into this it works fine:
    def forward(self, x):
        x = self.activation(self.in_conv(x))
        for i, conv in enumerate(self.mid_conv):
            x = self.activation(conv(x))
        return self.out_conv(x)

Here self.activation is F.relu, self.mid_conv is nn.Sequential