Greetings!
Suppose I want to rescale the initialized weight matrix in a certain way like:
class Net(nn.Module):
    def __init__(self, R):
        super(Net, self).__init__()
        self.lin1 = nn.Linear(2, 100)
        self.lin2 = nn.Linear(100, 3)
        self.lin2.weight.mul_( (R / torch.sqrt(torch.sum(self.lin2.weight.detach()**2 ,axis=1)))[:, None] )

So I want to change the weight of lin2 based on the current elements of the weights. Do I need the detach ()?
Also, code gives the error “a leaf Variable that requires grad is being used in an in-place operation”, so the mul_ does not seem to work. Can I just reassign the right-hand expression to my weight matrix, i.e. self.lin2.weight = ...?