Skip to content

Conversation

@yanxi-chen
Copy link
Collaborator

Description

  • Add to RECPolicyLossFn: support clip_mode = "gspo-one-side" and weight = "gspo_importance_sampling"
  • Update REC algorithm's default kl and entropy settings; set kl_coef = 0 explicitly in configs
  • In GSPOLossFn, enforce loss_agg_mode = "seq-mean-token-mean", as required by GSPO's rationale

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has passed all tests
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yanxi-chen, 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 GSPO-style variant for the REC (Reinforcement with Expert Correction) algorithm, enhancing its policy loss function with new clipping and weighting mechanisms. It also refines the default KL and entropy settings for REC and ensures proper loss aggregation for GSPO, making the algorithm more flexible and robust for various reinforcement learning tasks.

Highlights

  • GSPO-style REC Variant: Introduced new clip_mode = "gspo-one-side" and weight = "gspo_importance_sampling" options within RECPolicyLossFn to support a GSPO-style variant of the REC algorithm.
  • REC Algorithm Defaults Update: Modified the default KL and entropy settings for the REC algorithm, explicitly setting kl_coef = 0 in configurations to align with the new variant's requirements.
  • GSPO Loss Aggregation Enforcement: Enforced loss_agg_mode = "seq-mean-token-mean" within GSPOLossFn to ensure consistency with GSPO's underlying rationale.
  • Configuration Updates: Updated example configurations in README.md and gsm8k.yaml to reflect the new GSPO-style REC variants and the explicit kl_coef settings.
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.

Copy link
Contributor

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

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 GSPO-style variant for the REC algorithm, adding new clipping and importance sampling methods. It also updates default configurations and enforces a specific loss aggregation mode for GSPO. The changes are mostly well-contained. I've identified a critical issue that could lead to a runtime error if new configuration options are mismatched, and another high-severity bug related to handling a configuration parameter. I've provided suggestions to fix both. The rest of the changes, including documentation and example updates, appear consistent with the code modifications.

Comment on lines 50 to 55
assert self.weight in [
"none",
"importance_sampling",
"gspo_importance_sampling",
"advantage",
], f"Invalid weight: {self.weight}"
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The new gspo_importance_sampling weight relies on normalized_seq_ratio, which is only calculated when clip_mode is gspo-one-side. This can lead to an UnboundLocalError if these options are used incorrectly. To prevent this, you should enforce that gspo_importance_sampling can only be used with gspo-one-side by adding an assertion.

 assert self.weight in [ "none", "importance_sampling", "gspo_importance_sampling", "advantage", ], f"Invalid weight: {self.weight}" if self.weight == "gspo_importance_sampling": assert ( self.clip_mode == "gspo-one-side" ), "'gspo_importance_sampling' weight must be used with 'gspo-one-side' clip mode."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant