diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index f5d00eab22..8d0eadb968 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "2025.2.8" +__version__ = "2025.2.9" __all__ = [ "SUPPORTS_BFLOAT16", diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py index ec6706e515..1eae97ff1c 100644 --- a/unsloth/models/llama.py +++ b/unsloth/models/llama.py @@ -708,7 +708,7 @@ def LlamaModel_fast_forward( if attention_mask is None: padding_mask = None elif self.training: - # elif attention_mask is not None and self.training: + # elif attention_mask is None: attention_mask = None padding_mask = None else: @@ -724,7 +724,8 @@ def LlamaModel_fast_forward( past_key_values_length, sliding_window = getattr(self.config, "sliding_window", None), ) - attention_mask = attention_mask.to(torch.bool) + if attention_mask is not None: + attention_mask = attention_mask.to(torch.bool) pass hidden_states = inputs_embeds diff --git a/unsloth/models/rl.py b/unsloth/models/rl.py index fc094b0839..3d601b0af1 100644 --- a/unsloth/models/rl.py +++ b/unsloth/models/rl.py @@ -565,8 +565,8 @@ pass def PatchFastRL(algorithm = None, FastLanguageModel = None): - return - # if FastLanguageModel is not None: PatchRL(FastLanguageModel) - # patch_trl_rl_trainers() - # if algorithm is not None: PatchRLStatistics(algorithm) + if FastLanguageModel is not None: PatchRL(FastLanguageModel) + patch_trl_rl_trainers() + if type(algorithm) is str and algorithm.islower(): + PatchRLStatistics(algorithm) pass diff --git a/unsloth/models/rl_replacements.py b/unsloth/models/rl_replacements.py index 4d7a4dbe09..82fd3f8d3c 100644 --- a/unsloth/models/rl_replacements.py +++ b/unsloth/models/rl_replacements.py @@ -101,23 +101,20 @@ RL_FUNCTIONS["sft_trainer"].append(sft_trainer_prepare_dataset) # Ignore mean_token_accuracy since it needs logits # We override it directly with our version -def _sft_trainer_compute_loss(self, model, inputs, return_outputs = False, num_items_in_batch = None): - (loss, outputs) = super().compute_loss( - model, - inputs, - return_outputs = return_outputs, - num_items_in_batch = num_items_in_batch, - ) - return (loss, outputs) if return_outputs else loss -pass - def sft_trainer_compute_loss(function_name, function): if function_name != "compute_loss": return function - function = inspect.getsource(_sft_trainer_compute_loss) - function = function.replace("def _sft_trainer_compute_loss", "def compute_loss") - function = function.split("\n") - function = "\n".join(" "*4+x for x in function) + def compute_loss(self, model, inputs, return_outputs = False, num_items_in_batch = None): + outputs = super().compute_loss( + model, + inputs, + return_outputs = return_outputs, + num_items_in_batch = num_items_in_batch, + ) + return outputs + pass + + function = inspect.getsource(compute_loss) return function pass RL_FUNCTIONS["sft_trainer"].append(sft_trainer_compute_loss)