Skip to content

Pull in main from upstream - #7

Closed
saforem2 wants to merge 6 commits into
saforem2:ezpzfrom
pytorch:main
Closed

saforem2 wants to merge 6 commits into
saforem2:ezpzfrom
pytorch:main

Conversation

@saforem2

@saforem2 saforem2 commented Mar 3, 2026

Copy link
Copy Markdown
Owner

Copilot Summary

This pull request introduces improvements to quantization support and simplifies distributed parallelism code in the torchtitan codebase. The main changes include standardizing quantization converter inheritance, updating metrics logging to handle quantization-aware scenarios, and removing unused or redundant distributed parallelism code.

Quantization infrastructure improvements:

  • Introduced a new base class QuantizationConverter in torchtitan/components/quantization/__init__.py for all quantization converter classes to inherit from, enabling easier type checking and standardization. ([torchtitan/components/quantization/__init__.pyR16-R33](https://github.com/saforem2/torchtitan/pull/7/files#diff-3c6b2f40c080f6bae2f48a99d49732cb4bbfa5e19cb9d1becdd98c8e1845de5dR16-R33))
  • Updated all quantization converter classes (e.g., Float8LinearConverter, Float8GroupedMMConverter, MXLinearConverter, MXGroupedMMConverter) to inherit from QuantizationConverter and use its nested Config class, ensuring consistency across quantization implementations. ([[1]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d521de2958f40ff8a59c8e99370ee82912c08fc33cdf4a0c5796c2ca3020d9bfL13-L15), [[2]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d521de2958f40ff8a59c8e99370ee82912c08fc33cdf4a0c5796c2ca3020d9bfL26-R30), [[3]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d521de2958f40ff8a59c8e99370ee82912c08fc33cdf4a0c5796c2ca3020d9bfL205-R209), [[4]](https://github.com/saforem2/torchtitan/pull/7/files#diff-1a1b8aa2c436eb5db983e7327f90645990e906b786ec3b7ea96d77b7050416c8L13-L15), [[5]](https://github.com/saforem2/torchtitan/pull/7/files#diff-1a1b8aa2c436eb5db983e7327f90645990e906b786ec3b7ea96d77b7050416c8L24-R33), [[6]](https://github.com/saforem2/torchtitan/pull/7/files#diff-1a1b8aa2c436eb5db983e7327f90645990e906b786ec3b7ea96d77b7050416c8L123-R130))

Metrics logging enhancements:

  • Added a has_quantization flag to the Config and constructor of the metrics component, and updated the logging logic to skip misleading MFU (Model FLOPS Utilization) calculations when quantization (e.g., FP8/MX) is active. The MFU metric is now only logged when appropriate, and displays as "N/A" otherwise. ([[1]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d4bd24d89043e414d3daf556f65d92cd86eb347a9e1f2f429caae9cc6457cde6R315), [[2]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d4bd24d89043e414d3daf556f65d92cd86eb347a9e1f2f429caae9cc6457cde6R331), [[3]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d4bd24d89043e414d3daf556f65d92cd86eb347a9e1f2f429caae9cc6457cde6R357-R358), [[4]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d4bd24d89043e414d3daf556f65d92cd86eb347a9e1f2f429caae9cc6457cde6L482-R492), [[5]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d4bd24d89043e414d3daf556f65d92cd86eb347a9e1f2f429caae9cc6457cde6L497), [[6]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d4bd24d89043e414d3daf556f65d92cd86eb347a9e1f2f429caae9cc6457cde6R516-R525), [[7]](https://github.com/saforem2/torchtitan/pull/7/files#diff-d4bd24d89043e414d3daf556f65d92cd86eb347a9e1f2f429caae9cc6457cde6L523-R534))

Distributed parallelism code cleanup:

  • Removed the NoParallel class and related logic from torchtitan/distributed/__init__.py, as well as unused or redundant input preparation code from torchtitan/distributed/expert_parallel.py, simplifying the distributed codebase and reducing maintenance overhead. ([[1]](https://github.com/saforem2/torchtitan/pull/7/files#diff-eb9f41e17c663e74830a9cf6de1771c8b656492b57c18dea4251aabe7de52654L7-L100), [[2]](https://github.com/saforem2/torchtitan/pull/7/files#diff-5a9b51fc9f1f473ff616d7449048b947a0f75b7957894c11c392043e0b59a7e1L21-L22), [[3]](https://github.com/saforem2/torchtitan/pull/7/files#diff-5a9b51fc9f1f473ff616d7449048b947a0f75b7957894c11c392043e0b59a7e1L50-L60), [[4]](https://github.com/saforem2/torchtitan/pull/7/files#diff-5a9b51fc9f1f473ff616d7449048b947a0f75b7957894c11c392043e0b59a7e1L84-L85), [[5]](https://github.com/saforem2/torchtitan/pull/7/files#diff-5a9b51fc9f1f473ff616d7449048b947a0f75b7957894c11c392043e0b59a7e1L198-L214))

wwwjn and others added 6 commits February 28, 2026 14:16
This PR is a combination of all the 4 different PRs: 
#2244
#2221
#2194
#2191

## Current status:

- Applied **the same parallelism** on trainer / generator, eg, Trainer
(TP=2) and Generator (TP=2)
- NOTE: now we have a strong assumption that the trainer and generator
must have the same parallelism, and are collocated. This is because we
unwrap the DTensor and assume we can always wrap it back with the same
device mesh and placement.
- We should be able to remove this constrain once we have more powerful
weight sync. cc @daniellepintz
- Weight transfer: Simply unwrap DTensor in trainer before sending
- Collocated trainer and generator

## Next Step:
- Patch batch-invariant kernel, test if the trainer / generator is
batch-invariant
- Supports different parallelism on trainer / generator side
- CI as a guard
…00/GB3… (#2451)

Hide MFU when quantization is active and add peak tflops for GB200 and
GB300. This is a short-term answer to
#560.

Before this pr, when fp8 is enabled. MFU is displayed but over bf16 peak
flops.
<img width="968" height="320" alt="1-26 2311505,123 - го61 -"
src="https://github.com/user-attachments/assets/0e77c8c4-c287-419e-a11f-a1afeadf1b67"
/>

After this pr, when fp8/mx quantization is active, MFU is shown to be
N/A.
<img width="1133" height="270" alt="6 71148 gred 10rk 2 445"
src="https://github.com/user-attachments/assets/ce68464a-a1c2-4cfd-888b-595a41a7bf49"
/>
solve #2387 where user reported a bug that MoE router weights diff on
each rank due to a missing all reduce under certain senarios:
- `self.score_before_experts=False` for both ETP=1 and ETP=TP
- `self.score_before_experts=True` and ETP=1 

similar fix was proposed #2388 by @fatih-uzlmz 
## Bug analysis 
**Case1:** 
When ETP=1 < TP, MoE is using TP2EP(`etp_mesh` is None, there is no
ETP), `gate` is Replicated(via NoParallel), experts weight is
Sharded(via EP mesh), MoE input is Replicated.

_Root Cause:_ `ReordererSequenceParallell` is applied to split
`top_scores` across TP ranks. Since each TP rank process its local slice
of tokens through the experts, `d_routed_input` is Partial and there is
no forced all-reduce.

**Case2:** 
When ETP = TP, MoE is using DP2EP, `gate` is Replicated(via NoParallel),
experts weight is Sharded(via ETP which force all reduce in bwd #1878),
MoE input is Replicated on TP mesh.

_Root Cause:_ The gradient flowing back to `gate.weight` is Partial when
`self.score_before_experts=False`, which we incorrectly marked as
Replicated and therefore results in wrong numerics.

_Explanation:_ 
When `self.score_before_experts=True`, `d_routed_input` is already all
reduced because of the fix #1878 we added to ETP.
```
routed_input = routed_input * top_scores_experts_sorted
routed_output = self.experts(routed_input, ...) 
out_experts = routed_output_unsorted.sum(dim=1)    
```

When `self.score_before_experts=False`, gradient of `top_scores` from
`bmm` is Partial. The previous all reduce fix only force all reduce on
`d_routed_input`, but not `d_top_scores` which is wrong.
```
routed_output = self.experts(routed_input, ...)
out_experts = bmm(top_scores, routed_output_unsorted) 
```

## The fix we propose that could fix both Case1 and 2
- We revert the fix in #1878 to keep Partial dx flowing back, and delay
the all reduce later at the boundary of MoE.
- We choose to not use
[`ColWiseParallel/RowwiseParallel`](https://github.com/pytorch/pytorch/blob/e81980ea58c65a283cf01a7132e0f420834ecf10/torch/distributed/tensor/parallel/style.py#L181)
for shared expert as they force all reduce dx; but we want to keep
Partial dx. So we introduced `MoEColWiseParallel/MoERowwiseParallel`
which removed the input and output hooks. See the [reasoning
here](https://gist.github.com/acisseJZhong/b27ecd7eca9ca1f0c050282516de2e21)
for more details.
- We annotate gradient of router to be partial in bwd through adding a
field to NoParallel(), so that DTensor will handle the all reduce


<img width="4096" height="2056" alt="image"
src="https://github.com/user-attachments/assets/8c65e360-434c-4138-9c58-f99041da5389"
/>
<img width="4096" height="2056" alt="image"
src="https://github.com/user-attachments/assets/474f431f-a469-400c-9256-77b514a40d7f"
/>

**Caveat:** The graph is plotted from [Claude generated computational
graph
](https://gist.github.com/acisseJZhong/7101c2542530365b7b06bdf1f78068cb),
please take it with a grain of salt.

cc @volcacius @fatih-uzlmz

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @saforem2, your pull request is larger than the review limit of 150000 diff characters

@saforem2 saforem2 closed this Mar 3, 2026
saforem2 added a commit that referenced this pull request May 22, 2026
Discovered while running the eval refresh (8503087/88/89): every
recent 20B run *logged* training progress past the latest persisted
ckpt, but the async checkpoint saves were killed mid-write by the
same bad-node crashes that ended each run. The partially-written
step-N00/ dirs stay in place but lack `.metadata` and `__*_0.distcp`
shards, making them unloadable.

Concretely:

- 20B 512N (8481645): logged step 800 → 1000, but step-900 ckpt dir
  is empty. Latest usable: step-800. Yesterday's "+200 fresh steps,
  step-1000 ckpt saved" claim was wrong.

- 20B 256N (8481646): logged step 301 → 500, but step-400 dir is
  stale (May 8 8470102 era, empty) and step-500 never written. No
  on-disk progress past step-300 in three weeks of dispatches.

- 2B 512N (8485509 + 8485511): both pinned at step-13400 logged but
  step-13300 ckpt is incomplete. Latest usable: step-13200. Both
  runs retraced the same step-13201 → 13400 window.

Updated:

- Production index: persisted vs logged columns for all three rows,
  new Known Issue #7 for the chronic async-save corruption pattern
  with proposed mitigation (sync mode for at least one save per
  chain, or detect-and-cleanup orphaned ckpt dirs).

- 20B 512N + 256N READMEs: explicit "Latest *complete* checkpoint"
  vs "Cumulative *persisted* steps" labels. Added explanatory blocks
  about the logged-vs-persisted gap.

- Failover writeup: caveat block noting the persistence failure is
  separate from the wrapper bug story. The wrapper itself worked
  perfectly (swap + retry); the persistence failure is an
  orthogonal async-ckpt-save robustness issue.
saforem2 added a commit that referenced this pull request May 22, 2026
2B 512N: ran lm-eval on all v2 ckpts at every 1000 steps from 1K → 13K
via 8503087 (capacity, 1N, ~1h44m). Added a "v2 512N — full sweep
(2026-05-22 refresh)" section with three sub-tables:

- Raw accuracy across all 4 tasks
- Length-normalized `acc_norm` where applicable
- Δ vs v1 ceiling: +33.3pp ARC-Easy, +13.9pp HellaSwag at 1.31T tokens

v2 ARC-Easy lifts cleanly above the 25% random baseline within the
first 2K steps and reaches 0.6115 at step-13000. HellaSwag breaks out
similarly, hitting 0.4926 (acc_norm) at step-13000. The bf16-master
fix is decisively validated.

Also added a "step-13300 unavailable" note (async ckpt save killed
mid-write — same issue as the 20B step-900 case, tracked as Known
Issue #7 in production index).

20B: clarified that the existing 100-800 step table is `acc_norm`,
added a parallel `acc` table that shows ARC-Easy lifting to 0.4444 by
step 800 (+17.0pp above v1's flat 0.27 ceiling — the previous +19.8pp
ARC-Easy headline was on `acc_norm` so this complements it). Noted
that the in-progress 8503089 will add the 20B 256N comparator.

Regenerated both v1_vs_v2.png figures using the updated JSON data via
the existing plot_v1_vs_v2.py scripts. Note: those scripts use the
walrus operator so must be run via `.venv/bin/python3`, not the system
python3 (3.6).
saforem2 added a commit that referenced this pull request May 22, 2026
…05-22

Added the new W&B run IDs from the last 2 weeks of dispatches to
plot_production_wandb.py and regenerated all 12 v2 production
figures (loss/tps/mfu + diagnostics + tokens-vs-time triples for 4
trajectories: 2b_v2_{256,512}, 20b_v2_{256,512}).

New runs added per trajectory:

  2b_v2_256:  +0qpf3hnc (8481320, failover)
  2b_v2_512:  +y70rh76h (8479989), +logai2xn (8485509), +2qqhpcrm (8485511)
  20b_v2_512: +gkzl19dg (8481645, failover validated swap), +10vf1mqr (8481647)
  20b_v2_256: +5481v99b (8479582), +yrq1s1ac (8481646, failover validated swap), +xt03uvp6 (8481648)

Total step coverage after refresh:

  2b_v2_256:  13,391 unique steps
  2b_v2_512:  13,391 unique steps
  20b_v2_512: 1,000 unique steps (logged — only step-800 is persisted on
              disk; the rest are W&B-only because the async ckpt saves
              were killed mid-write by bad-node crashes — see Known
              Issue #7 in production index)
  20b_v2_256: 500 unique steps (logged — same persistence issue; only
              step-300 is loadable)

The 20B 512N concat output is particularly illustrative: rows
s6b159xk (2 rows) + gkzl19dg (201 rows) + 10vf1mqr (119 rows) all
overlap in the step-800..1000 window, retracing the same steps as
each subsequent failover/continuation resumes from the latest
persisted ckpt. The figures now visually show this re-tracing
pattern.
saforem2 added a commit that referenced this pull request May 22, 2026
Eval job 8503089 finished — 3 ckpts (step-100/200/300) evaluated
on the 20B 256N comparator chain (gbs6144). Added a new
"v2 256N comparator (2026-05-22)" section to the 20B eval README:

- Raw accuracy table for the 3 new ckpts.
- Per-step comparison vs 512N: at matched step counts, the two
  trajectories are within lm-eval stderr (256N +0.05/+0.3/+0.2pp
  HellaSwag, +0.4/-0.8/+0.7pp ARC-Easy).
- This confirms the large-batch under-training hypothesis from 2B
  generalizes to 20B: at matched optimizer steps the two batch
  sizes produce equivalent learning.

Plot script regenerated as a side effect (no data change for 20B
since plot still globs only 512N); 2B plot also re-rendered for
consistency.

Followup noted in README: extending plot_v1_vs_v2.py to overlay
256N as a third line. Not blocking — the table conveys the
finding clearly.

8503089 ckpt step-400 was unavailable (empty dir from earlier
crash, same async-save corruption pattern as Known Issue #7).
saforem2 added a commit that referenced this pull request May 22, 2026
…-training confirmed

Promotes the "v2 256N comparator (in-progress)" section in
docs/evals/agpt/20b/README.md to a completed writeup. Job 8503089
evaluated the 20B 256N chain (gbs6144, SophiaG LR=2.28e-5) at steps
100/200/300; step-400 was unavailable due to the chronic async-save
ckpt corruption (Known Issue #7).

Raw accuracy at steps 100/200/300:
- HellaSwag: 0.258 -> 0.258 -> 0.261
- ARC-Easy:  0.270 -> 0.282 -> 0.311
- ARC-Chall: 0.201 -> 0.184 -> 0.182
- Winogrande: 0.493 -> 0.505 -> 0.507

At matched step counts, 256N vs 512N is within lm-eval stderr
(HellaSwag Δ ≤ 0.3pp, ARC-Easy Δ ≤ 0.8pp). This is the same
per-step parity we already saw at 2B (see
../2b/README.md#v2-256n-vs-v2-512n--same-model-two-batch-sizes),
confirming the **large-batch under-training hypothesis generalizes
from 2B to 20B**: at matched optimizer steps the two batch sizes
produce equivalent learning, so 512N gets there in 2× the wall-clock
but spends 2× the tokens.

Followup: plot_v1_vs_v2.py needs extending to overlay 256N as a
third trajectory (currently only 512N is shown).

Also refreshes v1_vs_v2.svg under 20b/ and 2b/ — matplotlib
regenerations only, no visual content change (timestamp + auto-IDs
differ).
saforem2 added a commit that referenced this pull request May 23, 2026
Added 6 new W&B run IDs from today's post-fix dispatches:

  2b_v2_256:  ni0etxx7 (8505118) + 0fk1bvtt (8505119)
              → chain coverage now 25,118 unique steps
  2b_v2_512:  inbisrc5 (8505120)
              → unchanged (run pinned at step-13400 again)
  20b_v2_512: qttj3l3p (8505124)
              → unchanged at 1,000 unique steps
  20b_v2_256: f1p8nyxh (8505122) + g6ekeu4j (8505123)
              → chain coverage now 500 unique steps

All 12 v2 production SVGs regenerated. The 2B 256N curve is the only
one extending into new territory (advanced from step ~23,500 to
step-25,100 on disk). The 512N + 20B 256N trajectories show the
re-trace pattern visually — multiple dispatches overlapping in the
same step window with no on-disk advancement, exactly the chronic
async-save-corruption issue documented as Known Issue #7.

Note: 8505121 + 8505125 are too new to have emitted W&B runs yet
(still in init phase). They'll be added to the registry next refresh.
@saforem2 saforem2 mentioned this pull request Jun 11, 2026
saforem2 added a commit to nscottnichols/torchtitan that referenced this pull request Jun 11, 2026
Replays the documented fix from upstream-sync.md (replay of upstream
PR pytorch#3389): replace `getattr(token_dispatcher, "comm_backend", "standard")`
with `isinstance(token_dispatcher, (DeepEPTokenDispatcher.Config,
HybridEPTokenDispatcher.Config))`.

Two bugs fixed together:

(1) The getattr lookup ALWAYS returned "standard" because
`make_ezpz_token_dispatcher_config` uses `comm_backend` as a function
arg that selects which Config TYPE to instantiate — it's never stored
as a field on the resulting Config. The downstream check
`if comm_backend in ("deepep", "hybridep")` therefore never fired.

(2) The branch's import `from torchtitan.models.common.moe_deepep import
DeepEPMoE` references a module that doesn't exist (only `moe.py`,
`moe_sharding.py`, `token_dispatcher.py` live in `models/common/`).
`DeepEPMoE` was removed from upstream when the dispatcher classes
took over the comm-backend-specific logic; the `MoE → DeepEPMoE.Config`
swap that used to live here is now dead and can be deleted entirely.

After this change:
- isinstance check on the dispatcher Config correctly detects
  deepep/hybridep configs
- the EP=1 guard fires correctly with a clear error message
  (`f"{dispatcher_name} requires expert parallelism..."`)
- no more dead import; no more no-op `MoE → DeepEPMoE.Config` swap

ezpz doesn't exercise deepep/hybridep on XPU (no DeepEP kernels),
but we keep the EP=1 guard so any CUDA-side ezpz user who flips the
dispatcher config to deepep gets the same error semantics as
upstream `deepseek_v3`.

Addresses review findings saforem2#6 + saforem2#7 on saforem2#14
(they were the same dead branch).
saforem2 added a commit that referenced this pull request Jul 18, 2026
monarch now builds clean (protoc fix worked -- torchmonarch 0.6.0.dev0 imports
OK). vllm from-source build then failed: ModuleNotFoundError setuptools_scm
(--no-build-isolation needs it present). Add to Step 2b build deps.
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.

6 participants