Skip to content
AI.info

How machines learn

The Training Loop: Predict, Measure, Update

Follow the core training loop from initialization through prediction, loss calculation, parameter updates, diagnostics, and stopping.

By the end you can

Analogy

A machine that improves by measured adjustment

A packaging machine is calibrated in cycles. You run a batch, measure how far packages differ from the target weight, adjust controls, and run another batch. One correction rarely solves every case, so the cycle repeats.

Model training follows a similar predict-measure-update rhythm. Model parameters interact across many dimensions, and a lower average loss can still hide poor behavior on important slices.

Visual

The six recurring stages of fitting

Implementations differ, but most parameter-learning procedures contain these conceptual stages.

FigureProcess · 6 steps
  1. 1. Initialize

    Choose starting parameter values and fixed training settings.

  2. 2. Select data

    Draw an example, mini-batch, episode, or another unit of experience.

  3. 3. Predict

    Compute model outputs from current parameters and inputs.

  4. 4. Measure

    Use a loss or feedback rule to score the outputs against the objective.

  5. 5. Update

    Change parameters in a direction intended to reduce future loss.

  6. 6. Check

    Track diagnostics and held-out performance, then continue, adjust, or stop.

Case

ResNet-50 in one hour: the same stages, different constants

A concrete instance carries numbers at every stage. ResNet-50 was trained on ImageNet with a minibatch of 8,192 images spread over 256 GPUs. It finished in one hour, matching the accuracy of small-batch training. Facebook published the run in 2017. What made it work was not a change of model. It was two changes to the update stage. A linear scaling rule raises the learning rate by the same factor as the batch size. A warmup then reaches the higher rate gradually instead of at the first step. Yang You and colleagues later took the same benchmark to a 32,768-image batch and 20 minutes. Their 2018 paper treats the one-hour result as the reference to beat. The stages were identical across those runs. Every constant attached to them was not.

Prediction and learning are different operations

During a forward computation, the model uses its current parameters to produce outputs. Training adds a feedback and update process on top of that, one that changes the parameters themselves. Inference usually performs only the output computation and leaves them fixed.

That distinction is why a deployed model does not automatically learn from every request it serves. Online updates require an explicit pipeline, an objective, safeguards, and new evidence, none of which appears by itself.

Microsoft built the exception and then published the post-mortem. Tay was released on Twitter on 23 March 2016 and did learn from its interactions with users. It tweeted more than 95,000 times within 16 hours. It was taken offline inside the first day. Peter Lee, then a Microsoft corporate vice president, gave the company's account on 25 March 2016: “In the first 24 hours of coming online, a coordinated attack by a subset of people exploited a vulnerability in Tay.” He wrote that Tay would return only when Microsoft could better anticipate malicious intent. The update loop was the easy half to build. The objective, the evidence and the safeguards around it were the half that was missing. The loop ran regardless — sixteen hours and ninety-five thousand tweets of it.

Using a model is not the same as updating it.

Key idea

Each update sees a partial view

A mini-batch is a small sample. Its loss and its update direction are noisy estimates of what would actually help across the whole training distribution.

How small that sample is, is itself a design decision, and the price of getting it wrong has been measured. Six networks were trained in two regimes, with everything fixed except the batch: 256 examples per step against a batch of 10% of the training set. Every configuration was repeated 5 times from different random starting points. The large-batch runs did not fail to converge. They converged, and then tested worse. Network F2 reached 64.02% with the small batch and 59.45% with the large one; network C4, 63.08% against 57.81%. Keskar and colleagues state the size of it in one line: “In our experiments, we have found the drop in generalization (also called generalization gap) to be as high as 5% even for smaller networks.” Hoffer and colleagues reproduced that gap independently in 2017. They closed most of it without touching the model, by training longer with Ghost Batch Normalization. Read the ResNet-50 run above against those numbers. The 8,192-image batch cost no accuracy, but only because the linear scaling rule and the warmup were added to the update stage to pay for it.

Noise can be useful because it makes training efficient and may help exploration. It also creates fluctuations. Do not diagnose a run from one batch or one unusually good step.

Training curves should be interpreted as trajectories, not as a sequence of independent verdicts.

Case

PaLM: twenty loss spikes, and the batches that were skipped

Google’s PaLM team met the extreme version of this while training a 540-billion-parameter model. They wrote down what they did about it. They “observed spikes in the loss roughly 20 times during training, despite the fact that gradient clipping was enabled”. The remedy was procedural. They restarted “from a checkpoint roughly 100 steps before the spike started”, then skipped “roughly 200–500 data batches”. Those covered the batches seen before and during the spike. The diagnosis matters more than the remedy. Replaying the same batches from an earlier checkpoint produced no spike at all. The team concluded that the cause was not bad data. It was an interaction between particular batches and a particular parameter state — a property of the run, invisible in any single batch.

Comparison

What training and validation curves can reveal

The same final training loss can accompany very different learning behavior.

The amber pattern below carries a warning the picture cannot show. It is a heuristic with published counter-examples. A ResNet18 was trained on CIFAR-10 with label noise, using Adam for up to 4,000 epochs. Test error fell, rose, and then fell again. The abstract names the effect: “double descent occurs not just as a function of model size, but also as a function of the number of training epochs”. Nakkiran and colleagues published that in 2020. The same paper identifies regimes where quadrupling the number of training samples hurts test performance. The model-size version of the curve had been established independently by Belkin and colleagues in 2019. So a run whose validation error has been climbing for a while may be in the middle of the second descent rather than past its best checkpoint. Stopping at the first divergence remains a sensible default. It is not a law, and the counter-example has a citation.

FigureComparison · 3 columns

Healthy progress

Training and validation improve, then level off near each other.

  • Optimization is making progress
  • Generalization remains stable
  • Later gains may be small
  • Candidate for stopping or refinement

Optimization trouble

Training loss barely improves or behaves erratically.

  • Learning rate may be unsuitable
  • Features or scales may be problematic
  • Gradients or implementation may fail
  • Capacity may also be insufficient

Overfitting pattern

Training improves while validation worsens after a point.

  • Model fits training-specific detail
  • Best checkpoint may occur earlier
  • More data or regularization may help
  • Evaluation split should also be audited

Example

A training run should leave evidence

Useful run records make failures reproducible rather than mysterious.

The second item on this list has a price attached. Ten trials of one algorithm on one task were run with identical hyperparameters, varying only the random seed. The trials were split into two groups of five, and each group was averaged. A 2-sample t-test separated the two average curves at t = -9.0916, p = 0.0016 on HalfCheetah. Henderson and colleagues put it this way in 2018: “Particularly for HalfCheetah, it is possible to get learning curves that do not fall within the same distribution at all, just by averaging different runs with the same hyperparameters, but different random seeds.” Same code, same data, same settings, two contradictory and publishable pictures. The only variable that distinguished them is the one a run record most often omits. Agarwal and colleagues later showed the same problem across the field, arguing that results from a small number of runs cannot be reported as bare point estimates.

  • Dataset, split, feature, code, and configuration versions.
  • Random seeds and initialization details — the variable that split ten identical HalfCheetah trials into two average curves at p = 0.0016.
  • Training and validation losses over time, with comparable evaluation intervals.
  • Task metrics on important slices, not only the aggregate objective.
  • Resource usage, runtime, warnings, numerical errors, and checkpoint locations.
  • Notes explaining manual interruptions, restarts, and deviations from the planned run.

Stopping is a decision, not the absence of patience

Training may stop after a fixed budget, when validation improvement becomes negligible, when a target criterion is reached, or when instability appears. The rule should be defined before the final test is examined.

An entire industry does exactly that, in public, and calls it a benchmark. MLPerf Training, run by MLCommons, fixes the quality first and measures the clock second: “MLPerf Training measures the time it takes to train machine learning models to a standard quality target in a variety of tasks including image classification, object detection, NLP, recommendation, and reinforcement learning.” For ResNet-50 on ImageNet the standard quality target is 75.90% top-1 accuracy. A submission is not scored on throughput, and not stopped at a fixed epoch budget. Training is stochastic, so each benchmark is run several times, the highest and lowest results are dropped, and the rest are averaged. That still leaves roughly ±2.5% variance on the imaging benchmarks. In the v1.1 round published on 1 December 2021, with 14 submitting organisations and over 185 peer-reviewed results, Graphcore reported reaching that 75.9% target on an IPU-POD16 in 28.3 minutes and 38 epochs. The 28.3 minutes means something only because the 75.90% was written down first.

The lowest training loss is rarely the only goal. Teams also care about validation behavior, calibration, latency, fairness, robustness, and cost. A stopping rule written around training loss alone will happily stop at the wrong place.

How long to keep going is the same class of decision. An entire field got it wrong for several years. Hoffmann and colleagues at DeepMind reported the size of that mistake in March 2022. Large language models had been trained on far too little data for their size. Model size and training tokens should be scaled in equal proportion: double the parameters, double the tokens. Their demonstration was Chinchilla. It has 70 billion parameters and was trained on 1.4 trillion tokens, at the same compute cost as the 280-billion-parameter Gopher. It outperformed Gopher and GPT-3 (175B), Jurassic-1 (178B) and Megatron-Turing NLG (530B), and reached 67.5% on the MMLU benchmark. A quarter of the parameters, four times the data, the same bill. The stopping rule was the design decision.

Steps

A first-response checklist for a bad run

Before changing the architecture, verify that the loop is solving the intended problem.

FigureProcess · 5 steps
  1. 1. Overfit a tiny sample

    Confirm the model and optimizer can drive loss down on a handful of examples.

  2. 2. Inspect inputs and targets

    View decoded records, labels, ranges, masks, and missing values.

  3. 3. Compare a baseline

    Check whether the model beats a trivial predictor under the same metric.

  4. 4. Watch the curves

    Separate no learning, instability, and generalization gaps.

  5. 5. Change one control

    Vary learning rate, capacity, or preprocessing without confounding the diagnosis.

The loop optimizes what you wrote, not what you meant

A correct implementation can efficiently reduce a poorly chosen loss on an unrepresentative dataset. Training success is therefore conditional on framing, labels, features, and evaluation.

The largest documented case of that sentence runs on about 200 million people a year in the United States. An algorithm used to help manage their care scored patients by predicted health-care cost rather than by illness. Nothing in the loop malfunctioned. It reduced the loss it was handed, on the target it was handed. Cost was a stand-in for the thing anyone actually wanted, which was sickness. Obermeyer and colleagues measured the gap between the two in Science in 2019. Only 17.7% of the patients the algorithm assigned to extra care were Black, against 46.5% if the score were unbiased.

The consequence arrived by letter, dated 25 October 2019. New York's Department of Financial Services and its Department of Health wrote jointly to United Health Group Incorporated about the Impact Pro algorithm: “We call on you to immediately investigate these reports and demonstrate that this algorithm is not racially discriminatory or to cease using Impact Pro (or any other data analytics program) if you cannot demonstrate that it does not rely on racial biases or perpetuate racially disparate impacts.” A regulator can order a company to stop running a loss function. It cannot debug one.

The loop is powerful precisely because it is literal. It will optimize exactly what you wrote down. That is why the broader learning system has to make sure the feedback signal corresponds to the behavior people actually need. No stage of the loop failed here. The objective did, and the loop pursued it at scale, in production, for years.

Key takeaways