Skip to content

Training Alignment Handbook

How to make two training or inference runs agree bit for bit, and how to find the first place where they stop agreeing.

The three workflows

The handbook teaches three workflows. Two of them start from a symptom. In the first, two pre-training runs that should agree do not (part 1). In the second, the rollout engine and the trainer give different log-probabilities for the same tokens (part 2). Both can end at an operator whose result depends on the other rows in its batch. When that happens, they hand the operator to the third workflow, which makes it batch-invariant (part 3). Part 0 teaches the ideas that all three rest on.

All three build on Part 0: Foundations, which defines the invariance levels L1–L5 and explains where and how to compare two runs.

Part 1 Pre-training Find where two runs stop agreeing

  1. PreflightTurn on the settings that make a run repeatable, and check that both runs really use them.
  2. Data alignmentCheck that every rank of both runs gets the same batches at every step.
  3. Localize with OpGuardCapture both runs, find the first operator where they differ, trace back from it to the cause, then fix the cause and confirm the fix.
  4. Training stepIf the cause lies in the backward pass, the optimizer, the loss or a resume, make that part repeat bit for bit.
  5. Data parallelIf the cause is a gradient that ranks sum together or shard, make the sum independent of how the work is split.
  6. Compiled codeIf the job runs torch.compile or CUDA graphs, take fingerprints inside the compiled code, which an eager capture cannot see.
  7. SDCOnce software is ruled out, find the hardware that silently returns wrong values.

Part 3 Batch-invariant kernels Make one operator batch-invariant

  1. GEMM and quantized GEMMUse the same tile and the same reduction order at every batch size.
  2. AttentionSplit the keys the same way in prefill, in decode and in the backward pass.
  3. MLA and sparse attentionDo the same when the keys are compressed or picked by top-k selection.
  4. Linear attentionUpdate the recurrent state in the same chunk order every time.
  5. MoEMake routing, the expert GEMMs and the combine independent of which tokens share a batch.
  6. CollectivesAdd up the partial results of all GPUs in one fixed order.

Part 2 RL train–inference Make the rollout engine and the trainer agree

  1. Whole modelMake one side give a sequence the same logits whether it runs alone, in a batch or in any serving mode.
  2. ParallelismKeep that true with tensor parallelism, and when prefill and decode run on separate servers.
  3. SamplingMake sure the sampled tokens can be reproduced from the logits and a seed.
  4. LoRAKeep each adapter's result unchanged when one batch mixes several adapters.
  5. Engine parityMake a real inference engine round at the same points as the trainer, so that the two sides agree.
  6. RL loopRecord each rollout, tell staleness apart from a real mismatch, and localize any gap offline.
  7. WalkthroughFollow every step on one real job: verl with FSDP2 and a vLLM rollout.

Afterwards, Part 4: Operations checks the results again whenever the software stack or the hardware changes.

A step drawn with a dashed border hands the operator it found to part 3. Hover over a step, or give it keyboard focus, to read what it does.

Not sure where to start? The alignment-pipeline skill asks you a few questions and sends you to the right workflow. The terms used throughout the handbook are defined in the glossary.

Part 1: when two pre-training runs stop agreeing

Start with the overview. The agent skill for this part is pretraining-alignment.

  1. Determinism and preflight: turn on the settings that make a run repeatable, and check that both runs really use them.
  2. Data alignment: check that every rank of both runs gets the same batches at every step.
  3. Localize with OpGuard: capture both runs, find the first operator where they differ, and trace back from it to the cause. Then fix the cause and confirm the fix.

After that, read the page for the place the first divergence points to:

  • Training step shows how to make the backward pass, the optimizer, the loss and a resume from a checkpoint repeat bit for bit.
  • Data parallel shows how to keep gradients equal when ranks sum them together or shard them.
  • Compiled code and CUDA graphs shows how to take fingerprints inside torch.compile and CUDA graphs, where an eager capture cannot see.
  • SDC shows how to find hardware that silently returns wrong values.

Part 2: when the rollout engine and the trainer disagree

Start with the overview. The agent skills for this part are engine-parity and OpGuard's rl-alignment.

  1. Whole model: make one side give a sequence the same logits whether it runs alone, in a batch or in any serving mode.
  2. Parallelism: keep that true with tensor parallelism, and when prefill and decode run on separate servers.
  3. Sampling: make sure the sampled tokens can be reproduced from the logits and a seed.
  4. LoRA: keep each adapter's result unchanged when one batch mixes several adapters.
  5. Engine parity: make a real inference engine round at the same points as the trainer, so that the two sides agree.
  6. RL loop: record each rollout, tell staleness apart from a real mismatch, and localize any gap offline.
  7. Walkthrough: follow every step on one real job, verl with FSDP2 and a vLLM rollout.

Part 3: making one operator batch-invariant

Start with the standard that every invariant operator must meet. The agent skill for this part is batch-invariant-kernel.

  1. GEMM and quantized GEMM: use the same tile and the same reduction order at every batch size.
  2. Attention: split the keys the same way in prefill, in decode and in the backward pass.
  3. MLA and sparse attention: do the same when the keys are compressed or picked by top-k selection.
  4. Linear attention: update the recurrent state in the same chunk order every time.
  5. MoE: make routing, the expert GEMMs and the combine independent of which tokens share a batch.
  6. Collectives: add up the partial results of all GPUs in one fixed order.

Part 5: the same method in other scenarios

The same method also works for other pairs of runs. See the overview, and the pages on framework migration, checkpoint conversion and offline post-training.

Part 4, the skills and the reference pages

Every claim on a page links to the report that holds its measurements and names the stack it was measured on.

Citation

If this handbook, its tools or its skills help your work, please cite it:

@misc{zhou2026trainingalignment,
  title        = {Training Alignment Handbook},
  author       = {Zhou, Ziming and Xu, Peiyu},
  year         = {2026},
  howpublished = {\url{https://training-alignment.github.io/training-alignment-handbook/}},
  note         = {Code and reports: \url{https://github.com/training-alignment/training-alignment-handbook}}
}