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
1daccf36
Commit
1daccf36
authored
Jan 30, 2023
by
comfyanonymous
Browse files
Run softmax in place if it OOMs.
parent
0d8ad938
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
comfy/ldm/modules/sub_quadratic_attention.py
comfy/ldm/modules/sub_quadratic_attention.py
+11
-2
No files found.
comfy/ldm/modules/sub_quadratic_attention.py
View file @
1daccf36
...
@@ -146,8 +146,17 @@ def _get_attention_scores_no_kv_chunking(
...
@@ -146,8 +146,17 @@ def _get_attention_scores_no_kv_chunking(
alpha
=
scale
,
alpha
=
scale
,
beta
=
0
,
beta
=
0
,
)
)
attn_probs
=
attn_scores
.
softmax
(
dim
=-
1
)
del
attn_scores
try
:
attn_probs
=
attn_scores
.
softmax
(
dim
=-
1
)
del
attn_scores
except
torch
.
cuda
.
OutOfMemoryError
:
print
(
"ran out of memory while running softmax in _get_attention_scores_no_kv_chunking, trying slower in place softmax instead"
)
torch
.
exp
(
attn_scores
,
out
=
attn_scores
)
summed
=
torch
.
sum
(
attn_scores
,
dim
=-
1
,
keepdim
=
True
)
attn_scores
/=
summed
attn_probs
=
attn_scores
hidden_states_slice
=
torch
.
bmm
(
attn_probs
,
value
)
hidden_states_slice
=
torch
.
bmm
(
attn_probs
,
value
)
return
hidden_states_slice
return
hidden_states_slice
...
...
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