Skip to content

[Loss] Split logging loss from backward loss#1962

Draft
HAOCHENYE wants to merge 1 commit into
reduce-sum-01-fsdp-helperfrom
reduce-sum-02-split-logging
Draft

[Loss] Split logging loss from backward loss#1962
HAOCHENYE wants to merge 1 commit into
reduce-sum-01-fsdp-helperfrom
reduce-sum-02-split-logging

Conversation

@HAOCHENYE

Copy link
Copy Markdown
Collaborator

This PR (2/5) — behavior-neutral. Routes displayed/logged losses through detached per-rank local components reduced by cross-rank SUM; the backward loss is still globally reduced. Isolates the display pipeline so the next PR flips gradients without touching logging.

Full stack (merge bottom-up, under #1959):

  1. reduce-sum-01-fsdp-helper — [FSDP] Add reduce-sum gradient reduction helper
  2. reduce-sum-02-split-logging — [Loss] Split logging loss from backward loss
  3. reduce-sum-03-switch-sum — [FSDP][Loss] Switch gradient reduction to SUM
  4. reduce-sum-04-remove-world-size — [Refactor] Remove unused world_size plumbing
  5. reduce-sum-05-drop-nonglobal — [Refactor] Drop non-global aux-loss averaging mode

Restore every displayed loss scalar from a detached per-rank LOCAL component
reduced across ranks with a SUM all_reduce, instead of mean-reducing the
(globally reduced) backward loss tensors. Because each term's cross-rank SUM
equals the global loss, the logged curves are unchanged while backward still
uses the current global autograd path; this decouples display from backward so
the reduce-sum switch can make backward per-rank-local without touching logs.

- BalancingLossContext.finalize / ZLossContext now also produce a detached local
  component (z-loss's without the x world_size factor); MoE forward records them
  on extra_info as local_*loss (CE already exposes local_base_loss, MTP mirrored).
- BaseModel.post_micro_batch_forward and train_step total_loss reduce these local
  components with detached SUM; train_step total_loss is now the global value.

Behavior-neutral: EP=2, balancing+z on, grad-acc=2, symmetric data reproduces
C1's total_loss / reduced_llm_loss / reduced_balancing_loss / reduced_z_loss
bit-for-bit.
@HAOCHENYE
HAOCHENYE force-pushed the reduce-sum-01-fsdp-helper branch from c216448 to 184b6ca Compare July 17, 2026 08:11
@HAOCHENYE
HAOCHENYE force-pushed the reduce-sum-02-split-logging branch from a13bca8 to 316b1cc Compare July 17, 2026 08:11
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.

1 participant