Repository navigation
[model] fix: import AutoModelForCausalLMWithValueHead from trl.experimental.ppo in utils/model.py - #7625
Merged
wuxibin89 merged 1 commit intoAug 31, 2026
Conversation
…mental.ppo in utils/model.py Completes the trl>=0.29 import fix for the value-head critic path: verl-project#6539 only covered verl/models/transformers/monkey_patch.py, while the two remaining top-level imports in verl/utils/model.py (patch_valuehead_model at :611 and load_valuehead_model at :657, used by the FSDP engine when loading a value-head critic) still crash with trl>=0.29/1.x, where the class was moved to trl.experimental.ppo (huggingface/trl#5044). Verified on trl 1.12.0: top-level import raises ImportError, trl.experimental.ppo import works. Mirror the existing monkey_patch try/except pattern at both sites; with trl<0.29 (e.g. the fsdp/megatron extra pin trl==0.27.0) the experimental import fails and falls back to the top-level import, preserving current behavior. Co-authored-by: DeepSeek Harness Agent
wuxibin89
approved these changes
Aug 31, 2026
ETOgaosion
added a commit
to ETOgaosion/verl
that referenced
this pull request
Aug 31, 2026
verl-project#7625 added an import block missing the blank line after the `from transformers import PreTrainedModel` import, which fails `ruff format` in the pre-commit `--all-files` CI run.
5 of 8 tasks
thecourageyu
pushed a commit
to thecourageyu/verl
that referenced
this pull request
Nov 11, 2026
…mental.ppo in utils/model.py (verl-project#7625) Fixes verl-project#5690 ## Motivation Fixes the remaining gap of [verl-project#5690](verl-project#5690) (`verl cannot import name 'AutoModelForCausalLMWithValueHead' from 'trl'`). PR [verl-project#6539](verl-project#6539) fixed the import for `trl >= 0.29` only in `verl/models/transformers/monkey_patch.py`, but the same top-level import still exists in **two places** in `verl/utils/model.py`, which are hit when the FSDP engine loads a value-head critic (`verl/workers/engine/fsdp/transformer_impl.py:272` -> `load_valuehead_model`): - `verl/utils/model.py:611` (`patch_valuehead_model`) - `verl/utils/model.py:657` (`load_valuehead_model`) With `trl >= 0.29` (e.g. the latest `trl==1.12.0`, which removed the top-level class in huggingface/trl#5044), PPO/RLHF training with a value-head critic on the FSDP engine crashes with `ImportError`. This also blocks trl dependency bumps (see closed dependabot PR verl-project#7478). Verified on `trl==1.12.0`: ``` >>> from trl import AutoModelForCausalLMWithValueHead ImportError: cannot import name 'AutoModelForCausalLMWithValueHead' from 'trl' >>> from trl.experimental.ppo import AutoModelForCausalLMWithValueHead OK # trl.experimental.ppo.modeling_value_head.AutoModelForCausalLMWithValueHead ``` ## Change Mirror the existing pattern in `verl/models/transformers/monkey_patch.py:351-353` at both sites in `verl/utils/model.py`: ```python try: from trl.experimental.ppo import AutoModelForCausalLMWithValueHead # type: ignore except ImportError: from trl import AutoModelForCausalLMWithValueHead # type: ignore ``` - `trl >= 0.29` (experimental path exists): uses `trl.experimental.ppo`. - `trl < 0.29` (e.g. the fsdp/megatron extra pin `trl==0.27.0`): experimental import fails and falls back to the top-level import — unchanged behavior. ## Why this is not duplicating an existing PR Checked `gh pr list --repo verl-project/verl --state open --search "trl"` and `--search "valuehead OR value_head OR AutoModelForCausalLMWithValueHead"`: no open PR touches `verl/utils/model.py` imports. verl-project#6539 (merged) covered only `monkey_patch.py`; this PR completes the same fix for the FSDP valuehead path that verl-project#6539 missed. ## Tests - `pip install trl==1.12.0` in a scratch env; both import paths verified as above (top-level fails, `trl.experimental.ppo` works). - Existing CPU unit tests unaffected: `python -m pytest tests/workers/rollout/test_chunked_prefill_batched_tokens_on_cpu.py -v` (6 passed) and the wider CPU suite (`cpu_tests_tf510.log`: 613 passed) were used as a regression baseline on this machine. - (Optional, pending reviewer preference) a unit test asserting the import resolves under both trl layouts via `sys.modules` stubbing. ## AI assistance disclosure Prepared with AI assistance (draft + verification). The submitting human has reviewed the design, will review every changed line, and has run the verification commands above before submitting. Co-authored-by: LiRunGuo <[email protected]>
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 #5690
Motivation
Fixes the remaining gap of #5690
(
verl cannot import name 'AutoModelForCausalLMWithValueHead' from 'trl').PR #6539 fixed the import for
trl >= 0.29only inverl/models/transformers/monkey_patch.py, but the sametop-level import still exists in two places in
verl/utils/model.py, whichare hit when the FSDP engine loads a value-head critic
(
verl/workers/engine/fsdp/transformer_impl.py:272->load_valuehead_model):verl/utils/model.py:611(patch_valuehead_model)verl/utils/model.py:657(load_valuehead_model)With
trl >= 0.29(e.g. the latesttrl==1.12.0, which removed the top-levelclass in huggingface/trl#5044), PPO/RLHF training with a value-head critic on
the FSDP engine crashes with
ImportError. This also blocks trl dependencybumps (see closed dependabot PR #7478).
Verified on
trl==1.12.0:Change
Mirror the existing pattern in
verl/models/transformers/monkey_patch.py:351-353at both sites in
verl/utils/model.py:trl >= 0.29(experimental path exists): usestrl.experimental.ppo.trl < 0.29(e.g. the fsdp/megatron extra pintrl==0.27.0): experimentalimport fails and falls back to the top-level import — unchanged behavior.
Why this is not duplicating an existing PR
Checked
gh pr list --repo verl-project/verl --state open --search "trl"and--search "valuehead OR value_head OR AutoModelForCausalLMWithValueHead":no open PR touches
verl/utils/model.pyimports. #6539 (merged) covered onlymonkey_patch.py; this PR completes the same fix for the FSDP valuehead paththat #6539 missed.
Tests
pip install trl==1.12.0in a scratch env; both import paths verified asabove (top-level fails,
trl.experimental.ppoworks).python -m pytest tests/workers/rollout/test_chunked_prefill_batched_tokens_on_cpu.py -v(6 passed)and the wider CPU suite (
cpu_tests_tf510.log: 613 passed) were used as aregression baseline on this machine.
resolves under both trl layouts via
sys.modulesstubbing.AI assistance disclosure
Prepared with AI assistance (draft + verification). The submitting human has
reviewed the design, will review every changed line, and has run the
verification commands above before submitting.