[Dev] Fix expert-aware optimizer gradient statistics - #6470
Conversation
Expert parameters use expert tensor-parallel ownership, but optimizer gradient filtering only received the dense TP group. This omitted valid expert shards when TP and ETP ownership differed and underestimated clipping norms. Preserve allreduce metadata on optimizer parameter copies and pass both TP groups through gradient-norm and zero-count filtering. Signed-off-by: guapisolo <guapisolo@gmail.com>
Standalone reproduction on current
|
| checkout / path | actual norm | zero count | status |
|---|---|---|---|
dev@12eed0a5 / BF16 optimizer, attempt 1 |
1.4142135623730951 |
2 |
BUG_REPRODUCED |
dev@12eed0a5 / BF16 optimizer, attempt 2 |
1.4142135623730951 |
2 |
BUG_REPRODUCED |
dev@12eed0a5 / DistributedOptimizer |
1.4142135381698608 |
2 |
BUG_REPRODUCED |
PR 3e72b966 / BF16 optimizer |
1.7320508075688772 |
3 |
FIX_VERIFIED |
PR 3e72b966 / DistributedOptimizer |
1.7320507764816284 |
3 |
FIX_VERIFIED |
On current dev, the report also shows expert_tp_group_size: null and expert_optimizer_allreduce_metadata: [null]. On the PR head these become 1 and [false], respectively. This isolates the remaining gap after #6165: the helper exists, but production optimizer group/metadata plumbing is missing.
What does this PR do?
Ports the expert-aware optimizer gradient-statistics plumbing from #5916 to
dev, on top of the duplicate-filter helper already added by #6165.Issue tracking
Related to #5916, #6165, #6015, and #6099.
Problem
The standard optimizer creates separate dense and expert children, but both children only receive the dense tensor-parallel group. The gradient-norm and zero-count filters therefore deduplicate expert parameters with dense TP ownership.
For example, with TP4 / EP4 / ETP1, each rank owns distinct expert shards and every ETP group has local rank 0. The old filter instead keeps only dense TP rank 0, omitting valid expert gradients from ranks 1-3. Backward still produces those gradients and the optimizer still updates the parameters, but the reported global norm is too small, so clipping is weaker than intended.
Mixed-precision and distributed optimizers have a second part of the same issue: their parameter copies did not preserve
allreduce=False, which is how the duplicate filter recognizes expert parameters.Fix
allreducemetadata when creating optimizer parameter copies or views.ChainedOptimizerpath.This is the optimizer-side subset of #5916. It intentionally does not port the separate gradient-synchronization, TE/native parameter-tagging, or parameter-norm logging changes from #5916, nor the LayerWise/Muon follow-up in #6099. As noted in #6015, this plumbing is also a prerequisite for a future
devcounterpart of #6099.Validation
sqrt(1 + world_size);1 + world_size.DistributedOptimizer: both passed on every rank.tests/unit_tests/test_optimizer.pyon one GPU:28 passed, 42 skipped.tools/autoformat.shin check-only mode againstdev: Black, isort, pylint, and Ruff passed (mypyreported the repository's existing ignored diagnostics).1.3e-7relative error;3.97%to5.49%low across the four nonzero steps in the second run.Contribution process
Pre-checks