liveBook · Manning

Torch.nn.Module

Also called Module class

torch.nn.Module is PyTorch’s base class for neural-network components, providing an interface for computation and managing registered parameters and submodules.

How 7 Manning books explain it

Deep Learning with PyTorch, Second Edition

The PyTorch base class for defining neural-network models as Python modules with parameters, submodules, and a forward method.

How it is used
Uses modules as reusable neural-network layers and whole models, from simple sequential chains to custom architectures and deployment.
How deep it goes
Explains subclass construction, callable behavior, hooks, submodule registration, and recursive parameter collection with worked examples.
Examples
Illustrates a pretrained vision transformer hierarchy, a custom convolutional classifier, and named parameter inspection.
What you can do after
Apply it via PyTorch to define custom models, inspect their parameters, and export a computation graph.

Read how Deep Learning with PyTorch, Second Edition explains torch.nn.Module →

Build AI Drug Discovery Pipelines

nn.Module is the PyTorch base class for defining neural-network components with registered parameters, submodules, and computation.

How it is used
Defines reusable PyTorch neural networks for molecular prediction and generative models.
How deep it goes
Explains subclassing, initialization, layer dimensions, affine transformations, and forward computation, but not training-loop mechanics.
Examples
Uses KinaseBinderNN with fingerprint vectors and VAECYC with embeddings, bidirectional GRUs, latent projections, and autoregressive decoding.
What you can do after
Build it from scratch by subclassing nn.Module, declaring layers, and routing input tensors through a forward method.

Read how Build AI Drug Discovery Pipelines explains torch.nn.Module →

Deep Learning with Python, Third Edition

The base class for defining stateful PyTorch models with parameters and a forward method.

How it is used
Packages trainable state and forward computation into reusable PyTorch model objects for gradient-based training.
How deep it goes
Demonstrates subclass definition, Parameter tracking, invocation, optimizer integration, training steps, and gradient clearing.
Examples
Uses a linear classifier with weight and bias Parameters, mean squared error, SGD, and a compact training step.
What you can do after
Build it from scratch using torch.nn.Module, torch.nn.Parameter, and torch.optim.SGD.

Read how Deep Learning with Python, Third Edition explains torch.nn.Module →

Inside Deep Learning: Math, Algorithms, Models

How it is used
Organizes neural-network building blocks as model objects that can be run during training.
How deep it goes
Defines forward and automatic backward behavior and describes module composition, but does not detail custom-module implementation.
Examples
Uses a linear layer and a Sequential moons classifier built from Linear and Tanh layers.
What you can do after
Apply it via PyTorch by composing layers into a model and passing that model to a training function.

Read how Inside Deep Learning: Math, Algorithms, Models explains torch.nn.Module →

Natural Language Processing in Action, Second Edition

A PyTorch module is a reusable neural-network component represented by the torch.nn.Module base class and its registered parameters and submodules.

How it is used
Defines a trainable PyTorch neuron for binary classification of names.
How deep it goes
Explains subclass construction and forward propagation, then demonstrates training without detailing Module internals.
Examples
Uses a LogisticRegressionNN module with 3,663 TF-IDF inputs and name predictions such as John, Ruby, and Sarah.
What you can do after
Build it from scratch by subclassing Module, defining forward propagation, and training the resulting model.

Read how Natural Language Processing in Action, Second Edition explains torch.nn.Module →

Math and Architectures of Deep Learning

The PyTorch base class that neural network models subclass to define learnable modules and a forward pass.

How it is used
Defines reusable neural-network models whose layers and forward computations participate in prediction and training.
How deep it goes
Descends through subclassing, initialization, Sequential chaining, forward execution, and optimizer integration, but not Module internals.
Examples
Uses a demand-prediction multilayer perceptron and a convolutional network with three Conv2d layers.
What you can do after
Build it from scratch by subclassing Module, composing layers, implementing forward(), and training through parameters and an optimizer.

Read how Math and Architectures of Deep Learning explains torch.nn.Module →

Deep Learning with R, Third Edition

torch.nn.Module is PyTorch's base class for building objects that represent neural-network modules and manage their parameters.

How it is used
Packages model state and forward computation for object-oriented PyTorch training.
How deep it goes
Defines subclass structure, invocation, optimizer integration, training steps, and gradient resetting, but not Module internals.
Examples
Demonstrates a linear classifier with weight and bias Parameters, matrix multiplication, loss backpropagation, SGD, and gradient clearing.
What you can do after
Build a trainable PyTorch model and operate its optimizer-driven training loop.

Read how Deep Learning with R, Third Edition explains torch.nn.Module →

What to know first

Related concepts

Questions about torch.nn.Module

What is torch.nn.Module?

torch.nn.Module is PyTorch’s base class for neural-network components, providing an interface for computation and managing registered parameters and submodules.

Which Manning books explain torch.nn.Module?

Deep Learning with PyTorch, Second Edition, Build AI Drug Discovery Pipelines, Deep Learning with Python, Third Edition, Inside Deep Learning: Math, Algorithms, Models, Natural Language Processing in Action, Second Edition, Math and Architectures of Deep Learning and Deep Learning with R, Third Edition.

What should I know before learning torch.nn.Module?

Manning books that teach torch.nn.Module usually introduce backpropagation, gradient descent, objective function and convolutional layer first.

What is torch.nn.Module also called?

Torch.nn.Module is also called Module class.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.