-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Weighted reward functions] Adding functionality to weigh rewards. Te…
…sts.
- Loading branch information
Showing
7 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import unittest | ||
|
||
from open_r1.grpo import GRPOScriptArguments | ||
|
||
|
||
class TestGRPOScriptArguments(unittest.TestCase): | ||
def test_default_weights(self): | ||
"""Test that default weights are correctly set when not provided.""" | ||
args = GRPOScriptArguments(dataset_name="ABC") | ||
self.assertEqual(len(args.reward_funcs), len(args.reward_weights)) | ||
self.assertEqual(args.reward_weights, [1.0] * len(args.reward_funcs)) | ||
|
||
def test_custom_weights_valid(self): | ||
"""Test that custom weights are accepted when matching reward_funcs length.""" | ||
args = GRPOScriptArguments( | ||
dataset_name="ABC", reward_funcs=["accuracy", "format", "reasoning_steps"], reward_weights=[0.5, 1.0, 2.0] | ||
) | ||
self.assertEqual(args.reward_weights, [0.5, 1.0, 2.0]) | ||
|
||
def test_custom_weights_invalid(self): | ||
"""Test that mismatched weights raise ValueError.""" | ||
with self.assertRaises(ValueError) as context: | ||
GRPOScriptArguments( | ||
dataset_name="ABC", reward_funcs=["accuracy", "format"], reward_weights=[1.0, 2.0, 3.0] | ||
) | ||
self.assertIn("Number of reward weights", str(context.exception)) | ||
self.assertIn("must match number of reward functions", str(context.exception)) | ||
|
||
def test_empty_weights_with_custom_funcs(self): | ||
"""Test that empty weights are filled with 1.0 for custom reward functions.""" | ||
args = GRPOScriptArguments( | ||
dataset_name="ABC", | ||
reward_funcs=["accuracy", "format", "reasoning_steps"], | ||
) | ||
self.assertEqual(len(args.reward_weights), 3) | ||
self.assertEqual(args.reward_weights, [1.0, 1.0, 1.0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters