[misc] chore: support transformers 5#5445
Conversation
There was a problem hiding this comment.
Code Review
This pull request successfully adds support for transformers version 5 by removing the upper version pin. The core of the change involves introducing compatibility layers to handle breaking changes, specifically the renaming of AutoModelForVision2Seq and the change in the return type of tokenizer.apply_chat_template. These changes are implemented cleanly using helper functions (get_auto_model_for_vision2seq and normalize_token_ids) and are applied consistently across the codebase. My main feedback is to consider adding an upper bound to the transformers dependency to prevent future breakages.
There was a problem hiding this comment.
Pull request overview
Updates the codebase to be compatible with Transformers 5 by centralizing version-dependent auto-model selection for vision-language models and normalizing tokenizer outputs across Transformers 4/5 behavior differences.
Changes:
- Add
get_auto_model_for_vision2seq()compatibility helper and replace scattered version checks / direct imports. - Add
normalize_token_ids()and apply it across rollout, agent loops, dataset length filtering, and tests to handleapply_chat_template(tokenize=True)output shape/type changes. - Relax
requirements.txtTransformers constraint to allow installing Transformers 5.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| verl/workers/rollout/vllm_rollout/vllm_async_server.py | Normalize prompt_ids before length/context calculations for vLLM rollout. |
| verl/workers/fsdp_workers.py | Replace direct AutoModelForVision2Seq import with compatibility getter. |
| verl/utils/transformers_compat.py | Introduce get_auto_model_for_vision2seq() helper for Transformers 4/5. |
| verl/utils/tokenizer.py | Add normalize_token_ids() utility and export it. |
| verl/utils/model.py | Route Vision2Seq auto-class selection through the compat helper. |
| verl/utils/dataset/rl_dataset.py | Ensure chat-template tokenization is explicit and normalize token IDs for prompt-length filtering. |
| verl/utils/checkpoint/fsdp_checkpoint_manager.py | Replace inline Transformers version branching with compat helper when saving HF models. |
| verl/utils/chat_template.py | Normalize token IDs from apply_chat_template(tokenize=True) to keep logic stable across versions. |
| verl/model_merger/base_model_merger.py | Use compat helper for Vision2Seq selection in model merger logic. |
| verl/experimental/vla/models/register_vla_models.py | Use compat helper for registering VLA models with the correct auto class. |
| verl/experimental/fully_async_policy/vllm_rollout/vllm_async_server.py | Normalize prompt_ids before computing max tokens in async rollout. |
| verl/experimental/fully_async_policy/agent_loop/partial_single_turn_agent_loop.py | Normalize tokenized chat-template outputs before downstream use. |
| verl/experimental/agent_loop/agent_loop.py | Normalize token IDs for both processor and tokenizer chat-template paths. |
| tests/workers/rollout/rollout_vllm/test_vllm_abort.py | Update test to normalize chat-template tokenization output. |
| tests/experimental/reward_loop/test_reward_model_genrm.py | Normalize token IDs in reward-loop prompt/response token slicing. |
| tests/experimental/reward_loop/test_reward_model_disrm.py | Normalize token IDs in reward-loop prompt/response token slicing. |
| scripts/legacy_model_merger.py | Use compat helper for Vision2Seq auto class selection. |
| requirements.txt | Remove <5.0.0 upper bound to allow Transformers 5. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0635b88 to
478cfbe
Compare
This PR is a Transformers v5 compatibility sweep plus guardrails for token ID shape consistency. - Remove the hard <5.0.0 block by changing dependency pinning in requirements.txt. - Add a single compat resolver get_auto_model_for_vision2seq() in transformers_compat.py to handle AutoModelForVision2Seq vs AutoModelForImageTextToText, and switch model-loading/registration codepaths to use that resolver instead of direct imports. - Introduce normalize_token_ids(...) in tokenizer.py, which normalizes apply_chat_template(tokenize=True) outputs to flat list[int] across v4/v5 return-shape differences. Signed-off-by: Hollow Man <hollowman@opensuse.org>
478cfbe to
f4ccb39
Compare
Signed-off-by: Hollow Man <hollowman@opensuse.org>
What does this PR do?
Refer to
vllm-project/vllm#30566
for all the patched needed for Transformers v5
This PR is a Transformers v5 compatibility sweep plus guardrails for token ID shape consistency.
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,veomni,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,cfg,reward,fully_async,one_step_off,like[megatron, fsdp, doc]{type}is infeat,fix,refactor,chore,test[BREAKING]to the beginning of the title.[BREAKING][fsdp, megatron] feat: dynamic batchingTest
API and Usage Example
# Add code snippet or script demonstrating how to use thisDesign & Code Changes
Checklist Before Submitting
Important
Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=alwaysci-requestchannel in theverlSlack workspace. (If not accessible, please try the Feishu group (飞书群).)recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main.