From f5c4bb1f027632575ada0ccbe873c34c64dc08ce Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Fri, 3 Jul 2026 17:18:11 -0400 Subject: [PATCH] Try to fix issue with ram cache for some users. --- comfy_execution/caching.py | 11 ++++++++--- main.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/comfy_execution/caching.py b/comfy_execution/caching.py index ba1e8bc84..42f4331a1 100644 --- a/comfy_execution/caching.py +++ b/comfy_execution/caching.py @@ -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() diff --git a/main.py b/main.py index 20ec83c9e..1b9ad8a22 100644 --- a/main.py +++ b/main.py @@ -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]