Skip to content

Replace removed tokenizer.batch_encode_plus with direct call - #2634

Open
rrrxxx0510 wants to merge 2 commits into
open-compass:mainfrom
rrrxxx0510:fix/batch-encode-plus-transformers-5
Open

Replace removed tokenizer.batch_encode_plus with direct call#2634
rrrxxx0510 wants to merge 2 commits into
open-compass:mainfrom
rrrxxx0510:fix/batch-encode-plus-transformers-5

Conversation

@rrrxxx0510

Copy link
Copy Markdown

Fixes #2573

batch_encode_plus was removed in transformers 5.x, so the HF backends crash for tokenizers that don't keep a fallback (e.g. Qwen2Tokenizer on Qwen3.5):

AttributeError: Qwen2Tokenizer has no attribute batch_encode_plus

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.py plus the one in huggingface.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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Qwen3.5 cannot run when using HuggingFacewithChatTemplate

2 participants