Handle Data Gym vocab files without trailing newline - #598
Open
tandede wants to merge 1 commit into
Open
Conversation
tandede
marked this pull request as ready for review
August 19, 2026 11:38
tandede
force-pushed
the
fix-data-gym-final-merge
branch
from
August 21, 2026 11:20
92b419d to
fa09801
Compare
Author
|
Hi maintainers, I’m following up on this PR in case it was missed. It addresses Data Gym vocabulary files that do not end with a trailing newline and is ready for review. I’d be happy to make any requested adjustments. Thank you! |
r2tbcb9n2c-hash
approved these changes
Aug 31, 2026
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
This looks right. splitlines()[1:] keeps the last merge whether or not the file ends in \n, while still dropping the header and not creating a fake empty merge for the normal trailing-newline case. The regression hits the actual failure by requiring a b to survive as rank 256. No issue from me.
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
vocab.bpefiles correctly when the final line has no trailing newlineWhy
The parser previously split on
\nand discarded the final list element unconditionally. That element is empty only when the file ends with a newline. For an otherwise valid file without one, the final BPE merge was silently dropped, causing the subsequent encoder consistency check to fail.Using
splitlines()preserves the final merge regardless of whether the file has a trailing newline while continuing to omit the terminal line boundary itself.Validation
python -m pytest tests/test_load.py -q(1 passed)python -m pytest tests --import-mode=append --hypothesis-seed=1(34 passed)cargo test(2 passed)cargo fmt --checkruff check --ignore PLC0206 tiktoken/load.py tests/test_load.pyruff format --check tests/test_load.py