ttnn.conv_transpose2d

ttnn.conv_transpose2d(input_tensor: ttnn.Tensor, weight_tensor: ttnn.Tensor, device: ttnn.MeshDevice, in_channels: int, out_channels: int, batch_size: int, input_height: int, input_width: int, kernel_size: tuple[int, int], stride: tuple[int, int], padding: tuple[int, int] or tuple[int, int, int, int], dilation: tuple[int, int], groups: int, *, bias_tensor: ttnn.Tensor | None, dtype: DataType | None, conv_config: ttnn.Conv2dConfig | None, compute_config: ttnn.DeviceComputeKernelConfig | None, mirror_kernel: bool | None, return_output_dim: bool | None, return_weights_and_bias: bool | None) The output tensor, output height and width, and the preprocessed weights and bias.

Applies a 2D transposed convolution operator over an input image composed of several input planes.

This module can be seen as the gradient of Conv2d with respect to its input. It is also known as a fractionally-strided convolution or a deconvolution

The input tensor is expected in the following format (N x H x W x C) differs from PyTorch where:

  • N is the batch size

  • H is the height of the input

  • W is the width of the input

  • C is the number of channels in the input

The weight tensor is expected in the following format (C x O / G x K_H x K_W). The bias tensor is optional and expected in the following format (O / G ). Where:

  • C is the number of input channels

  • O is the number of output channels

  • G is the number of groups

  • K_H is the height of the kernel

  • K_W is the width of the kernel

The shape of the output tensor is given by the following equation :

  • H_out = (H_in - 1) * stride[0] - 2 * padding[0] + dilation[0] * (kernel_size[0] - 1) + output_padding[0] + 1

  • W_out = (W_in - 1) * stride[1] - 2 * padding[1] + dilation[1] * (kernel_size[1] - 1) + output_padding[1] + 1

Parameters:
  • input_tensor (ttnn.Tensor) – the input tensor.

  • weight_tensor (ttnn.Tensor) – the weight tensor.

  • device (ttnn.MeshDevice) – the device to use.

  • in_channels (int) – number of input channels.

  • out_channels (int) – number of output channels.

  • batch_size (int) – batch size.

  • input_height (int) – height of the input tensor.

  • input_width (int) – width of the input tensor.

  • kernel_size (tuple[int, int]) – size of the convolving kernel.

  • stride (tuple[int, int]) – stride of the cross-correlation.

  • padding (tuple[int, int] or tuple[int, int, int, int]) – zero-padding added to both sides of the input. [pad_height, pad_width] or [pad_top, pad_bottom, pad_left, pad_right].

  • dilation (tuple[int, int]) – spacing between kernel elements.

  • groups (int) – number of blocked connections from input channels to output channels.

Keyword Arguments:
  • bias_tensor (ttnn.Tensor, optional) – optional bias tensor. Default: None

  • dtype (DataType, optional) – the data type of the output tensor. Default: None (will use the same dtype as input_tensor).

  • conv_config (ttnn.Conv2dConfig, optional) – configuration for convolution. Default: None

  • compute_config (ttnn.DeviceComputeKernelConfig, optional) – configuration for compute kernel. Default: None

  • mirror_kernel (bool, optional) – Determines if the op should mirror the kernel internally. Should be set to True if the kernel has already been mirrored. Default: False

  • return_output_dim (bool, optional) – If true, the op also returns the height and width of the output tensor in [N, H, W, C] format. Default: False

  • return_weights_and_bias (bool, optional) – If true, the op also returns the preprocessed weight and bias on device. Default: False

Returns:

The output tensor, output height and width, and the preprocessed weights and bias.

  • ttnn.Tensor: the output tensor, when return_output_dim = False and return_weights_and_bias = False

  • tuple[ttnn.Tensor, tuple[int, int]]: the output tensor, and its height and width, if return_output_dim = True

  • tuple[ttnn.Tensor, tuple[ttnn.Tensor, ttnn.Tensor]]: the output tensor, and its weights and biases, if return_weights_and_bias = True

  • tuple[ttnn.Tensor, tuple[int, int], tuple[ttnn.Tensor, ttnn.Tensor]]: the output tensor, and its height and width, and its weights and biases, if return_output_dim = True and return_weights_and_bias = True