alekseynp:

I discovered that .eval() doesn’t change the requires_grad for the parameters in my ScriptModule. Is this intended behaviour?


Yes, this is expected and also won’t change the requires_grad attributes of an “eager” model.
model.eval() and model.train() change the internal self.training flag of all modules recursively starting from the parent module. By doing so, the behavior of some layers will be changed.
E.g. dropout will be disabled and batchnorm layers will use their running statistics to normalize the incoming data instead of calculating the batch statistics.
If you want to freeze the parameters, you would have to set their .requires_grad attribute to False.
You could of course use both in combination, e.g. freeze all parameters, but leave the dropout layers enabled, or let all parameters train, but use the running stats of batchnorm layers.