快捷方式

torch.baddbmm

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

執行 batch1batch2 中矩陣的批次矩陣乘法。結果中新增 input

batch1batch2 必須是 3-D 張量,且每個張量包含相同數量的矩陣。

如果 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 輸入時,此模組在反向傳播時會使用 不同的精度

引數
  • input (Tensor) – 要新增的張量

  • batch1 (Tensor) – 要相乘的第一批矩陣

  • batch2 (Tensor) – 要相乘的第二批矩陣

關鍵字引數
  • beta (Number, optional) – input 的乘數 (β\beta)

  • alpha (Number, optional) – batch1@batch2\text{batch1} \mathbin{@} \text{batch2} 的乘數 (α\alpha)

  • out (Tensor, optional) – 輸出張量。

示例

>>> 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])

© 版權所有 PyTorch 貢獻者。

使用 Sphinx 構建,主題由 Read the Docs 提供。

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢資源並獲得問題解答

檢視資源