From 4724be861e8aca0470bb6c69e5b01da9d047dff2 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 6 Feb 2025 01:10:42 -0800 Subject: [PATCH] Update rl.py --- unsloth/models/rl.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index bc6fa0f7a7..1f33d46e6d 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -372,14 +372,13 @@ def _patch_trl_rl_trainers(trainer_file = "grpo_trainer"): # Import all functions imports = list(set(imports)) imports = f"from trl.trainer.{trainer_file} import (\n" + ',\n'.join(imports) + ")" - imported_functions = {} - exec(imports, imported_functions) + exec(imports, locals()) # Patch all functions for function in changed: - exec(changed[function], imported_functions, globals()) + exec(changed[function], locals(), globals()) print(changed[function]) - exec(f"trl.trainer.{trainer_file}.{RLTrainer_name}.{function} = _unsloth_{function}", imported_functions, globals()) + exec(f"trl.trainer.{trainer_file}.{RLTrainer_name}.{function} = _unsloth_{function}", locals(), globals()) pass pass