Merge pull request #160 from VE-FORBRYDERNE/gc

Delete all torch tensors before loading model
This commit is contained in:
henk717 2022-06-22 18:38:21 +02:00 committed by GitHub
commit 3de22f2b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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: