Maybe, you have to modify CustomLoss slightly. An issue due to a custom loss has been reported:

  
    
    
    One of the variables needed for gradient computation has been modified by an inplace operation_ autograd
  
  
    I have made a custom loss function which is taking parameters calculated from a intermediate function ( a function which is taking as input the output of my CNN network). but from loss.backward() I am getting the error 
one of the variables needed for gradient computation has been modified by an inplace operation. 
I couldn’t find out the source of the error so I am embedding both functions. 
Loss function is 

class my_Loss(torch.nn.Module):
    
    def __init__(self):
       super(my_Loss,sel…
  


He resolved this problem by cloning tensors in the custom loss.