[transformers] set return dict false for transformers v5 compatibility#1325
[transformers] set return dict false for transformers v5 compatibility#1325erictang000 wants to merge 1 commit intoNovaSky-AI:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates calls to tokenizer.apply_chat_template to be compatible with transformers v5 by explicitly setting return_dict=False. While most changes are correct, there is a critical issue in inference_engine_client.py where the code attempts to access ['input_ids'] on the result of apply_chat_template. This will cause a TypeError because with return_dict=False, the function returns a list directly, not a dictionary. This needs to be fixed to prevent runtime errors.
| prompt_token_ids = self.tokenizer.apply_chat_template( | ||
| prompts, | ||
| add_generation_prompt=True, | ||
| return_dict=True, | ||
| return_dict=False, | ||
| tokenize=True, | ||
| )["input_ids"] |
There was a problem hiding this comment.
With return_dict=False, self.tokenizer.apply_chat_template will return a list of token IDs directly, not a dictionary. Accessing ["input_ids"] on the result will cause a TypeError at runtime. You should remove the dictionary key access.
| prompt_token_ids = self.tokenizer.apply_chat_template( | |
| prompts, | |
| add_generation_prompt=True, | |
| return_dict=True, | |
| return_dict=False, | |
| tokenize=True, | |
| )["input_ids"] | |
| prompt_token_ids = self.tokenizer.apply_chat_template( | |
| prompts, | |
| add_generation_prompt=True, | |
| return_dict=False, | |
| tokenize=True, | |
| ) |
| return_dict=False, | ||
| tokenize=True, | ||
| )["input_ids"] |
There was a problem hiding this comment.
🔴 return_dict=False result indexed with ["input_ids"] causes TypeError
The PR changed return_dict=True to return_dict=False at line 101, but line 103 still accesses the result with ["input_ids"]. With return_dict=False, apply_chat_template returns a plain list (or list of lists) of token IDs, not a dictionary. Attempting list["input_ids"] will raise a TypeError: list indices must be integers or slices, not str. This crashes whenever generate() is called with prompts instead of prompt_token_ids.
| return_dict=False, | |
| tokenize=True, | |
| )["input_ids"] | |
| return_dict=False, | |
| tokenize=True, | |
| ) |
Was this helpful? React with 👍 or 👎 to provide feedback.
Sets
return_dict=Falsewhere needed for transformers-v5 compatibility - this can be merged prior to explicitly upgrading to transformers v5 in the pyproject.toml, since vllm still does not technically fully support it in the latest release.This change should be backwards compatible with transformers v4.*, since the behavior prior to v5 was that the default value for
return_dictwasNone, which was interpreted as False.