fix: resolve GPU memory leak in webui_svc

This commit is contained in:
jlqian98
2026-03-16 14:59:04 +08:00
parent a925a3fb50
commit 5c45496542
+7 -1
View File
@@ -1,6 +1,7 @@
import random import random
import sys import sys
import traceback import traceback
import gc
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import Literal from typing import Literal
@@ -165,6 +166,9 @@ class AppState:
vocal_f0 = save_path / "vocal_f0.npy" vocal_f0 = save_path / "vocal_f0.npy"
if not vocal_wav.exists() or not vocal_f0.exists(): if not vocal_wav.exists() or not vocal_f0.exists():
return False, f"preprocess output missing: {vocal_wav} or {vocal_f0}", None, None return False, f"preprocess output missing: {vocal_wav} or {vocal_f0}", None, None
gc.collect()
if torch.cuda.is_available():
torch.cuda.empty_cache()
return True, "ok", vocal_wav, vocal_f0 return True, "ok", vocal_wav, vocal_f0
except Exception as e: except Exception as e:
return False, f"preprocess failed: {e}", None, None return False, f"preprocess failed: {e}", None, None
@@ -241,7 +245,9 @@ class AppState:
mixed_path = save_dir / "generated_mixed.wav" mixed_path = save_dir / "generated_mixed.wav"
sf.write(str(mixed_path), mixed, mix_sr) sf.write(str(mixed_path), mixed, mix_sr)
generated = mixed_path generated = mixed_path
gc.collect()
if torch.cuda.is_available():
torch.cuda.empty_cache()
return True, "svc inference done", generated return True, "svc inference done", generated
except Exception as e: except Exception as e:
return False, f"svc inference failed: {e}", None return False, f"svc inference failed: {e}", None