[Fix] Preserve buffered samples across packed batch flushes - #308
Open
primorLee wants to merge 1 commit into
Open
[Fix] Preserve buffered samples across packed batch flushes#308primorLee wants to merge 1 commit into
primorLee wants to merge 1 commit into
Conversation
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
Problem
PackedDatasetprefers samples from its overflow buffer while the current pack is short. If a popped sample still exceedsmax_num_tokenswhen combined with the current pack, the iterator yields that pack and resets its state. Because the sample was already removed from the buffer and the existing buffering branch only accepts newly sampled items, the popped sample was silently discarded.This changes the effective training distribution: the underlying dataset iterator has advanced, but the buffered sample appears in no emitted batch.
Fix
After the current packed batch is yielded, put the popped sample back into the buffer before resetting. The next iteration can retry it against a fresh pack without changing the maximum buffer occupancy, since the same sample was removed from the buffer earlier.
Validation
The regression uses token lengths
6, 6, 3, 6with a 10-token hard limit. Before the fix, the first two emitted packs are('a',)and('c', 'd'), sobdisappears. After the fix they are('a',)and('b', 'c').python -m unittest data.test_dataset_base -vpython -m ruff check data/dataset_base.py data/test_dataset_base.pypython -m compileall -q data/dataset_base.py data/test_dataset_base.pyCloses #278