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 llama.py

Daniel Han8e899bf95603
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index 47a57024a26..f4609b81e9f 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -738,6 +738,10 @@ def LlamaModel_fast_forward(
past_key_values_length,
sliding_window = None,
)
+ # Fixes https://github.com/unslothai/unsloth/issues/853
+ # Unsloth needs a 2D mask, not a [2, 1, n, n] mask!
+ if self.SWA_mask.dim() == 4: self.SWA_mask = self.SWA_mask[0][0]
+ if self. GA_mask.dim() == 4: self. GA_mask = self. GA_mask[0][0]
elif not hasattr(self, "SWA_mask"):
if HAS_FLEX_ATTENTION:
# Use Flex Attention instead!