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.

Convert mask to float (#1762)

Edd16e69efc96b6
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index 27651be97af..909dfc339bf 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -775,9 +775,12 @@ def LlamaModel_fast_forward(
self.SWA_mask = True
self.GA_mask = False
elif attention_mask is not None:
-
# Fixes https://github.com/unslothai/unsloth/issues/853
# Unsloth needs a 2D mask, not a [2, 1, n, n] mask!
+
+ # https://github.com/pytorch/pytorch/issues/103749
+ # Need to convert to float and not using bool
+ attention_mask = (1.0 - attention_mask.float()) * torch.finfo(inputs_embeds.dtype).min
dynamic_SWA_mask = _prepare_4d_causal_attention_mask_for_sdpa(
attention_mask,
(batch_size, seq_length),