[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2025-12-09 03:51:23 +00:00
commit 13ddc5293d
2 changed files with 9 additions and 5 deletions

View file

@ -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)

View file

@ -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)