From 911745377aba2ded64eaf96e09e9ee3495d54763 Mon Sep 17 00:00:00 2001 From: Daniel Han-Chen Date: Sun, 25 Feb 2024 02:30:06 +1100 Subject: [PATCH] Update gemma.py --- unsloth/models/gemma.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/unsloth/models/gemma.py b/unsloth/models/gemma.py index 5629221ec7..4104dd8df4 100644 --- a/unsloth/models/gemma.py +++ b/unsloth/models/gemma.py @@ -75,12 +75,14 @@ class FastGemmaRotaryEmbedding(torch.nn.Module): t = torch.arange(position_ids.shape[1], device="cpu", dtype=torch.int64).float() freqs = torch.outer(t, self.inv_freq) - emb = torch.cat((freqs, freqs), dim=-1).to("cuda") + emb_old = torch.cat((freqs, freqs), dim=-1).to("cuda") - # inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1) - # position_ids_expanded = position_ids[:, None, :].float() - # freqs = (inv_freq_expanded @ position_ids_expanded).transpose(1, 2) - # emb = torch.cat((freqs, freqs), dim=-1) + inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1) + position_ids_expanded = position_ids[:, None, :].float() + freqs = (inv_freq_expanded @ position_ids_expanded).transpose(1, 2) + emb_new = torch.cat((freqs, freqs), dim=-1) + + print(torch.dist(emd_old, emd_new)) return emb.cos().to(dtype=x.dtype), emb.sin().to(dtype=x.dtype) pass