espnet2.tts.prodiff.denoiser.ResidualBlock
espnet2.tts.prodiff.denoiser.ResidualBlock
class espnet2.tts.prodiff.denoiser.ResidualBlock(adim: int, channels: int, dilation: int)
Bases: Module
Residual Block for Diffusion Denoiser.
This class implements a residual block used in the diffusion denoiser architecture. It consists of a convolutional layer, linear projection, and several activation functions, facilitating the transformation of input tensors through skip connections and conditioning inputs.
conv
1D convolutional layer for processing input channels.
- Type: nn.Conv1d
diff_proj
Linear projection for diffusion step.
- Type: nn.Linear
cond_proj
Convolutional layer for conditioning inputs.
- Type: nn.Conv1d
out_proj
Convolutional layer for output processing.
Type: nn.Conv1d
Parameters:
- adim (int) – Size of dimensions.
- channels (int) – Number of channels.
- dilation (int) – Size of dilations.
Returns: Tuple of output tensor and skip connection.
Return type: Union[torch.Tensor, torch.Tensor]
####### Examples
>>> block = ResidualBlock(adim=256, channels=64, dilation=2)
>>> x = torch.randn(1, 64, 100) # Input tensor
>>> condition = torch.randn(1, 256, 100) # Conditioning tensor
>>> step = torch.randn(1, 256) # Diffusion step
>>> output, skip = block(x, condition, step)
>>> print(output.shape, skip.shape)
(torch.Size([1, 64, 100]), torch.Size([1, 128, 100]))
Initialization.
- Parameters:
- adim (int) – Size of dimensions.
- channels (int) – Number of channels.
- dilation (int) – Size of dilations.
forward(x: Tensor, condition: Tensor, step: Tensor) → Tensor
Calculate forward propagation.
This method performs the forward pass of the Residual Block, incorporating the input tensor, conditioning tensor, and the diffusion step tensor. The output consists of a residual and a skip connection.
- Parameters:
- x (torch.Tensor) – Input tensor.
- condition (torch.Tensor) – Conditioning tensor.
- step (torch.Tensor) – Number of diffusion step.
- Returns: A tuple containing: : - Output tensor (residual)
- Skip connection tensor.
- Return type: Union[torch.Tensor, torch.Tensor]
####### Examples
>>> block = ResidualBlock(adim=128, channels=256, dilation=2)
>>> x = torch.randn(32, 256, 100) # Batch of 32, 256 channels, 100 time steps
>>> condition = torch.randn(32, 128, 100) # Conditioning tensor
>>> step = torch.randn(32, 1) # Diffusion step
>>> output, skip = block(x, condition, step)
>>> output.shape
torch.Size([32, 256, 100])
>>> skip.shape
torch.Size([32, 256, 100])