ttnn.mul_bw
- ttnn.mul_bw(grad_tensor: ComplexTensor or ttnn.Tensor, input_tensor_a: ComplexTensor or ttnn.Tensor, input_tensor_b: ComplexTensor or ttnn.Tensor or Number, *, are_required_outputs: List[bool] = [True, True], memory_config: ttnn.MemoryConfig = None, input_grad: ttnn.Tensor = None, other_grad: ttnn.Tensor = None) List of ttnn.Tensor
-
Performs backward operations for multiply on
input_tensor_a,input_tensor_b, with givengrad_tensor.- Parameters:
-
grad_tensor (ComplexTensor or ttnn.Tensor)the input gradient tensor.
input_tensor_a (ComplexTensor or ttnn.Tensor)the input tensor.
input_tensor_b (ComplexTensor or ttnn.Tensor or Number)the input tensor.
- Keyword Arguments:
-
are_required_outputs (List[bool], optional)List of required outputs. Defaults to [True, True].
memory_config (ttnn.MemoryConfig, optional)Memory configuration for the operation. Defaults to None.
input_grad (ttnn.Tensor, optional)Preallocated output tensor for gradient of input_tensor_a. Defaults to None.
other_grad (ttnn.Tensor, optional)Preallocated output tensor for gradient of input_tensor_b. Defaults to None.
- Returns:
-
List of ttnn.Tensorgradients shaped as their respective operands (PyTorch parity). Preallocated input_grad/other_grad must match input_tensor_a/input_tensor_b shape, not grad_tensor — differs from the pre-#56601 grad-shape contract on broadcast.
Note
Supported dtypes and layouts:
Dtypes
Layouts
BFLOAT16, BFLOAT8_B
TILE, ROW_MAJOR
bfloat8_b/bfloat4_b is only supported on TILE_LAYOUT
Example
# Create gradient and input tensors for multiplication backward grad_tensor = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device ) tensor1 = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16, requires_grad=True), layout=ttnn.TILE_LAYOUT, device=device ) tensor2 = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16, requires_grad=True), layout=ttnn.TILE_LAYOUT, device=device ) # Compute gradients for multiplication operation output = ttnn.mul_bw(grad_tensor, tensor1, tensor2) logger.info(f"Multiplication backward result: {output}") grad_tensor = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16), layout=ttnn.TILE_LAYOUT, device=device ) tensor1 = ttnn.from_torch( torch.tensor([[1, 2], [3, 4]], dtype=torch.bfloat16, requires_grad=True), layout=ttnn.TILE_LAYOUT, device=device ) scalar = 4 output = ttnn.mul_bw(grad_tensor, tensor1, scalar) logger.info(f"Multiplication backward with scalar result: {output}")