Skip to content

vllm_omni.diffusion.models.soulx_singer.modules.note_transcription

BackboneNet

Bases: Module

hidden_size instance-attribute

hidden_size = hparams['hidden_size']

net instance-attribute

net = Unet(
    hidden_size,
    down_layers=len(updown_rates),
    mid_layers=hparams.get("bkb_layers", 12),
    up_layers=len(updown_rates),
    kernel_size=3,
    updown_rates=updown_rates,
    channel_multiples=channel_multiples,
    is_btc=True,
    constant_channels=False,
    mid_net=None,
    use_skip_layer=hparams.get("unet_skip_layer", False),
)

forward

forward(x)

ConformerLayers

Bases: Module

encoder_layers instance-attribute

encoder_layers = nn.ModuleList(
    [
        (
            EncoderLayer(
                hidden_size,
                RelPositionMultiHeadedAttention(
                    num_heads, hidden_size, 0.0
                ),
                positionwise_layer(
                    *positionwise_layer_args
                ),
                positionwise_layer(
                    *positionwise_layer_args
                ),
                ConvolutionModule(
                    hidden_size, kernel_size, Swish()
                ),
            )
        )
        for _ in (range(num_layers))
    ]
)

hiddens instance-attribute

hiddens = []

layer_norm instance-attribute

layer_norm = nn.LayerNorm(hidden_size)

layers instance-attribute

layers = nn.ModuleList()

pos_embed instance-attribute

pos_embed = RelPositionalEncoding(hidden_size)

save_hidden instance-attribute

save_hidden = save_hidden

use_last_norm instance-attribute

use_last_norm = use_last_norm

forward

forward(x, padding_mask=None)

:param x: [B, T, H] :param padding_mask: [B, T] :return: [B, T, H]

ConvBlocks

Bases: Module

Decodes the expanded phoneme encoding into spectrograms.

is_btc instance-attribute

is_btc = is_btc

last_norm instance-attribute

last_norm = LayerNorm(hidden_size, dim=1, eps=ln_eps)

post_net1 instance-attribute

post_net1 = nn.Conv1d(
    hidden_size,
    out_dims,
    kernel_size=post_net_kernel,
    padding=post_net_kernel // 2,
)

res_blocks instance-attribute

res_blocks = nn.Sequential(*res_blocks)

forward

forward(
    x: Tensor, nonpadding: Tensor | None = None
) -> Tensor

ConvolutionModule

Bases: Module

activation instance-attribute

activation = activation

depthwise_conv instance-attribute

depthwise_conv = nn.Conv1d(
    channels,
    channels,
    kernel_size=kernel_size,
    padding=(kernel_size - 1) // 2,
    groups=channels,
    bias=bias,
)

norm instance-attribute

norm = nn.BatchNorm1d(channels)

pointwise_conv1 instance-attribute

pointwise_conv1 = nn.Conv1d(
    channels, 2 * channels, kernel_size=1, bias=bias
)

pointwise_conv2 instance-attribute

pointwise_conv2 = nn.Conv1d(
    channels, channels, kernel_size=1, bias=bias
)

forward

forward(x)

EncoderLayer

Bases: Module

A single encoder layer: optional macaron FFN, self-attn, conv, FFN, norms. Args: size (int): Input dimension. self_attn (nn.Module): Self-attention module. feed_forward (nn.Module): Standard feed-forward network. feed_forward_macaron (nn.Module): Optional, second FFN in macaron structure. conv_module (nn.Module): Optional, convolution module. normalize_before (bool): If True, use pre-layer norm. Else, post-layer norm. concat_after (bool): If True, concat attn in/out, else residual.

concat_after instance-attribute

concat_after = concat_after

concat_linear instance-attribute

concat_linear = nn.Linear(2 * size, size)

conv_module instance-attribute

conv_module = conv_module

feed_forward instance-attribute

feed_forward = feed_forward

feed_forward_macaron instance-attribute

feed_forward_macaron = feed_forward_macaron

ff_scale instance-attribute

ff_scale = 0.5 if feed_forward_macaron is not None else 1.0

norm_conv instance-attribute

norm_conv = LayerNorm(size)

norm_ff instance-attribute

norm_ff = LayerNorm(size)

norm_ff_macaron instance-attribute

norm_ff_macaron = (
    LayerNorm(size)
    if feed_forward_macaron is not None
    else None
)

norm_final instance-attribute

norm_final = LayerNorm(size)

norm_mha instance-attribute

norm_mha = LayerNorm(size)

normalize_before instance-attribute

normalize_before = normalize_before

self_attn instance-attribute

self_attn = self_attn

size instance-attribute

size = size

forward

forward(x_input, mask, cache=None) -> tuple

Forward pass for the encoder layer.

Parameters:

Name Type Description Default
x_input Tensor or Tuple

Input tensor of shape (batch, time, size) or tuple (x, pos_emb) where pos_emb is the positional embedding.

required
mask Tensor

Mask tensor of shape (batch, time) or (batch, 1, time).

required
cache Tensor

Input cache for streaming (can be None).

None

Returns:

Type Description
tuple

Tuple[Tensor, Tensor]: (outputs, mask), where outputs either includes pos_emb or not, depending on input.

LambdaLayer

Bases: Module

lambd instance-attribute

lambd = lambd

forward

forward(x)

LayerNorm

Bases: LayerNorm

dim instance-attribute

dim = dim

forward

forward(x)

MultiHeadedAttention

Bases: Module

Multi-Head Attention layer. Args: n_head (int): The number of heads. n_feat (int): The number of features. dropout_rate (float): Dropout rate.

attn instance-attribute

attn = None

d_k instance-attribute

d_k = n_feat // n_head

dropout instance-attribute

dropout = nn.Dropout(p=dropout_rate)

dropout_rate instance-attribute

dropout_rate = dropout_rate

flash instance-attribute

flash = flash

h instance-attribute

h = n_head

linear_k instance-attribute

linear_k = nn.Linear(n_feat, n_feat)

linear_out instance-attribute

linear_out = nn.Linear(n_feat, n_feat)

linear_q instance-attribute

linear_q = nn.Linear(n_feat, n_feat)

linear_v instance-attribute

linear_v = nn.Linear(n_feat, n_feat)

forward

forward(query, key, value, mask)

Compute scaled dot product attention. Args: query (torch.Tensor): Query tensor (#batch, time1, size). key (torch.Tensor): Key tensor (#batch, time2, size). value (torch.Tensor): Value tensor (#batch, time2, size). mask (torch.Tensor): Mask tensor (#batch, 1, time2) or (#batch, time1, time2). Returns: torch.Tensor: Output tensor (#batch, time1, d_model).

forward_attention

forward_attention(value, scores, mask)

Compute attention context vector. Args: value (torch.Tensor): Transformed value (#batch, n_head, time2, d_k). scores (torch.Tensor): Attention score (#batch, n_head, time1, time2). mask (torch.Tensor): Mask (#batch, 1, time2) or (#batch, time1, time2). Returns: torch.Tensor: Transformed value (#batch, time1, d_model) weighted by the attention score (#batch, time1, time2).

forward_qkv

forward_qkv(query, key, value)

Transform query, key and value. Args: query (torch.Tensor): Query tensor (#batch, time1, size). key (torch.Tensor): Key tensor (#batch, time2, size). value (torch.Tensor): Value tensor (#batch, time2, size). Returns: torch.Tensor: Transformed query tensor (#batch, n_head, time1, d_k). torch.Tensor: Transformed key tensor (#batch, n_head, time2, d_k). torch.Tensor: Transformed value tensor (#batch, n_head, time2, d_k).

MultiLayeredConv1d

Bases: Module

Multi-layered Conv1d that replaces feed-forward in Transformer block.

Reference

FastSpeech: Fast, Robust and Controllable Text to Speech https://arxiv.org/pdf/1905.09263.pdf

w_1 instance-attribute

w_1 = nn.Conv1d(
    in_chans, hidden_chans, kernel_size, padding=padding
)

w_2 instance-attribute

w_2 = nn.Conv1d(
    hidden_chans, in_chans, kernel_size, padding=padding
)

forward

forward(x)

Parameters:

Name Type Description Default
x Tensor

(batch, time, in_chans)

required

Returns: torch.Tensor: (batch, time, in_chans)

Permute

Bases: Module

args instance-attribute

args = args

forward

forward(x)

PositionalEncoding

Bases: Module

Positional encoding. Args: d_model (int): Embedding dimension. max_len (int): Maximum input length. reverse (bool): Whether to reverse the input position.

d_model instance-attribute

d_model = d_model

pe instance-attribute

pe = None

reverse instance-attribute

reverse = reverse

xscale instance-attribute

xscale = math.sqrt(self.d_model)

extend_pe

extend_pe(x)

Reset the positional encodings.

forward

forward(x: Tensor)

Add positional encoding. Args: x (torch.Tensor): Input tensor (batch, time, *). Returns: torch.Tensor: Encoded tensor (batch, time, *).

RelPositionMultiHeadedAttention

Bases: MultiHeadedAttention

Multi-Head Attention layer with relative position encoding. Paper: https://arxiv.org/abs/1901.02860 Args: n_head (int): The number of heads. n_feat (int): The number of features. dropout_rate (float): Dropout rate.

linear_pos instance-attribute

linear_pos = nn.Linear(n_feat, n_feat, bias=False)

pos_bias_u instance-attribute

pos_bias_u = nn.Parameter(torch.Tensor(self.h, self.d_k))

pos_bias_v instance-attribute

pos_bias_v = nn.Parameter(torch.Tensor(self.h, self.d_k))

forward

forward(query, key, value, pos_emb, mask)

Compute 'Scaled Dot Product Attention' with rel. positional encoding. Args: query (torch.Tensor): Query tensor (#batch, time1, size). key (torch.Tensor): Key tensor (#batch, time2, size). value (torch.Tensor): Value tensor (#batch, time2, size). pos_emb (torch.Tensor): Positional embedding tensor (#batch, time2, size). mask (torch.Tensor): Mask tensor (#batch, 1, time2) or (#batch, time1, time2). Returns: torch.Tensor: Output tensor (#batch, time1, d_model).

rel_shift

rel_shift(x, zero_triu=False)

Compute relative positinal encoding. Args: x (torch.Tensor): Input tensor (batch, time, size). zero_triu (bool): If true, return the lower triangular part of the matrix. Returns: torch.Tensor: Output tensor.

RelPositionalEncoding

Bases: PositionalEncoding

Relative positional encoding module. See : Appendix B in https://arxiv.org/abs/1901.02860 Args: d_model (int): Embedding dimension. max_len (int): Maximum input length.

forward

forward(x)

Compute positional encoding. Args: x (torch.Tensor): Input tensor (batch, time, *). Returns: torch.Tensor: Encoded tensor (batch, time, *). torch.Tensor: Positional embedding tensor (1, time, *).

Reshape

Bases: Module

shape instance-attribute

shape = args

forward

forward(x)

ResidualBlock

Bases: Module

Implements a residual block pattern: [Norm] → [Conv1d] → [Scale] → [Activation] → [Conv1d] repeated n times, each as a residual unit.

blocks instance-attribute

blocks = nn.ModuleList(
    [
        (
            nn.Sequential(
                LayerNorm(channels, dim=1, eps=ln_eps),
                nn.Conv1d(
                    channels,
                    c_multiple * channels,
                    kernel_size,
                    dilation=dilation,
                    padding=dilation
                    * (kernel_size - 1)
                    // 2,
                ),
                LambdaLayer(
                    lambda x: x * kernel_size**-0.5
                ),
                nn.LeakyReLU(),
                nn.Conv1d(
                    c_multiple * channels,
                    channels,
                    kernel_size=1,
                    dilation=dilation,
                ),
            )
        )
        for _ in (range(n))
    ]
)

forward

forward(x: Tensor) -> Tensor

Swish

Bases: Module

Swish activation function.

forward

forward(x)

Unet

Bases: Module

down instance-attribute

down = UnetDown(
    hidden_size,
    down_layers,
    kernel_size,
    updown_rates,
    channel_multiples,
    is_btc,
    constant_channels,
)

mid instance-attribute

mid = UnetMid(
    hidden_size,
    kernel_size,
    mid_layers,
    in_dims=down_out_dims,
    out_dims=down_out_dims,
    is_btc=is_btc,
    net=mid_net,
)

up instance-attribute

up = UnetUp(
    hidden_size,
    up_layers,
    kernel_size,
    updown_rates,
    channel_multiples,
    is_btc,
    constant_channels,
    use_skip_layer,
    skip_scale,
)

forward

forward(x, mid_cond=None, **kwargs)

UnetDown

Bases: Module

downs instance-attribute

downs = nn.ModuleList()

hidden_size instance-attribute

hidden_size = hidden_size

is_btc instance-attribute

is_btc = is_btc

last_norm instance-attribute

last_norm = LayerNorm(out_channels, dim=1, eps=1e-06)

layers instance-attribute

layers = nn.ModuleList()

n_layers instance-attribute

n_layers = n_layers

post_net instance-attribute

post_net = nn.Conv1d(
    out_channels,
    out_channels,
    kernel_size=kernel_size,
    padding=kernel_size // 2,
)

forward

forward(x, **kwargs)

UnetMid

Bases: Module

is_btc instance-attribute

is_btc = is_btc

net instance-attribute

net = net

post instance-attribute

post = nn.Conv1d(
    hidden_size,
    out_dims,
    kernel_size,
    padding=kernel_size // 2,
)

pre instance-attribute

pre = nn.Conv1d(
    in_dims,
    hidden_size,
    kernel_size,
    padding=kernel_size // 2,
)

forward

forward(x, cond=None, **kwargs)

UnetUp

Bases: Module

hidden_size instance-attribute

hidden_size = hidden_size

in_channels_lst instance-attribute

in_channels_lst = (
    (
        np.cumprod([1] + channel_multiples) * hidden_size
    ).astype(int)
    if not constant_channels
    else [hidden_size for _ in (range(self.n_layers + 1))]
)

is_btc instance-attribute

is_btc = is_btc

last_norm instance-attribute

last_norm = LayerNorm(out_channels, dim=1, eps=1e-06)

layers instance-attribute

layers = nn.ModuleList()

n_layers instance-attribute

n_layers = n_layers

out_channels instance-attribute

out_channels = out_channels

post_net instance-attribute

post_net = nn.Conv1d(
    out_channels,
    out_channels,
    kernel_size=kernel_size,
    padding=kernel_size // 2,
)

skip_layers instance-attribute

skip_layers = nn.ModuleList()

skip_scale instance-attribute

skip_scale = skip_scale

ups instance-attribute

ups = nn.ModuleList()

forward

forward(x, skips, **kwargs)

Embedding

Embedding(
    num_embeddings,
    embedding_dim,
    padding_idx=None,
    init_type="normal",
)

Linear

Linear(
    in_features: int,
    out_features: int,
    bias: bool = True,
    init_type: str = "xavier",
)