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
chenpangpang
ComfyUI
Commits
1c794a21
"git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "f61798749853149c27346122805efb659441de9f"
Commit
1c794a21
authored
Aug 27, 2023
by
comfyanonymous
Browse files
Fallback to slice attention if xformers doesn't support the operation.
parent
d935ba50
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
15 deletions
+7
-15
comfy/ldm/modules/diffusionmodules/model.py
comfy/ldm/modules/diffusionmodules/model.py
+7
-15
No files found.
comfy/ldm/modules/diffusionmodules/model.py
View file @
1c794a21
...
@@ -286,25 +286,17 @@ class MemoryEfficientAttnBlock(nn.Module):
...
@@ -286,25 +286,17 @@ class MemoryEfficientAttnBlock(nn.Module):
# compute attention
# compute attention
B
,
C
,
H
,
W
=
q
.
shape
B
,
C
,
H
,
W
=
q
.
shape
q
,
k
,
v
=
map
(
lambda
x
:
rearrange
(
x
,
'b c h w -> b (h w) c'
),
(
q
,
k
,
v
))
q
,
k
,
v
=
map
(
q
,
k
,
v
=
map
(
lambda
t
:
t
.
unsqueeze
(
3
)
lambda
t
:
t
.
view
(
B
,
C
,
-
1
).
transpose
(
1
,
2
).
contiguous
(),
.
reshape
(
B
,
t
.
shape
[
1
],
1
,
C
)
.
permute
(
0
,
2
,
1
,
3
)
.
reshape
(
B
*
1
,
t
.
shape
[
1
],
C
)
.
contiguous
(),
(
q
,
k
,
v
),
(
q
,
k
,
v
),
)
)
out
=
xformers
.
ops
.
memory_efficient_attention
(
q
,
k
,
v
,
attn_bias
=
None
,
op
=
self
.
attention_op
)
out
=
(
try
:
out
.
unsqueeze
(
0
)
out
=
xformers
.
ops
.
memory_efficient_attention
(
q
,
k
,
v
,
attn_bias
=
None
,
op
=
self
.
attention_op
)
.
reshape
(
B
,
1
,
out
.
shape
[
1
],
C
)
out
=
out
.
transpose
(
1
,
2
).
reshape
(
B
,
C
,
H
,
W
)
.
permute
(
0
,
2
,
1
,
3
)
except
NotImplementedError
as
e
:
.
reshape
(
B
,
out
.
shape
[
1
],
C
)
out
=
slice_attention
(
q
.
view
(
B
,
-
1
,
C
),
k
.
view
(
B
,
-
1
,
C
).
transpose
(
1
,
2
),
v
.
view
(
B
,
-
1
,
C
).
transpose
(
1
,
2
)).
reshape
(
B
,
C
,
H
,
W
)
)
out
=
rearrange
(
out
,
'b (h w) c -> b c h w'
,
b
=
B
,
h
=
H
,
w
=
W
,
c
=
C
)
out
=
self
.
proj_out
(
out
)
out
=
self
.
proj_out
(
out
)
return
x
+
out
return
x
+
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