Skip to content

fix(loss): return fp32 empty log-probs from the chunked path - #2827

Closed
yueming-yuan wants to merge 1 commit into
mainfrom
yueming/fix-empty-logprob-dtype
Closed

yueming-yuan wants to merge 1 commit into
mainfrom
yueming/fix-empty-logprob-dtype

Conversation

@yueming-yuan

@yueming-yuan yueming-yuan commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

With model-precision logits (#2764/#2818), a CP rank whose contiguous half holds no response logits returns its empty log-probs as logits.new_zeros((0,))in bf16/fp16 — while every other rank returns fp32 CE outputs. The dtype leaks through allgather_cp_redistribute (zeros(dtype=value.dtype)) into the cross-rank dist.nn.all_reduce, and the byte-size mismatch crashes the collective:

gloo::EnforceNotMet: op.preamble.length <= op.nbytes. 24 vs 12.
Received data size doesn't match expected size.

Before #2764 the logits reaching this code were always fp32 on the Megatron backend, so the empty tensor's dtype could not diverge. Reachable with allgather-CP + bf16 whenever one rank's half contains only prompt tokens (long prompts).

The fix pins the empty log-probs/entropy of the chunked (non-true-on-policy) path to fp32, matching the dtype the fused CE produces on non-empty ranks. The true-on-policy path is untouched: its non-empty outputs stay in model precision, so its empty tensor already matches.

Tests

Covered by the 2-rank allgather-CP consistency tests in #2826 (stacked on this PR): the contiguous_empty_rank case crashes on this exact path without the fix and passes with it.

@claude claude 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.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@yueming-yuan
yueming-yuan force-pushed the yueming/fix-empty-logprob-dtype branch from abe8274 to 75cbdb5 Compare August 31, 2026 05:22
@yueming-yuan

Copy link
Copy Markdown
Collaborator Author

Folded into #2818.

@yueming-yuan
yueming-yuan deleted the yueming/fix-empty-logprob-dtype branch August 31, 2026 05:31
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