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 Han87c4fcf1bbc5
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py
index 680402a178a..1a8fff9ada8 100644
--- a/unsloth/models/_utils.py
+++ b/unsloth/models/_utils.py
@@ -986,7 +986,9 @@ def _unsloth_pre_compute_loss(self, model, inputs, *args, **kwargs):
"Read more on gradient accumulation issues here: https://unsloth.ai/blog/gradient"
)
pass
- return self._old_compute_loss(model, inputs, *args, **kwargs)
+ with torch.autocast(device_type = "cuda", dtype = torch.float32):
+ outputs = self._old_compute_loss(model, inputs, *args, **kwargs)
+ return outputs
pass