Skip to content

Conversation

@garyzhang99
Copy link
Collaborator

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.

  • Code has passed all tests
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review

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.

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

  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 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
@pan-x-c pan-x-c requested a review from Copilot August 18, 2025 10:13
Copy link

Copilot AI left a 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.

@pan-x-c
Copy link
Collaborator

pan-x-c commented Aug 18, 2025

/unittest-module-common

@pan-x-c
Copy link
Collaborator

pan-x-c commented Aug 18, 2025

/unittest-module-trainer

@github-actions
Copy link

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
27 26 1 0 0 0 296ms

Failed Tests

Failed Tests ❌ Fail Message
❌ tests/common/config_test.py::TestConfig::test_all_examples_are_valid The test failed in the call phase due to an exception

Tests

Test Name Status Flaky Duration
tests/common/config_test.py::TestConfig::test_all_examples_are_valid 1ms
tests/common/config_test.py::TestConfig::test_config_flatten 1ms
tests/common/config_test.py::TestConfig::test_continue_from_checkpoint_is_valid 1ms
tests/common/config_test.py::TestConfig::test_load_default_config 4ms
tests/common/experience_test.py::TestEID::test_eid_properties 1ms
tests/common/experience_test.py::TestExperience::test_action_mask_and_logprobs_type 1ms
tests/common/experience_test.py::TestExperience::test_assertions 1ms
tests/common/experience_test.py::TestExperience::test_dpo_experience 1ms
tests/common/experience_test.py::TestExperience::test_gather 1ms
tests/common/experience_test.py::TestExperience::test_multi_turn_experience 1ms
tests/common/experience_test.py::TestExperience::test_serialize_deserialize 1ms
tests/common/experience_test.py::TestExperience::test_single_turn_experience 1ms
tests/common/experience_test.py::TestExperience::test_to_dict 1ms
tests/common/experience_test.py::TestExperienceConversion::test_batch_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_dpo_experience_batch_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_experience_model_experience_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_gather_experiences_with_custom_fields 1ms
tests/common/experience_test.py::TestExperienceConversion::test_multiturn_experience_batch_converstion 1ms
tests/common/vllm_test.py::ModelWrapperTest_0::test_generate 35ms
tests/common/vllm_test.py::ModelWrapperTest_1::test_generate 52ms
tests/common/vllm_test.py::ModelWrapperTest_2::test_generate 48ms
tests/common/vllm_test.py::ModelWrapperTest_3::test_generate 36ms
tests/common/vllm_test.py::ModelWrapperTest_4::test_generate 46ms
tests/common/vllm_test.py::TestAPIServer::test_api 23ms
tests/common/vllm_test.py::TestTokenizer::test_assistant_token_mask 1ms
tests/common/vllm_test.py::TestAPIServerToolCall_0_deepseek_r1::test_api_tool_calls 22ms
tests/common/vllm_test.py::TestAPIServerToolCall_1::test_api_tool_calls 19ms

Github Test Reporter by CTRF 💚

@github-actions
Copy link

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
9 9 0 0 0 0 481ms

Tests

Test Name Status Flaky Duration
tests/trainer/trainer_test.py::BaseTrainerCase::test_trainer 2ms
tests/trainer/trainer_test.py::TestTrainerCountdown::test_trainer 131ms
tests/trainer/trainer_test.py::TestStepAheadAsyncRL::test_trainer 56ms
tests/trainer/trainer_test.py::TestTrainerGSM8K::test_trainer 42ms
tests/trainer/trainer_test.py::TestTrainerSFTWarmupGSM8K::test_trainer 60ms
tests/trainer/trainer_test.py::TestTrainerDPO::test_trainer 31ms
tests/trainer/trainer_test.py::TestTrainerSFT::test_trainer 29ms
tests/trainer/trainer_test.py::TestFullyAsyncMode::test_fully_async_mode_0_queue 58ms
tests/trainer/trainer_test.py::TestFullyAsyncMode::test_fully_async_mode_1_priority_queue 65ms

Github Test Reporter by CTRF 💚

@hiyuchang
Copy link
Collaborator

/unittest-module-common

@github-actions
Copy link

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
27 26 1 0 0 0 297ms

Failed Tests

Failed Tests ❌ Fail Message
❌ tests/common/config_test.py::TestConfig::test_all_examples_are_valid The test failed in the call phase due to an exception

Tests

Test Name Status Flaky Duration
tests/common/config_test.py::TestConfig::test_all_examples_are_valid 1ms
tests/common/config_test.py::TestConfig::test_config_flatten 1ms
tests/common/config_test.py::TestConfig::test_continue_from_checkpoint_is_valid 1ms
tests/common/config_test.py::TestConfig::test_load_default_config 4ms
tests/common/experience_test.py::TestEID::test_eid_properties 1ms
tests/common/experience_test.py::TestExperience::test_action_mask_and_logprobs_type 1ms
tests/common/experience_test.py::TestExperience::test_assertions 1ms
tests/common/experience_test.py::TestExperience::test_dpo_experience 1ms
tests/common/experience_test.py::TestExperience::test_gather 1ms
tests/common/experience_test.py::TestExperience::test_multi_turn_experience 1ms
tests/common/experience_test.py::TestExperience::test_serialize_deserialize 1ms
tests/common/experience_test.py::TestExperience::test_single_turn_experience 1ms
tests/common/experience_test.py::TestExperience::test_to_dict 1ms
tests/common/experience_test.py::TestExperienceConversion::test_batch_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_dpo_experience_batch_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_experience_model_experience_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_gather_experiences_with_custom_fields 1ms
tests/common/experience_test.py::TestExperienceConversion::test_multiturn_experience_batch_converstion 1ms
tests/common/vllm_test.py::ModelWrapperTest_0::test_generate 35ms
tests/common/vllm_test.py::ModelWrapperTest_1::test_generate 53ms
tests/common/vllm_test.py::ModelWrapperTest_2::test_generate 48ms
tests/common/vllm_test.py::ModelWrapperTest_3::test_generate 35ms
tests/common/vllm_test.py::ModelWrapperTest_4::test_generate 45ms
tests/common/vllm_test.py::TestAPIServer::test_api 24ms
tests/common/vllm_test.py::TestTokenizer::test_assistant_token_mask 1ms
tests/common/vllm_test.py::TestAPIServerToolCall_0_deepseek_r1::test_api_tool_calls 22ms
tests/common/vllm_test.py::TestAPIServerToolCall_1::test_api_tool_calls 20ms

Github Test Reporter by CTRF 💚

@garyzhang99
Copy link
Collaborator Author

/unittest-module-common

@github-actions
Copy link

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
27 27 0 0 0 0 297ms

Tests

Test Name Status Flaky Duration
tests/common/config_test.py::TestConfig::test_all_examples_are_valid 2ms
tests/common/config_test.py::TestConfig::test_config_flatten 1ms
tests/common/config_test.py::TestConfig::test_continue_from_checkpoint_is_valid 1ms
tests/common/config_test.py::TestConfig::test_load_default_config 4ms
tests/common/experience_test.py::TestEID::test_eid_properties 1ms
tests/common/experience_test.py::TestExperience::test_action_mask_and_logprobs_type 1ms
tests/common/experience_test.py::TestExperience::test_assertions 1ms
tests/common/experience_test.py::TestExperience::test_dpo_experience 1ms
tests/common/experience_test.py::TestExperience::test_gather 1ms
tests/common/experience_test.py::TestExperience::test_multi_turn_experience 1ms
tests/common/experience_test.py::TestExperience::test_serialize_deserialize 1ms
tests/common/experience_test.py::TestExperience::test_single_turn_experience 1ms
tests/common/experience_test.py::TestExperience::test_to_dict 1ms
tests/common/experience_test.py::TestExperienceConversion::test_batch_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_dpo_experience_batch_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_experience_model_experience_conversion 1ms
tests/common/experience_test.py::TestExperienceConversion::test_gather_experiences_with_custom_fields 1ms
tests/common/experience_test.py::TestExperienceConversion::test_multiturn_experience_batch_converstion 1ms
tests/common/vllm_test.py::ModelWrapperTest_0::test_generate 35ms
tests/common/vllm_test.py::ModelWrapperTest_1::test_generate 53ms
tests/common/vllm_test.py::ModelWrapperTest_2::test_generate 49ms
tests/common/vllm_test.py::ModelWrapperTest_3::test_generate 36ms
tests/common/vllm_test.py::ModelWrapperTest_4::test_generate 45ms
tests/common/vllm_test.py::TestAPIServer::test_api 23ms
tests/common/vllm_test.py::TestTokenizer::test_assistant_token_mask 1ms
tests/common/vllm_test.py::TestAPIServerToolCall_0_deepseek_r1::test_api_tool_calls 21ms
tests/common/vllm_test.py::TestAPIServerToolCall_1::test_api_tool_calls 19ms

Github Test Reporter by CTRF 💚

@garyzhang99 garyzhang99 merged commit 4f8cb4c into modelscope:main Aug 18, 2025
1 check passed
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.

3 participants