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
1938f5c5
Commit
1938f5c5
authored
Sep 04, 2023
by
comfyanonymous
Browse files
Add a force argument to soft_empty_cache to force a cache empty.
parent
7746bdf7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
3 deletions
+4
-3
comfy/ldm/modules/attention.py
comfy/ldm/modules/attention.py
+1
-1
comfy/ldm/modules/diffusionmodules/model.py
comfy/ldm/modules/diffusionmodules/model.py
+1
-0
comfy/model_management.py
comfy/model_management.py
+2
-2
No files found.
comfy/ldm/modules/attention.py
View file @
1938f5c5
...
...
@@ -323,7 +323,7 @@ class CrossAttentionDoggettx(nn.Module):
break
except
model_management
.
OOM_EXCEPTION
as
e
:
if
first_op_done
==
False
:
model_management
.
soft_empty_cache
()
model_management
.
soft_empty_cache
(
True
)
if
cleared_cache
==
False
:
cleared_cache
=
True
print
(
"out of memory error, emptying cache and trying again"
)
...
...
comfy/ldm/modules/diffusionmodules/model.py
View file @
1938f5c5
...
...
@@ -186,6 +186,7 @@ def slice_attention(q, k, v):
del
s2
break
except
model_management
.
OOM_EXCEPTION
as
e
:
model_management
.
soft_empty_cache
(
True
)
steps
*=
2
if
steps
>
128
:
raise
e
...
...
comfy/model_management.py
View file @
1938f5c5
...
...
@@ -639,14 +639,14 @@ def should_use_fp16(device=None, model_params=0, prioritize_performance=True):
return
True
def
soft_empty_cache
():
def
soft_empty_cache
(
force
=
False
):
global
cpu_state
if
cpu_state
==
CPUState
.
MPS
:
torch
.
mps
.
empty_cache
()
elif
is_intel_xpu
():
torch
.
xpu
.
empty_cache
()
elif
torch
.
cuda
.
is_available
():
if
is_nvidia
():
#This seems to make things worse on ROCm so I only do it for cuda
if
force
or
is_nvidia
():
#This seems to make things worse on ROCm so I only do it for cuda
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
ipc_collect
()
...
...
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