Monitoring
What to watch at each stage of the pipeline, the threshold that turns each signal into an alarm, what an alarm looks like, and the scripts that check them for you.
What you will do
- Start the loggers that run for as long as the machine does: the GPU logger and the monitor loop.
- Know the handful of signals to watch at each stage, what healthy looks like, and what makes an alarm.
- Read an alarm, and know the first thing to do about it.
- Check, at the end, that every metric you meant to record was recorded.
All thresholds come from the project’s metrics reference, and code/scripts/run_monitor.py implements them.
Hardware
Every level. The loops run on the GPU machine; the reports also run on a laptop, from the copied outputs.
The tools
| Tool | What it does |
|---|---|
| the GPU logger | nvidia-smi every 10 s into gpu.csv: utilization, temperature, power, memory, clocks, uncorrected ECC errors |
| run_monitor.py | one pass over every run’s outputs and gpu.csv; one line per alarm, then a summary |
| W&B and TensorBoard | each run’s scalars; $RUN_DIR/tb is the local record |
| stall_guard.py | stops a run whose logs stop changing (the run helper of the setup guide) |
router_watch.py |
MaxVio and dead experts from the expert counts; routing entropy from the routing traces |
| gspo_run_report.py | GSPO’s KL median and p99, clipping by mini-batch, the first-update ratio, the sampler–learner gap |
| metrics_report.py | the final coverage check: every row of the metrics reference has a producer (it needs that reference, which is not in the public repository) |
router_watch.py and expert_watch.py come from the Hugging Face MoE handbook’s companion gist, which the setup script
clones at a pinned commit.
Start the monitor loop
nohup bash -c 'while sleep 120; do python -I code/scripts/run_monitor.py --runs /workspace/runs --gpu-csv \
/workspace/gpu.csv --json /workspace/runs/monitor.json > /workspace/runs/monitor_latest.txt 2>&1; done' >/dev/null 2>&1 &
Every 2 minutes it rewrites /workspace/runs/monitor_latest.txt. A missing input is reported as “no data”, never
silently skipped.
Make sure the metrics reach W&B
Two Megatron details decide whether your dashboard has curves at all:
-
Megatron sends its training scalars to W&B only inside its TensorBoard branch, so
--tensorboard-diris required. -
Without
--log-timers-to-tensorboard, TFLOP/s and step time appear only in the text log. Our rehearsal’s dense run had 21 TensorBoard tags and neither of them.
Both are in the shared logging arrays of common.sh. A configured metric is not a recorded one: open the output and
check that the numbers are there.
MaxVio, the routing health number
where \(c_e\) is the number of tokens routed to expert \(e\) in one layer and step, and \(\bar{c}\) the mean over that layer’s experts.
In words: how far the busiest expert is above an even share, as a multiple of that share.
0 is perfectly even. If every token’s \(k\) choices land on the same \(k\) of \(E\) experts, those get \(E/k\) times the mean, so the maximum is \(E/k - 1\). For 64 experts and top-8 that is 7, the value our collapsed routers sat at.
We report the “whole-layer” value, pooled over the 8 GPUs; one GPU’s 8 local experts give a different number.
| Stage | What our healthy MaxVio looked like |
|---|---|
| pretraining, after the collapsed start | 0.737 at step 100, 0.437 at step 200, then 0.17–0.30 |
| SFT | 0.062 at step 26, 0.039 at step 104 |
| GSPO | 6.29–6.41 at every step, flat: padding tokens dominate the counts |
The GSPO row is why RL uses a relative rule: compare MaxVio with its own value at the start of the stage, not with an absolute number.
What to watch, stage by stage
Pretraining and SFT
| Signal | Healthy | Alarm |
|---|---|---|
| training loss | falls smoothly | a spike above 10× the median of the previous 50 logged losses; or iterations 151–200 not below iterations 1–50 |
| NaN iterations | 0 | any |
| gradient norm | settles after the warm-up | a spike above 10× the running median |
| peak allocated memory | under 70 GB | above 70 GB |
| MaxVio | falls, then stays level | above 2 in pretraining; above 2× its first value in the stage, for SFT |
| dead experts | none | an expert with 0 tokens in a pooled step |
| format compliance (SFT) | above 80% after SFT | below 50% at the RL gate |
Ours, for scale: the main run’s gradient norm fell from 4.76 to 0.10–0.26, with no NaN or skipped step, and its MoE
study arms peaked at 58.8 GiB allocated.
Megatron’s own spike detector, --check-for-spiky-loss, flags a loss above 10× the maximum of the first 100 steps
and re-runs that step once.
GSPO
| Signal | Healthy | Alarm |
|---|---|---|
| reward spread within the batch | above 0 | 0: no learning signal |
| solve rate | between 0.1 and 0.8 | below 0.1 (too hard) or above 0.8 (too easy) |
| mixed groups | at least 30% | below 30% |
| first update’s ratio | exactly 1 | anything else |
| KL to the reference, 10-step mean | rises slowly, under 0.1 | above 0.1 |
| clipped share, updates 2–4 of a step | under 0.30 | above 0.30 |
| sampler–learner gap | level | above 2× its level over the first 5 steps |
| MaxVio | level | above 2× its step-1 value |
| answer length | stable | median of 2 tokens or less (collapse); p99 at the 1,536-token stop for 5 steps running (explosion) |
| mean reward against solve rate | move together | over 10 steps, the reward rises while the solve rate falls (reward hacking) |
| format compliance | above 90% | below 90% |
The sampler–learner gap is the per-token difference between the log-probabilities the inference engine sampled with and the ones the trainer computes, at the same weights. Ours was 0.0133 nats per token on the one-GPU rehearsal and 0.0072 on the one-GPU control run.
On our 8-GPU run the first update’s ratio was not exactly 1, so that alarm fired for a known reason: see the RL guide.
GPUs, the whole time
| Signal | Alarm |
|---|---|
| temperature | above 83 °C, where throttling starts |
| uncorrected ECC errors | above 0 |
| power | above 705 W, as a warning: the H100’s 700 W limit plus the reading’s 5 W tolerance |
Ours peaked at 60–67 °C with no ECC errors through pretraining. One-second power readings of 706–715 W at the 700 W cap showed up as warnings, not alarms.
When an alarm fires
| Alarm | First action |
|---|---|
| MaxVio above 2× its baseline | raise β from 0.01 to 0.05, then halve the learning rate |
| a dead expert | investigate at once: a router or balancing bug |
| a loss spike above 10× | Megatron re-runs the step; check the data, the gradients, the routing, the hardware |
| a gradient-norm spike above 10× | in RL, check for a kernel mismatch; otherwise a hardware fault |
| KL above 0.1 | raise β to 0.05, then halve the learning rate |
| clipping above 0.30 | lower the learning rate |
| solve rate below 0.1 or above 0.8 | move to an easier or a harder tier |
| mixed groups below 30% | the difficulty is wrong for the model |
| ECC errors above 0 | investigate before continuing |
| the first update’s ratio is not 1 | check that the kernels and the batch layout match |
| the sampler–learner gap doubles | check the kernels and the precision |
What an alarm looks like
run_monitor.py prints one line per alarm, with its severity, run, check and detail, then a summary line.
Three real examples from our runs:
- A true alarm on a known cause. The rehearsal’s shrunk model solves nothing, so the monitor raised the expected alarms: solve rate 0, mixed groups 0, format compliance 0%.
- An alarm from a bug in the monitor. During pretraining it reported “MaxVio > 2x baseline”, for example “layer 1 step 100: 0.527 vs 0.210”, on values that were falling. It had compared one GPU’s MaxVio with another GPU’s first value. After the fix, pretraining had 0 such alarms.
- A line that looks like an error and is not. Megatron’s re-run check logged “found unexpected large grads”, re-ran the step, reproduced the value, and logged “Continuing normal execution because failed validation was not fatal”. A reproduced value means the batch caused the spike, not the GPU. Gradient clipping then scaled that update down.
Watch for silence too
An alarm needs a log line, and a hung run writes none. After its one error line, a crashed RL run once sat for 24 minutes at 0% GPU, holding 25.9 GB. A grader once spun forever on the thread that drives generation, and the log went silent mid-step.
So:
-
every run goes through the stall guard, which stops it after 15 quiet minutes (
STALL_MIN); -
any watch you write must report silence, not only the lines it expects;
-
before you call a run finished, check that its process is gone and its GPU is free.
At the end: the coverage check
code/scripts/metrics_report.py reads the project’s metrics reference, lists
every row with its producer and status, and exits non-zero if any row has none.
That reference document is not in the public repository, so the script cannot run from it: it looks for
pretraining/Metrics-and-Monitoring-Reference.md beside code/, and its unit test skips itself.
What you can use instead: the script’s MAP table names, for every metric we tracked, what writes it and where it
lands, and the metrics glossary defines each one. At the end of a run, check by hand
that each run folder holds the numbers you meant to record.
A producer is whatever writes the number down: a Megatron flag, one of our scripts, or a step a person takes.
At the end of our main run, all 281 rows had one: 113 verified, 110 built, 23 configuration, 13 done, 8 claims, 6 not applicable, 4 manual, 3 needing 8 GPUs, and 1 to do.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
| no TFLOP/s or step time in W&B | --log-timers-to-tensorboard missing |
the flag is in the shared logging array |
| no training curves in W&B at all | no TensorBoard writer | --tensorboard-dir on every run |
| W&B’s step axis jumps during RL | the inference engine’s own W&B logging writes without a step number | leave --inference-wandb-logging off |
| RL tokens/s looks too high | Megatron’s RL tokens/s counts padding | compute tokens/s from rollouts.jsonl and the rollout timer |
| a background wait never fires | it matched a field name the file does not use (“step” against “iter”) | test a wait’s pattern on a real file first |
| a renamed metric silently loses its producer | the coverage tracker still used the old name | a test fails on any reference row without a producer |
Read more
- Part 13: evaluation and Part 15: lessons discuss what the alarms caught.
- The metrics glossary defines every metric named here.
- Code: code/scripts/run_monitor.py, code/scripts/stall_guard.py, code/scripts/gspo_run_report.py, code/scripts/run_report.py, code/scripts/metrics_report.py, code/scripts/gpu_health_check.py.