Repository navigation
[CI Fix] Refresh MI350X goldens for FP32 first-WGRAD accumulation - #5423
Merged
Merged
Conversation
acisseJZhong
marked this pull request as ready for review
October 15, 2026 18:51
acisseJZhong
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
October 15, 2026 18:51
tianyu-l
approved these changes
Oct 15, 2026
acisseJZhong
added a commit
that referenced
this pull request
Oct 20, 2026
## Summary - Refresh the Kimi K3 multimodal per-head DistMuon B200 golden. - Preserve the strict equality comparison and ten-step coverage. Fixes #5449. ## Root cause #5399 intentionally changed the first accumulated weight gradient from a BF16 GEMM result later upcast to FP32 into a GEMM that produces FP32 directly. Kimi uses eight chunked LM-head losses even when outer gradient accumulation is one, so this changes the first WGRAD and the seven following in-place FP32 accumulations. The next optimizer update consequently changes losses from step 2 onward. #5399 refreshed affected A10G goldens and #5423 refreshed MI350X goldens, but the Kimi B200 golden was omitted. The observed B200 sequence is bitwise identical across independent runs and later PyTorch nightlies: - https://github.com/pytorch/torchtitan/actions/runs/38830975496 - https://github.com/pytorch/torchtitan/actions/runs/39182322613 - https://github.com/pytorch/torchtitan/actions/runs/39349362724 Step 1 loss and grad norm remain unchanged, matching the expected first-update boundary. ## Test plan - `SKIP=pyrefly-check pre-commit run --all-files` (pass) - Validate the strict ten-step comparison through `ciflow/b200`. Local Pyrefly is unavailable because the shared venv uses PyTorch 2.14 and older optional APIs than current main.
tianyu-l
pushed a commit
that referenced
this pull request
Nov 4, 2026
## why `ChunkedLossWrapper` runs several head-only backwards before decoder backward. main restores head sync unconditionally on the final chunk, overwriting the caller's FSDP and HSDP accumulation policies. an inner root callback can also reduce earlier decoder gradients before the current microbatch arrives. pipeline schedules choose their backward policy after the loss runs. the wrapper now follows the schedule's manual-finalization owner from the first head pass, so GPipe, 1F1B and Interleaved1F1B all defer every head microbatch until schedule finalization, the same way PP no-sync already treats every other group on the stage. ## what changed - keep runtime policy and grouped-forward handling in `torchtitan/distributed/fsdp_lifecycle.py`, shared by loss and validation. the loss loop uses `before_last_forward` and `after_forward` without private FSDP reads. - save and restore each group's reduction, replica all-reduce and reshard settings and the root's `is_last_backward`, including when a chunk raises. - keep decoder gradients, prefetched weights and root finalization out of the inner head-only backwards. outside manual finalization, retain pending-gradient detection so a shared norm/head group coalesces its accumulated gradients into one reduction. - defer head reduction unconditionally under manual pipeline finalization, including the first microbatch. parameter residency stays with the schedule. outside pipelines, preserve the caller's early-reshard policy and the unreduced-gradient lifetime. - complete partial grouped forwards for training with a frozen decoder and for evaluation cleanup. register root iteration reset after dynamic pipeline metadata inference on success and failure, preserving gradients between normal accumulated schedule steps. - replace the private-state mock with real FSDP lifecycle observations, including tuple multi-output unshard and reshard behavior. - regenerate the three A10G pipeline goldens whose head reduction order changes. GraphTrainer's production path uses SimpleFSDP and keeps its separate reduction owner. ## pipeline numerics and goldens one reduction per step changes the head's fp32 summation order from `RS(g0) + RS(g1) + ...` to `RS(g0 + g1 + ...)`. with bf16 parameters and fp32 reduction the drift stays around 1e-6 relative, steps 1 and 2 stay bitwise equal, and the first changed step is 4 for `llama3_pp.txt` and 3 for `gpt_oss_pp.txt` and `deepseek_v3_cp_pp.txt`. `e41cf117e` imports the new A10G values from the "Baseline metrics in import file format" section of the [models job](https://github.com/pytorch/torchtitan/actions/runs/41582312136/job/125739765775) at `636e16d` and keeps the file headers. the [main models job](https://github.com/pytorch/torchtitan/actions/runs/41754606663/job/126327728943) at `73c4ebdac` ran the same `2.16.0.dev20261102+cu132` build and reproduced the previous goldens exactly, so the runner repeats across runs and the only change in the imported values is this reduction order. the models job on the current head is the second same-environment run of the new values. the MI350X copies of the same three files need a ROCm run. `ciflow/rocm` on this PR would produce them here, otherwise they follow the [#5423](#5423) refresh pattern, since `integration_test_rocm.yaml` runs these configs on every push to main. `test_dense_llama3_hsdp_graph_pp_vs_eager` uses eager Interleaved1F1B PP as its baseline with `rtol=1e-4` and `atol=1e-5`. its workflow is path-filtered to `torchtitan/experiments/graph_trainer/**` and won't run on this PR, and the observed drift sits well inside that tolerance, so the next scheduled main run covers it. ## last-stage memory and throughput four Hopper GPUs on one host (sm_90, 132 SMs, 139.8 GiB each, reported by `nvidia-smi` as `NVIDIA L20X`), PyTorch `2.16.0.dev20261102+cu130` with the CUDA 13.0 `580.95.05` forward-compat user-mode driver on kernel driver `570.172.08`. the host is shared and eight free GPUs weren't available, so the runs use FSDP2 `dp_shard=2` × `pp=2`. the model is the Llama3 8B shape (32 layers, dim 4096, vocab 128256) with flex attention, `ChunkedLossWrapper`, bf16 parameters, fp32 reduction, one 8192-token sequence per microbatch, eight microbatches per step and accelerator graphs off. each run trains 20 steps and reports the median per-rank throughput and step time after five warmup steps, plus the per-rank `max_active` and `max_reserved` memory over the run. main is `887d89561` (the following main commit only changes SFT goldens), and the PR arm is code-identical to the current head. main and PR alternate order across two repetitions. | schedule | main tps/GPU | PR tps/GPU | main step | PR step | last-stage peak active | last-stage peak reserved | | --- | --- | --- | --- | --- | --- | --- | | 1F1B | 8939, 8951 | 9316, 9354 | 3.666, 3.661 s | 3.518, 3.503 s | 61.49 → 57.80 GiB | 71.66 → 67.95 GiB | | 1F1B, 2 accumulation steps, `fsdp_defer_gradient_reduction` | 9063, 9066 | 9418, 9425 | 7.231, 7.229 s | 6.959, 6.954 s | 61.49 → 57.80 GiB | 71.67 → 67.95 GiB | | Interleaved1F1B, 2 stages per rank | 9242, 9259 | 9601, 9623 | 3.546, 3.539 s | 3.413, 3.405 s | 68.90 → 66.47 GiB | 79.12 → 74.56 GiB | | GPipe | 2286, 2364 | 2251, 2438 | 14.33, 13.86 s | 14.56, 13.44 s | 128.93 → 127.72 GiB | 134.88 → 134.88 GiB | 1F1B and Interleaved1F1B gain about 4% throughput on every rank, and the deferred-accumulation row covers `finalize_gradients=False` across schedule steps with the same result. GPipe keeps all eight microbatches' activations live and runs at 96% of device memory, so its throughput spread is wider than any difference and stays inconclusive. the first-stage ranks peak at 68.75 GiB under 1F1B and 75.27 GiB under Interleaved1F1B in both arms, so the job-wide peak in these two layouts is unchanged and the reduction lands on the output stage. under GPipe the output stage sets the job-wide peak, and it goes from 128.93 to 127.72 GiB with the first stage at 126.53 GiB in both arms. a 1F1B profiler step on the output-stage rank shows 33 all-gathers and 25 reduce-scatters on main against 17 and 17 with this change, with all-gather time going from 142.1 to 47.8 ms and reduce-scatter time from 98.6 to 90.1 ms. the first-stage rank runs 17 and 17 in both arms. a six-step 1F1B memory snapshot on the output-stage rank shows where the difference comes from. main's peak holds 3.914 GiB of FSDP collective buffers, exactly the size of two fp32 copies of the 128256 × 4096 head gradient, and this change holds none at its peak. the other allocation categories at the peak stay within 0.4 GiB of each other, including 7.48 GiB from `_fsdp_param.py:alloc_storage` and 13.00 GiB from `_restore_unsharded_grad_dtypes` in both arms. the snapshot covers one profiled step, so its peaks of 54.00 and 50.32 GiB sit below the 20-step maxima with the same 3.68 GiB difference as the table. so in these runs keeping the head unsharded until finalization adds nothing at the peak, and main's per-microbatch head reduction is what places staging buffers on top of the live activations. losses vary run to run in both arms at this learning rate, so these runs measure memory and speed only. numerics come from the lifecycle scenario and goldens above. ## current integration and validation merged `main@2124d73` in `c45720e4d`. main stopped re-exporting `ParallelismConfig` from `torchtitan.config`, so the lifecycle scenario imports it from `torchtitan.config.parallelism`, and the partial-backward implementation is otherwise unchanged by the merge. on macOS arm64, Python `3.13.18`, PyTorch `2.16.0.dev20261026` and four Gloo ranks, the lifecycle scenario passed 56 combinations plus one real grouped, frozen-decoder, two-output scenario. the matrix covers FSDP and HSDP, GPipe and 1F1B, deferred finalization, frozen decoders, tied weights, caller-policy restoration, reset/retry and losses, gradients and updated parameters against a full-logits reference. each finalized pipeline accumulation performs two reduce-scatters for a trainable decoder or one for a frozen decoder, and an accumulation without finalization performs zero. the same reduction-count scenario fails on the previous `e0029100edbb` revision, where GPipe performs five reductions in the checked accumulation. on the current head the lifecycle entry and the selected loss and pipeline regressions report 90 passed with one LoRA CPU FlexAttention case deselected, and changed-file pre-commit checks, including Pyrefly, pass. ```bash GLOO_SOCKET_IFNAME=lo0 pytest tests/unit_tests/cpu/components/test_chunked_loss_fsdp.py -q pytest tests/unit_tests/cpu/components/test_loss.py tests/unit_tests/cpu/distributed/test_pipeline_parallel.py -k 'not lora' -q ``` ## remaining merge gate - the models job on the current head should pass the regenerated A10G goldens. - MI350X goldens need the ROCm run above. - representative convergence beyond the 10-step goldens hasn't run on this revision. ## upstream lifecycle trackers - [pytorch/pytorch#203176](pytorch/pytorch#203176) tracks scoped partial backwards and completion of repeated standalone grouped forwards, including frozen inputs and evaluation cleanup. - [pytorch/pytorch#203177](pytorch/pytorch#203177) tracks value-based policy snapshots and exact restoration, including independent HSDP replica all-reduce settings. - [pytorch/pytorch#203178](pytorch/pytorch#203178) tracks FSDP iteration reset after pipeline metadata inference. all three include self-contained two-rank CPU reproductions on PyTorch `2.16.0.dev20261026`. the related [pipeline policy RFC](pytorch/pytorch#202853) owns broader configurable schedule reduction and residency policy, and this PR implements the existing schedule's finalization contract. ## earlier GPU evidence - `e0029100edbb`, November 2 [multi-GPU job](https://github.com/pytorch/torchtitan/actions/runs/41279432895/job/125188411936) on eight A10G with PyTorch `2.16.0.dev20261101+cu132` passed the prior 40-combination lifecycle scenario. - `65b11734`, [real-PG features job](https://github.com/pytorch/torchtitan/actions/runs/40465656973/job/122060375318) passed `fsdp_deferred_gradient_reduction` on two ranks and `fsdp_pp_deferred_gradient_reduction` on four ranks with recorded CUDA graphs, and `fsdp_per_group_cuda_graph` and `shared_eval_cuda_graph` passed in the [fake-PG job](https://github.com/pytorch/torchtitan/actions/runs/40465656973/job/122060361622). - `1bbb64b44`, two H100 with deterministic algorithms, kept ordinary FSDP loss, gradients, grad norm and parameters bitwise equal across sixteen reduced-model configurations, and deferred eager reduce-scatters dropped from seven to three separate owners or two grouped owners. these results retain their recorded revisions. --------- Signed-off-by: ZenAlexa <[email protected]>
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.
ROCm model/SFT numerical checks still use MI350X goldens from before #5399. That change produces the first accumulated WGRAD directly in the parameter's FP32 gradient dtype instead of rounding through BF16, and refreshed the A10G goldens only.
Refresh the nine MI350X Real-PG golden files used by ten integration configurations. Values come from full-precision TensorBoard scalars in main ROCm CI, using
torch==2.16.0.dev20261015+rocm10.0. Preserve the existing ten-step coverage, parallelism/config metadata, and strict loss/gradient-norm equality checks. The two Llama3 configurations sharing one golden produce identical values.Validation in progress:
38753451439and38778179164), covering both metrics at every step.