Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize rl #2065

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
optimize: Improve performance in RL module by optimizing regex and st…
…ring operations
  • Loading branch information
NinoRisteski committed Mar 17, 2025
commit 9712a46e44dd6ea2889039616c927b0fed742d7a
12 changes: 8 additions & 4 deletions unsloth/models/rl.py
Original file line number Diff line number Diff line change
@@ -576,10 +576,14 @@ def patch_functions(RLTrainer, trainer_file, RLTrainer_name, all_imports, import
old_init = init

# Remove peft_config
init = init.replace("elif peft_config is None:", "elif False:")
init = init.replace("elif peft_config is not None:", "elif False:")
init = init.replace("if peft_config is None:", "if False:")
init = init.replace("if peft_config is not None:", "if False:")
replacements = {
"elif peft_config is None:": "elif False:",
"elif peft_config is not None:": "elif False:",
"if peft_config is None:": "if False:",
"if peft_config is not None:": "if False:",
}
for old, new in replacements.items():
init = init.replace(old, new)
init = init.replace("get_peft_model(model, peft_config)", "model")

# Set use_vllm if not set