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.

Gemma inference fix

Daniel Han-Chendb4a24e60228
diff --git a/pyproject.toml b/pyproject.toml
index 324e01157ba..9c862a2617b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -36,7 +36,7 @@ huggingface = [
"tyro",
"transformers>=4.38.2",
"datasets>=2.16.0",
- "sentencepiece",
+ "sentencepiece>=0.2.0",
"tqdm",
"psutil",
"wheel>=0.42.0",
diff --git a/unsloth/models/gemma.py b/unsloth/models/gemma.py
index 0259ab78892..c0cce75e2f6 100644
--- a/unsloth/models/gemma.py
+++ b/unsloth/models/gemma.py
@@ -145,7 +145,12 @@ def GemmaModel_fast_forward_inference(
bsz, q_len, hd = hidden_states.shape
seq_len = past_key_values[0][0].shape[-2]
if bsz != 1:
- attention_mask = _prepare_4d_causal_attention_mask(attention_mask, (bsz, q_len), hidden_states, seq_len,)
+ attention_mask = _prepare_4d_causal_attention_mask_for_sdpa(
+ attention_mask,
+ (bsz, q_len),
+ hidden_states,
+ seq_len,
+ )
pass
next_decoder_cache = []