Training Dynamics, Regularization & Diagnosis
A working model is not enough. You need controls that distinguish an objective, optimization, data, mode, numerical or capacity failure before changing the configuration.
Section 3 of 8 · 8 units · about 35 hours
By the end you can Given an unfamiliar failing compact run, choose a discriminating control, repair the causal defect, add a regression test, and defend the configuration with activation, gradient, update and generalization evidence across two seeds.
Units
- Initialization and signal scale across depth5h
- Dead, saturated and exploding units, and residual paths4h
- Batch, layer, group and RMS normalization4h
- Regularization: dropout, label smoothing, augmentation and weight decay4h
- Optimizers from SGD to AdamW5h
- Schedules, gradient accumulation and clipping5h
- Objective checks, tiny-set overfit and shuffled-label controls3h
- Diagnosing failed runs: divergence, stale state, slices and seeds5h
Build it
Mini project · about 10 to 14 hours
Seeded-fault diagnosis of a compact run
Instrument a small MLP or CNN trained with your section 2 trainer, inject faults you do not choose yourself, and diagnose each with a discriminating control, a repair, a regression test and evidence across two seeds. Finish by defending one configuration with measurements.
- 1Instrument the run: per-layer activation mean and std, dead or saturated fractions, gradient norms, update-to-weight ratios, loss, and train and validation metrics, logged per step.
- 2Run the controls first and keep them as tests: overfit one fixed batch to near-zero loss, and train on shuffled labels until training accuracy rises while held-out accuracy stays at chance.
- 3Write a fault script that applies one fault from a seeded list and seals the choice until diagnosis is committed. Cover a
softmaxbeforeCrossEntropyLoss, missingzero_grad, eval mode left on, an excessive learning rate, bad init scale and augmented validation data. - 4Diagnose three injected faults. For each, write rival hypotheses first, run one control that separates them, repair, and add a regression test that fails on the fault and passes on the repair.
- 5Compare SGD with momentum and AdamW with decoupled weight decay at matched budgets, with warmup, a cosine schedule and gradient clipping, across two seeds.
- 6Check gradient accumulation: micro-batches of size match one batch of size times within tolerance for a model without batch normalization or dropout, and show what breaks when the loss is not divided by .
What you hand in
- The instrumented trainer, the control tests and the fault script.
- Three postmortems, each with symptom, rival hypotheses, discriminating control, repair, regression test and one limitation.
- A configuration defense: two-seed curves with activation, gradient, update and validation evidence for the chosen optimizer and schedule.
How to check it
- Self-grade with the rubric below
How it's graded
Controls
Pass: The fixed batch reaches near-zero loss, and shuffled labels leave held-out accuracy at chance.
Great: Both run as automated CPU tests.
Diagnosis
Pass: Each of three faults is found with a stated discriminating control.
Great: Each postmortem names at least two rival hypotheses and shows why the control separates them.
Regression guards
Pass: Each repair has a test that fails on the fault.
Great: The tests run on both seeds and check a mechanism, such as a norm, a mode flag or a reduction, not only the final loss.
Configuration evidence
Pass: Two seeds for the chosen configuration, with activation, gradient and update statistics.
Great: Update-to-weight ratios and the validation gap support the chosen learning rate and decay against one rejected alternative.
Accumulation
Pass: Accumulated gradients match the large batch within a stated tolerance.
Great: You also show the mismatch caused by an undivided loss and explain why batch normalization breaks exact equivalence.
Resources
- Understanding Deep Learning - fitting, gradients and regularizationSimon J. D. Prince
Use Chapters 6-9 and targeted parts of Chapter 20 for optimization, initialization, measurement, regularization and why training works. Re-derive the update rules you keep in the trainer.
- D2L - optimization and regularization sliceD2L authors
Use MLP implementation, dropout, deep generalization, numerical stability, optimization introduction, SGD, minibatch SGD, momentum, AdaGrad, RMSProp, Adam and learning-rate scheduler. Implement momentum, AdamW, initialization, dropout, one normalization, clipping and one schedule.
- TrenTorch - training mechanics questionsTrenTorch
Solve only the questions the units name: Weight Initialization, Layer Normalization, Label Smoothing, Gradient Accumulation, and Warmup and Cosine Decay. Read the tests first; they run in the browser IDE.
- Hands-On Machine Learning with Scikit-Learn and PyTorchAurelien Geron (O'Reilly, 2025)
Read the Chapter 11 sections named in the units for the PyTorch side of initialization, normalization, clipping and schedules.
- Deep-ML candidate - optimization and normalization problemsDeep-ML
After the platform admission check, use at most one of 146 Momentum, 169 AdamW, 197 Global-Norm Clipping, 109 LayerNorm or 115 BatchNorm as a changed-prompt drill.
- PyTorch - optimization and automatic mixed precision examplesPyTorch
Check optimizer, scheduler, gradient clipping and AMP API semantics. Preserve the correct order for zeroing, scaling, backward, unscaling, clipping, stepping and updating.
- PyTorch GroupNorm referencePyTorch
Read how input channels are split into
num_groupsgroups and which axes each group normalizes; comparenum_groups1 againstnum_channels. - PyTorch RMSNorm referencePyTorch
Read the RMS formula and which axes
normalized_shapecovers; note the missing mean centering and bias. - PyTorch torch.optim.AdamW referencePyTorch
Read the AdamW algorithm box for the decoupled weight-decay step, the bias-corrected moments and the defaults, and follow the Decoupled Weight Decay Regularization link for the argument.
- PyTorch CrossEntropyLoss referencePyTorch
Read Shape, Parameters (
weight,ignore_index,reduction,label_smoothing) and both Examples; extend the class-index example withignore_indexand a classweight. - Cyclical Learning Rates for Training Neural Networks (Smith, 2017)arXiv
Read the abstract and the range test: increase the rate linearly for a few epochs and read usable bounds off the loss curve.
- Deep Learning Tuning Playbook FAQ: debugging optimization failuresGoogle Research
Read How can optimization failures be debugged and mitigated (identifying unstable workloads, warmup, clipping) and Batch normalization implementation details.