Mask loss at document boundaries - #4075
Open
francesco-bertolotti wants to merge 1 commit into
Open
Conversation
francesco-bertolotti
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
August 6, 2026 06:53
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
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.
This is probably not a significant issue, but it seems like the more correct way to handle document packing.
Currently, when training with document packing, the last token of one document is used to predict the first token of the next document.
Because the tokenizer always appends an EOS token and prepends a BOS token, the model is effectively trained to predict a BOS token after every EOS token. Given this behavior, the current implementation does not introduce an issue. However, without these special tokens, the last token of one document would be trained to predict the first token of an unrelated document, which is clearly undesirable.
Although this is not a problem in the current setup, I believe the correct approach is to ignore the loss for the last token of each document. This avoids learning cross-document transitions and aligns the training objective with document boundaries. Additionally, implementing this requires only a one-line change.
This PR probably breaks some tests. Before fixing those too, I would like to know what do you think about this.