ttnn.fill
- ttnn.fill(input_tensor: ttnn.Tensor, fill_value: float / int, *, memory_config: ttnn.MemoryConfig = None, output_tensor: ttnn.Tensor = None) ttnn.Tensor
-
Applies fill to
input_tensorelement-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/int) – 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.
- Returns:
-
ttnn.Tensor – the output tensor.
Note
Supported dtypes, layouts, and ranks:
Dtypes
Layouts
Ranks
BFLOAT16, BFLOAT8_B, FLOAT32, INT32, UINT32
TILE
1, 2, 3, 4, 5, 6
Host memory is not supported.
Example
# Create a tensor with specific values 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 # Fill tensor with a specific value output = ttnn.fill(tensor, fill_value) logger.info(f"Fill: {output}")