Solving the cache not being cleared in mps

This commit is contained in:
Ftps 2024-05-03 20:02:04 +09:00
parent fb16ba36b9
commit fba94a0bf7
3 changed files with 11 additions and 0 deletions

View File

@ -105,4 +105,7 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
if torch.cuda.is_available():
torch.cuda.empty_cache()
logger.info("Executed torch.cuda.empty_cache()")
elif torch.backends.mps.is_available():
torch.mps.empty_cache()
logger.info("Executed torch.mps.empty_cache()")
yield "\n".join(infos)

View File

@ -62,6 +62,8 @@ class VC:
) = None
if torch.cuda.is_available():
torch.cuda.empty_cache()
elif torch.backends.mps.is_available():
torch.mps.empty_cache()
###楼下不这么折腾清理不干净
self.if_f0 = self.cpt.get("f0", 1)
self.version = self.cpt.get("version", "v1")
@ -82,6 +84,8 @@ class VC:
del self.net_g, self.cpt
if torch.cuda.is_available():
torch.cuda.empty_cache()
elif torch.backends.mps.is_available():
torch.mps.empty_cache()
return (
{"visible": False, "__type__": "update"},
{

View File

@ -291,6 +291,8 @@ class Pipeline(object):
del feats, p_len, padding_mask
if torch.cuda.is_available():
torch.cuda.empty_cache()
elif torch.backends.mps.is_available():
torch.mps.empty_cache()
t2 = ttime()
times[0] += t1 - t0
times[2] += t2 - t1
@ -472,4 +474,6 @@ class Pipeline(object):
del pitch, pitchf, sid
if torch.cuda.is_available():
torch.cuda.empty_cache()
elif torch.backends.mps.is_available():
torch.mps.empty_cache()
return audio_opt