Skip to content

[FSDP] Separate the deferred chunked-loss head from the final norm - #6253

Draft
JavaZeroo wants to merge 1 commit into
pytorch:mainfrom
JavaZeroo:perf/fsdp-separate-deferred-chunked-head-20261119
Draft

JavaZeroo wants to merge 1 commit into
pytorch:mainfrom
JavaZeroo:perf/fsdp-separate-deferred-chunked-head-20261119

Conversation

@JavaZeroo

@JavaZeroo JavaZeroo commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Why

ChunkedLossWrapper runs the untied language-model head after decoder forward and finishes its backward before decoder backward. FSDP currently manages the final norm and head in one unit. The norm backward can therefore gather the full head weight after the loss has already completed the head gradients. In the always-reshard policy, entering the loss can also repeat the head gather that was prefetched by the last decoder block.

For an untied head with eager chunked loss, explicit prefetch and always resharding, the 0.4 comparison observes these gathers per microbatch.

Shared group: decoder prefetch (norm + head)
              chunked loss (norm + head)
              decoder backward (norm + head)
Split groups: decoder prefetch (norm and head)
              chunked loss uses the prefetched head
              decoder backward gathers norm

What changed

Give the final norm and untied head separate FSDP lifetimes for eager chunked-loss training without pipeline parallelism. Keep the existing forward prefetch targets and anchor the last decoder block's backward prefetch to the final norm. Tied models, eager unchunked loss, and the PP and accelerator-graph paths retain their existing grouping. The model, projections, loss, and checkpoint keys remain the same.

Numerics and testing

  • On TorchTitan main@cc020983a483, the four-rank Gloo production-path regression verifies that the head consumes exactly one all-gather in the explicitly prefetched path. Loss and all local gradients match the shared-group control bitwise.
  • A separate two-rank Gloo comparison covers nine configurations, including explicit prefetch on and off, three reshard policies, and tied, PP configuration, and standard-loss fallbacks. The head gathers dropped from two to one under default and never-reshard policies, and from three to one under always-reshard. Loss, sharded gradients, post-update parameters, and reduce-scatter order matched exactly across two updates with two microbatches each.
  • On a TorchTitan 0.4 training stack, an eight-NPU GA24 Kimi K3.1 profile showed three head-sized gathers per microbatch. The calls from the loss wrapper and the final norm backward accounted for 195.3 ms of exposed communication in the profiled step. The matched two-rank Gloo experiment on that version reduced the steady head-sized gathers from three to one. A two-rank Ascend 950DT/HCCL component A/B on the pinned 0.4 training stack passed all nine configurations. Across two updates with two microbatches, all 564 compared tensors were bitwise identical and the 344 ordered reduce-scatter calls matched. Each of the six split configurations used one head-sized all-gather per steady microbatch in place of three. The official-main patch was independently checked with the Gloo comparisons above. The communication times above are from the original profile.
  • The existing pipeline lifecycle test hits a missing ScheduleGPipe.register_post_metadata_inference_cleanup in the local PyTorch 2.15 CPU build on both the main control and the candidate. The PP configuration keeps the existing grouping.

Eight-device training performance on the 0.4 backport

An independent sequential control/candidate pair used eight Ascend 950DT devices, EP8/FSDP8, sequence length 16,384, accumulation 24, the full 163,840-token vocabulary, eight loss chunks and the same activation checkpoint policy. Both arms completed 12 steps. Steps 6–12 use the slowest rank for each update.

Metric Control Split head
Mean step time, steps 6–12 96.106 s 95.730 s
Step-time P90, steps 6–12 96.213 s 95.817 s
MFU at 432 TFLOP/s per device 60.353% 60.590%
Mean step time, all 12 steps 104.096 s 103.794 s
Peak active / reserved memory 76.961 / 87.648 GiB 76.959 / 87.629 GiB

The split head was faster at all seven matched steady steps, saving a mean 0.376 seconds per update and increasing MFU by 0.237 percentage points. The FSDP group probe confirmed the selected grouping on every rank and was removed after verification. Both arms had zero allocation retries and OOMs. Across 96 matched rank-step measurements, token counts and global gradient norms were identical and the maximum absolute global loss difference was 0.000136.

Earlier work explored separate grouping together with a different autograd treatment in #3229. This patch uses the current partial-backward behavior introduced by #5563.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 19, 2026
@pytorch-bot

pytorch-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:

  • ciflow/rl

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant