Skip to content

Conversation

@yaochaorui
Copy link
Contributor

@yaochaorui yaochaorui commented Sep 20, 2025

Description

  • Implemented several instantiations of group-relative REINFORCE families.
  • Added usage examples: configs for various instantiations etc.

It includes three major families:

  • REC family (clipping + importance sampling)
  • REP family (regularization-based variants)
  • RED family (data-distribution shaping strategies)

We also provide baseline implementations such as Vanilla REINFORCE and GRPO.

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
  • Code is ready for review

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yaochaorui, 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 expands the reinforcement learning capabilities by integrating several "Group-relative REINFORCE Families." It introduces new algorithms focusing on clipping, importance sampling, regularization, and data-distribution shaping, along with baseline implementations. The changes include new advantage and policy loss functions, all designed with modularity in mind, and are accompanied by practical examples for common datasets like GSM8k and MATH.

Highlights

  • New REINFORCE Families Implemented: Introduced several instantiations of group-relative REINFORCE families, including REC (clipping + importance sampling), REP (regularization-based), and RED (data-distribution shaping), along with baseline implementations like Vanilla REINFORCE and GRPO.
  • Modular Configuration for Algorithms: All new algorithms are instantiated through modular YAML configurations, facilitating easy reproduction and extension of experiments.
  • REC Advantage Function: Added RECGroupedAdvantage for calculating group-relative advantages, which includes options for standard normalization and strategies to balance positive and negative examples by dropping extra negative ones.
  • REC Policy Loss Function: Implemented RECPolicyLossFn to compute the policy loss for REC, supporting various clipping modes (none, one-side, two-side, ring), weighting strategies (importance sampling, advantage), and regularization methods (forward-kl, k2).
  • New Usage Examples: Provided new example configurations and READMEs for running REC on the GSM8k and MATH datasets, demonstrating practical application of the new algorithms.
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

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 implementations for several group-relative REINFORCE families (REC, REP, RED) and their usage examples. The changes include new algorithm types, advantage functions, and policy loss functions, along with example configurations for GSM8k and MATH datasets. The code is well-structured with a clear separation of concerns. My review identifies a couple of minor issues in the advantage calculation logic and a suggestion to reduce documentation duplication for better maintainability.

@pan-x-c
Copy link
Collaborator

pan-x-c commented Sep 22, 2025

/unittest-module-common

@github-actions
Copy link

Summary

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

Tests

Test Name Status Flaky Duration
tests/common/config_test.py::TestConfig::test_all_examples_are_valid 13ms
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_hf_datasets_conversion 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 59ms
tests/common/vllm_test.py::ModelWrapperTest_1::test_generate 35ms
tests/common/vllm_test.py::ModelWrapperTest_2::test_generate 47ms
tests/common/vllm_test.py::TestModelLen_0::test_model_len 20ms
tests/common/vllm_test.py::TestModelLen_1::test_model_len 20ms
tests/common/vllm_test.py::TestAPIServer::test_api 24ms
tests/common/vllm_test.py::TestAsyncAPIServer::test_api_async 23ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask 1ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask_with_tools 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 💚

@yaochaorui yaochaorui force-pushed the cr/rec branch 2 times, most recently from 1369c5c to 3950c30 Compare September 22, 2025 20:23
@pan-x-c
Copy link
Collaborator

pan-x-c commented Sep 25, 2025

/unittest-module-common

@github-actions
Copy link

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
30 18 12 0 0 0 14ms

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/common/config_test.py::TestConfig::test_continue_from_checkpoint_is_valid The test failed in the call phase
❌ tests/common/config_test.py::TestConfig::test_load_default_config The test failed in the call phase
❌ tests/common/vllm_test.py::ModelWrapperTest_0::test_generate The test failed in the call phase
❌ tests/common/vllm_test.py::ModelWrapperTest_1::test_generate The test failed in the call phase
❌ tests/common/vllm_test.py::ModelWrapperTest_2::test_generate The test failed in the call phase
❌ tests/common/vllm_test.py::TestModelLen_0::test_model_len The test failed in the call phase
❌ tests/common/vllm_test.py::TestModelLen_1::test_model_len The test failed in the call phase
❌ tests/common/vllm_test.py::TestAPIServer::test_api The test failed in the call phase
❌ tests/common/vllm_test.py::TestAsyncAPIServer::test_api_async The test failed in the call phase
❌ tests/common/vllm_test.py::TestAPIServerToolCall_0_deepseek_r1::test_api_tool_calls The test failed in the call phase
❌ tests/common/vllm_test.py::TestAPIServerToolCall_1::test_api_tool_calls The test failed in the call phase

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 1ms
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_hf_datasets_conversion 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 2ms
tests/common/vllm_test.py::ModelWrapperTest_1::test_generate 1ms
tests/common/vllm_test.py::ModelWrapperTest_2::test_generate 1ms
tests/common/vllm_test.py::TestModelLen_0::test_model_len 1ms
tests/common/vllm_test.py::TestModelLen_1::test_model_len 1ms
tests/common/vllm_test.py::TestAPIServer::test_api 1ms
tests/common/vllm_test.py::TestAsyncAPIServer::test_api_async 1ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask 1ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask_with_tools 1ms
tests/common/vllm_test.py::TestAPIServerToolCall_0_deepseek_r1::test_api_tool_calls 1ms
tests/common/vllm_test.py::TestAPIServerToolCall_1::test_api_tool_calls 1ms

Github Test Reporter by CTRF 💚

@pan-x-c
Copy link
Collaborator

pan-x-c commented Sep 25, 2025

/unittest-module-common

@github-actions
Copy link

Summary

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Other ❓ Flaky 🍂 Duration ⏱️
30 29 1 0 0 0 290ms

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 7ms
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 2ms
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_hf_datasets_conversion 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 58ms
tests/common/vllm_test.py::ModelWrapperTest_1::test_generate 36ms
tests/common/vllm_test.py::ModelWrapperTest_2::test_generate 46ms
tests/common/vllm_test.py::TestModelLen_0::test_model_len 21ms
tests/common/vllm_test.py::TestModelLen_1::test_model_len 20ms
tests/common/vllm_test.py::TestAPIServer::test_api 25ms
tests/common/vllm_test.py::TestAsyncAPIServer::test_api_async 24ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask 1ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask_with_tools 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 💚

@pan-x-c
Copy link
Collaborator

pan-x-c commented Sep 25, 2025

/unittest-module-common

@github-actions
Copy link

Summary

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

Tests

Test Name Status Flaky Duration
tests/common/config_test.py::TestConfig::test_all_examples_are_valid 34ms
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 5ms
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_hf_datasets_conversion 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 58ms
tests/common/vllm_test.py::ModelWrapperTest_1::test_generate 37ms
tests/common/vllm_test.py::ModelWrapperTest_2::test_generate 47ms
tests/common/vllm_test.py::TestModelLen_0::test_model_len 21ms
tests/common/vllm_test.py::TestModelLen_1::test_model_len 20ms
tests/common/vllm_test.py::TestAPIServer::test_api 24ms
tests/common/vllm_test.py::TestAsyncAPIServer::test_api_async 24ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask 1ms
tests/common/vllm_test.py::TestTokenizer::test_action_mask_with_tools 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 21ms

Github Test Reporter by CTRF 💚

@pan-x-c
Copy link
Collaborator

pan-x-c commented Sep 25, 2025

/unittest-module-algorithm

@github-actions
Copy link

Summary

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

Tests

Test Name Status Flaky Duration
tests/algorithm/advantage_fn_test.py::TestGroupedAdvantageFn::test_duplicate_grpo 1ms
tests/algorithm/advantage_fn_test.py::TestGroupedAdvantageFn::test_grpo_advantage 1ms
tests/algorithm/advantage_fn_test.py::TestGroupedAdvantageFn::test_grpo_correct_bias 1ms
tests/algorithm/advantage_fn_test.py::TestGroupedAdvantageFn::test_grpo_reward_std 1ms
tests/algorithm/advantage_fn_test.py::TestGroupedAdvantageFn::test_step_wise_grpo_advantage 1ms
tests/algorithm/policy_loss_test.py::VerlPolicyLossTest::test_dpo_policy_loss 1ms
tests/algorithm/policy_loss_test.py::VerlPolicyLossTest::test_gspo_policy_loss 1ms
tests/algorithm/policy_loss_test.py::VerlPolicyLossTest::test_mix_policy_loss 1ms
tests/algorithm/policy_loss_test.py::VerlPolicyLossTest::test_opmd_policy_loss 1ms
tests/algorithm/policy_loss_test.py::VerlPolicyLossTest::test_ppo_policy_loss 1ms
tests/algorithm/policy_loss_test.py::VerlPolicyLossTest::test_sft_policy_loss 1ms

Github Test Reporter by CTRF 💚

@pan-x-c pan-x-c merged commit f777fb2 into modelscope:main Sep 25, 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.

2 participants