From 13ddc5293d7caf3b439d046db06181576f8016ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Dec 2025 03:51:23 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/models/rl.py | 5 ++++- unsloth/models/rl_replacements.py | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 4ba2842991..b2173d73ac 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -1326,13 +1326,16 @@ def patch_trl_rl_trainers(): _patch_trl_rl_trainers(trainer) return + def patch_trl_openenv(): from unsloth.models.rl_replacements import RL_ADDITIONAL_FUNCTIONS + for function in RL_ADDITIONAL_FUNCTIONS["openenv"]: - print(f'Unsloth: Patching trl openenv with function: {function.__name__}') + print(f"Unsloth: Patching trl openenv with function: {function.__name__}") function() # Call the function to apply the patch return + def PatchFastRL(algorithm = None, FastLanguageModel = None): if FastLanguageModel is not None: PatchRL(FastLanguageModel) diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py index 7ab147b428..17e045b0e1 100644 --- a/unsloth/models/rl_replacements.py +++ b/unsloth/models/rl_replacements.py @@ -936,16 +936,16 @@ def openenv_vllm_reload_weights(): import trl.experimental.openenv.utils as openenv_utils import trl.experimental.openenv as openenv except ImportError as e: - print(f'Unsloth: Failed to import trl openenv: {e}') + print(f"Unsloth: Failed to import trl openenv: {e}") return src = inspect.getsource(openenv_utils.generate_rollout_completions) src = textwrap.dedent(src) original_src = src - src = re.sub(r'.*\.collective_rpc\("reload_weights"\).*\n?', '', src) + src = re.sub(r'.*\.collective_rpc\("reload_weights"\).*\n?', "", src) if original_src == src: - print('Unsloth: Warning - regex did not match, patch may have failed') + print("Unsloth: Warning - regex did not match, patch may have failed") return # Execute and explicitly assign to module @@ -956,6 +956,7 @@ def openenv_vllm_reload_weights(): # Patch both the utils module and the parent openenv module openenv_utils.generate_rollout_completions = patched_func openenv.generate_rollout_completions = patched_func - print('Unsloth: Patched trl openenv generate_rollout_completions') + print("Unsloth: Patched trl openenv generate_rollout_completions") + RL_ADDITIONAL_FUNCTIONS["openenv"].append(openenv_vllm_reload_weights)