Skip to content

feat: atropos reward registry - pluggable reward bridge - #68

Open
1HazyOne707 wants to merge 6 commits into
verl-project:mainfrom
1HazyOne707:atropos-reward-registry
Open

feat: atropos reward registry - pluggable reward bridge#68
1HazyOne707 wants to merge 6 commits into
verl-project:mainfrom
1HazyOne707:atropos-reward-registry

Conversation

@1HazyOne707

Copy link
Copy Markdown

Adds a pluggable reward registry that complements the existing Atropos integration (#61).

Problem: verl raises NotImplementedError for unknown data sources, causing crashes with custom environments (see verl#5558, verl#5531, verl#5536).

Solution: RewardRegistry gracefully handles unknown data sources by trying verl built-ins first, then registered handlers, then Atropos scoring, then returning 0.0.

Built-in: openai/gsm8k handler with flexible answer extraction. 5/5 tests passing.

Companion to verl-project/verl#5520.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a flexible reward registry for the verl framework, designed to prevent crashes caused by unknown data sources. It establishes a robust fallback mechanism, first attempting verl's built-in functions, then custom registered handlers, followed by Atropos scoring, and finally returning a default score of 0.0. This enhancement significantly improves the system's resilience and extensibility for custom environments and datasets, ensuring smoother operation and broader applicability.

Highlights

  • New Reward Registry: Introduced a pluggable RewardRegistry to enhance the existing Atropos integration within the verl framework.
  • Graceful Error Handling: Implemented a robust fallback mechanism to prevent NotImplementedError crashes when verl encounters unknown data sources, ensuring the system returns 0.0 instead of failing.
  • Extensible Reward System: Enabled registration of custom reward handlers, allowing users to define and integrate their own scoring logic for specific data sources.
  • Atropos Scoring Fallback: Integrated Atropos scoring via HTTP as a final fallback option when no built-in or registered handlers can compute a score.
  • Built-in GSM8K Handler: Included a built-in handler for openai/gsm8k that extracts answers with flexible parsing, addressing a common data source issue.
Changelog
  • atropos_reward/README.md
    • Added a new README file explaining the purpose, problem, solution, built-in handlers, and issues addressed by the Atropos Reward Registry.
  • atropos_reward/reward_registry.py
    • Implemented the RewardRegistry class, which provides a pluggable reward bridge with a tiered fallback logic.
    • Included a _gsm8k_score function for handling openai/gsm8k data sources.
    • Added register and compute_score methods to the RewardRegistry class, along with module-level helper functions.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

Copy link
Copy Markdown
Contributor

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 introduces a pluggable reward registry to gracefully handle unknown data sources in Atropos, which is a solid improvement. The implementation is generally good, but I've identified a couple of areas in atropos_reward/reward_registry.py where robustness can be improved. Specifically, I'm suggesting a refactoring of the _gsm8k_score function to fix a correctness bug and improve its reliability, and enhancing the error handling when calling the verl built-in reward function.

Comment on lines +23 to +40
if not solutions:
# flexible fallback
numbers = re.findall(r"(\-?[0-9\.,]+)", solution_str)
final = None
for n in reversed(numbers):
if n not in ["", "."]:
final = n
break
else:
final = solutions[-1].replace(",", "").replace("$", "")

if final is None:
return 0.0
try:
gt = str(ground_truth).replace(",", "").replace("$", "").strip()
return 1.0 if final.strip() == gt else 0.0
except Exception:
return 0.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current implementation of _gsm8k_score has a few issues that affect its correctness and robustness:

  1. Inconsistent Cleaning: The fallback logic for number extraction does not clean the extracted string (e.g., removing , or $), while the primary path for #### answers does. This can lead to incorrect comparisons.
  2. Broad Exception: The except Exception clause is too broad and can hide underlying bugs. It's better to catch more specific exceptions.

I suggest refactoring this section to address these points. The proposed change unifies the logic to ensure the extracted number string is always cleaned and catches more specific exceptions, making the function more reliable.

Suggested change
if not solutions:
# flexible fallback
numbers = re.findall(r"(\-?[0-9\.,]+)", solution_str)
final = None
for n in reversed(numbers):
if n not in ["", "."]:
final = n
break
else:
final = solutions[-1].replace(",", "").replace("$", "")
if final is None:
return 0.0
try:
gt = str(ground_truth).replace(",", "").replace("$", "").strip()
return 1.0 if final.strip() == gt else 0.0
except Exception:
return 0.0
final = None
if not solutions:
# flexible fallback
numbers = re.findall(r"(\-?[0-9\.,]+)", solution_str)
for n in reversed(numbers):
if n not in ["", "."]:
final = n
break
else:
final = solutions[-1]
if final is None:
return 0.0
final = final.replace(",", "").replace("$", "")
try:
gt = str(ground_truth).replace(",", "").replace("$", "").strip()
return 1.0 if final.strip() == gt else 0.0
except (ValueError, TypeError):
return 0.0

Comment thread atropos_reward/reward_registry.py Outdated
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.

1 participant