Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Update _utils.py

Daniel Han14886235e383
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py
index a02cadd08af..d2bc4af2fc7 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