Skip to content

fsdp: materialize clip_grad_norm's DTensor before logging#35

Merged
zhihengy merged 1 commit into
mainfrom
fix/grad-norm-logging
Jul 13, 2026
Merged

fsdp: materialize clip_grad_norm's DTensor before logging#35
zhihengy merged 1 commit into
mainfrom
fix/grad-norm-logging

Conversation

@zhihengy

@zhihengy zhihengy commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

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 the train/grad_norm metric 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_norm curves to step up (×2 on the dp4 recipe) after this merges — historical values were under-reported, not the new ones inflated.

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>
@zhihengy zhihengy force-pushed the fix/grad-norm-logging branch from d2361fd to 41d9bbb Compare July 13, 2026 21:20

@Rockdu Rockdu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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>
@zhihengy zhihengy merged commit e833151 into main Jul 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants