fsdp: materialize clip_grad_norm's DTensor before logging#35
Merged
Conversation
clip_grad_norm_ returns a lazily-reduced partial-norm DTensor; logging it without full_tensor() leaks the local shard's norm, under-reporting grad_norm by sqrt(n_shards) (2x on the dp4 recipe). Clipping itself was always correct — the coefficient is computed in DTensor arithmetic. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d2361fd to
41d9bbb
Compare
zhihengy
added a commit
that referenced
this pull request
Jul 13, 2026
Partial revert of 0420f3b: that commit also carried the dp_mesh -> fsdp_mesh line (folded in during a rebase), which belongs to the SP placement and stays. Only the DTensor import and the full_tensor materialization leave; they land independently as #35, which this PR's cross-placement grad_norm comparisons depend on. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
clip_grad_norm_on DTensor parameters returns a lazily-reduced partial norm; the logging path (.detach()→.mean().item()) leaked the local shard's value, under-reporting thetrain/grad_normmetric by ×√(n_shards) on every FSDP config (historical dp4 wandb curves are ×2 too low). Clipping itself was always correct — the clip coefficient is computed inside DTensor arithmetic — only the logged metric was wrong.Fix:
.full_tensor()before logging.Found while cross-validating the two SP parameter placements in #21 (different shard counts → reported norms differed by √2 while instrumented per-param grads were bitwise identical). #21's validation claims depend on this landing first.
Expect wandb
grad_normcurves to step up (×2 on the dp4 recipe) after this merges — historical values were under-reported, not the new ones inflated.