From 0d1ec74bf001b1ff6ef482f71e58cb793cf101e7 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sat, 21 Dec 2024 01:11:30 -0800 Subject: [PATCH] Update _utils.py --- unsloth/models/_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index a02cadd08a..d2bc4af2fc 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -1086,6 +1086,14 @@ def patch_gradient_accumulation_fix(Trainer): "if num_items_in_batch is not None: loss *= self.args.gradient_accumulation_steps", ) function = function.replace("def training_step", "def _unsloth_training_step", 1) + + # Fix 4.47.0 issue where num_items_in_batch was removed + # See https://github.com/huggingface/transformers/pull/35121 + function = function.replace( + "if self.model_accepts_loss_kwargs:", + "if False:", + ) + exec(function, globals()) Trainer.training_step = _unsloth_training_step pass