Skip to content

01_Pytorch_Workflow ~05:34 y_preds = model_0(X_test) #298

Answered by mrdbourke
ozzyoz14 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes you're right it is a little confusing.

However, behind the scenes every subclass of torch.nn.Module calls forward() by default when it's called.

In regular Python classes this kind of functionality might go behind a __call__() method, see more here: https://stackoverflow.com/questions/9663562/what-is-the-difference-between-init-and-call

However, for some reason the PyTorch developers chose to override this functionality with forward(), see more here: https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.forward

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mrdbourke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants