From 19001c915f8a577d000ff21c4251852817ce254a Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Wed, 28 May 2025 05:23:07 -0700 Subject: [PATCH] Update rl.py --- unsloth/models/rl.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index f19ca5ee96..c909eb6a5e 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -503,6 +503,17 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): extra_args += check_dr_grpo pass + # Check GRPO num_generations mismatch + if "per_device_train_batch_size" in call_args and "num_generations" in call_args: + check_num_generations = \ + "if (per_device_train_batch_size // num_generations) * num_generations != per_device_train_batch_size:\n"\ + " print('Unsloth: We now expect `per_device_train_batch_size` to be a multiple of `num_generations`.\\n"\ + "We will change the batch size of ' + str(per_device_train_batch_size) + ' to the `num_generations` of ' + str(num_generations))\n"\ + " per_device_train_batch_size = num_generations\n"\ + "\n" + extra_args += check_dr_grpo + pass + # Edit config with anything extra if trainer_file in RL_CONFIG_CHANGES: process_extra_args = RL_CONFIG_CHANGES[trainer_file]