Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions comfy/sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ def generate(self, tokens, do_sample=True, max_length=256, temperature=1.0, top_
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
Expand Down Expand Up @@ -1251,6 +1254,8 @@ def temporal_compression_decode(self):
except:
return None

def is_dynamic(self):
return self.patcher.is_dynamic()

class StyleModel:
def __init__(self, model, device="cpu"):
Expand Down
21 changes: 20 additions & 1 deletion comfy_execution/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,21 @@ async def ensure_subcache_for(self, node_id, children_ids):

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):
Expand Down Expand Up @@ -533,7 +548,11 @@ def ram_release(self, target, free_active=False):
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):
Expand Down
Loading