Replace removed tokenizer.batch_encode_plus with direct call - #2634
Open
rrrxxx0510 wants to merge 2 commits into
Open
Replace removed tokenizer.batch_encode_plus with direct call#2634rrrxxx0510 wants to merge 2 commits into
rrrxxx0510 wants to merge 2 commits into
Conversation
batch_encode_plus was removed in transformers 5.x, which breaks the
HuggingFace backends for any model whose tokenizer is a Qwen2Tokenizer
(e.g. Qwen3.5) and likely others:
AttributeError: Qwen2Tokenizer has no attribute batch_encode_plus
The tokenizer __call__ API accepts the same kwargs and returns the same
BatchEncoding, so this is a drop-in replacement. Covers all call sites
in huggingface_above_v4_33.py and huggingface.py.
Fixes open-compass#2573
The tests mocked tokenizer.batch_encode_plus, which the previous commit replaced with a direct tokenizer call, so the mocked dict was never returned and three tests failed. Mock tokenizer.return_value instead. Verified: 15 passed with this change, 3 failed without it.
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.
Fixes #2573
batch_encode_pluswas removed in transformers 5.x, so the HF backends crash for tokenizers that don't keep a fallback (e.g. Qwen2Tokenizer on Qwen3.5):The tokenizer call API takes the same kwargs and returns the same BatchEncoding, so it's a drop-in swap. Covers all call sites in
huggingface_above_v4_33.pyplus the one inhuggingface.py, which has the same problem.Checked on transformers 5.16: the old call raises the AttributeError above, the direct call with identical kwargs returns the expected
input_ids/attention_mask.