Skip to content

Ignore padding positions in the replaced-token detection loss - #26

Open
gss10282025 wants to merge 1 commit into
voidism:masterfrom
gss10282025:codex/fix-16-20260918
Open

gss10282025 wants to merge 1 commit into
voidism:masterfrom
gss10282025:codex/fix-16-20260918

Conversation

@gss10282025

Copy link
Copy Markdown

Summary

Replace RTD labels at attention_mask == 0 with -100 before 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 from 1.04826645 to 8.90219e-13 normalized L2, the parameter-update difference from 0.79828865 to 4.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

  • Python syntax checks and git diff --check pass.
  • The numerical results above come from the existing local reproductions; the repository training/CI suite has not been run on this branch.

Prepared with AI assistance; opened as a draft for code review.

Signed-off-by: sandel <326855337+gss10282025@users.noreply.github.com>

Assisted-by: OpenAI Codex
@gss10282025
gss10282025 marked this pull request as ready for review September 18, 2026 03:19
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.

[Bug] Padding positions count as negatives in the replaced-token detection loss

1 participant