Delete all torch tensors before loading model

This commit is contained in:
vfbd 2022-06-22 12:07:36 -04:00
parent f127918114
commit 53034ee533
1 changed files with 8 additions and 0 deletions

View File

@ -1528,6 +1528,14 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal
model = None
generator = None
model_config = None
for tensor in gc.get_objects():
try:
if torch.is_tensor(tensor):
with torch.no_grad():
tensor.set_(torch.tensor((), device=tensor.device, dtype=tensor.dtype))
except:
pass
gc.collect()
try:
torch.cuda.empty_cache()
except: