vllm_omni.diffusion.models.soulx_singer.modules.note_transcription ¶
BackboneNet ¶
Bases: Module
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),
)
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))
]
)
forward ¶
:param x: [B, T, H] :param padding_mask: [B, T] :return: [B, T, H]
ConvBlocks ¶
Bases: Module
Decodes the expanded phoneme encoding into spectrograms.
post_net1 instance-attribute ¶
post_net1 = nn.Conv1d(
hidden_size,
out_dims,
kernel_size=post_net_kernel,
padding=post_net_kernel // 2,
)
ConvolutionModule ¶
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.
norm_ff_macaron instance-attribute ¶
norm_ff_macaron = (
LayerNorm(size)
if feed_forward_macaron is not None
else None
)
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. |
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.
forward ¶
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 ¶
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 ¶
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
forward ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x | Tensor | (batch, time, in_chans) | required |
Returns: torch.Tensor: (batch, time, in_chans)
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.
forward ¶
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.
forward ¶
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 ¶
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 ¶
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, *).
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))
]
)
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,
)
UnetDown ¶
Bases: Module
post_net instance-attribute ¶
post_net = nn.Conv1d(
out_channels,
out_channels,
kernel_size=kernel_size,
padding=kernel_size // 2,
)
UnetUp ¶
Bases: Module
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))]
)
post_net instance-attribute ¶
post_net = nn.Conv1d(
out_channels,
out_channels,
kernel_size=kernel_size,
padding=kernel_size // 2,
)