mirror of
https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-06-15 07:50:39 +08:00
chore(format): run black on dev (#9)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
96604e8175
commit
44725ddd2c
@@ -9,7 +9,13 @@ from torch.nn import functional as F
|
|||||||
from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm
|
from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm
|
||||||
from infer.lib.infer_pack import modules
|
from infer.lib.infer_pack import modules
|
||||||
|
|
||||||
from rvc.utils import get_padding, call_weight_data_normal_if_Conv, sequence_mask, slice_on_last_dim, rand_slice_segments_on_last_dim
|
from rvc.utils import (
|
||||||
|
get_padding,
|
||||||
|
call_weight_data_normal_if_Conv,
|
||||||
|
sequence_mask,
|
||||||
|
slice_on_last_dim,
|
||||||
|
rand_slice_segments_on_last_dim,
|
||||||
|
)
|
||||||
from rvc.encoders import TextEncoder
|
from rvc.encoders import TextEncoder
|
||||||
|
|
||||||
has_xpu = bool(hasattr(torch, "xpu") and torch.xpu.is_available())
|
has_xpu = bool(hasattr(torch, "xpu") and torch.xpu.is_available())
|
||||||
@@ -120,7 +126,8 @@ class PosteriorEncoder(nn.Module):
|
|||||||
self, x: torch.Tensor, x_lengths: torch.Tensor, g: Optional[torch.Tensor] = None
|
self, x: torch.Tensor, x_lengths: torch.Tensor, g: Optional[torch.Tensor] = None
|
||||||
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
|
||||||
x_mask = torch.unsqueeze(
|
x_mask = torch.unsqueeze(
|
||||||
sequence_mask(x_lengths, x.size(2)), 1,
|
sequence_mask(x_lengths, x.size(2)),
|
||||||
|
1,
|
||||||
).to(x.dtype)
|
).to(x.dtype)
|
||||||
x = self.pre(x) * x_mask
|
x = self.pre(x) * x_mask
|
||||||
x = self.enc(x, x_mask, g=g)
|
x = self.enc(x, x_mask, g=g)
|
||||||
@@ -688,7 +695,9 @@ class SynthesizerTrnMs256NSFsid(nn.Module):
|
|||||||
m_p, logs_p, x_mask = self.enc_p(phone, pitch, phone_lengths)
|
m_p, logs_p, x_mask = self.enc_p(phone, pitch, phone_lengths)
|
||||||
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
||||||
z_p = self.flow(z, y_mask, g=g)
|
z_p = self.flow(z, y_mask, g=g)
|
||||||
z_slice, ids_slice = rand_slice_segments_on_last_dim(z, y_lengths, self.segment_size)
|
z_slice, ids_slice = rand_slice_segments_on_last_dim(
|
||||||
|
z, y_lengths, self.segment_size
|
||||||
|
)
|
||||||
# print(-1,pitchf.shape,ids_slice,self.segment_size,self.hop_length,self.segment_size//self.hop_length)
|
# print(-1,pitchf.shape,ids_slice,self.segment_size,self.hop_length,self.segment_size//self.hop_length)
|
||||||
pitchf = slice_on_last_dim(pitchf, ids_slice, self.segment_size)
|
pitchf = slice_on_last_dim(pitchf, ids_slice, self.segment_size)
|
||||||
# print(-2,pitchf.shape,z_slice.shape)
|
# print(-2,pitchf.shape,z_slice.shape)
|
||||||
@@ -906,7 +915,9 @@ class SynthesizerTrnMs256NSFsid_nono(nn.Module):
|
|||||||
m_p, logs_p, x_mask = self.enc_p(phone, None, phone_lengths)
|
m_p, logs_p, x_mask = self.enc_p(phone, None, phone_lengths)
|
||||||
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
||||||
z_p = self.flow(z, y_mask, g=g)
|
z_p = self.flow(z, y_mask, g=g)
|
||||||
z_slice, ids_slice = rand_slice_segments_on_last_dim(z, y_lengths, self.segment_size)
|
z_slice, ids_slice = rand_slice_segments_on_last_dim(
|
||||||
|
z, y_lengths, self.segment_size
|
||||||
|
)
|
||||||
o = self.dec(z_slice, g=g)
|
o = self.dec(z_slice, g=g)
|
||||||
return o, ids_slice, x_mask, y_mask, (z, z_p, m_p, logs_p, m_q, logs_q)
|
return o, ids_slice, x_mask, y_mask, (z, z_p, m_p, logs_p, m_q, logs_q)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,11 @@ from torch.nn import Conv1d
|
|||||||
from torch.nn import functional as F
|
from torch.nn import functional as F
|
||||||
from torch.nn.utils import remove_weight_norm, weight_norm
|
from torch.nn.utils import remove_weight_norm, weight_norm
|
||||||
|
|
||||||
from rvc.utils import get_padding, call_weight_data_normal_if_Conv, activate_add_tanh_sigmoid_multiply
|
from rvc.utils import (
|
||||||
|
get_padding,
|
||||||
|
call_weight_data_normal_if_Conv,
|
||||||
|
activate_add_tanh_sigmoid_multiply,
|
||||||
|
)
|
||||||
from rvc.transforms import piecewise_rational_quadratic_transform
|
from rvc.transforms import piecewise_rational_quadratic_transform
|
||||||
from rvc.norms import LayerNorm
|
from rvc.norms import LayerNorm
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,10 @@ class MultiHeadAttention(nn.Module):
|
|||||||
"""
|
"""
|
||||||
batch, heads, length, _ = x.size()
|
batch, heads, length, _ = x.size()
|
||||||
# Concat columns of pad to shift from relative to absolute indexing.
|
# Concat columns of pad to shift from relative to absolute indexing.
|
||||||
x = F.pad(x, [0, 1, 0, 0, 0, 0, 0, 0], )
|
x = F.pad(
|
||||||
|
x,
|
||||||
|
[0, 1, 0, 0, 0, 0, 0, 0],
|
||||||
|
)
|
||||||
|
|
||||||
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
||||||
x_flat = x.view([batch, heads, length * 2 * length])
|
x_flat = x.view([batch, heads, length * 2 * length])
|
||||||
|
|||||||
@@ -146,7 +146,8 @@ class TextEncoder(nn.Module):
|
|||||||
x = self.lrelu(x)
|
x = self.lrelu(x)
|
||||||
x = torch.transpose(x, 1, -1) # [b, h, t]
|
x = torch.transpose(x, 1, -1) # [b, h, t]
|
||||||
x_mask = torch.unsqueeze(
|
x_mask = torch.unsqueeze(
|
||||||
sequence_mask(lengths, x.size(2)), 1,
|
sequence_mask(lengths, x.size(2)),
|
||||||
|
1,
|
||||||
).to(x.dtype)
|
).to(x.dtype)
|
||||||
x = self.encoder(x * x_mask, x_mask)
|
x = self.encoder(x * x_mask, x_mask)
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -66,13 +66,15 @@ def sequence_mask(
|
|||||||
|
|
||||||
|
|
||||||
def total_grad_norm(
|
def total_grad_norm(
|
||||||
parameters: Iterator[torch.nn.Parameter], norm_type: float=2.0,
|
parameters: Iterator[torch.nn.Parameter],
|
||||||
|
norm_type: float = 2.0,
|
||||||
) -> float:
|
) -> float:
|
||||||
norm_type = float(norm_type)
|
norm_type = float(norm_type)
|
||||||
total_norm = 0.0
|
total_norm = 0.0
|
||||||
|
|
||||||
for p in parameters:
|
for p in parameters:
|
||||||
if p.grad is None: continue
|
if p.grad is None:
|
||||||
|
continue
|
||||||
param_norm = p.grad.data.norm(norm_type)
|
param_norm = p.grad.data.norm(norm_type)
|
||||||
total_norm += float(param_norm.item()) ** norm_type
|
total_norm += float(param_norm.item()) ** norm_type
|
||||||
total_norm = total_norm ** (1.0 / norm_type)
|
total_norm = total_norm ** (1.0 / norm_type)
|
||||||
|
|||||||
Reference in New Issue
Block a user