ttnn.pad

ttnn.pad(input_tensor: ttnn.Tensor, padding: ttnn.Tensor, output_tensor_shape: shape, input_tensor_start: shape, value: number, *, memory_config: ttnn.MemoryConfig | None = None, queue_id: int | None = 0) List of ttnn.Tensor

Returns a padded tensor, with a specified value at the specified location. If the input tensor is on host, the pad will be performed on host, and if its on device it will be performed on device.

Equivalent pytorch code:

torch.pad(input_tensor, padding, value)
torch.pad(input_tensor, output_tensor_shape, input_tensor_start, value)
Parameters:
  • input_tensor (ttnn.Tensor) – the input tensor.

  • padding (ttnn.Tensor) – padding to apply. Each element of padding should be a tuple of 2 integers, with the first integer specifying the number of values to add before the tensor and the second integer specifying the number of values to add after the tensor. Mutually exclusive to output_tensor_shape and input_tensor_start.

  • output_tensor_shape (shape) – Final shape of padded tensor. This along with input_tensor_start is mutually exclusive from padding.

  • input_tensor_start (shape) – Shape describing where to start padding. This along with output_tensor_shape is mutually exclusive from padding.

  • value (number) – value to pad with.

Keyword Arguments:
  • memory_config (ttnn.MemoryConfig, optional) – Memory configuration for the operation. Defaults to None.

  • queue_id (int, optional) – command queue id. Defaults to 0.

Returns:

List of ttnn.Tensor – the output tensor.