Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Skip unloading dynamic model patchers in current workflow. (#14799)

comfyanonymous439bd807f880
diff --git a/comfy/sd.py b/comfy/sd.py
index 610c4e2b8..faf3104f3 100644
--- a/comfy/sd.py
+++ b/comfy/sd.py
@@ -468,6 +468,9 @@ class CLIP:
def decode(self, token_ids, skip_special_tokens=True):
return self.tokenizer.decode(token_ids, skip_special_tokens=skip_special_tokens)
+ def is_dynamic(self):
+ return self.patcher.is_dynamic()
+
class VAE:
def __init__(self, sd=None, device=None, config=None, dtype=None, metadata=None):
if 'decoder.up_blocks.0.resnets.0.norm1.weight' in sd.keys(): #diffusers format
@@ -1251,6 +1254,8 @@ class VAE:
except:
return None
+ def is_dynamic(self):
+ return self.patcher.is_dynamic()
class StyleModel:
def __init__(self, model, device="cpu"):
diff --git a/comfy_execution/caching.py b/comfy_execution/caching.py
index ba1e8bc84..ad75a0e50 100644
--- a/comfy_execution/caching.py
+++ b/comfy_execution/caching.py
@@ -503,6 +503,21 @@ RAM_CACHE_DEFAULT_RAM_USAGE = 0.05
RAM_CACHE_OLD_WORKFLOW_OOM_MULTIPLIER = 1.3
+
+def all_outputs_dynamic(outputs):
+ if outputs is None:
+ return False
+
+ for output in outputs:
+ if isinstance(output, (list, tuple)):
+ if not all_outputs_dynamic(output):
+ return False
+ elif not hasattr(output, "is_dynamic") or not output.is_dynamic():
+ return False
+
+ return True
+
+
class RAMPressureCache(LRUCache):
def __init__(self, key_class, enable_providers=False):
@@ -533,7 +548,11 @@ class RAMPressureCache(LRUCache):
for key, cache_entry in self.cache.items():
if not free_active and self.used_generation[key] == self.generation:
continue
- oom_score = RAM_CACHE_OLD_WORKFLOW_OOM_MULTIPLIER ** (self.generation - self.used_generation[key])
+
+ if all_outputs_dynamic(cache_entry.outputs) and self.used_generation[key] == self.generation:
+ continue
+
+ oom_score = RAM_CACHE_OLD_WORKFLOW_OOM_MULTIPLIER ** (self.generation - self.used_generation[key])
ram_usage = RAM_CACHE_DEFAULT_RAM_USAGE
def scan_list_for_ram_usage(outputs):