Hi,
Please see below posts:

  
    
    
    Setting part of the training value into zero 
  
  
    When I training my network, I want to set a specific part of latent space into the zero value based on the label. 
For example, after input values come out from convolution layer, there would be (B, C, H, W) 4-D tensor value would come out. 
I want to make half of the Channel part into zero based on the label. 
[image] 
Like this but I got an error like this. 
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1,…
  



  
    
    
    Why this code will throw out an inplace error autograd
  
  
    Hi, 
In this line, you are updating B variable but autograd needs all previous values to compute the backpropagation. 
You can do something like this to ensure you are not losing the value of B: 
import torch

A = torch.nn.Parameter(torch.randn(3, 3))
B = torch.randn(2, 4, 3)
z = B[0, :, :].mm(A)
loss = z.sum()
loss.backward()

When I assign updated B to z, I am not mutating B so autograd has access to original B. 
Best regards 
Nik
  


Bests
Nik