From dcfb446acd0bab4b98637da80c42999967eeb34b Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Thu, 6 Feb 2025 01:06:40 -0800 Subject: [PATCH] Update rl.py --- unsloth/models/rl.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 0a516bce2a..5b9aec652a 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -371,12 +371,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) + ")" - exec(imports, locals(), globals()) + imported_functions = {} + exec(imports, imported_functions) # Patch all functions for function in changed: - exec(changed[function], locals(), globals()) - exec(f"trl.trainer.{trainer_file}.{RLTrainer_name}.{function} = _unsloth_{function}", locals(), globals()) + exec(changed[function], imported_functions, globals()) + exec(f"trl.trainer.{trainer_file}.{RLTrainer_name}.{function} = _unsloth_{function}", imported_functions, globals()) pass pass