Repository navigation
[test] numerical alignment: parameter contract, device audit, zero-token steps, resume state, exact plugin recipes - #6506
Merged
Merged
Conversation
…ken steps, resume state, exact plugin recipes Addresses the items of #6488 left open after #6505. - Parameter contract, checked in every run: the optimizer must hold every trainable parameter (by identity), and parameters declared tied with NumericsSpec(tied_params=...) must be one Parameter in each run's own model, also after the plugin wrapped it; undeclared shared parameters fail too. Failures name the logical parameter (optim/param/<name>, tied/<names>). - The recipe audit records the device type with every dtype, and what the optimizer updates, so master weights or Adam moments offloaded on one side only raise RecipeMismatch. - Token-weighted data parallelism: a micro-batch without valid tokens records its summed loss instead of 0 / 0 and still takes part in the reduction; a step without any valid token raises ValueError on every rank before the first forward. - Resume also compares, after the last step, the tensors the optimizer updates (the float32 master weights where the plugin keeps them), Adam's state, the scheduler's state, the loss scale and the random number generator states; the data-progress and RNG boundary is documented. - prepare keeps the models on the CPU and each run copies the one it needs to the device, so one model is on the device at a time and the float64 truth is cast on the way there. - Gradient checkpointing (non-reentrant, enabled in prepare_fn) is verified through every supported plugin. - Recipe fixes: FSDP MixedPrecision's master weights start from the unrounded float32 weights, not from their cast (FSDP bf16 on Mixtral: 1.42, now 1.00); with master weights the fp16 loss scale is divided out in float32, as Gemini does (Gemini fp16 on Mixtral: 1.68, now 1.07). The self-tests now require exact reproduction on one device, Gemini fp16 excepted: HybridAdam and torch's AdamW differ in the last float32 bit. - The reference cache key covers the declared unused and tied parameters and reads the optimizer's groups from the real parameters.
JazyJiang
force-pushed
the
feat/numerics-gaps
branch
from
November 5, 2026 03:39
1427f65 to
6a62961
Compare
yuxuan-lou
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Related issues
Related to #6488: the items left open after #6505 (see the status table in #6488 (comment)). Follows #6505.
2. Background
#6505 added whole-model, data-parallel and resume checks for model_zoo entries. Its review against #6488 left open: an optimizer coverage check and tied-parameter declarations (D2), a device audit next to the dtype audit (D3), steps and micro-batches without valid tokens (D4), a direct comparison of the optimizer and scheduler state on resume, a stated RNG / data-progress boundary, and not holding several models on the device at once (D5), and gradient checkpointing in the support matrix (D0).
3. Changes
All under
tests/kit/numericsandtests/test_numerics; nothing incolossalai/or CI changes.judge.require_gradients, with the logical parameter name:optim/param/<name>). Anoptimizer_fnthat builds parameter groups and leaves one out does so on both sides, so the numbers alone would pass;NumericsSpec(tied_params=(("embed_tokens.weight", "lm_head.weight"),)): each declared group must be oneParameterin each run's own model, also after the plugin wrapped it (FSDP excepted); undeclared shared parameters fail too (tied/<names>). A tied parameter is compared once, under its first name.float32@cpu), and the audit also records what the optimizer updates (optim/params), so master weights or Adam moments offloaded on one side only raiseRecipeMismatchbefore numbers are judged.token_weighted=True): a micro-batch without valid tokens records its summed loss, 0, instead of0 / 0, and still takes part in the gradient reduction; a step without any valid token raisesValueErroron every rank before the first forward, so no rank waits in a collective. The README states how DDP's rank averaging and the token weighting relate.run_stepsalso records, in the plugin's own layout, the tensors the optimizer updates (optim/<group>.<index>/param, the float32 master weights where the plugin keeps them), Adam's state, the scheduler's state, the fp16 loss scale and the RNG states (rng/cpu,rng/cuda);resume.checkcompares them bit for bit. The docstring and README state what the scenario carries itself and a booster checkpoint does not: data progress and RNG state. A model that draws random numbers while training fails onrng/*.preparekeeps the model and reference on the CPU; each run copies the one it needs to the device, and the float64 truth is cast on the way there. For a 111M-parameter Llama this removes 0.44 GiB (one float32 copy) from every run's peak (truth 5.49 → 5.05 GiB, ref 3.27 → 2.83 GiB, LowLevelZero bf16 3.48 → 3.03 GiB).prepare_fn, verified to recompute every layer and to align through TorchDDP, LowLevelZero (bf16, offload), Gemini, FSDP and HybridParallel (bf16,tp_size=1).MixedPrecisionkeeps the model's own float32 weights as its sharded parameters, so the reference's master weights now start from the unrounded float32 weights (Recipe.master_from_float32), not from their cast. Mixtralfsdp_bf16: max ratio 1.42 → 1.00; a model with tied embeddings had reached 237 on one loss.GeminiOptimizerdoes in its step (div_scale). Mixtralgemini_fp16: 1.68 → 1.07. The rest is HybridAdam against torch's AdamW, which differ in the last float32 bit of a few elements; Gemini fp16 is the one configuration exempt from the exactness assertion.optimizer_fnthat filters parameters by shape no longer fails on a dummy one).4. User and compatibility impact
colossalai, checkpoint format, training behavior, performance: none.NumericsSpecgains an optionaltied_params(default()). An entry whose model shares parameters without declaring them now failstied/...; no model_zoo entry with aNumericsSpecis affected (Mixtral has no tied parameters).Recipegainsmaster_from_float32(default False). Cached reference runs are invalidated by the changed capture code, as designed.optim/param/...,tied/..., and on resumeoptim/...,scheduler/...,loss_scale,rng/....5. Test environment
torch2.13-cu130-tf5.17.0)ci_layer_1_pr.ymlinstalls it: torch 2.5.1+cpu,requirements/requirements.txt, Python 3.10.126. Test commands and results
No
xfail,--ignoreor manual reruns; FAST_TEST is not used.Acceptance of the Mixtral entry under all 14 configurations (
python -m tests.kit.numerics.acceptance --entry transformers_mixtral, 2 GPUs): 29 passed, 12 failed, 2 unsupported, 14 not run, the same verdicts as on main. Every failure is one of #6490, #6492, #6493, #6496, #6497, #6498. All whole-model alignments have max ratio 1.00 exceptgemini_fp16(1.07).7. Known issues
8. Risks and rollback
tests/depends on it.9. Documentation and release impact
tests/kit/numerics/README.md: parameter contract, device audit, large models, zero valid tokens, resume state and boundary, gradient checkpointing, recipe table, calibration note.