Update gemma.py

This commit is contained in:
Daniel Han-Chen 2024-02-25 02:26:57 +11:00
commit e56eb3f406

View file

@ -70,12 +70,12 @@ class FastGemmaRotaryEmbedding(torch.nn.Module):
# x: [bs, num_attention_heads, seq_len, head_size]
if self.inv_freq is None:
self.inv_freq = 1.0 / (
self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64, device=x.device).float() / self.dim)
self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64, device="cpu").float() / self.dim)
)
t = torch.arange(self.max_position_embeddings, device="cpu", dtype=torch.int64).float()
freqs = torch.outer(t, self.inv_freq)
emb = torch.cat((freqs, freqs), dim=-1)
emb = 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()