1
0
mirror of https://github.com/fumiama/Retrieval-based-Voice-Conversion-WebUI.git synced 2026-06-05 09:10:25 +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:
github-actions[bot]
2024-06-07 20:29:03 +09:00
committed by GitHub
parent 96604e8175
commit 44725ddd2c
5 changed files with 31 additions and 10 deletions

View File

@@ -9,7 +9,13 @@ from torch.nn import functional as F
from torch.nn.utils import remove_weight_norm, spectral_norm, weight_norm
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
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
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
x_mask = torch.unsqueeze(
sequence_mask(x_lengths, x.size(2)), 1,
sequence_mask(x_lengths, x.size(2)),
1,
).to(x.dtype)
x = self.pre(x) * x_mask
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)
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_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)
pitchf = slice_on_last_dim(pitchf, ids_slice, self.segment_size)
# 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)
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_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)
return o, ids_slice, x_mask, y_mask, (z, z_p, m_p, logs_p, m_q, logs_q)

View File

@@ -7,7 +7,11 @@ from torch.nn import Conv1d
from torch.nn import functional as F
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.norms import LayerNorm

View File

@@ -173,7 +173,10 @@ class MultiHeadAttention(nn.Module):
"""
batch, heads, length, _ = x.size()
# 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).
x_flat = x.view([batch, heads, length * 2 * length])

View File

@@ -57,7 +57,7 @@ class Encoder(nn.Module):
)
)
self.norm_layers_2.append(LayerNorm(hidden_channels))
def __call__(self, x: torch.Tensor, x_mask: torch.Tensor) -> torch.Tensor:
return super().__call__(x, x_mask)
@@ -146,7 +146,8 @@ class TextEncoder(nn.Module):
x = self.lrelu(x)
x = torch.transpose(x, 1, -1) # [b, h, t]
x_mask = torch.unsqueeze(
sequence_mask(lengths, x.size(2)), 1,
sequence_mask(lengths, x.size(2)),
1,
).to(x.dtype)
x = self.encoder(x * x_mask, x_mask)
"""

View File

@@ -66,13 +66,15 @@ def sequence_mask(
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:
norm_type = float(norm_type)
total_norm = 0.0
for p in parameters:
if p.grad is None: continue
if p.grad is None:
continue
param_norm = p.grad.data.norm(norm_type)
total_norm += float(param_norm.item()) ** norm_type
total_norm = total_norm ** (1.0 / norm_type)