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
509c7dfc
"test/vscode:/vscode.git/clone" did not exist on "72ae755ab8951f08949ea53983418ecef02d85bb"
Commit
509c7dfc
authored
Feb 10, 2023
by
comfyanonymous
Browse files
Use real softmax in split op to fix issue with some images.
parent
7e1e193f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
12 deletions
+4
-12
comfy/ldm/modules/diffusionmodules/model.py
comfy/ldm/modules/diffusionmodules/model.py
+4
-12
No files found.
comfy/ldm/modules/diffusionmodules/model.py
View file @
509c7dfc
...
...
@@ -215,32 +215,24 @@ class AttnBlock(nn.Module):
if
mem_required
>
mem_free_total
:
steps
=
2
**
(
math
.
ceil
(
math
.
log
(
mem_required
/
mem_free_total
,
2
)))
first_op_done
=
False
while
True
:
try
:
slice_size
=
q
.
shape
[
1
]
//
steps
if
(
q
.
shape
[
1
]
%
steps
)
==
0
else
q
.
shape
[
1
]
for
i
in
range
(
0
,
q
.
shape
[
1
],
slice_size
):
end
=
i
+
slice_size
s1
=
torch
.
bmm
(
q
[:,
i
:
end
],
k
)
*
scale
first_op_done
=
True
torch
.
exp
(
s1
,
out
=
s1
)
summed
=
torch
.
sum
(
s1
,
dim
=
2
,
keepdim
=
True
)
s1
/=
summed
s2
=
s1
.
permute
(
0
,
2
,
1
)
s2
=
torch
.
nn
.
functional
.
softmax
(
s1
,
dim
=
2
).
permute
(
0
,
2
,
1
)
del
s1
r1
[:,
:,
i
:
end
]
=
torch
.
bmm
(
v
,
s2
)
del
s2
break
except
OOM_EXCEPTION
as
e
:
if
first_op_done
==
False
:
steps
*=
2
if
steps
>
128
:
raise
e
print
(
"out of memory error, increasing steps and trying again"
,
steps
)
else
:
raise
e
h_
=
r1
.
reshape
(
b
,
c
,
h
,
w
)
del
r1
...
...
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