fix many problems

This commit is contained in:
lllyasviel
2024-01-29 09:28:38 -08:00
parent dcdc80810e
commit 7b14cb3f9f
7 changed files with 208 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
import time
import torch
import contextlib
from ldm_patched.modules import model_management
@@ -48,14 +49,14 @@ def automatic_memory_management():
torch.nn.Module.__init__ = original_init
torch.nn.Module.to = original_to
count = 0
for module in set(module_list):
module_params = getattr(module, '_parameters', [])
if len(module_params) > 0:
module.cpu()
count += 1
start = time.perf_counter()
module_list = set(module_list)
for module in module_list:
module.cpu()
print(f'Automatic Memory Management: {count} Modules.')
model_management.soft_empty_cache()
end = time.perf_counter()
print(f'Automatic Memory Management: {len(module_list)} Modules in {(end - start)%.3} seconds.')
return