DEEP LEARNING / 8. TRAINING TRICKS
Training Tricks
The difference between a model that trains and one that doesn't
EXPLANATION
Architecture matters, but training tricks often matter more. These are the techniques that separate a model that converges cleanly from one that explodes or collapses. Essential tricks: • Batch Normalization → normalizes activations per mini-batch, stabilizes training, allows higher lr • Layer Normalization → normalizes per sample (used in transformers, independent of batch size) • Dropout → randomly zeroes activations during training, prevents co-adaptation (overfitting) • Gradient Clipping → caps gradient norm to prevent exploding gradients (critical for RNNs/transformers) • Weight Init → Kaiming (ReLU), Xavier (tanh/sigmoid). Bad init → dead neurons or explosions • Mixed Precision → train in float16, keep master weights in float32. ~2× speedup on modern GPUs • Early Stopping → stop when val loss stops improving, save best checkpoint
DATA FLOW
Training instabilities and fixes: Exploding gradients → gradient clipping (clip_grad_norm_) Vanishing gradients → residual connections, LayerNorm, better init Overfitting → dropout, weight decay, data augmentation Slow convergence → learning rate warmup, better optimizer Covariate shift → BatchNorm (CNNs) or LayerNorm (Transformers) Training checklist: ✓ Normalize inputs (zero mean, unit variance) ✓ Use proper weight init (Kaiming for ReLU) ✓ Clip gradients (max_norm=1.0) ✓ Warmup lr for first N steps ✓ Monitor grad norms — if exploding, something is wrong
CODE