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.

CE Loss

Daniel Han37b160d72475
diff --git a/unsloth/kernels/__init__.py b/unsloth/kernels/__init__.py
index 78e70a65b50..3b31f499992 100644
--- a/unsloth/kernels/__init__.py
+++ b/unsloth/kernels/__init__.py
@@ -15,6 +15,7 @@
from .cross_entropy_loss import (
fast_cross_entropy_loss,
post_patch_loss_function,
+ patch_loss_functions,
)
from .rms_layernorm import (
fast_rms_layernorm,
diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.py
index 92e64bfa9ba..41bce690e1d 100644
--- a/unsloth/kernels/cross_entropy_loss.py
+++ b/unsloth/kernels/cross_entropy_loss.py
@@ -20,7 +20,7 @@ from transformers.models.llama.modeling_llama import logger
from packaging.version import Version
from unsloth_zoo.loss_utils import (
- patch_loss_functions,
+ patch_loss_functions as _patch_loss_functions,
post_patch_loss_function,
)
@@ -393,4 +393,6 @@ if (Version(torch.__version__) < Version("2.4.0")) and \
pass
# Patch CE Losses in transformers
-patch_loss_functions(fast_cross_entropy_loss)
+def patch_loss_functions():
+ _patch_loss_functions(fast_cross_entropy_loss)
+pass
diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py
index f49c9db1ff2..45b9569c0d9 100644
--- a/unsloth/models/_utils.py
+++ b/unsloth/models/_utils.py
@@ -48,6 +48,7 @@ __all__ = [
"patch_regional_compilation",
"patch_layernorm",
"patch_torch_compile",
+ "patch_loss_functions",
]
import torch