快捷方式

torch.addbmm

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

執行儲存在 batch1batch2 中的矩陣的批次矩陣-矩陣乘積,並進行簡化的加法步驟(所有矩陣乘法都沿著第一個維度累加)。 input 會被加到最終結果。

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

如果 batch1 是一個 (b×n×m)(b \times n \times m) 張量,batch2 是一個 (b×m×p)(b \times m \times p) 張量,input 必須可以與 broadcastable(n×p)(n \times p) 張量進行廣播,並且 out 將會是一個 (n×p)(n \times p) 張量。

out=β input+α (i=0b1batch1i@batch2i)out = \beta\ \text{input} + \alpha\ (\sum_{i=0}^{b-1} \text{batch1}_i \mathbin{@} \text{batch2}_i)

如果 beta 是 0,那麼 input 將會被忽略,並且其中的 naninf 不會被傳播。

對於 FloatTensorDoubleTensor 類型的輸入,參數 betaalpha 必須是實數,否則它們應該是整數。

此運算子支援 TensorFloat32

在某些 ROCm 裝置上,當使用 float16 輸入時,此模組將對 backward 使用 不同的精度

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

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

關鍵字參數
  • beta (Number, optional) – 用於 input 的乘數 (β\beta) (數字, 可選)

  • input (Tensor) – 要加入的矩陣

  • alpha (Number, optional) – 用於 batch1 @ batch2 的乘數 (α\alpha) (數字, 可選)

  • out (Tensor, optional) – 輸出 tensor。(Tensor, 可選)

範例

>>> M = torch.randn(3, 5)
>>> batch1 = torch.randn(10, 3, 4)
>>> batch2 = torch.randn(10, 4, 5)
>>> torch.addbmm(M, batch1, batch2)
tensor([[  6.6311,   0.0503,   6.9768, -12.0362,  -2.1653],
        [ -4.8185,  -1.4255,  -6.6760,   8.9453,   2.5743],
        [ -3.8202,   4.3691,   1.0943,  -1.1109,   5.4730]])

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並取得問題的解答

檢視資源