What is the difference between torch.nn and torch.nn.functional?

Have a look at this post for some more information and my point of view.

TLDR: the modules (nn.Module) use internally the functional API.
There is no difference as long as you store the parameters somewhere (manually if you prefer the functional API or in an nn.Module “automatically”).
Having the nn.Module containers as an abstraction layer makes development easy and keeps the flexibility to use the functional API.

3 Likes