Milestone 3 of 7
Overfit one sequence
Use one repeated sequence to test whether targets, loss, gradients, and parameter updates form a learnable path.
Before training the corpus, repeat one sequence until the decoder can fit it. This is a narrow diagnostic of the connected training path, not a test of generalization.
Milestone goal
Train only
input: <bos> A B C
target: A B C <eos>
for 500 updates with the frozen model, initialization, optimizer, learning rate, and clipping rule. Preserve the complete diagnostic record and make a GO/NO-GO decision for corpus training.
Record the update in dependency order
For every step:
- enter training mode;
- clear old gradients;
- calculate logits and aligned cross-entropy;
- run backward;
- record the global gradient norm before clipping;
- clip to 1.0 and record the norm after clipping;
- update parameters.
At selected steps, switch temporarily to evaluation mode and record full-batch loss, the probability assigned to each of the four targets, and the predicted token at each position.
Do not reuse a loss tensor after its parameters have changed. Label whether a measurement was taken before or after the update.
Establish the expected pattern
The initial loss should be in the neighborhood of the uniform baseline , although initialization can move it. A correct and expressive training path should reduce the loss close to zero on this single repeated row.
The checked reference reaches final loss 0.00186184. Treat that number as a
regression clue, not a universal threshold: framework versions and floating-
point kernels can change the last digits. What matters is a large, stable loss
reduction and high probability on all four declared targets.
Preserve a diagnostic table
Use at least these fields:
| step | loss | gradient norm before clip | after clip | minimum target probability | four predicted tokens |
|---|
Record steps 0, 1, 2, 5, 10, 25, 50, 100, 250, and 500. A final loss alone cannot show an unstable spike, permanently clipped gradients, or one target that never learned.
Diagnose a failed overfit
Check contracts before adding width, depth, or more steps:
| Observation | First checks |
|---|---|
| loss does not move | gradient existence, zero_grad, backward, and optimizer step |
| one position stays wrong | input-target shift and causal visibility |
| loss is NaN | logits, mask rows, learning rate, and gradient norm |
| gradient is always zero | detached logits, frozen parameters, or saturated path |
| gradient is clipped every step | pre-clip norm and learning-rate scale |
| training predictions are correct but loss is high | target IDs, flattening, and reduction |
Change one suspected cause at a time and preserve the failed trace. Silent trial-and-error destroys the evidence this milestone is meant to create.
Question. Interpret the diagnostic
The model overfits one repeated sequence but corpus validation remains poor. What has and has not been established?
Select one choice, then check.
Hint
Solution
Acceptance gate
Issue GO only if:
- the loss falls from its initialized value to a small, finite value;
- every target probability rises and every final target prediction is correct;
- gradients are present, finite, and recorded before and after clipping;
- repeating the run with the same environment and seeds reproduces the trace within the declared tolerance;
- the result is described only as a one-sequence training-path diagnostic.
Otherwise issue NO-GO, preserve the first failing check, and repair it before corpus training.
Deliverable: the diagnostic table, target-probability trace, final predictions, failed checks if any, and the signed GO/NO-GO decision.