From 35d37ea5671a6ca2977b67995d1d1f70c26e7660 Mon Sep 17 00:00:00 2001 From: marcandrelarochelle Date: Fri, 20 Jun 2025 09:28:58 -0400 Subject: [PATCH] Fix TRL 1.8.2 (#2774) * Fix for TRL 1.8.2 Regex matching LLM initialization * Update Regex --- unsloth/models/rl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index 08d7cbf38b..69785be206 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -746,7 +746,7 @@ def patch_functions(RLTrainer, trainer_file, RLTrainer_name, all_imports, import if trl_version >= "0.18": # Replace LLM init with already existing vLLM engine for colocate mode - vllm_llm_init_pattern = r"self\.llm\s*=\s*LLM\([^)]*\)*\)" + vllm_llm_init_pattern = r"self\.llm\s*=\s*LLM\(.*?\)*\)\s*?\n(?!,)" vllm_llm_replacement = "self.llm = model.vllm_engine\n" new_vllm_part = re.sub( vllm_llm_init_pattern,