liveBook · Manning

Torch.nn.Sequential

As explained in Math and Architectures of Deep Learning

The PyTorch container that chains modules in order so the output of one becomes the input of the next.

torch.nn.Sequential is a PyTorch container for composing layers in a fixed order. If the layers represent functions f₁, f₂, and f₃, the model computes f₃(f₂(f₁(X))). Each layer receives the previous layer’s output, turning the forward pass into a readable chain. section 8.5 section 10.6.1

A Sequential pipeline can combine:

  • Linear layers and sigmoid activations for a regression model. section 8.5
  • Convolutional layers and intervening layers for an image-oriented neural network. section 10.6.1
  • A custom Module’s forward method can delegate computation to the Sequential object. section 8.5

Two hidden-layer regression network

A model receives three input features, applies Linear(input_size, 10), Sigmoid(), Linear(10, 5), Sigmoid(), and Linear(5, 1), then returns self.model(X). Training calls nn(X) for the forward pass before computing MSE loss and gradients. section 8.5

How Math and Architectures of Deep Learning covers it

How deep it goes
Defines ordered data flow and shows implementation in Module.forward, but defers detailed convolutional architecture treatment.
Examples
Uses a demand-prediction multilayer perceptron and a sample convolutional neural network.
What it assumes
Assumes familiarity with torch.nn.Module, forward methods, neural-network layers, and tensor inputs.
What you can do after
Build sequential PyTorch models by placing compatible layers in order and invoking the resulting Module on input data.
How it connects
Connects Module, forward propagation, linear layers, sigmoid activation, convolution, MSE loss, and backpropagation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.