Equivalent of model.eval()

In trying to understand what is really going on when switching from .train() to .eval() mode, I’ve been experimenting with replacing it with the following loop within my model:

for module in self.children():
            module.training = False

Is this exactly the same as calling model.eval() from outside though? A few tests with BatchNorm and Dropout seem to look good enough; but if not, what would be required to fully replace .eval?

Note: This is just for understanding, I don’t think there is any benefit in doing so :slight_smile:

You would need to call this recursively on all the children as well if you want this to work for models with nested Modules.
You can check the actual implementation here if you’re curious.