Repository navigation
Fix left-padded BOS removal along the last tensor axis - #1891
Merged
jlarson4 merged 1 commit intoOct 12, 2026
Merged
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.
Description
Use the final tensor dimension when removing the BOS token from left-padded sequences.
get_tokens_with_bos_removeddocuments sequence length as the last dimension and already uses that dimension to locate BOS and shape the result, but its scatter operation is hard-coded to dimension 1. Rank-1 inputs raise a dimension error; rank-3 inputs scatter along the wrong axis or fail for valid leading padding.The fix changes only the scatter dimension to
-1. Eight synthetic value-based cases cover rank-1/2/3 inputs, BOS equal to PAD, a BOS-only sequence, right-padding and no-BOS controls. Existing tokenizer tests remain unchanged. No dependencies or public signatures change.Type of Change
Validation
make formatwas executed through isolateduv runenvironments using the lockfile formatter versions. The isolated tools do not synchronize the complete project environment.make check-formatrun with those versions passes (Pycln, isort, Black). As with the normal lockfile, this tool environment does not include Black's optional notebook-formatting extras. An additional check with those extras exposed unrelated notebook formatting/parser problems; none of those generated edits are included here.mypy .passes with 391 source files checked, using mypy 1.17.0 and the isolated locked Transformers 5.13.0 / Tokenizers 0.22.1 / Hub 1.15.0 / Datasets 4.8.5 prefix. The affected file's ten tests also pass with that prefix in an independent root run. No shared dependency installation was changed.Checklist
Assistance
AI-assisted implementation, tests, and description, with independent orchestrator code review and test execution.