Multiply conv layer weight by 2

For example, I want to explicitly multiply 2 on the convolution layers’ weight.

I motify the official from :

    def forward(self, input):
        return self._conv_forward(input, self.weight)


    def forward(self, input):
        new_weight = self.weight * torch.ones(self.weight.size())*2
        return self._conv_forward(input, new_weight)

I noticed that the type of new_weight becomes torch.Tensor rather than torch.nn.parameter.Parameter.

So I wonder whether it’s OK to do this? And can the backward process works correctly?
Thanks in advance!


No need to ping, we look at the posts :wink:

And yes it is expected that after doing any differentiable operation on it, you get a Tensor.
Keep in mind that nn.Parameter are only the leafs stored in the nn.Module that nn recognize as being part of the parameters.

Also you can write the same thing as new_weight = self.weight * 2 to make it easier to read :smiley:


Thank you very much.