fix memory lack error

This commit is contained in:
david 2024-08-06 16:33:47 +08:00
parent 66ccde3bd4
commit 03d548fb36
2 changed files with 4 additions and 2 deletions

View File

@ -45,6 +45,8 @@ class ModelCache:
item['sd'] = (keys, values) item['sd'] = (keys, values)
def cache_clip(self, key, clip_key, clip): def cache_clip(self, key, clip_key, clip):
if not self._cache_state:
return
item = self._get_item(key) item = self._get_item(key)
item[clip_key] = clip item[clip_key] = clip

View File

@ -503,11 +503,11 @@ def cleanup_models(keep_clone_weights_loaded=False):
to_delete = [] to_delete = []
for i in range(len(current_loaded_models)): for i in range(len(current_loaded_models)):
if sys.getrefcount(current_loaded_models[i].model) <= 2: if sys.getrefcount(current_loaded_models[i].model) <= 3:
if not keep_clone_weights_loaded: if not keep_clone_weights_loaded:
to_delete = [i] + to_delete to_delete = [i] + to_delete
# TODO: find a less fragile way to do this. # TODO: find a less fragile way to do this.
elif sys.getrefcount(current_loaded_models[i].real_model) <= 3: # references from .real_model + the .model elif sys.getrefcount(current_loaded_models[i].real_model) <= 4: # references from .real_model + the .model
to_delete = [i] + to_delete to_delete = [i] + to_delete
for i in to_delete: for i in to_delete: