From 20da5547f58cc08bab2adb6fa1d9c86a0578b84a Mon Sep 17 00:00:00 2001 From: Daniel Han-Chen Date: Sun, 25 Feb 2024 03:19:34 +1100 Subject: [PATCH] Update gemma.py --- unsloth/models/gemma.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/unsloth/models/gemma.py b/unsloth/models/gemma.py index 2c0606a181..c3b183ef3a 100644 --- a/unsloth/models/gemma.py +++ b/unsloth/models/gemma.py @@ -93,10 +93,8 @@ class FastGemmaRotaryEmbedding(torch.nn.Module): if length > self.max_seq_len_cached: self._set_cos_sin_cache(seq_len=length, device=x.device, dtype=x.dtype) - return ( - self.cos_cached[:seq_len].to(dtype=x.dtype), - self.sin_cached[:seq_len].to(dtype=x.dtype), - ) + old_cos = self.cos_cached[:seq_len].to(dtype=x.dtype) + old_sin = self.sin_cached[:seq_len].to(dtype=x.dtype) # x: [bs, num_attention_heads, seq_len, head_size] if self.inv_freq is None: @@ -111,7 +109,10 @@ class FastGemmaRotaryEmbedding(torch.nn.Module): emb = torch.cat((freqs, freqs), dim=-1) seq_len = position_ids.shape[1] - return emb.cos().to(dtype=x.dtype)[:seq_len], emb.sin().to(dtype=x.dtype)[:seq_len] + new_cos = emb.cos().to(dtype=x.dtype)[:seq_len] + new_sin = emb.sin().to(dtype=x.dtype)[:seq_len] + + logger.warning_once(str(torch.dist(new_cos, old_cos))) pass