From 1a2220bfe43349190c4e800f932df238b0ea9484 Mon Sep 17 00:00:00 2001 From: wataru Date: Mon, 26 Jun 2023 03:13:25 +0900 Subject: [PATCH] test --- .../RVC/inferencer/InferencerManager.py | 1 + .../rvc_models/infer_pack/commons.py | 3 ++- .../RVC/inferencer/voras_beta/commons.py | 21 +++++++------------ .../SoVitsSvc40/models/modules/commons.py | 3 ++- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/server/voice_changer/RVC/inferencer/InferencerManager.py b/server/voice_changer/RVC/inferencer/InferencerManager.py index ef4bea5e..a4201d67 100644 --- a/server/voice_changer/RVC/inferencer/InferencerManager.py +++ b/server/voice_changer/RVC/inferencer/InferencerManager.py @@ -10,6 +10,7 @@ from voice_changer.RVC.inferencer.WebUIInferencer import WebUIInferencer from voice_changer.RVC.inferencer.WebUIInferencerNono import WebUIInferencerNono from voice_changer.RVC.inferencer.VorasInferencebeta import VoRASInferencer + class InferencerManager: currentInferencer: Inferencer | None = None diff --git a/server/voice_changer/RVC/inferencer/rvc_models/infer_pack/commons.py b/server/voice_changer/RVC/inferencer/rvc_models/infer_pack/commons.py index a5ca879b..b058bd32 100644 --- a/server/voice_changer/RVC/inferencer/rvc_models/infer_pack/commons.py +++ b/server/voice_changer/RVC/inferencer/rvc_models/infer_pack/commons.py @@ -94,7 +94,8 @@ def subsequent_mask(length): return mask -@torch.jit.script +# @torch.jit.script +@torch.jit._script_if_tracing def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels): n_channels_int = n_channels[0] in_act = input_a + input_b diff --git a/server/voice_changer/RVC/inferencer/voras_beta/commons.py b/server/voice_changer/RVC/inferencer/voras_beta/commons.py index 79731d2b..16c274aa 100644 --- a/server/voice_changer/RVC/inferencer/voras_beta/commons.py +++ b/server/voice_changer/RVC/inferencer/voras_beta/commons.py @@ -23,9 +23,7 @@ def convert_pad_shape(pad_shape): def kl_divergence(m_p, logs_p, m_q, logs_q): """KL(P||Q)""" kl = (logs_q - logs_p) - 0.5 - kl += ( - 0.5 * (torch.exp(2.0 * logs_p) + ((m_p - m_q) ** 2)) * torch.exp(-2.0 * logs_q) - ) + kl += 0.5 * (torch.exp(2.0 * logs_p) + ((m_p - m_q) ** 2)) * torch.exp(-2.0 * logs_q) return kl @@ -46,7 +44,7 @@ def slice_segments(x, ids_str, segment_size=4): idx_str = ids_str[i] idx_end = idx_str + segment_size r = x[i, :, idx_str:idx_end] - ret[i, :, :r.size(1)] = r + ret[i, :, : r.size(1)] = r return ret @@ -56,7 +54,7 @@ def slice_segments2(x, ids_str, segment_size=4): idx_str = ids_str[i] idx_end = idx_str + segment_size r = x[i, idx_str:idx_end] - ret[i, :r.size(0)] = r + ret[i, : r.size(0)] = r return ret @@ -64,7 +62,7 @@ def rand_slice_segments(x, x_lengths, segment_size=4, ids_str=None): b, d, t = x.size() if ids_str is None: ids_str = torch.zeros([b]).to(device=x.device, dtype=x_lengths.dtype) - ids_str_max = torch.maximum(torch.zeros_like(x_lengths).to(device=x_lengths.device ,dtype=x_lengths.dtype), x_lengths - segment_size + 1 - ids_str) + ids_str_max = torch.maximum(torch.zeros_like(x_lengths).to(device=x_lengths.device, dtype=x_lengths.dtype), x_lengths - segment_size + 1 - ids_str) ids_str += (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long) ret = slice_segments(x, ids_str, segment_size) return ret, ids_str @@ -73,12 +71,8 @@ def rand_slice_segments(x, x_lengths, segment_size=4, ids_str=None): def get_timing_signal_1d(length, channels, min_timescale=1.0, max_timescale=1.0e4): position = torch.arange(length, dtype=torch.float) num_timescales = channels // 2 - log_timescale_increment = math.log(float(max_timescale) / float(min_timescale)) / ( - num_timescales - 1 - ) - inv_timescales = min_timescale * torch.exp( - torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment - ) + log_timescale_increment = math.log(float(max_timescale) / float(min_timescale)) / (num_timescales - 1) + inv_timescales = min_timescale * torch.exp(torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment) scaled_time = position.unsqueeze(0) * inv_timescales.unsqueeze(1) signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], 0) signal = F.pad(signal, [0, 0, 0, channels % 2]) @@ -103,7 +97,8 @@ def subsequent_mask(length): return mask -@torch.jit.script +# @torch.jit.script +@torch.jit._script_if_tracing def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels): n_channels_int = n_channels[0] in_act = input_a + input_b diff --git a/server/voice_changer/SoVitsSvc40/models/modules/commons.py b/server/voice_changer/SoVitsSvc40/models/modules/commons.py index b3e1becf..df0a072f 100644 --- a/server/voice_changer/SoVitsSvc40/models/modules/commons.py +++ b/server/voice_changer/SoVitsSvc40/models/modules/commons.py @@ -121,7 +121,8 @@ def subsequent_mask(length): return mask -@torch.jit.script +#@torch.jit.script +@torch.jit._script_if_tracing def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels): n_channels_int = n_channels[0] in_act = input_a + input_b