Does gradients change in Model.eval()?

The gradient calculation is independent from the training mode in the model, which is changed via model.train() and model.eval().
To disable the gradient calculation, set the .requires_grad attribute of all parameters so False or wrap the forward pass into with torch.no_grad().
Calling model.eval() will change the behavior of some layers, such as nn.Dropout, which will be disabled, and nn.BatchNormXd, which will use the running stats during evaluation.

3 Likes