ttnn.std_hw

ttnn.std_hw(input_tensor: ttnn.Tensor, *, memory_config: ttnn.MemoryConfig = None) → ttnn.Tensor

Computes the population standard deviation over the last two dimensions, height (H) and width (W), for every index of the leading dimensions. The standard deviation is calculated as \(\sigma = \sqrt{\mathrm{Var}[X]}\) where the variance is computed over H and W, dividing by the logical H x W, so tile padding is not counted. The output keeps the input’s rank with H and W reduced to 1, e.g. [N, C, 1, 1] for an [N, C, H, W] input and [1, 1] for an [H, W] input.

\[\mathrm{{output\_tensor}}_i = \verb|std_hw|(\mathrm{{input\_tensor}}_i)\]
Parameters:

input_tensor (ttnn.Tensor)the input tensor.

Keyword Arguments:

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

Returns:

ttnn.Tensorthe output tensor.

Note

Supported dtypes and layouts:

Dtypes

Layouts

BFLOAT16

TILE

Example

# Create a 4D tensor
tensor = ttnn.from_torch(torch.randn(1, 2, 64, 64, dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device)

# Compute standard deviation across height and width dimensions
output = ttnn.std_hw(tensor)
logger.info(f"Standard Deviation HW: {output}")