Skip to content
mentoor

Topic 5 of 6 · 5 min read

Monitoring and recovering long runs

Goal: Read a training log with a loss spike or throughput drop and choose the right recovery action.

A long run needs three things from the start: metrics you watch, checkpoints you can resume from, and a rule for what to do when the numbers go wrong.

Check yourself · 1 of 3

Which items belong in a checkpoint so a resumed run continues properly?

Choose one answer

Why it matters

A run that takes 20 hours will, sooner or later, hit a spot-instance interruption, a NaN, or a silent slowdown. If you only look at the end, you pay for all the wasted hours. Large published runs have the same problem: the PaLM paper describes loss spikes during training and the fix of restarting from an earlier checkpoint and skipping the batches around the spike.

What to watch

  1. Loss, per step. A slow downward trend is healthy. A sudden spike that recovers may be a bad batch. A spike that stays up, or nan, means the run is broken.
  2. Gradient norm. It often rises before a loss spike, so it is an early warning.
  3. Throughput (tokens per second). A sudden drop means data loading, a failing GPU or a network problem.
  4. GPU utilisation and memory. Check with nvidia-smi. Low utilisation with high CPU use usually means the data loader cannot keep up.
  5. Validation loss every N steps. Training loss alone hides overfitting.

Checkpoints and recovery

Save model, optimizer state, scheduler, step and random seeds, not just weights. Without optimizer state, a resumed run behaves like a new one. Save every 30 to 60 minutes of wall-clock time, keep the last few, and write them to storage that outlives the machine. Test a resume early, on a short run.

python train.py --resume_from_checkpoint output/checkpoint-2400

Decision rules

  • Loss spike that recovers within a few hundred steps: note it and continue.
  • Loss spike that stays up: stop, resume from the last checkpoint before it, lower the learning rate, and skip the suspect data.
  • NaN: stop, resume from before it, and check precision settings.
  • Throughput halves: check the data loader and nvidia-smi before touching the model.

What goes wrong

  • Weights-only checkpoints. Resuming resets Adam and the scheduler.
  • Checkpoints on local disk of a preemptible machine. They disappear with the instance.
  • No alert. Nobody notices the NaN until the morning.

Examples

Reading a spike

step 5200 loss 1.71 gnorm 0.8 tok/s 41k
step 5250 loss 1.69 gnorm 3.9 tok/s 41k
step 5300 loss 4.60 gnorm 55.2 tok/s 41k
step 5350 loss 4.41 gnorm 31.0 tok/s 40k

The gradient norm rose at step 5250, before the loss jumped. Throughput is normal, so hardware is fine. The loss is still high at step 5350. Resume from the checkpoint at step 5000, lower the learning rate and skip the data around step 5250.

Throughput drop

Tokens per second falls from 41k to 18k at step 3000 while GPU utilisation shows 35 percent. Loss is normal. The likely cause is the data loader or storage, for example a network disk, not the model.

Key points

  • Log loss, gradient norm, tokens per second and validation loss at a regular interval, and chart them.
  • A rising gradient norm often precedes a loss spike, which makes it an early warning.
  • A checkpoint needs model, optimizer, scheduler, step and seeds, or the resumed run is not the same run.
  • Store checkpoints on storage that survives the machine, and test a resume before the long run.
  • Match the action to the symptom: continue, resume from before the spike, or fix precision or data loading.

Common mistakes

  • Saving only weights, which turns a resume into a restart of optimizer and scheduler.
  • Keeping the only checkpoint on a spot instance's local disk.
  • Watching training loss alone and missing a validation loss that has started to rise.
  • Continuing a run after a persistent spike in the hope that it recovers.

Check yourself · 2 of 3

Tokens per second halves while loss looks normal and GPU utilisation drops. What should you check first?

Choose one answer

Check yourself · 3 of 3

The loss jumps from 1.7 to 4.6 and stays high for hundreds of steps. What is a sound recovery?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic