From 7e48279c6c4c76c7267cfe2ec114f03bd6c054df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:44:27 +0900 Subject: [PATCH] optimize(vc): use np.multiply instead of general `*` --- configs/config.py | 2 +- infer-web.py | 4 ++++ infer/modules/vc/modules.py | 2 +- infer/modules/vc/pipeline.py | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/configs/config.py b/configs/config.py index 50c63f0..75bc145 100644 --- a/configs/config.py +++ b/configs/config.py @@ -32,7 +32,7 @@ version_config_list = [ def singleton_variable(func): def wrapper(*args, **kwargs): - if not wrapper.instance: + if wrapper.instance is None: wrapper.instance = func(*args, **kwargs) return wrapper.instance diff --git a/infer-web.py b/infer-web.py index 034fb92..0a47e07 100644 --- a/infer-web.py +++ b/infer-web.py @@ -6,6 +6,10 @@ now_dir = os.getcwd() sys.path.append(now_dir) load_dotenv() load_dotenv("sha256.env") + +if sys.platform == "darwin": + os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" + from infer.modules.vc import VC from infer.modules.uvr5.modules import uvr from infer.lib.train.process_ckpt import ( diff --git a/infer/modules/vc/modules.py b/infer/modules/vc/modules.py index b67ae64..06769fc 100644 --- a/infer/modules/vc/modules.py +++ b/infer/modules/vc/modules.py @@ -201,7 +201,7 @@ class VC: self.version, protect, f0_file, - ) + ).astype(np.int16) if self.tgt_sr != resample_sr >= 16000: tgt_sr = resample_sr else: diff --git a/infer/modules/vc/pipeline.py b/infer/modules/vc/pipeline.py index 78a542f..b5baf06 100644 --- a/infer/modules/vc/pipeline.py +++ b/infer/modules/vc/pipeline.py @@ -288,7 +288,7 @@ class Pipeline(object): hasp = pitch is not None and pitchf is not None arg = (feats, p_len, pitch, pitchf, sid) if hasp else (feats, p_len, sid) audio1 = (net_g.infer(*arg)[0][0, 0]).data.cpu().float().numpy() - del hasp, arg + del arg del feats, p_len, padding_mask if torch.cuda.is_available(): torch.cuda.empty_cache() @@ -469,7 +469,7 @@ class Pipeline(object): max_int16 = 32768 if audio_max > 1: max_int16 /= audio_max - audio_opt = (audio_opt * max_int16).astype(np.int16) + np.multiply(audio_opt, max_int16, audio_opt) del pitch, pitchf, sid if torch.cuda.is_available(): torch.cuda.empty_cache()