Skip to content

Commit

Permalink
rescale values to prevent linear attention from overflowing in fp16 s…
Browse files Browse the repository at this point in the history
…etting
  • Loading branch information
lucidrains committed Jul 27, 2022
1 parent 6b504c4 commit 12f95b3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions denoising_diffusion_pytorch/denoising_diffusion_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ def forward(self, x):
k = k.softmax(dim = -1)

q = q * self.scale
v = v / (h * w)

context = torch.einsum('b h d n, b h e n -> b h d e', k, v)

out = torch.einsum('b h d e, b h d n -> b h e n', context, q)
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 = 'denoising-diffusion-pytorch',
packages = find_packages(),
version = '0.26.3',
version = '0.26.4',
license='MIT',
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
author = 'Phil Wang',
Expand Down

0 comments on commit 12f95b3

Please sign in to comment.