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.

fix/transformers-unpack (#1180)

Edd79effae03d3d
diff --git a/unsloth/kernels/cross_entropy_loss.py b/unsloth/kernels/cross_entropy_loss.py
index 1c8f8c8d990..57d07af493f 100644
--- a/unsloth/kernels/cross_entropy_loss.py
+++ b/unsloth/kernels/cross_entropy_loss.py
@@ -388,6 +388,13 @@ from transformers.models.llama.modeling_llama import (
List,
Tuple,
)
+
+try:
+ from transformers.models.llama.modeling_llama import Unpack, KwargsForCausalLM
+except ImportError:
+ logger.warning("Unsloth: Could not find Unpack, KwargsForCausalLM in LlamaForCausalLM. "
+ "This is expected if you are using an older version of Transformers (<4.46.0). ")
+
import inspect, re
function = inspect.getsource(LlamaForCausalLM.forward)
function = function.split("\n")