Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Difference Between forward and __call__ Methods of a Module in PyTorch

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

  1. The Module.__call__ method register all hooks and call the method Module.forward. In short, when you train the model you should use the method forward, while when you test the model during training or when you do prediction using a well trained model, you should use the method __call__. model.__call__(data) is equivalent to model(data).

References

Why there are different output between model.forward(input) and model(input)

Is model.forward(x) the same as model.call(x)?

Why can you call model without specifying forward method

Any different between model(input) and model.forward(input)