Skip to content

Commit

Permalink
demonstrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Birch-san committed Sep 11, 2022
1 parent 18bb5f8 commit d2d533d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ldm/modules/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def forward(self, x, context=None, mask=None):

q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> (b h) n d', h=h), (q, k, v))

sim = einsum('b i d, b j d -> b i j', q, k) * self.scale
sim = torch.matmul(q, k.transpose(1, 2)) * self.scale
del q, k

if exists(mask):
Expand All @@ -193,7 +193,7 @@ def forward(self, x, context=None, mask=None):
attn = sim.softmax(dim=-1)
del sim

out = einsum('b i j, b j d -> b i d', attn, v)
out = torch.matmul(attn, v)
del attn, v
out = rearrange(out, '(b h) n d -> b n (h d)', h=h)
del h
Expand Down

0 comments on commit d2d533d

Please sign in to comment.