The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Add a force argument to soft_empty_cache to force a cache empty.
comfyanonymous1938f5c5fe47
diff --git a/comfy/ldm/modules/attention.py b/comfy/ldm/modules/attention.pyindex 8f953d337..34484b288 100644--- a/comfy/ldm/modules/attention.py+++ b/comfy/ldm/modules/attention.py@@ -323,7 +323,7 @@ class CrossAttentionDoggettx(nn.Module):breakexcept 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 = Trueprint("out of memory error, emptying cache and trying again")diff --git a/comfy/ldm/modules/diffusionmodules/model.py b/comfy/ldm/modules/diffusionmodules/model.pyindex 431548483..5f38640c3 100644--- a/comfy/ldm/modules/diffusionmodules/model.py+++ b/comfy/ldm/modules/diffusionmodules/model.py@@ -186,6 +186,7 @@ def slice_attention(q, k, v):del s2breakexcept model_management.OOM_EXCEPTION as e:+ model_management.soft_empty_cache(True)steps *= 2if steps > 128:raise ediff --git a/comfy/model_management.py b/comfy/model_management.pyindex bdbbbd843..b663e8f59 100644--- a/comfy/model_management.py+++ b/comfy/model_management.py@@ -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_stateif 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 cudatorch.cuda.empty_cache()torch.cuda.ipc_collect()