Activate eval mode in forward

I’m calling self.eval() in the forward() of a nn.Module object, the loss becomes NaN.
Is this normal?

No, quite likely there is something else amiss.
Calling self.eval() in the forward is likely not the ideal way of doing things, either. But to say something about a better way, it would be good if you could share what should happen that led you to do that.

Best regards


Thank you, Thomas!

I want to calculate the value in the evaluation mode, so that it could be compared with the regular forward( ) output.

I just figure out a workaround: copying the code of the evaluation mode, and use an boolean variable to control the execution. It works.