I want to set some of my model frozen. Following the official docs:
with torch.no_grad(): linear = nn.Linear(1, 1
Here is the way;
linear = nn.Linear(1,1) for param in linear.parameters(): param.requires_grad = False with torch.no_grad(): linear.eval() print(linear.weight.requires_grad)
OUTPUT: False