Skip to content

Commit

Permalink
fix the cache for xpos scale
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Apr 28, 2023
1 parent 6868f6f commit 22cac59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions rotary_embedding_torch/rotary_embedding_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def rotate_queries_and_keys(self, q, k, seq_dim = -2):
assert self.use_xpos
device, seq_len = q.device, q.shape[seq_dim]
seq = torch.arange(seq_len, device = device)
freqs = self.forward(lambda: seq, cache_key = seq_len)
scale = self.get_scale(lambda: seq, cache_key = seq_len)
freqs = self.forward(lambda: seq, cache_key = f'freqs:{seq_len}')
scale = self.get_scale(lambda: seq, cache_key = f'scale:{seq_len}')
rotated_q = apply_rotary_emb(freqs, q, scale = scale)
rotated_k = apply_rotary_emb(freqs, k, scale = scale ** -1)
return rotated_q, rotated_k
Expand All @@ -127,7 +127,7 @@ def get_scale(self, t, cache_key = None):
scale = torch.cat((scale, scale), dim = -1)

if exists(cache_key):
self.cache[cache_key] = freqs
self.cache[cache_key] = scale

return scale

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name = 'rotary-embedding-torch',
packages = find_packages(),
version = '0.2.1',
version = '0.2.2',
license='MIT',
description = 'Rotary Embedding - Pytorch',
long_description_content_type = 'text/markdown',
Expand Down

0 comments on commit 22cac59

Please sign in to comment.