-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[rollout] feat: compute reward score in agent loop #3055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vermouth1992
merged 7 commits into
volcengine:main
from
wuxibin89:wuxibin/agent_loop_reward
Aug 19, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7e38a8c
[rollout] feat: compute reward score in agent loop
wuxibin89 bb30927
fix unit test
wuxibin89 d58321e
fix unit test
wuxibin89 16105e4
fix trainer
wuxibin89 3944d5a
fix unit test
wuxibin89 2c952ce
fix unit test
wuxibin89 1bf2409
fix unnit test
wuxibin89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Copyright 2024 Bytedance Ltd. and/or its affiliates | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import os | ||
|
|
||
| import ray | ||
| from hydra import compose, initialize_config_dir | ||
| from torchdata.stateful_dataloader import StatefulDataLoader | ||
| from transformers import AutoTokenizer | ||
|
|
||
| from tests.experimental.agent_loop.agent_utils import init_agent_loop_manager | ||
| from verl.protocol import DataProto | ||
| from verl.trainer.main_ppo import create_rl_sampler | ||
| from verl.utils.dataset.rl_dataset import RLHFDataset, collate_fn | ||
|
|
||
|
|
||
| def test_agent_loop_compute_score(): | ||
| ray.init( | ||
| runtime_env={ | ||
| "env_vars": { | ||
| "TOKENIZERS_PARALLELISM": "true", | ||
| "NCCL_DEBUG": "WARN", | ||
| "VLLM_LOGGING_LEVEL": "INFO", | ||
| "VLLM_USE_V1": "1", | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| with initialize_config_dir(config_dir=os.path.abspath("verl/trainer/config")): | ||
| config = compose("ppo_trainer") | ||
|
|
||
| model_path = "Qwen/Qwen2.5-1.5B-Instruct" | ||
| config.data.return_raw_chat = True | ||
| config.actor_rollout_ref.model.path = model_path | ||
| config.actor_rollout_ref.actor.use_dynamic_bsz = True | ||
| config.actor_rollout_ref.rollout.name = os.environ["ROLLOUT_NAME"] | ||
| config.actor_rollout_ref.rollout.mode = "async" | ||
| config.actor_rollout_ref.rollout.prompt_length = 1024 | ||
| config.actor_rollout_ref.rollout.response_length = 4096 | ||
|
|
||
| # 1. init agent loop manager | ||
| agent_loop_manager = init_agent_loop_manager(config) | ||
|
|
||
| # 2. init dataset and dataloader | ||
| local_folder = os.path.expanduser("~/verl-data/gsm8k/") | ||
| data_files = [os.path.join(local_folder, "train.parquet")] | ||
| tokenizer = AutoTokenizer.from_pretrained(model_path) | ||
|
|
||
| dataset = RLHFDataset( | ||
| data_files=data_files, | ||
| tokenizer=tokenizer, | ||
| config=config.data, | ||
| processor=None, | ||
| ) | ||
|
|
||
| batch_size = 128 | ||
| sampler = create_rl_sampler(config.data, dataset) | ||
| dataloader = StatefulDataLoader( | ||
| dataset=dataset, | ||
| batch_size=batch_size, | ||
| num_workers=config.data.dataloader_num_workers, | ||
| drop_last=True, | ||
| collate_fn=collate_fn, | ||
| sampler=sampler, | ||
| ) | ||
|
|
||
| # 3. generate_sequences with agent loop | ||
| batch_dict = next(iter(dataloader)) | ||
| batch = DataProto.from_single_dict(batch_dict) | ||
| gen_batch = agent_loop_manager.generate_sequences(prompts=batch) | ||
|
|
||
| rm_scores = gen_batch.batch["rm_scores"] | ||
| sample_scores = rm_scores.sum(dim=1) | ||
| assert sample_scores.min() == 0.0, f"min score: {sample_scores.min()}" | ||
| assert sample_scores.max() == 1.0, f"max score: {sample_scores.max()}" | ||
| print(f"gsm8k acc: {sample_scores.mean()}") | ||
|
|
||
| print("Test passed!") | ||
| ray.shutdown() | ||
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.