Delete all torch tensors before loading model
This commit is contained in:
parent
f127918114
commit
53034ee533
|
@ -1528,6 +1528,14 @@ def load_model(use_gpu=True, gpu_layers=None, disk_layers=None, initial_load=Fal
|
||||||
model = None
|
model = None
|
||||||
generator = None
|
generator = None
|
||||||
model_config = 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:
|
try:
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in New Issue