Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
b903d3d3
You need to sign in or sign up before continuing.
Commit
b903d3d3
authored
Jun 08, 2022
by
patil-suraj
Browse files
fix einsum
parent
a9374a02
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
src/diffusers/models/unet_ldm.py
src/diffusers/models/unet_ldm.py
+3
-3
No files found.
src/diffusers/models/unet_ldm.py
View file @
b903d3d3
...
@@ -6,7 +6,7 @@ import numpy as np
...
@@ -6,7 +6,7 @@ import numpy as np
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
from
einops
import
repeat
,
rearrange
,
einsum
from
einops
import
repeat
,
rearrange
from
..configuration_utils
import
ConfigMixin
from
..configuration_utils
import
ConfigMixin
from
..modeling_utils
import
ModelMixin
from
..modeling_utils
import
ModelMixin
...
@@ -180,7 +180,7 @@ class CrossAttention(nn.Module):
...
@@ -180,7 +180,7 @@ class CrossAttention(nn.Module):
q
,
k
,
v
=
map
(
lambda
t
:
rearrange
(
t
,
'b n (h d) -> (b h) n d'
,
h
=
h
),
(
q
,
k
,
v
))
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
.
einsum
(
'b i d, b j d -> b i j'
,
q
,
k
)
*
self
.
scale
if
exists
(
mask
):
if
exists
(
mask
):
mask
=
rearrange
(
mask
,
'b ... -> b (...)'
)
mask
=
rearrange
(
mask
,
'b ... -> b (...)'
)
...
@@ -191,7 +191,7 @@ class CrossAttention(nn.Module):
...
@@ -191,7 +191,7 @@ class CrossAttention(nn.Module):
# attention, what we cannot get enough of
# attention, what we cannot get enough of
attn
=
sim
.
softmax
(
dim
=-
1
)
attn
=
sim
.
softmax
(
dim
=-
1
)
out
=
einsum
(
'b i j, b j d -> b i d'
,
attn
,
v
)
out
=
torch
.
einsum
(
'b i j, b j d -> b i d'
,
attn
,
v
)
out
=
rearrange
(
out
,
'(b h) n d -> b n (h d)'
,
h
=
h
)
out
=
rearrange
(
out
,
'(b h) n d -> b n (h d)'
,
h
=
h
)
return
self
.
to_out
(
out
)
return
self
.
to_out
(
out
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment