juniorPyTorch
What is nn.Module in PyTorch?
Updated May 17, 2026
Short answer
nn.Module is the base class for all neural network models in PyTorch.
Deep explanation
It provides structure for layers, parameters, and forward propagation logic.
Real-world example
All custom neural networks inherit from nn.Module.
Common mistakes
- Not calling super().__init__() or forgetting forward method.
Follow-up questions
- What happens if forward is not defined?
- How are parameters registered?