Skip to content

Commit

Permalink
address #10
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Aug 8, 2023
1 parent 8d560e9 commit 14ecab4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions recurrent_memory_transformer_pytorch/attend.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def flash_attn(self, q, k, v, mask = None):
if exists(mask):
if mask.ndim != 4:
mask = rearrange(mask, 'b j -> b 1 1 j')

mask = mask.expand(-1, heads, q_len, -1)

# Check if there is a compatible device for flash attention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,13 @@ def forward(
causal_mask = F.pad(causal_mask, (0, mem_length, read_mem_length, 0), value = False)
causal_mask = F.pad(causal_mask, (read_mem_length, 0, 0, mem_length), value = True)

assert not exists(mask)
mask = rearrange(causal_mask, 'i j -> 1 1 i j')
causal_mask = rearrange(causal_mask, 'i j -> 1 1 i j')

if exists(mask):
mask = rearrange(mask, 'b j -> b 1 1 j')
mask = mask & causal_mask
else:
mask = causal_mask

# rotary embedding - offset main positions by 10000, and keep all memories at position 0

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 = 'recurrent-memory-transformer-pytorch',
packages = find_packages(exclude=[]),
version = '0.4.2',
version = '0.4.3',
license='MIT',
description = 'Recurrent Memory Transformer - Pytorch',
author = 'Phil Wang',
Expand Down

0 comments on commit 14ecab4

Please sign in to comment.