Remove spurious warning for tokenize_and_concatenate#1177
Merged
jlarson4 merged 6 commits intoTransformerLensOrg:devfrom Feb 20, 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
Summary: Suppress the spurious "Token indices sequence length is longer than the specified maximum sequence length for this model" warning when using
tokenize_and_concatenatewith long text and a tokenizer that has amodel_max_length.Context:
tokenize_and_concatenatesplits text into chunks, tokenizes them in parallel (with padding), then strips padding and reshapes into fixed-length sequences of sizemax_length. Some intermediate chunks can tokenize to longer than the tokenizer'smodel_max_length. The Hugging Face tokenizer warns when it produces any sequence longer than that, but TransformerLens ultimately never feeds those long sequences to the model. So the warning is misleading in this use case.Change: In
transformer_lens/utils.py, we temporarily settokenizer.deprecation_warnings["sequence-length-is-longer-than-the-specified-maximum"] = Falsebefore the tokenization step and restore the original value in afinallyblock so the tokenizer is not left in a modified state. We only touch this when the tokenizer has adeprecation_warningsdict (guarded withhasattr/isinstance).Fixes #1134
Type of change
Checklist: