Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: implemented reward redistribution and implicit reward redistribution#6

Open
maharajamihir wants to merge 3 commits into
mainp-doom/verl:mainfrom
feat/reward-redistributionp-doom/verl:feat/reward-redistributionCopy head branch name to clipboard
Open

feat: implemented reward redistribution and implicit reward redistribution#6
maharajamihir wants to merge 3 commits into
mainp-doom/verl:mainfrom
feat/reward-redistributionp-doom/verl:feat/reward-redistributionCopy head branch name to clipboard

Conversation

@maharajamihir

Copy link
Copy Markdown

No description provided.

@maharajamihir
maharajamihir requested review from Copilot and emergenz May 13, 2025 20:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces reward redistribution logic (both explicit and implicit) into different components of the training pipeline.

  • In the reward manager, explicit reward redistribution is applied by splitting the reward among tokens.
  • In the PPO trainer and core algorithms, implicit redistribution is implemented via scaling advantages and configuration updates.
  • The configuration file now includes new flags to toggle these reward redistribution approaches.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
verl/workers/reward_manager/naive.py Applies explicit reward redistribution to token scores.
verl/trainer/ppo/ray_trainer.py Incorporates implicit reward redistribution and adds an assert to enforce mutual exclusivity.
verl/trainer/ppo/core_algos.py Implements advantage scaling when implicit redistribution is enabled.
verl/trainer/config/ppo_trainer.yaml Introduces new configuration flags for both redistribution methods.
Comments suppressed due to low confidence (2)

verl/trainer/ppo/ray_trainer.py:898

  • Using an assert for configuration validation may be bypassed in optimized runs; consider replacing it with an explicit check that raises an appropriate exception to ensure reliable error handling in production.
assert not ( self.config.algorithm.redistribute_reward and self.config.algorithm.redistribute_reward_implicit ), ( "Only one of `redistribute_reward` and `redistribute_reward_implicit` can be True" )

verl/trainer/ppo/ray_trainer.py:570

  • [nitpick] The assignment of redistribution flags to meta_info is repeated in the test loop; consider abstracting this logic into a helper function to reduce duplication and improve maintainability.
test_batch.meta_info["redistribute_reward"] = ( self.config.algorithm.redistribute_reward )

Comment thread verl/trainer/ppo/core_algos.py Outdated
Comment thread verl/trainer/ppo/core_algos.py Outdated
reward = score

reward_tensor[i, valid_response_length - 1] = reward
if data_item.meta_info["redistribute_reward"]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we exclusively use the naive reward manager?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also implement RR for the batch reward manager

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

@emergenz emergenz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Implicit reward redistribution currently contains a bug

# Scale the advantages by (T-t)/T
if redistribute_reward_implicit:
# Compute per‐example length T from the response mask
lengths = response_mask.sum(dim=1, keepdim=True).to(advantages)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the .to necessary?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove the .to

# Scale the advantages by (T-t)/T
if redistribute_reward_implicit:
# Compute per‐example length T from the response mask
lengths = response_mask.sum(dim=1, keepdim=True).to(advantages)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
lengths = response_mask.sum(dim=1, keepdim=True).to(advantages)
lengths = response_mask.sum(dim=1, keepdim=True)

# Compute per‐example length T from the response mask
lengths = response_mask.sum(dim=1, keepdim=True).to(advantages)
# Build a [1, T_max] tensor of time indices
time_idx = torch.arange(gen_len, device=advantages.device, dtype=advantages.dtype).unsqueeze(0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
time_idx = torch.arange(gen_len, device=advantages.device, dtype=advantages.dtype).unsqueeze(0)
time_idx = torch.arange(gen_len).unsqueeze(0)

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.