ttnn.pad

ttnn.pad() 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. Any rank of tensor is supported, however tensors with rank > 4 can only apply padding to the lower 3 dimensions.

:param * input_tensor: (ttnn.Tensor): the input tensor. :param * padding: (list[Tuple[int,int]]): 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. :param * value: (Union[float,int]): value to pad with.

:keyword * use_multicore: (Optional[bool]) switch to use multicore implementation :keyword * memory_config: (Optional[ttnn.MemoryConfig]): Memory configuration for the operation. Defaults to None.

Returns:

List of ttnn.Tensor – the output tensor.

Example

# Create a tensor to pad
input_tensor = ttnn.rand((1, 1, 4, 4), dtype=ttnn.bfloat16, device=device)

# Pad the tensor with 1 zero on all sides
padded_tensor = ttnn.pad(input_tensor, [(0, 0), (0, 0), (0, 12), (0, 12)], 0)
logger.info("Padded Tensor Shape:", padded_tensor.shape)  # Padded Tensor Shape: Shape([1, 1, 16, 16])