Add TOPR and CISPO algorithm#185
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @garyzhang99, 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 the foundational code for two novel reinforcement learning algorithms, TOPR and CISPO, based on recent academic research. It includes the core logic for these algorithms, their specific policy loss functions, and a new strategy for calculating advantages. The changes lay the groundwork for integrating these advanced algorithms into the existing system, though the PR is currently a Work In Progress with further configuration and testing planned.
Highlights
- New Algorithm Implementations: This pull request introduces the initial implementations of the TOPR (Training with Optimal Policy Regularization) and CISPO (Clipped Importance Sampleed Policy Optimization) algorithms, directly referencing their respective research papers.
- REINFORCE Advantage Strategy: A new
REINFORCEAddStrategyclass has been added, designed to calculate advantages simply by using rewards, which can be integrated with various reinforcement learning algorithms. - Algorithm Registration: The
TOPRAlgorithmandCISPOAlgorithmclasses are now registered as new algorithm types, complete with their default configurations for components likeadd_strategy,sample_strategy, andpolicy_loss_fn. - CISPO Policy Loss Function: The
CISPOPolicyLossFnhas been implemented in a new file, providing the specific policy loss calculation for the CISPO algorithm, including logic for importance ratio clipping and masking based on advantage signs. - TOPR Policy Loss Function: A new
TOPRPolicyLossFnhas been added, which computes the policy loss for the TOPR algorithm by applying a conditional weighting factor (alpha) to the loss, determined by a reward threshold, as outlined in the TOPR paper.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request introduces the TOPR and CISPO algorithms. The implementation is a good start, but there are several areas for improvement. I've identified a critical bug in the CISPO policy loss metric calculation that would cause a runtime error. Additionally, the new file for the TOPR policy loss appears to be misnamed, which could cause confusion. I've also suggested some improvements for code clarity and efficiency in the new REINFORCEAddStrategy and the CISPO implementation. Addressing these points will improve the quality and robustness of the new code.
|
/unittest-module-common |
Summary
Failed Tests
Tests
Github Test Reporter by CTRF 💚 |
|
/unittest-module-common |
Summary
Tests
Github Test Reporter by CTRF 💚 |
Co-authored-by: 问昊 <zwh434786@alibaba-inc.com>
Description
As the title says.
The TOPR algorithm: https://arxiv.org/pdf/2503.14286v1
The CISPO algorithm: https://arxiv.org/pdf/2506.13585
TODO: Add config yamls and run results.
Checklist
Please check the following items before code is ready to be reviewed.