ttnn.fill

ttnn.fill(input_tensor: ttnn.Tensor, fill_value: float, *, memory_config: ttnn.MemoryConfig | None = None, output_tensor: ttnn.Tensor | None = None, queue_id: int | None = 0) ttnn.Tensor

Applies fill to input_tensor element-wise with fill_value.

This will create a tensor of same shape and dtype as input reference tensor with fill_value.

\[\mathrm{output\_tensor}_i = \verb|fill|(\mathrm{input\_tensor}_i, \verb|fill_value|)\]
Parameters:
  • input_tensor (ttnn.Tensor) – the input tensor.

  • fill_value (float) – The value to be filled in the output tensor.

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

  • output_tensor (ttnn.Tensor, optional) – preallocated output tensor. Defaults to None.

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

Returns:

ttnn.Tensor – the output tensor.

Note

Supported dtypes, layouts, and ranks:

Dtypes

Layouts

Ranks

BFLOAT16, BFLOAT8_B

TILE

2, 3, 4

Support provided for float32 dtypes in Wormhole_B0. System memory is not supported.

Example

>>> tensor = ttnn.from_torch(torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)
>>> fill_value = 3
>>> output = ttnn.fill(tensor, fill_value)