Skip to content
← Learn PyTorch

nn.Module Mechanics

PyTorch

Define modules with parameters, buffers and child modules. Save and restore state, switch training modes, and reason about shared weights.

7 exercises

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Not solved yet. Register a sequence of model layers Practice · Medium
  2. 2 Not solved yet. Compare dropout in training and evaluation modes Practice · Easy
  3. 3 Not solved yet. What the optimiser updates Practice · Medium
  4. 4 Not solved yet. Share one weight parameter between two layers Practice · Medium
  5. 5 Not solved yet. Report missing and unexpected checkpoint keys Practice · Medium
  6. 6 Not solved yet. Read the middle of a model Practice · Medium
  7. 7 Not solved yet. Initialise the whole tree Practice · Medium

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

With the default settings shown here, which BatchNorm values are registered parameters?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

from torch import nn

m = nn.BatchNorm1d(3)
print("parameters:", [name for name, _ in m.named_parameters()])
print("buffers:", [name for name, _ in m.named_buffers()])
Question 1 of 4