ttnn.fill_rm

ttnn.fill_rm(N: number, C: number, H: number, W: number, hOnes: number, wOnes: number, any: ttnn.tensor, val_hi: number, val_lo: number, *, memory_config: ttnn.MemoryConfig = None) ttnn.Tensor

Generates an NCHW row-major tensor and fill it with high values up to hOnes, wOnes in each HW tile with the rest padded with high values. So for H=2, W=3, hFill=1, wFill=2 the following tensor will be generated:

+------------> W
| hi hi lo
| lo lo lo
|
v H

H, W are expected to be multiples of 32.

The ‘any’ Tensor arg is only used to pass the device and resulting tensor dtype.

val_hi/lo are expected to be floats.

Argument

Description

Data type

Valid range

Required

N

Batch count of output tensor

int

N > 0

Yes

C

Channel count of output tensor

int

C > 0

Yes

H

Height count of output tensor

int

H > 0

Yes

W

Width count of output tensor

int

W > 0

Yes

hOnes

Height of high values region

int

hOnes <= H

Yes

wOnes

Width of high values region

int

wOnes <= W

Yes

any

Any input tensor with desired device and data types for output tensor

tt_lib.tensor.Tensor

Yes

val_hi

High value to use

float

Yes

val_lo

Low value to use

float

Yes

Parameters:
  • N (number) – Batch count of output tensor.

  • C (number) – Channel count of output tensor.

  • H (number) – Height count of output tensor.

  • W (number) – Width count of output tensor.

  • hOnes (number) – Height of high values region.

  • wOnes (number) – Width of high values region.

  • any (ttnn.tensor) – Any input tensor with desired device and data types for output tensor. value greater than 0

  • val_hi (number) – High value to use.

  • val_lo (number) – Low value to use.

Keyword Arguments:

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

Returns:

ttnn.Tensor – the output tensor.

Example

# Define tensor dimensions
N = 2
C = 3
H = 64
W = 96

# Define fill dimensions
hOnes = 33
wOnes = 31

# Define fill values
val_hi = 1.0
val_lo = 0.0

# Create input tensor
input = torch.zeros((N, C, H, W))
xt = ttnn.Tensor(
    input.reshape(-1).tolist(),
    input.shape,
    ttnn.bfloat16,
    ttnn.TILE_LAYOUT,
).to(device)

# Fill the tensor
output = ttnn.fill_rm(N, C, H, W, hOnes, wOnes, xt, val_hi, val_lo)
logger.info("Filled Tensor Shape:", output.shape)