Recognizing the Effects of Fundamental Hyperparameters
This lesson explains the small set of hyperparameters, settings chosen before training, that control how training proceeds, and how to recognise their effects from symptoms.
Learning outcomes
After completing this lesson, you will be able to:
- Explain epochs, steps and batch size.
- Diagnose a learning rate that is too high or too low.
- Tune algorithm-specific hyperparameters such as XGBoost max_depth.
Epochs, steps and batch size
An epoch is one full pass through the training data. The batch size is the number of examples used to compute one gradient update, and a step (iteration) is one such update, so steps per epoch equal the number of examples divided by the batch size. Some jobs are configured by total steps rather than epochs. Too few epochs underfit; too many overfit unless early stopping is used.
Larger batches give smoother gradient estimates and use GPUs more efficiently, so each epoch is faster, but they need more memory and can generalise slightly worse. Smaller batches add noise that can help generalisation but train more slowly. If a GPU runs out of memory, reduce the batch size or use gradient accumulation.
Epochs and steps
Learning rate
The learning rate sets the size of each weight update and is usually the most important hyperparameter. If it is too high, the loss oscillates or diverges, and may even become NaN; if it is too low, training is slow or gets stuck in a poor solution.
Learning-rate schedules, such as step decay and cosine decay, reduce the learning rate as training progresses, allowing large steps early and fine adjustments later. Warmup, which starts with a small learning rate and increases it over the first steps, stabilises the start of training, particularly for transformers. When the batch size increases, the learning rate is often increased proportionally.
The following diagram sketches training loss under three learning rates.

Learning rate schedules
Algorithm-specific hyperparameters
Tree ensembles have their own important settings. In XGBoost, num_round sets the number of trees, and max_depth limits how deep each tree grows: deeper trees capture more complex patterns but overfit more. eta is the learning rate, which shrinks each tree's contribution, so lower values need more rounds.
subsample and colsample_bytree train each tree on a random sample of rows and columns, which adds randomness that reduces overfitting, and alpha, lambda and gamma add regularisation. The following table summarises common symptoms and how to respond to them.
| Symptom | Likely cause | Adjust |
|---|---|---|
| Loss oscillates or becomes NaN | Learning rate too high | Lower learning rate, add warmup |
| Loss decreases very slowly | Learning rate too low | Raise learning rate |
| GPU out of memory | Batch too large | Smaller batch or gradient accumulation |
| Validation loss rises after some epochs | Too many epochs | Fewer epochs or early stopping |
| XGBoost overfits | Trees too deep | Lower max_depth, raise min_child_weight, subsample |
Tuning a fine-tuning run
A text classifier fine-tunes for 5 epochs on 40,000 examples with batch size 16 and learning rate 5e-4. Training loss jumps around and validation accuracy peaks at epoch 2, then falls.
Steps per epoch = 40,000 / 16 = 2,500 -> 12,500 steps total
Learning rate 5e-4 is high for transformer fine-tuning -> try 2e-5 with 10% warmup
Validation peaks at epoch 2 -> 2-3 epochs with early stoppingWith a lower learning rate, warmup and early stopping, loss becomes smooth and the best checkpoint is kept. Increasing epochs, as first proposed, would have made overfitting worse.
Training loss oscillates or becomes NaN. What is the likely cause?
Show answer
A learning rate that is too high.
Exam Tips
Remember for the exam
- Steps per epoch = examples / batch size.
- Loss oscillating or NaN: learning rate too high.
- Out of memory: reduce batch size or use gradient accumulation.
- Validation loss rising: too many epochs; use early stopping.
- Raise the learning rate when increasing batch size.