-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[WIP][algo] Migrate and implement the GDPO algorithm into the existing framework. #5422
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| export DATA_DIR="verl/dataset/rlla_4k" | ||
| export BASE_MODEL="Qwen/Qwen2.5-1.5B-Instruct" | ||
| export EXPERIMENT_NAME="qwen2.5-1.5B-GDPO" | ||
| export CKPT_DIR="verl/results/gdpo" | ||
|
|
||
| PROJECT_DIR="$(pwd)" | ||
|
|
||
| trainer_n_gpus_per_node=8 | ||
| trainer_nnodes=1 | ||
|
|
||
| python3 -u -m verl.trainer.main_ppo \ | ||
| algorithm.adv_estimator=gdpo \ | ||
| data.train_files=$DATA_DIR/train.parquet \ | ||
| data.val_files=$DATA_DIR/test.parquet \ | ||
| data.train_batch_size=32 \ | ||
| data.val_batch_size=16 \ | ||
| data.max_prompt_length=2048 \ | ||
| data.max_response_length=1024 \ | ||
| actor_rollout_ref.model.path=$BASE_MODEL \ | ||
| actor_rollout_ref.actor.optim.lr=1e-6 \ | ||
| actor_rollout_ref.model.use_remove_padding=True \ | ||
| actor_rollout_ref.actor.ppo_mini_batch_size=4 \ | ||
| actor_rollout_ref.actor.use_dynamic_bsz=True \ | ||
| actor_rollout_ref.actor.use_kl_loss=False \ | ||
| actor_rollout_ref.actor.kl_loss_coef=0.001 \ | ||
| actor_rollout_ref.actor.kl_loss_type=low_var_kl \ | ||
| actor_rollout_ref.model.enable_gradient_checkpointing=True \ | ||
| actor_rollout_ref.actor.fsdp_config.param_offload=False \ | ||
| actor_rollout_ref.actor.fsdp_config.grad_offload=False \ | ||
| actor_rollout_ref.actor.fsdp_config.optimizer_offload=False \ | ||
| actor_rollout_ref.rollout.tensor_model_parallel_size=1 \ | ||
| actor_rollout_ref.rollout.name=vllm \ | ||
| actor_rollout_ref.rollout.gpu_memory_utilization=0.6 \ | ||
| actor_rollout_ref.rollout.n=4 \ | ||
| actor_rollout_ref.ref.fsdp_config.param_offload=True \ | ||
| algorithm.kl_ctrl.kl_coef=0.001 \ | ||
| reward.custom_reward_function.path="$PROJECT_DIR/verl/experimental/reward_loop/reward_manager/gdpo.py" \ | ||
| reward.custom_reward_function.name=compute_score \ | ||
| trainer.critic_warmup=0 \ | ||
| trainer.logger=['console'] \ | ||
| trainer.project_name=Var_inspect \ | ||
| trainer.n_gpus_per_node=$trainer_n_gpus_per_node \ | ||
| trainer.experiment_name=$EXPERIMENT_NAME \ | ||
| trainer.n_gpus_per_node=$trainer_nnodes \ | ||
| trainer.nnodes=1 \ | ||
| trainer.save_freq=5 \ | ||
| trainer.test_freq=10 \ | ||
| trainer.default_local_dir=$CKPT_DIR \ | ||
| trainer.total_epochs=15 \ | ||
| trainer.val_before_train=False 2>&1 | tee ${LOG_PATH} |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,102 @@ | ||||||||||||||||||||||||||||||||||||||||
| # 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 inspect | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| from verl import DataProto | ||||||||||||||||||||||||||||||||||||||||
| from verl.experimental.reward_loop.reward_manager import register | ||||||||||||||||||||||||||||||||||||||||
| from verl.experimental.reward_loop.reward_manager.base import RewardManagerBase | ||||||||||||||||||||||||||||||||||||||||
| from verl.utils.reward_score import default_compute_score | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @register("gdpo") | ||||||||||||||||||||||||||||||||||||||||
| class GDPOdRewardManager(RewardManagerBase): | ||||||||||||||||||||||||||||||||||||||||
| """GDPO Reward Manager.""" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def __init__(self, config, tokenizer, compute_score, reward_router_address=None, reward_model_tokenizer=None): | ||||||||||||||||||||||||||||||||||||||||
| super().__init__(config, tokenizer, compute_score) | ||||||||||||||||||||||||||||||||||||||||
| self.compute_score = compute_score or default_compute_score | ||||||||||||||||||||||||||||||||||||||||
| self.is_async_reward_score = inspect.iscoroutinefunction(self.compute_score) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # GDPO Reward Config | ||||||||||||||||||||||||||||||||||||||||
| self.max_resp_len = config.reward.get("reward_kwargs", {}).get("max_resp_len", None) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| self.reward_router_address = reward_router_address | ||||||||||||||||||||||||||||||||||||||||
| self.reward_model_tokenizer = reward_model_tokenizer | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| async def run_single(self, data: DataProto) -> dict: | ||||||||||||||||||||||||||||||||||||||||
| assert len(data) == 1, "Only support single data item" | ||||||||||||||||||||||||||||||||||||||||
| data_item = data[0] | ||||||||||||||||||||||||||||||||||||||||
| response_ids = data_item.batch["responses"] | ||||||||||||||||||||||||||||||||||||||||
| response_length = response_ids.shape[-1] | ||||||||||||||||||||||||||||||||||||||||
| valid_response_length = data_item.batch["attention_mask"][-response_length:].sum() | ||||||||||||||||||||||||||||||||||||||||
| valid_response_ids = response_ids[:valid_response_length] | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| data_source = data_item.non_tensor_batch["data_source"] | ||||||||||||||||||||||||||||||||||||||||
| ground_truth = data_item.non_tensor_batch["reward_model"]["ground_truth"] | ||||||||||||||||||||||||||||||||||||||||
| extra_info = data_item.non_tensor_batch.get("extra_info", {}) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| response_str = await self.loop.run_in_executor( | ||||||||||||||||||||||||||||||||||||||||
| None, lambda: self.tokenizer.decode(valid_response_ids, skip_special_tokens=True) | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| extra_reward_kwargs = ( | ||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||
| "reward_router_address": self.reward_router_address, | ||||||||||||||||||||||||||||||||||||||||
| "reward_model_tokenizer": self.reward_model_tokenizer, | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| if self.reward_router_address is not None | ||||||||||||||||||||||||||||||||||||||||
| else {} | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| if self.is_async_reward_score: | ||||||||||||||||||||||||||||||||||||||||
| result = await self.compute_score( | ||||||||||||||||||||||||||||||||||||||||
| data_source=data_source, | ||||||||||||||||||||||||||||||||||||||||
| solution_str=response_str, | ||||||||||||||||||||||||||||||||||||||||
| ground_truth=ground_truth, | ||||||||||||||||||||||||||||||||||||||||
| extra_info=extra_info, | ||||||||||||||||||||||||||||||||||||||||
| **extra_reward_kwargs, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||
| result = await self.loop.run_in_executor( | ||||||||||||||||||||||||||||||||||||||||
| None, | ||||||||||||||||||||||||||||||||||||||||
| lambda: self.compute_score( | ||||||||||||||||||||||||||||||||||||||||
| data_source=data_source, | ||||||||||||||||||||||||||||||||||||||||
| solution_str=response_str, | ||||||||||||||||||||||||||||||||||||||||
| ground_truth=ground_truth, | ||||||||||||||||||||||||||||||||||||||||
| extra_info=extra_info, | ||||||||||||||||||||||||||||||||||||||||
| **extra_reward_kwargs, | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # result = { | ||||||||||||||||||||||||||||||||||||||||
| # "score": score, | ||||||||||||||||||||||||||||||||||||||||
| # "score_list": [fomrat_score, correctness_score], | ||||||||||||||||||||||||||||||||||||||||
| # } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # return = {"reward_score": reward, "reward_extra_info": reward_extra_info} | ||||||||||||||||||||||||||||||||||||||||
| # reward_extra_info = {"score": score, "score_list": [fomrat_score, correctness_score]} | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| reward_extra_info = {} | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| score: float | ||||||||||||||||||||||||||||||||||||||||
| if isinstance(result, dict): | ||||||||||||||||||||||||||||||||||||||||
| score = result["score"] | ||||||||||||||||||||||||||||||||||||||||
| for key, value in result.items(): | ||||||||||||||||||||||||||||||||||||||||
| reward_extra_info[key] = value | ||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||
| score = result | ||||||||||||||||||||||||||||||||||||||||
| reward_extra_info["acc"] = score | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+92
to
+98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current logic for processing the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| reward = score | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return {"reward_score": reward, "reward_extra_info": reward_extra_info} | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a typo in the class name
GDPOdRewardManager. It should likely beGDPORewardManagerto align with the algorithm name ("gdpo") it's registered for. This will improve clarity and prevent confusion.