-
Notifications
You must be signed in to change notification settings - Fork 47
Standardize Experience and Sample Strategy #141
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 @pan-x-c, 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 significantly enhances the Experience and Experiences data structures by introducing advantages and returns fields, which are essential for advanced reinforcement learning. Concurrently, I've standardized how logprobs and action_masks are represented, ensuring they consistently pertain only to the generated response, rather than the entire sequence. This change streamlines data handling, improves clarity, and prepares the system for more robust RL algorithm implementations.
Highlights
- Data Model Enhancement: I've extended the
ExperienceandExperiencesdata structures to include new fields:advantagesandreturns. These additions are crucial for supporting more sophisticated reinforcement learning algorithms that rely on these values for policy optimization. - Standardized Response-Only Tensors: I've refined the definition and handling of
logprobsandaction_maskswithin theExperienceandExperiencesclasses. They now consistently represent only the generated response tokens, excluding the prompt tokens. This simplifies data processing and aligns the data structures with common RL paradigms where prompt and response components are often treated separately. - Improved Prompt Length Handling: The
prompt_lengthis now explicitly returned by tokenization utilities (tokenize_and_mask_messages_hf,tokenize_and_mask_messages_default) and is used to correctly sliceaction_masksandlogprobs. This ensures that these tensors accurately reflect only the response portion of the sequence, improving data integrity and consistency. - Refined Test Cases and Utilities: I've updated existing test cases in
experience_test.pyto validate the newadvantagesandreturnsfields, as well as the refined handling oflogprobsandaction_masks. Corresponding utility functions for gathering and batching experiences (gather_action_masks,gather_logprobs, etc.) have been adjusted to accommodate these changes, ensuring correct data aggregation.
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 or fill out our survey to provide feedback.
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
The pull request introduces significant improvements to the Experience and Experiences classes, including the addition of advantages and returns. The review focuses on potential bugs in tensor handling and opportunities for code deduplication to improve maintainability.
|
/unittest-module-trainer |
Summary
Tests
Github Test Reporter by CTRF 💚 |
|
/unittest-all |
|
/unittest-all |
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 standardizes the Experience and Sample Strategy components by adding new fields, reducing unnecessary padding, enabling custom fields support, and consolidating sampling logic within the Trainer class.
- Adds
advantagesandreturnsfields to Experience/Experiences classes for better RL algorithm support - Moves SampleStrategy from trainer implementations into the base Trainer class for consistency
- Introduces custom fields support in Experiences for flexible data handling
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| trinity/common/experience.py | Adds advantages/returns fields, CustomField support, and optimizes logprobs/action_mask handling |
| trinity/trainer/trainer.py | Moves SampleStrategy initialization and train_step logic into base Trainer class |
| trinity/trainer/verl_trainer.py | Removes sampling logic and monitoring code, now delegates to base Trainer |
| trinity/trainer/verl/converter.py | New converter module for transforming Experiences to verl DataProto format |
| trinity/algorithm/sample_strategy/ | Updates sample strategies to return Experiences instead of trainer-specific formats |
| trinity/common/models/ | Updates model classes to handle new logprobs format (response-only) |
| tests/ | Updates test cases to match new Experience structure |
Comments suppressed due to low confidence (1)
trinity/trainer/verl_trainer.py:272
- [nitpick] The return type annotation shows
Tuple[bool, Dict]but should be more specific likeTuple[bool, Dict[str, Any]]to indicate what the Dict contains (metrics).
def train_step(self, batch: Experiences) -> Tuple[bool, Dict]: # noqa C901
|
/unittest-all |
Summary
Tests
Github Test Reporter by CTRF 💚 |
yanxi-chen
left a comment
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.
lgtm
Description
advantagesandreturnstoExperienceandExperiencesExperienceandExperiencesExperiencesSampleStrategyintoTrainerSampleStrategyreturnExperiencesChecklist
Please check the following items before code is ready to be reviewed.