From f5caa53e263157939fe72cd814446897f1a9c0cb Mon Sep 17 00:00:00 2001 From: Datta Nimmaturi Date: Mon, 8 Dec 2025 05:50:02 +0000 Subject: [PATCH] Use regex instead of static string --- unsloth/models/rl_replacements.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py index 5c78938143..8549567f8e 100644 --- a/unsloth/models/rl_replacements.py +++ b/unsloth/models/rl_replacements.py @@ -224,7 +224,13 @@ def grpo_trainer__generate_single_turn(function_name, function): return function # Remove the reload_weights collective RPC call from the generate function's source - function = function.replace('self.llm.collective_rpc("reload_weights")', "") + # function = function.replace('self.llm.collective_rpc("reload_weights")', "") + # The regex below does the same thing but is more flexible and can handle single or double quotes + function = re.sub( + r"self\.llm\.collective_rpc\(\s*(['\"])reload_weights\1\s*\)", + "", + function, + ) return function