Skip to content

fix(dschat): avoid NaN from masked PPO log-probability padding - #1022

Open
ot4562-glitch wants to merge 1 commit into
deepspeedai:masterfrom
ot4562-glitch:fix/dschat-ppo-mask-before-exp
Open

ot4562-glitch wants to merge 1 commit into
deepspeedai:masterfrom
ot4562-glitch:fix/dschat-ppo-mask-before-exp

Conversation

@ot4562-glitch

Copy link
Copy Markdown

Summary

DeepSpeed-Chat's PPO actor loss computes log_ratio = (logprobs - old_logprobs) * mask. Padded positions may carry -inf sentinel values or nonfinite logprobs. When (-inf - -inf) becomes NaN, multiplying by zero does not remove it. The subsequent exp and PPO loss then become NaN despite the valid response tokens being finite.

Select zero with torch.where(mask.bool(), ..., 0) before exponentiation, preserving the valid-token policy ratio and clipping objective.

Regression

New CPU tests invoke the real DeepSpeedPPOTrainer.actor_loss_fn directly using an uninitialized trainer stub with cliprange=0.2. They exercise -inf/-inf and NaN padded logprobs, assert finite loss, zero excluded-token gradient, and unchanged valid-token gradients. A normal case is included.

The source-equivalent PyTorch 2.10 CPU screen reproduced NaN before and finite values after the change. The project's full DeepSpeed environment, GPU training, and CI suite were not run here. This PR does not claim to handle an all-empty action mask.

QuotientGuard

This issue was triaged during a 10-repository numerical investigation using QuotientGuard (https://github.com/ot4562-glitch/QuotientGuard), including explicit synthetic coefficient controls. The controls were source-equivalent, not DeepSpeed-Chat runtime capture, and QuotientGuard did not automatically certify a bug (reconstruction_validation=false). The independent PyTorch regression is the primary evidence; no new dependency is added.

Signed-off-by: ot4562-glitch <266149313+ot4562-glitch@users.noreply.github.com>
@ot4562-glitch
ot4562-glitch force-pushed the fix/dschat-ppo-mask-before-exp branch from eb72230 to 5fd77ac Compare October 26, 2026 07:02
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