diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py index 002e4d1863..d6d9352d98 100644 --- a/unsloth/models/rl_replacements.py +++ b/unsloth/models/rl_replacements.py @@ -176,7 +176,7 @@ def grpo_trainer__prepare_inputs(function_name, function): import re # This matches the function signature, decorators and any comments immediately following pattern = r"(\s*@profiling_decorator\s*\n\s*def _prepare_inputs\s*\([^\)]*\)\s*(->\s*[^:]+)?\s*:\s*\n(?:[ ]*#[^\n]*\n)*)" - + match = re.search(pattern, function) insert = ( " if hasattr(self, 'llm'):\n" @@ -196,7 +196,7 @@ def grpo_trainer__prepare_inputs(function_name, function): rest_of_function, flags=re.DOTALL | re.MULTILINE ) - + # We also need to remove the old wake up call from the beginning of the function # since it's injected before the comments. header_and_comments = re.sub( @@ -373,7 +373,7 @@ def grpo_trainer_compute_loss(function_name, function): _input_ids = input_ids _logits_to_keep = logits_to_keep - get_logps_func = lambda model, input_ids, attention_mask, logits_to_keep, batch_size=None, compute_entropy=False: self._get_per_token_logps(model, input_ids, attention_mask, logits_to_keep, batch_size) if hasattr(self, "_get_per_token_logps") else self._get_per_token_logps_and_entropies(model, input_ids, attention_mask, logits_to_keep, batch_size, compute_entropy)['logps'] + get_logps_func = lambda model, input_ids, attention_mask, logits_to_keep, batch_size=None, compute_entropy=False: self._get_per_token_logps(model, input_ids, attention_mask, logits_to_keep) if hasattr(self, "_get_per_token_logps") else self._get_per_token_logps_and_entropies(model, input_ids, attention_mask, logits_to_keep, batch_size, compute_entropy)['logps'] per_token_logps = get_logps_func(model, input_ids, attention_mask, logits_to_keep)