Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 16 — Assignment Project: Rescuing a Training Run

Open in Colab

Overview

A colleague’s network does not learn. Their configuration is below: a deep network of sigmoid units with a tiny initialisation, trained with plain SGD at a large rate. Your job is to find out why, fix it one change at a time with evidence for each change, and then make the fixed network generalise from a small, noisy training set. Everything runs on CPU in a few minutes, on scikit-learn’s digits.

PartTaskPoints
ADiagnose the broken run15
BFix the initialisation and the activations20
CChoose the optimiser and the learning rate20
DMake it generalise25
EReport20

Part A — Diagnose (15 points)

  1. Plot the broken run’s training and validation loss. What value does the loss sit at, and what does that value mean?

  2. Compute, at initialisation, the gradient norm of each nn.Linear layer’s weights on one batch of 256 training images. Plot it against the layer’s depth on a log scale.

  3. In three sentences: what is wrong, and why does a learning rate of 2.0 not rescue it?

Your diagnosis:


Part B — Fix the Initialisation and the Activations (20 points)

Change one thing at a time, and for each version report the gradient norms of the first and last layers at initialisation and the validation accuracy after 30 epochs (SGD at 0.03 with momentum 0.9):

  1. sigmoid, Xavier-like initialisation (init_std = 1 / sqrt(64));

  2. ReLU, He initialisation (act=nn.ReLU, init_std='he');

  3. ReLU, He initialisation, with batch normalisation.

Which change mattered most? Justify with the numbers.

Your comparison:


Part C — Optimiser and Learning Rate (20 points)

Keep the best network of Part B.

  1. Run a learning-rate range test with SGD and momentum (rates from 10-4 to 10, multiplied after every batch) and choose a rate.

  2. Compare SGD with momentum at your rate, and Adam at 10-3, each with three seeds (the initialisation and the batch order change). Report the mean and the spread of the validation accuracy after 20 epochs.

  3. Is the difference between them larger than the spread between seeds?

Your answer:


Part D — Make It Generalise (25 points)

The data you will get in practice are small and noisy. Build a training set of the first 250 training images, and replace 25% of their labels by random ones (seed 7).

  1. With 250 images, ten layers are far too many: use two hidden layers of 256 ReLU units with He initialisation, no batch normalisation (build(depth=2, width=256, act=nn.ReLU, init_std='he')), and AdamW at 0^{-3}$. Train it for 150 epochs (batches of 32): without regularisation, with dropout 0.5, with weight decay 0.5, and with both. Plot the validation loss of each.

  2. Add early stopping (patience 15, restore the best weights) to the best of them.

  3. Evaluate your final model on the test set, once, and give its accuracy.

Your comments:


Part E — Report (20 points)

One page for your colleague:

  • what was wrong with the original run, and the evidence (Part A);

  • the changes, in order, with the effect of each (Parts B and C);

  • what you did against overfitting and what each remedy contributed (Part D);

  • the test accuracy, and a sentence on how much to trust it;

  • the three checks you would run first on the next network that does not learn.

Grading Rubric

CriterionExcellentAdequateInsufficient
A (15)loss at ln 10 explained, vanishing gradient shown by layerone of the twono evidence
B (20)one change at a time, numbers for each, the main cause identifiedchanges made togethermissing
C (20)range test, three seeds, difference compared to the spreadone seedrate guessed
D (25)curves, early stopping with restored weights, test used onceno early stoppingtest set used for choices
E (20)clear, ordered, evidence for each claim, honest about uncertaintygenericmissing