How to get the gradient?

I want to compute a coefficient for each channels, and then multiply the features with coefficient:

coefficient = self.bknet(feature)
feature[:,:,:] = feature[:,:,:]*coefficient[:,:,:]

where “feature” is output of some conv layers, but when I train the net, the error is:

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

and I try to add


but it still not work.

thanks for your help!