Judge the model is train or validation

How can I judge the model is train or validation in the ‘forward’ function?
In fact, I have construct a network, and write the ‘forward’ function. I want to judge whether this forward process happened in the training process or in the validation process.

Hi @linyu,

You can know by checking the value of the nn.Module attribute self.training in forward (set to True in net.train() and to False in net.eval()) .