Skip to content

fix: exclude last position from loss_mask after target shift#341

Open
AchuthReddy-16 wants to merge 1 commit into
SafeAILab:mainfrom
AchuthReddy-16:fix-317-loss-mask-shift
Open

fix: exclude last position from loss_mask after target shift#341
AchuthReddy-16 wants to merge 1 commit into
SafeAILab:mainfrom
AchuthReddy-16:fix-317-loss-mask-shift

Conversation

@AchuthReddy-16

Copy link
Copy Markdown

Fixes #317

target and input_ids are shifted left by one position in dataprepare()
via padding(..., left=False), which puts a zero-padding value in the
last position instead of a real next-token value. loss_mask wasn't
adjusted to match, so training was computing loss on that final,
invalid position.

This adds one line to exclude the last position from the mask after
the shift, as originally suggested in the issue.

Verified with a small repro (numpy, mirrors the actual padding() logic):

before fix
target: [202 203 204 205 0]
loss_mask: [1 1 1 1 1] <- last position still marked for training

after fix
target: [202 203 204 205 0]
loss_mask: [1 1 1 1 0] <- correctly excluded

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.

loss_mask not adjusted after target shift, causing loss on invalid padding

1 participant