1. Pre-training alignment¶
Where we are¶
Part 0 showed that the bits of a sum depend on the order of its additions, and that two runs can be compared bit for bit at operator boundaries using fingerprints. This part applies those ideas to two training runs that should agree but do not. Typical reasons to start are:
- a loss spike or a slow drift after an upgrade, a migration or a config change;
- a run that, after a resume, does not follow the same trajectory as before;
- a machine suspected of silent data corruption (SDC).
The workflow takes you from the symptom to a confirmed fix and a regression check. It is the method OpGuard is built around, and the pretraining-alignment skill lets an agent carry it out.
- 1. Choose the reference run. It decides which question the comparison answers.
- 2. Preflight and control: make sure the two runs differ only in the one thing you are testing.
- 3. Capture fingerprints at every boundary on both runs. If the job runs compiled code, read that page first.
- 4. Find the first boundary whose bits differ.
- 5. Classify: the first divergence points to a kind of cause.
- Each common kind of cause has its own page.
- 6. Fix the cause there, with the smallest change that removes it.
- 7. Confirm: capture the pair again and check that it agrees everywhere.
- 8. Keep the pair in the regression suite, so that it goes on agreeing.
| Step | What the step establishes | Page |
|---|---|---|
| 1. Choose the reference run | Which question the comparison answers | this page |
| 2. Preflight and control | That the two runs differ only in the one thing you are testing | Determinism and preflight; for the parts of a training step, Training step; for the collectives that sum gradients, Data parallel |
| 2. Preflight and control, for the data | That every rank sees the same token bits at every step | Data alignment |
| 3. Capture | That both runs have fingerprints at every model-level boundary | Localize with OpGuard; if the job runs torch.compile or CUDA graphs, also Compiled code and CUDA graphs |
| 4. First divergence | Which boundary is the first whose bits differ | Localize with OpGuard |
| 5. Classify | Which kind of cause it is: a setting, a part of the training step, a collective, compiled code, a kernel or the hardware | this page, then the page for that kind of cause |
| 6. Fix | The smallest change that removes the cause | the page for that kind of cause, or part 3 for a kernel |
| 7. Confirm | That the pair, captured again, agrees everywhere | Localize with OpGuard |
| 8. Regression | That the pair stays in a suite and goes on agreeing | Regression |
The pages of this part follow the workflow. Step 2 comes first, in
Determinism and preflight and then in
Data alignment. Next comes the core loop,
Localize with OpGuard, where you capture both runs,
find the first divergence, trace it to its cause, fix the cause and confirm
the fix. The pages after it cover the places a first divergence most often
points to: Training step for the backward pass, the
optimizer, the loss and resume; Data parallel for the
collectives that sum gradients;
Compiled code and CUDA graphs for
torch.compile and CUDA graphs; and SDC for the hardware.
The idea: make the two runs differ in exactly one thing¶
If you keep everything equal except one thing that you have declared, the first bitwise difference between the runs is either that thing or a fault. Here is a small example. Two runs are identical except that, in the suspect run, the norm multiplies by its weight before rounding to bf16. These are their fingerprints at each boundary, in call order:
- The two runs are identical except where the suspect's norm multiplies by its weight. Their fingerprints are listed in call order.
- The token embedding is equal on both runs.
- The attention norm differs. This is the first divergence.
- The q projection differs too, because its input already differs.
- So does every later boundary.
- Read only the first difference, and trace from it to the cause.
Everything after the norm differs as well, because its input already differs. So read only the first difference, and trace from it to the cause.
Rule. Make the two runs differ in exactly one thing, and write that thing down. Compare them bit for bit in call order, and start from the first difference. This is a controlled experiment, and the reference run is its control.
The steps¶
Step 1: choose a reference run¶
Pick the reference run that isolates your question. One captured suspect run and one reference run are enough, and the suspect run does not have to be deterministic.
| Reference run | The question it answers |
|---|---|
| The same job run again, with everything the same | Is there residual nondeterminism, a race or SDC? |
| The last commit that was stable | Which change introduced the drift? |
| The same config with one feature turned off (overlap, offload, recompute or fusion) | Does this feature change the computation? |
| The previous library or driver version | Did the upgrade change the numerics? |
| The same model in another framework | Where do the two implementations disagree? |
| One GPU, or a TP simulator that keeps logical TP above 1 | Is the parallel implementation wrong? |
Give both runs the same data, seeds and checkpoint, and write down the one
difference you are testing; you pass it to the preflight diff as declared.
You are ready when you can name the difference in one sentence and nothing
else is meant to differ.
Step 2: control the avoidable variation and check it¶
The avoidable variation comes from five surfaces: randomness and data order, library kernels, collectives, checkpoint resume and the TP degree. Set them, read them back from inside each job with determinism_preflight.py, and diff the two reports (Determinism and preflight); the diff must list only the declared difference. For the parts of a training step, see Training step; for the collectives that sum gradients, see Data parallel.
Do not pin scheduling or user kernels: if they change the bits, that change is the signal you are looking for.
Step 3: capture fingerprints on both runs¶
Record fingerprints of the inputs and outputs at every model-level boundary on
both runs; they are computed on the operator's own stream and add no
synchronization. opguard_bridge.py runs both
sides through OpGuard's harness, which discovers the boundaries, plans where
to instrument, captures and compares. If the code runs under torch.compile
or CUDA graphs, an eager capture does not show the bits that production
computes; use graph_probe.py instead
(Compiled code and CUDA graphs).
| Option | What it gives | Cost class | When to choose it |
|---|---|---|---|
| An eager OpGuard capture | Every boundary it discovers, with its call site | small at each boundary (a few device kernels and no synchronization); the overhead of a whole capture is not measured here | The run is eager, or replaying it in eager shows the symptom |
| A graph probe inside compiled code | The bits that compiled code and graph replays actually produce | small for each probe inside a CUDA graph, large outside one; many probes on a small step add up to large | Production uses torch.compile or CUDA graphs |
| A full tensor dump | The values themselves, not fingerprints | large (2x or more) | Only for a region that a fingerprint has already named |
The capture is complete when opguard_bridge.coverage(run) shows that the
region you care about, GEMMs included, was captured.
Step 4: find the first divergence¶
You want the first boundary, in call order, whose fingerprints differ. The two traces never line up position by position, because overlap, fusion and rewrites move events around, and one side may have events that the other lacks. OpGuard therefore pairs the events with an order-preserving match, anchored on boundaries it can identify without doubt, and leaves the uncertain events unpaired, as gaps.
The first pair that differs is the pivot, and
opguard_bridge.first_divergence(...) collects the facts about it
(Localize with OpGuard). You are done when the
pivot has no unaligned event before it; an unpaired event is not a difference.
Step 5: decide what kind of cause it is¶
Each kind of cause has its own fix and its own page. Read the pivot's source
line, the operators that produced its inputs, and the status of each call at
its call site; opguard_bridge.suggest(...) lists possible leads, each with
its reason. You end with one hypothesis and the evidence that points to it.
The root causes that OpGuard has pinpointed in production fall into these
classes:
| Kind of cause | Example | Where to go |
|---|---|---|
| A setting that is missing or wrong | deterministic mode not set for one backward kernel | Determinism and preflight |
| A racy or nondeterministic kernel | the backward of torch.embedding, a fused embedding backward, a Triton kernel that lacks a barrier |
Training step; part 3 |
| State that is restored wrongly | an optimizer's step variable overwritten on resume | Training step |
| A reduction that depends on the topology | a reduce-scatter under a different NCCL topology | Data parallel |
| Compiled code | a fusion or a graph bucket that changes a reduction | Compiled code and CUDA graphs |
| Streams used wrongly | a stream race in an fp32 RMSNorm; activation offload | Localize with OpGuard |
| A wrong assumption about layout | QKV projections that silently assume a contiguous tensor | Localize with OpGuard |
| MoE routing | mismatched histogram bins that make the routing drift | part 3: MoE |
| Silent data corruption in hardware | a boolean scatter that sends one token to the wrong place, which shows up as a shape mismatch many operators later | SDC |
Step 6: fix the cause¶
Make the smallest change that removes the cause; how depends on its kind.
Correct a setting in the preflight, fix a part of the training step with that
page's checklist, and fix a kernel with the
batch-invariant-kernel skill
and its recipes.
OpGuard's harness skill validate-hypothesis tests one cause at a time; the
change should affect the pivot in the way the hypothesis predicts.
Step 7: confirm the fix¶
Capture the pair again with the fix applied, to show that the fix and nothing else made the runs agree. No event may differ, no event may be unaligned, and the final parameters must be bit-identical.
Step 8: keep the pair as a regression check¶
Add the pair, or the smallest case that reproduces it, to the regression suite (Regression), and record the stack on which the agreement holds, so that the runs still agree after the next upgrade. The suite should run the case and report it equal.
What can go wrong¶
More than one difference between the runs
Two undeclared differences produce one first divergence that neither of them explains on its own, and you end up chasing a mixture of causes. Diff the preflight reports, and remove every difference except the declared one before you capture.
A capture that misses the region
A boundary that was not instrumented cannot be the first divergence, so
the pivot lands later, in the wrong operator. Check coverage before you
read a first difference.
Mistaking the pivot for the cause
The first difference is where wrong bits first become visible, not where they were produced. A nondeterministic backward pass, for example, has no boundary of its own, so its effect shows first at the next operator that consumes its output. Trace upstream from the pivot, and test the hypothesis.
Calling a disagreement between devices SDC too early
Different drivers or libraries give different bits without any fault. If you call that SDC, you take a healthy node out of service. Rule out software differences first (SDC).
Summary¶
- Choose a reference run that isolates one question, and write down the one difference between the runs.
- Control the avoidable nondeterminism, and check it with the preflight diff.
- Capture the model-level boundaries, check the coverage, and take the first bitwise difference that has no unaligned event before it.
- Decide what kind of cause it is, fix it with the smallest change, confirm the fix by capturing again, and keep the pair as a regression check.
Go deeper¶
- The pretraining-alignment skill runs this workflow as an agent.
- The tools: opguard_bridge.py, determinism_preflight.py, graph_probe.py and sdc_scan.py.
- Report: the OpGuard walkthrough, and an earlier version of this overview that includes the production numbers.
- Part 3 covers the case where the cause is a kernel that has no invariant implementation.