mirror of
https://github.com/lllyasviel/stable-diffusion-webui-forge.git
synced 2025-12-28 05:35:00 +00:00
fix/workaround for potential memory leak (#2315)
unload old models, based on reference count <= 2 (in practise only noticed extra copies of JointTextEncoder, never KModel or IntegratedAutoencoderKL) #2281 #2308 and others
This commit is contained in:
parent
98e0adcc78
commit
19a9a78c9b
@ -560,6 +560,11 @@ def unload_model_clones(model):
|
||||
|
||||
|
||||
def free_memory(memory_required, device, keep_loaded=[], free_all=False):
|
||||
# this check fully unloads any 'abandoned' models
|
||||
for i in range(len(current_loaded_models) - 1, -1, -1):
|
||||
if sys.getrefcount(current_loaded_models[i].model) <= 2:
|
||||
current_loaded_models.pop(i).model_unload(avoid_model_moving=True)
|
||||
|
||||
if free_all:
|
||||
memory_required = 1e30
|
||||
print(f"[Unload] Trying to free all memory for {device} with {len(keep_loaded)} models keep loaded ... ", end="")
|
||||
|
||||
@ -450,7 +450,7 @@ def reload_model_weights(sd_model=None, info=None, forced_reload=False):
|
||||
|
||||
def unload_model_weights(sd_model=None, info=None):
|
||||
memory_management.unload_all_models()
|
||||
pass
|
||||
return
|
||||
|
||||
|
||||
def apply_token_merging(sd_model, token_merging_ratio):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user