Repository navigation
Conversation
Since pytorch#2963, `_dist_reduce` short-circuits all DTensor inputs with `return float(x.full_tensor().item())`, skipping the requested mesh all_reduce entirely. The justification in the comment ("avoid double-counting") only holds when the DTensor's own mesh covers the requested reduction mesh; when they are orthogonal — as in the trainer's loss reduction where the loss is a Replicated DTensor on the TP mesh and the requested mesh is `loss_mesh = batch x cp` — the cross-batch sum is silently dropped. Symptom: every TP > 1 run reports `loss = true_loss / dp_world_size`. For a 2B run at TP=2 with 24 ranks, step-1 loss is 1.08 instead of the ~12.95 ln(vocab) baseline observed at TP=1. Gradients and optimizer steps are unaffected because backward goes through `loss.backward()` not `_dist_reduce` — only the printed/logged loss is wrong. Fix: detect mesh axis overlap via `mesh_dim_names`. If the DTensor's mesh shares any axis with the requested mesh, `full_tensor()` already covers that axis and we skip the explicit all_reduce as before. If the meshes are disjoint, we materialize via `full_tensor()` and fall through to the plain-tensor path so the requested-mesh all_reduce runs. Adds a unit test covering both the orthogonal case (was broken) and the same-mesh case (must not double-count).
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
There was a problem hiding this comment.
Pull request overview
Fixes _dist_reduce handling of DTensor inputs so that reductions requested on an orthogonal mesh are no longer skipped (restoring correct cross-mesh loss/metric aggregation in TP>1 runs).
Changes:
- Update
_dist_reduceDTensor path to materialize viafull_tensor()and only short-circuit when the DTensor mesh overlaps the requested reduction mesh. - Add
_meshes_share_axes()helper to detect mesh-axis overlap viamesh_dim_names. - Add unit tests covering orthogonal-mesh reduction and same-mesh no-double-count behavior for DTensor inputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
torchtitan/distributed/utils.py |
Adjusts DTensor reduction logic to ensure requested mesh all-reduces run for orthogonal meshes; introduces mesh-overlap helper. |
tests/unit_tests/test_dist_reduce_dtensor.py |
Adds regression tests for DTensor reductions on orthogonal meshes and for avoiding double-counting on same-mesh reductions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """ | ||
| a_names = set(a.mesh_dim_names or ()) | ||
| b_names = set(b.mesh_dim_names or ()) | ||
| return bool(a_names & b_names) | ||
|
|
||
|
|
| "with extra_pg when the DTensor's mesh covers the " | ||
| "requested reduction mesh: ``full_tensor()`` already " | ||
| "reduces over that mesh and extra_pg is orthogonal. " | ||
| "Pass a plain tensor when using extra_pg." |
Upstream `_dist_reduce` (torchtitan/distributed/utils.py) since 2026-04-27 (commit 1786292) short-circuits DTensor inputs by returning `float(x.full_tensor().item())` and skipping the requested mesh all_reduce. This is correct only when the DTensor's mesh covers the reduction mesh. The trainer's loss reduction passes orthogonal meshes (loss is a Replicated DTensor on the TP mesh; reduction is requested across loss_mesh = batch x cp), so the cross-batch sum is silently dropped — every TP > 1 run reports `loss = true_loss / dp_world_size`. Workaround: convert loss DTensor to a plain tensor before the dist_sum/dist_max calls in `train_step`, so the regular all_reduce path runs. Verified on agpt_2b at TP=2 (step-1 loss 12.94, matches the known TP=1 baseline of 12.95). Filed upstream as pytorch#3204 with a proper fix that detects mesh axis overlap. Once that lands, this workaround can be removed. Adds docs/guides/loss-reporting-tp-dist-reduce.md describing the diagnosis, blast radius (production 80B dashboards under-reported by dp_world_size), and the workaround, plus docs/upstream-issues/dist_reduce_dtensor_skip.md with the upstream PR reference.
TP > 1 loss-reporting bug diagnosis + workaround + upstream PR pytorch#3204, agpt_50b_wide as a working compile + AC + TP=2 dense config (replaces the OOM-crashing agpt_60b), and partial validation-loss wiring through blendcorpus's already-built validation split.
First entry in a new docs/meeting-notes/ directory for pre-meeting agendas, discussion summaries, and action-item tracking. Files are named YYYY-MM-DD-<meeting>.md so dates are unambiguous and the directory sorts chronologically. Today's agenda surfaces the TP > 1 loss-reporting bug (production 80B W&B is 1536x under-reporting; PR pytorch#3204 awaiting review), 2B/20B 512N production status with the v1-vs-v2 lm-eval headline, the new agpt_50b_wide bisect target showing the 80B compile+AC+TP=2 crash is depth-sensitive (does not reproduce at 48 layers), and the open validation-loss wiring waiting on consensus about cadence.
| # plain-tensor path with the materialized full tensor. | ||
| x_mesh = x.device_mesh | ||
| x = x.full_tensor() | ||
| if mesh is None or _meshes_share_axes(x_mesh, mesh): |
There was a problem hiding this comment.
- do we need to handle the
mesh is Nonespecially here? - when
_meshes_share_axesis True, it doesn't mean the result is correct? but you would just return. I think a workaround is to just error out when two meshes are not identical.
Surgical update + structural pass in one. The file was last edited 2026-04-27 and missed every major thread from the last week: - bf16-master RMSNorm-freeze fix (2026-04-29) and the v1→v2 production restart, with the +19.8pp ARC-Easy / +15.4pp HellaSwag smoking-gun validation at 503B tokens. - TP > 1 loss-reporting bug filed as pytorch#3204, local workaround in trainer.py + new EzpzValidator subclass. - agpt_50b_wide as a smaller bisect target proving the 80B compile+AC+TP=2 crash is depth-sensitive (does NOT reproduce at 48 layers, only at 84). - HSDP `aten.normal_.default` failure on `dp_replicate × dp_shard > 1`. - Recurring Aurora `signal 9` NODE_FAIL pattern across 3 jobs. - EzpzValidator + blendcorpus validation split wired in (default off). Reorganization: - Move the rule-shaped lines (never kill jobs, never discard local changes, terse responses) from "User Preferences" up to "Golden Rules" so they get the priority they deserve. - New "Recent Findings (2026-04-29 → 2026-05-04)" section between Competitions and Common Pitfalls. Each finding links to its canonical writeup under docs/. - Refresh "Production Training Status" with v2 numbers (2B 512N step 5,073 / 510B tokens, 20B 512N step ~862 / loss 3.47, 20B 256N NODE_FAIL at step 364) and drop the stale v1 entries (still preserved per-trajectory under docs/production/). - Refresh "Known Bugs / Open Issues" — add TP loss-reporting, HSDP init crash, depth-sensitive 80B crash, Aurora NODE_FAIL. Existing bugs that are still active stay; outdated ones removed. - Refresh "Common Pitfalls" with HSDP and TP-loss callouts and the --dataloader.dataset-path silent-override warning. - Update "Key Paths" with the docs/ subdirs added since the last edit (summaries/, meeting-notes/, evals/, experiments/, upstream-issues/) and the new top-level files (validator.py, blendcorpus/). - Tighten "User Preferences" down to the truly preference-only items (formatting, table style, doc-cross-linking) since the rules moved up. 7 cross-links to docs/ verified to resolve.
| x_mesh = x.device_mesh | ||
| x = x.full_tensor() | ||
| if mesh is None or _meshes_share_axes(x_mesh, mesh): |
There was a problem hiding this comment.
I want to argue that the only clean workaround is to_local(). Then we don't need to infer whether it is full dtensor or non-full dtensor + TP. The actual fix is to deprecate the non-full dtensor case. Then we will unconditionally apply full_tensor() here. But given that it is hard to do deprecation without full dtensor being ready, we should just make it a plain tensor, which was what we always did for the TP case before this April -- we changed the TP-enabled model to always use DTensor for activation and loss this April.
I fixed this issue in #3159. If you want to land with this PR, I prefer landing to_local().
cc., @tianyu-l
|
Closing as superseded. The orthogonal-mesh under-reporting was fixed by @fegin in #3159
That's the same case the #3204 tests covered (Replicate-on-TP loss @fegin / @tianyu-l — thanks for the review and pointer to #3159. |
…rker Reflects that upstream PR pytorch#3159 (commit d64eabc, 2026-05-18) landed the `to_local()` fix and PR pytorch#3204 was closed as superseded. - guides/loss-reporting-tp-dist-reduce.md: rewritten as resolved doc with the historical window, the symptom table, the as-shipped fix shape, and the affected-window-only advice for 80B W&B traces. - upstream-issues/dist_reduce_dtensor_skip.md: status header flipped to resolved with the upstream commit/PR link and the disposition of PR pytorch#3204. - docs/README.md: status column updated for both linked docs. - .claude/CLAUDE.md: Recent Findings entry rewritten as past-tense with the fix commit; Known Bugs entry removed entirely. - summaries/2026-06-05_to_2026-06-12.md: bump four→five upstream syncs, add 54th-sync row to the syncs table, and replace bullet-list-marker "+ cherry-picks" with "and cherry-picks" to fix a markdown reflow that broke the opening paragraph.
Since #2963,
_dist_reduceshort-circuits all DTensor inputs withreturn float(x.full_tensor().item()), skipping the requested mesh all_reduce entirely. The justification in the comment ("avoid double-counting") only holds when the DTensor's own mesh covers the requested reduction mesh; when they are orthogonal — as in the trainer's loss reduction where the loss is a Replicated DTensor on the TP mesh and the requested mesh isloss_mesh = batch x cp— the cross-batch sum is silently dropped.Symptom: every TP > 1 run reports
loss = true_loss / dp_world_size. For a 2B run at TP=2 with 24 ranks, step-1 loss is 1.08 instead of the ~12.95 ln(vocab) baseline observed at TP=1. Gradients and optimizer steps are unaffected because backward goes throughloss.backward()not_dist_reduce— only the printed/logged loss is wrong.Fix: detect mesh axis overlap via
mesh_dim_names. If the DTensor's mesh shares any axis with the requested mesh,full_tensor()already covers that axis and we skip the explicit all_reduce as before. If the meshes are disjoint, we materialize viafull_tensor()and fall through to the plain-tensor path so the requested-mesh all_reduce runs.Adds a unit test covering both the orthogonal case (was broken) and the same-mesh case (must not double-count).