-
Notifications
You must be signed in to change notification settings - Fork 47
Add CHORD algorithm example #194
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
Conversation
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.
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 CHORD algorithm as a new example within the Trinity-RFT framework. It migrates the algorithm from a legacy version, providing a runnable example and integrating its core components. The changes also include significant updates to the documentation, particularly a detailed explanation of the Synchronizer module, and enhancements to the experience handling to support mixed expert and non-expert data.
Highlights
- CHORD Algorithm Integration: A new MIXCHORDAlgorithm is added, along with its specialized policy loss functions (MIXCHORDPolicyLossFn, SFTISLossFn, SFTPhiLossFn), enabling the framework to support this novel reinforcement learning approach.
- Comprehensive Example: A complete example for running the CHORD algorithm is provided, including a README.md for setup, a data preparation script (get_openr1_data.py), and detailed configuration files (mix_chord.yaml, train_mix_chord.yaml).
- Synchronizer Documentation: Extensive documentation for the Synchronizer module has been added, clarifying its role in coordinating Trainer and Explorer components, detailing various synchronization methods (NCCL, MEMORY, CHECKPOINT) and styles (FIXED, DYNAMIC_BY_EXPLORER), and explaining state management.
- Enhanced Experience Handling: The Experiences dataclass is updated to support custom fields, and the MixSampleStrategy now includes is_expert and step information, which are crucial for the CHORD algorithm's mixed loss calculation.
- Mixed Entropy Loss: A new MixEntropyLossFn is introduced to correctly calculate entropy loss for datasets containing both expert and non-expert experiences.
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.
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 comprehensive example for the CHORD algorithm, including documentation, example scripts, and the core implementation of the algorithm itself. The changes are well-structured and the documentation is clear. My review focuses on the new implementation details. I've identified a significant performance issue in the data preparation script that could make it very slow for large datasets, and a minor usability improvement for the same script. The core logic for the CHORD policy loss seems correct and handles edge cases like zero-step warmups or decays properly. The other changes correctly integrate the new algorithm into the existing framework.
- Migrate CHORD from legacy code version to new code version - Enable phi function - Merge latest changes from main
1040dea to
0414330
Compare
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.
Pull Request Overview
This PR implements the CHORD (CHoice of Off-policy RL and Data) algorithm by migrating it from a legacy version. The CHORD algorithm combines on-policy RL with off-policy expert data through dynamic weighting strategies.
Key changes:
- Implements CHORD policy loss functions with importance sampling and phi function variants
- Adds mixed entropy loss function for handling expert vs. non-expert data
- Introduces MIX_CHORD algorithm type with proper configuration
- Provides complete example implementation with dataset processing scripts
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
trinity/trainer/verl_trainer.py |
Adds null check for algorithm to prevent potential errors |
trinity/trainer/verl/dp_actor.py |
Passes additional data parameters to entropy loss function |
trinity/algorithm/sample_strategy/mix_sample_strategy.py |
Enhances sample strategy with step tracking and advantages for expert data |
trinity/algorithm/policy_loss_fn/chord_policy_loss.py |
Core CHORD implementation with multiple loss function variants |
trinity/algorithm/policy_loss_fn/__init__.py |
Exports new CHORD policy loss functions |
trinity/algorithm/entropy_loss_fn/entropy_loss_fn.py |
Adds mixed entropy loss for expert/non-expert data handling |
trinity/algorithm/algorithm.py |
Registers new MIX_CHORD algorithm type |
examples/mix_math/mix_math.yaml |
Updates configuration parameters for existing mix algorithm |
examples/mix_chord/train_mix_chord.yaml |
Training configuration for CHORD algorithm |
examples/mix_chord/mix_chord.yaml |
Main configuration file for CHORD experiments |
examples/mix_chord/get_openr1_data.py |
Dataset processing script for OpenR1 data |
examples/mix_chord/README.md |
Documentation and usage instructions |
Comments suppressed due to low confidence (1)
examples/mix_chord/get_openr1_data.py:38
- The comment on line 37 mentions 'PREFERENCE_SAMPLE_SIZE' but the actual variable is named 'RL_SAMPLE_SIZE'. This inconsistency should be corrected.
if "\u4e00" <= char <= "\u9fff":
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
/unittest-module-common |
|
/unittest-module-trainer |
Summary
Failed Tests
Tests
Github Test Reporter by CTRF 💚 |
Summary
Tests
Github Test Reporter by CTRF 💚 |
|
/unittest-module-common |
Summary
Failed Tests
Tests
Github Test Reporter by CTRF 💚 |
|
/unittest-module-common |
Summary
Tests
Github Test Reporter by CTRF 💚 |
Description
As the title says.
feat: migrate CHORD algorithm from legacy version to main
https://arxiv.org/pdf/2508.11408
Checklist
Please check the following items before code is ready to be reviewed.