ttnn.addcmul

ttnn.addcmul(input_a: ttnn.Tensor, input_b: ttnn.Tensor, input_c: ttnn.Tensor, *, value: float = 1.0, memory_config: ttnn.MemoryConfig = None, output_tensor: ttnn.Tensor = None) ttnn.Tensor

Multiplies input_tensor_b by a scalar, multiplies the result element-wise by input_tensor_c, and adds it to input_tensor_a. Returns a tensor with the same layout as input_tensor_a.

\[\mathrm{{output\_tensor}}_i = \mathrm{{input\_tensor\_a}}_i + (value * \mathrm{input\_tensor\_b}_i * \mathrm{input\_tensor\_c}_i)\]
Parameters:
  • input_a (ttnn.Tensor) – the first input tensor.

  • input_b (ttnn.Tensor) – the second input tensor.

  • input_c (ttnn.Tensor) – the third input tensor.

Keyword Arguments:
  • value (float, optional) – scalar value used in the operation. Defaults to 1.0.

  • 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 and layouts:

Dtypes

Layouts

FLOAT32, BFLOAT16, BFLOAT8_B, INT32

TILE

Only TTT (tensor-tensor-tensor) variant is supported.

Example

# Create three tensors and a value for the operation
value = 1.0
tensor1 = ttnn.from_torch(
    torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device
)
tensor2 = ttnn.from_torch(
    torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device
)
tensor3 = ttnn.from_torch(
    torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device
)

# Perform the addcmul operation: tensor1 + value * (tensor2 * tensor3)
output = ttnn.addcmul(tensor1, tensor2, tensor3, value=value)
logger.info(f"Addcmul result: {output}")