Ignore padding positions in the replaced-token detection loss - #26
Open
gss10282025 wants to merge 1 commit into
Open
gss10282025 wants to merge 1 commit into
gss10282025 wants to merge 1 commit into
Conversation
Signed-off-by: sandel <326855337+gss10282025@users.noreply.github.com> Assisted-by: OpenAI Codex
gss10282025
marked this pull request as ready for review
September 18, 2026 03:19
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.
Summary
Replace RTD labels at
attention_mask == 0with-100before the existing cross-entropy call, so padding contributes neither a negative-class target nor an element of the mean's denominator.Valid-token labels, the RTD weight and the contrastive objective are unchanged. The reduction stays a mean.
Validation
At
33b29a38, one FP64 AdamW update on a small BERT, same batch padded to widths 8 and 16: the full-gradient difference drops from1.04826645to8.90219e-13normalized L2, the parameter-update difference from0.79828865to4.46219e-12. A no-padding batch is unaffected. Reproduced on a second host.The FP64 cast and the deterministic fixture belong to the reproducer, not to this patch. Earlier FP32 runs did not pass all validation checks; FP16 was not evaluated.
Issue links
Fixes #25
Checks on this branch
git diff --checkpass.Prepared with AI assistance; opened as a draft for code review.