Merge pull request #4 from comfyanonymous/master

Fix bug when model cannot be partially unloaded.
This commit is contained in:
John Slegers 2024-08-13 15:08:56 +02:00 committed by GitHub
commit ae7cae919a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -338,8 +338,9 @@ class LoadedModel:
def model_unload(self, memory_to_free=None, unpatch_weights=True):
if memory_to_free is not None:
if memory_to_free < self.model.loaded_size():
self.model.partially_unload(self.model.offload_device, memory_to_free)
return False
freed = self.model.partially_unload(self.model.offload_device, memory_to_free)
if freed >= memory_to_free:
return False
self.model.unpatch_model(self.model.offload_device, unpatch_weights=unpatch_weights)
self.model.model_patches_to(self.model.offload_device)
self.weights_loaded = self.weights_loaded and not unpatch_weights