Never update gradients for a layer

In the init method, can I do something like

 self.input = nn.Linear(28 * 28, 28 * 28, requires_gradients=False)

or is it not they way it should be done?

maybe u can do this way

self.input = nn.Linear(28*28, 28*28)
self.input.weight.data.requires_grad=False
self.input.bias.data.requires_grad=False
1 Like

That looks like it should work. Is there a reason why you wrote the second line twice?

I make a mistake, the second line should be bias if u use default parameter in nn.Linear