Skip to content

[misc] chore: support transformers 5#5445

Merged
vermouth1992 merged 2 commits intoverl-project:mainfrom
HollowMan6:transformers5
Mar 3, 2026
Merged

[misc] chore: support transformers 5#5445
vermouth1992 merged 2 commits intoverl-project:mainfrom
HollowMan6:transformers5

Conversation

@HollowMan6
Copy link
Collaborator

@HollowMan6 HollowMan6 commented Mar 1, 2026

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.

  • 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.

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, 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
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

Copilot AI review requested due to automatic review settings March 1, 2026 07:36
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 handle apply_chat_template(tokenize=True) output shape/type changes.
  • Relax requirements.txt Transformers 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.

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>
Signed-off-by: Hollow Man <hollowman@opensuse.org>
@vermouth1992 vermouth1992 merged commit 19f0bd8 into verl-project:main Mar 3, 2026
90 of 96 checks passed
@HollowMan6 HollowMan6 deleted the transformers5 branch March 3, 2026 05:21
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.

3 participants