Rate this Page

torch.mm#

torch.mm(input,mat2,out_dtype=None,*,out=None)Tensor#

Performs a matrix multiplication of the matricesinput andmat2.

Ifinput is a(n×m)(n \times m) tensor,mat2 is a(m×p)(m \times p) tensor,out will be a(n×p)(n \times p) tensor.

Note

This function does notbroadcast.For broadcasting matrix products, seetorch.matmul().

Supports strided and sparse 2-D tensors as inputs, autograd withrespect to strided inputs.

This operation has support for arguments withsparse layouts.Ifout is provided its layout will be used. Otherwise, the resultlayout will be deduced from that ofinput.

Warning

Sparse support is a beta feature and some layout(s)/dtype/device combinations may not be supported,or may not have autograd support. If you notice missing functionality pleaseopen a feature request.

This operator supportsTensorFloat32.

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

Parameters
  • input (Tensor) – the first matrix to be matrix multiplied

  • mat2 (Tensor) – the second matrix to be matrix 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

out (Tensor,optional) – the output tensor.

Example:

>>>mat1=torch.randn(2,3)>>>mat2=torch.randn(3,3)>>>torch.mm(mat1,mat2)tensor([[ 0.4851,  0.5037, -0.3633],        [-0.0760, -3.6705,  2.4784]])