Support unloading vision models

You can also use the built-in "unload after generate", but this gives a bit more control.
This commit is contained in:
SeanScripts
2024-10-04 21:28:03 -07:00
parent 3af5b43920
commit 90f6043f46
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -32,6 +32,16 @@ class UnloadModelNode:
if kwargs.get("model") in loaded_models:
print(" - Model found in memory, unloading...")
loaded_models.remove(kwargs.get("model"))
else:
# Just delete it, I need the VRAM!
model = kwargs.get("model")
if type(model) == dict:
keys = [(key, type(value).__name__) for key, value in model.items()]
for key, model_type in keys:
if key == 'model':
print(f"Unloading model of type {model_type}")
del model[key]
# Emptying the cache after this should free the memory.
model_management.free_memory(1e30, model_management.get_torch_device(), loaded_models)
model_management.soft_empty_cache(True)
try: