Try to fix issue with ram cache for some users.

This commit is contained in:
comfyanonymous 2026-07-03 17:18:11 -04:00
parent 1073a74976
commit f5c4bb1f02
2 changed files with 9 additions and 4 deletions

View File

@ -8,6 +8,7 @@ from typing import Sequence, Mapping, Dict
from comfy.model_patcher import ModelPatcher
from comfy_execution.graph import DynamicPrompt
from abc import ABC, abstractmethod
import gc
import nodes
@ -553,11 +554,15 @@ class RAMPressureCache(LRUCache):
oom_score *= ram_usage
#In the case where we have no information on the node ram usage at all,
#break OOM score ties on the last touch timestamp (pure LRU)
bisect.insort(clean_list, (oom_score, self.timestamps[key], key))
bisect.insort(clean_list, (oom_score, self.timestamps[key], ram_usage, key))
while psutil.virtual_memory().available < target and clean_list:
_, _, key = clean_list.pop()
to_free = target - psutil.virtual_memory().available
while to_free > 0 and clean_list:
oom_score, _, ram_usage, key = clean_list.pop()
del self.cache[key]
self.used_generation.pop(key, None)
self.timestamps.pop(key, None)
self.children.pop(key, None)
to_free -= ram_usage
gc.collect()

View File

@ -314,7 +314,7 @@ def prompt_worker(q, server_instance):
cache_ram = 0
cache_ram_inactive = 0
if not args.cache_classic and not args.cache_none and args.cache_lru <= 0:
cache_ram = min(10.0, max(2.0, comfy.model_management.total_ram * 0.10 / 1024.0))
cache_ram = min(10.0, max(1.5, comfy.model_management.total_ram * 0.05 / 1024.0))
cache_ram_inactive = min(96.0, comfy.model_management.total_ram / 1024.0)
if len(args.cache_ram) > 0:
cache_ram = args.cache_ram[0]