Rate this Page

torch.baddbmm#

torch.baddbmm(input,batch1,batch2,out_dtype=None,*,beta=1,alpha=1,out=None)Tensor#

Performs a batch matrix-matrix product of matrices inbatch1andbatch2.input is added to the final result.

batch1 andbatch2 must be 3-D tensors each containing the samenumber of matrices.

Ifbatch1 is a(b×n×m)(b \times n \times m) tensor,batch2 is a(b×m×p)(b \times m \times p) tensor, theninput must bebroadcastable with a(b×n×p)(b \times n \times p) tensor andout will be a(b×n×p)(b \times n \times p) tensor. Bothalpha andbeta mean thesame as the scaling factors used intorch.addbmm().

outi=β inputi+α (batch1i@batch2i)\text{out}_i = \beta\ \text{input}_i + \alpha\ (\text{batch1}_i \mathbin{@} \text{batch2}_i)

Ifbeta is 0, then the content ofinput will be ignored, andnan andinf init will not be propagated.

For inputs of typeFloatTensor orDoubleTensor, argumentsbeta andalpha must be real numbers, otherwise they should be integers.

This operator supportsTensorFloat32.

On certain ROCm devices, when using float16 inputs this module will usedifferent precision for backward.

Parameters
  • input (Tensor) – the tensor to be added

  • batch1 (Tensor) – the first batch of matrices to be multiplied

  • batch2 (Tensor) – the second batch of matrices to be multiplied

  • out_dtype (dtype,optional) – the dtype of the output tensor,Supported only on CUDA and for torch.float32 giventorch.float16/torch.bfloat16 input dtypes

Keyword Arguments

Example:

>>>M=torch.randn(10,3,5)>>>batch1=torch.randn(10,3,4)>>>batch2=torch.randn(10,4,5)>>>torch.baddbmm(M,batch1,batch2).size()torch.Size([10, 3, 5])