Repository navigation
fix(decision): preserve gradients for confidently wrong predictions - #10355
Merged
Merged
Conversation
Use masked FP32 log_softmax instead of clipping probabilities before log. Add focused regression coverage and update bilingual documentation. Fixes modelscope#10354 Co-authored-by: OpenAI Codex
z0o0ey
approved these changes
Oct 14, 2026
z0o0ey
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the revisions, you were right, and I've merged them.
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.
PR type
PR information
Fixes #10354
Decision cross-entropy currently clamps probabilities to
1e-9before taking their logarithm. For a confidently wrong hard-label prediction, this caps the loss at approximately 20.7233 and removes the corrective gradient. For example, logits[30, -30]with the second class as the target produce zero gradients instead of[1, -1].Compute masked log-probabilities directly with FP32
log_softmax. Handle empty option rows and clear padded log-probabilities before multiplying by targets to avoid NaNs. Update the paired decision documentation and add three focused regression tests (four parametrized cases): FP32/BF16 extreme wrong predictions throughDistillRPSLoss, masked soft-target CE value/gradient equivalence, and all-padding rows. Existing decision head structural tests cover ordinary loss and gradient behavior.Experiment results
Local CPU validation: Python 3.12.13, PyTorch 2.14.1, Transformers 5.19.0, editable repository installation on macOS arm64.
The four new cases against the original loss method give 2 failed, 2 passed; both failures assert the missing corrective gradient (FP32/BF16). With this fix, the same extreme input produces loss 60 and gradient [1, -1].
No full model training or GPU validation was rerun for this local patch. The change addresses the shared CE term; additional calibration terms can still contribute their own gradients.
Checklist