Shortcuts

torch.baddbmm

torch.baddbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) 张量

batch1batch2 中的矩阵执行批量矩阵-矩阵乘积。 input 被添加到最终结果中。

batch1batch2 必须是每个都包含相同数量矩阵的3维张量。

如果 batch1 是一个 (b×n×m)(b \times n \times m) 张量,batch2 是一个 (b×m×p)(b \times m \times p) 张量,那么 input 必须与一个 可广播(b×n×p)(b \times n \times p) 张量兼容,并且 out 将是一个 (b×n×p)(b \times n \times p) 张量。alphabeta 的含义与 torch.addbmm() 中使用的缩放因子相同。

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

如果 beta 为 0,则 input 将被忽略,并且其中的 naninf 将不会传播。

对于类型为 FloatTensorDoubleTensor 的输入,参数 betaalpha 必须是实数,否则它们应该是整数。

此操作符支持 TensorFloat32

在某些 ROCm 设备上,当使用 float16 输入时,此模块将在反向传播中使用 不同的精度

Parameters
  • 输入 (张量) – 要被添加的张量

  • batch1 (张量) – 要相乘的第一个矩阵批次

  • batch2 (张量) – 要相乘的第二个矩阵批次

Keyword Arguments
  • beta (数字, 可选) – input 的乘数 (β\beta)

  • alpha (数字, 可选) – batch1@batch2\text{batch1} \mathbin{@} \text{batch2} 的乘数 (α\alpha)

  • 输出 (张量, 可选) – 输出张量。

示例:

>>> 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])
优云智算