ttnn.empty_like

ttnn.empty_like = Operation(python_fully_qualified_name='ttnn.empty_like', function=<ttnn._ttnn.operations.creation.empty_like_t object>, preprocess_golden_function_inputs=<function default_preprocess_golden_function_inputs>, golden_function=<function _golden_function>, postprocess_golden_function_outputs=<function default_postprocess_golden_function_outputs>, is_cpp_operation=True, is_experimental=False)

Creates a new tensor with the same shape as the given reference, but without initializing its values. The data type, layout, device, and memory configuration of the new tensor can be specified.

Parameters:

reference (ttnn.Tensor) – The reference tensor whose shape will be used for the output tensor.

Keyword Arguments:
  • dtype (ttnn.DataType, optional) – The desired data type of the output tensor. Defaults to ttnn.bfloat16.

  • layout (ttnn.Layout, optional) – The desired layout of the output tensor. Defaults to ttnn.ROW_MAJOR.

  • device (ttnn.Device | ttnn.MeshDevice, optional) – The device where the tensor will be allocated. Defaults to None.

  • memory_config (ttnn.MemoryConfig, optional) – The memory configuration for the operation. Defaults to ttnn.DRAM_MEMORY_CONFIG.

Returns:

ttnn.Tensor – The output uninitialized tensor with the same shape as the reference tensor.

Example

>>> reference = ttnn.from_torch(torch.randn(2, 3), dtype=ttnn.bfloat16)
>>> tensor = ttnn.empty_like(reference, dtype=ttnn.float32)
>>> print(tensor)
ttnn.Tensor([[[[0.87, 0.45, 0.22], [0.60, 0.75, 0.25]]]], shape=Shape([2, 3]), dtype=DataType::BFLOAT16, layout=Layout::ROW_MAJOR)