mirror of
https://github.com/wassname/denoising-diffusion-pytorch.git
synced 2026-09-12 12:22:11 +08:00
rescale values to prevent linear attention from overflowing in fp16 setting
This commit is contained in:
@@ -211,6 +211,8 @@ class LinearAttention(nn.Module):
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user