Merge pull request #160 from VE-FORBRYDERNE/gc
Delete all torch tensors before loading model
This commit is contained in:
commit
3de22f2b27
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue