liveBook · Manning

Sequential

As explained in Inside Deep Learning: Math, Algorithms, Models

A PyTorch container module that applies a sequence of submodules in order.

Sequential is a PyTorch container for feed-forward models: provide submodules in order, then pass each module’s output to the next. It turns a network definition into a readable chain that can be trained and used for inference like any other model. section 2.2.2

Two-layer fully connected network

model = nn.Sequential(\n nn.Linear(1, 10),\n nn.Linear(10, 1),\n)\n\nThe first layer maps one input feature to ten hidden units; the second maps those units to one output. The same model can be passed to the existing training and inference code. section 2.2.2

Use Sequential when the computation is naturally a simple ordered pipeline:

  • Stack linear layers and nonlinearities to build fully connected networks. section 2.7
  • Combine preprocessing, convolution, normalization, and activation modules inside a larger component. section 6.5.2
  • Reuse a module object inside the sequence when layers need shared weights. section 4.1.1
Figure 2.6 Converting the conceptual feed-forward fully connected network into a PyTorch Module. nn.Sequential is a wrapper that takes two nn.Linear layers. The first nn.Linear defines the mapping from input to hidden layer, and the second nn.Linear defines the mapping from hidden layerto output.

Shows how Sequential wraps two linear layers, connecting the input to a hidden layer and then to the output. section 2.2.2

How Inside Deep Learning: Math, Algorithms, Models covers it

How deep it goes
Defines ordered execution and module reuse, but stops short of architectures that require nonsequential computation.
Examples
Uses stacked Linear layers, MNIST classifiers, shared hidden layers, and convolutional residual blocks.
What it assumes
Assumes familiarity with PyTorch modules and tensor flow, while demonstrating the container pattern through simple Linear layers.
What you can do after
Build it from scratch: define ordered PyTorch models and insert reusable submodules into larger architectures.
How it connects
Connects PyTorch modules with fully connected networks, linear layers, nonlinearities, weight sharing, and residual blocks.

Also explained in

Compare how 2 books explain Sequential →

Related concepts

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