.. _l-onnx-doc-Gemm: ==== Gemm ==== .. contents:: :local: .. _l-onnx-op-gemm-13: Gemm - 13 ========= **Version** * **name**: `Gemm (GitHub) `_ * **domain**: **main** * **since_version**: **13** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 13**. **Summary** General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 A' = transpose(A) if transA else A B' = transpose(B) if transB else B Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check `Broadcasting in ONNX `_. This operator has **optional** inputs/outputs. See `ONNX `_ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. **Attributes** * **alpha**: Scalar multiplier for the product of input tensors A * B. Default value is ``1.0``. * **beta**: Scalar multiplier for input tensor C. Default value is ``1.0``. * **transA**: Whether A should be transposed Default value is ``0``. * **transB**: Whether B should be transposed Default value is ``0``. **Inputs** Between 2 and 3 inputs. * **A** (heterogeneous) - **T**: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero. * **B** (heterogeneous) - **T**: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero. * **C** (optional, heterogeneous) - **T**: Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N). **Outputs** * **Y** (heterogeneous) - **T**: Output tensor of shape (M, N). **Type Constraints** * **T** in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64) ): Constrain input and output types to float/int tensors. **Examples** **_default_zero_bias** :: node = onnx.helper.make_node("Gemm", inputs=["a", "b", "c"], outputs=["y"]) a = np.random.ranf([3, 5]).astype(np.float32) b = np.random.ranf([5, 4]).astype(np.float32) c = np.zeros([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c) expect(node, inputs=[a, b, c], outputs=[y], name="test_gemm_default_zero_bias") **_default_no_bias** :: node = onnx.helper.make_node("Gemm", inputs=["a", "b"], outputs=["y"]) a = np.random.ranf([2, 10]).astype(np.float32) b = np.random.ranf([10, 3]).astype(np.float32) y = gemm_reference_implementation(a, b) expect(node, inputs=[a, b], outputs=[y], name="test_gemm_default_no_bias") **_default_scalar_bias** :: node = onnx.helper.make_node("Gemm", inputs=["a", "b", "c"], outputs=["y"]) a = np.random.ranf([2, 3]).astype(np.float32) b = np.random.ranf([3, 4]).astype(np.float32) c = np.array(3.14).astype(np.float32) y = gemm_reference_implementation(a, b, c) expect( node, inputs=[a, b, c], outputs=[y], name="test_gemm_default_scalar_bias" ) **_default_single_elem_vector_bias** :: node = onnx.helper.make_node("Gemm", inputs=["a", "b", "c"], outputs=["y"]) a = np.random.ranf([3, 7]).astype(np.float32) b = np.random.ranf([7, 3]).astype(np.float32) c = np.random.ranf([1]).astype(np.float32) y = gemm_reference_implementation(a, b, c) expect( node, inputs=[a, b, c], outputs=[y], name="test_gemm_default_single_elem_vector_bias", ) **_default_vector_bias** :: node = onnx.helper.make_node("Gemm", inputs=["a", "b", "c"], outputs=["y"]) a = np.random.ranf([2, 7]).astype(np.float32) b = np.random.ranf([7, 4]).astype(np.float32) c = np.random.ranf([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c) expect( node, inputs=[a, b, c], outputs=[y], name="test_gemm_default_vector_bias" ) **_default_matrix_bias** :: node = onnx.helper.make_node("Gemm", inputs=["a", "b", "c"], outputs=["y"]) a = np.random.ranf([3, 6]).astype(np.float32) b = np.random.ranf([6, 4]).astype(np.float32) c = np.random.ranf([3, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c) expect( node, inputs=[a, b, c], outputs=[y], name="test_gemm_default_matrix_bias" ) **_transposeA** :: node = onnx.helper.make_node( "Gemm", inputs=["a", "b", "c"], outputs=["y"], transA=1 ) a = np.random.ranf([6, 3]).astype(np.float32) b = np.random.ranf([6, 4]).astype(np.float32) c = np.zeros([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c, transA=1) expect(node, inputs=[a, b, c], outputs=[y], name="test_gemm_transposeA") **_transposeB** :: node = onnx.helper.make_node( "Gemm", inputs=["a", "b", "c"], outputs=["y"], transB=1 ) a = np.random.ranf([3, 6]).astype(np.float32) b = np.random.ranf([4, 6]).astype(np.float32) c = np.zeros([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c, transB=1) expect(node, inputs=[a, b, c], outputs=[y], name="test_gemm_transposeB") **_alpha** :: node = onnx.helper.make_node( "Gemm", inputs=["a", "b", "c"], outputs=["y"], alpha=0.5 ) a = np.random.ranf([3, 5]).astype(np.float32) b = np.random.ranf([5, 4]).astype(np.float32) c = np.zeros([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c, alpha=0.5) expect(node, inputs=[a, b, c], outputs=[y], name="test_gemm_alpha") **_beta** :: node = onnx.helper.make_node( "Gemm", inputs=["a", "b", "c"], outputs=["y"], beta=0.5 ) a = np.random.ranf([2, 7]).astype(np.float32) b = np.random.ranf([7, 4]).astype(np.float32) c = np.random.ranf([1, 4]).astype(np.float32) y = gemm_reference_implementation(a, b, c, beta=0.5) expect(node, inputs=[a, b, c], outputs=[y], name="test_gemm_beta") **_all_attributes** :: node = onnx.helper.make_node( "Gemm", inputs=["a", "b", "c"], outputs=["y"], alpha=0.25, beta=0.35, transA=1, transB=1, ) a = np.random.ranf([4, 3]).astype(np.float32) b = np.random.ranf([5, 4]).astype(np.float32) c = np.random.ranf([1, 5]).astype(np.float32) y = gemm_reference_implementation( a, b, c, transA=1, transB=1, alpha=0.25, beta=0.35 ) expect(node, inputs=[a, b, c], outputs=[y], name="test_gemm_all_attributes") **Differences** .. raw:: html
00General Matrix multiplication:General Matrix multiplication:
11https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3
22
33A' = transpose(A) if transA else AA' = transpose(A) if transA else A
44
55B' = transpose(B) if transB else BB' = transpose(B) if transB else B
66
77Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),
88input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),
99and output tensor Y has shape (M, N). A will be transposed before doing theand output tensor Y has shape (M, N). A will be transposed before doing the
1010computation if attribute transA is non-zero, same for B and transB.computation if attribute transA is non-zero, same for B and transB.
1111This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.
1212This operator has **optional** inputs/outputs. See ONNX _ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.This operator has **optional** inputs/outputs. See ONNX _ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.
1313
1414**Attributes****Attributes**
1515
1616* **alpha**:* **alpha**:
1717 Scalar multiplier for the product of input tensors A * B. Default value is 1.0. Scalar multiplier for the product of input tensors A * B. Default value is 1.0.
1818* **beta**:* **beta**:
1919 Scalar multiplier for input tensor C. Default value is 1.0. Scalar multiplier for input tensor C. Default value is 1.0.
2020* **transA**:* **transA**:
2121 Whether A should be transposed Default value is 0. Whether A should be transposed Default value is 0.
2222* **transB**:* **transB**:
2323 Whether B should be transposed Default value is 0. Whether B should be transposed Default value is 0.
2424
2525**Inputs****Inputs**
2626
2727Between 2 and 3 inputs.Between 2 and 3 inputs.
2828
2929* **A** (heterogeneous) - **T**:* **A** (heterogeneous) - **T**:
3030 Input tensor A. The shape of A should be (M, K) if transA is 0, or Input tensor A. The shape of A should be (M, K) if transA is 0, or
3131 (K, M) if transA is non-zero. (K, M) if transA is non-zero.
3232* **B** (heterogeneous) - **T**:* **B** (heterogeneous) - **T**:
3333 Input tensor B. The shape of B should be (K, N) if transB is 0, or Input tensor B. The shape of B should be (K, N) if transB is 0, or
3434 (N, K) if transB is non-zero. (N, K) if transB is non-zero.
3535* **C** (optional, heterogeneous) - **T**:* **C** (optional, heterogeneous) - **T**:
3636 Optional input tensor C. If not specified, the computation is done Optional input tensor C. If not specified, the computation is done
3737 as if C is a scalar 0. The shape of C should be unidirectional as if C is a scalar 0. The shape of C should be unidirectional
3838 broadcastable to (M, N). broadcastable to (M, N).
3939
4040**Outputs****Outputs**
4141
4242* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
4343 Output tensor of shape (M, N). Output tensor of shape (M, N).
4444
4545**Type Constraints****Type Constraints**
4646
4747* **T** in (* **T** in (
48 tensor(bfloat16),
4849 tensor(double), tensor(double),
4950 tensor(float), tensor(float),
5051 tensor(float16), tensor(float16),
5152 tensor(int32), tensor(int32),
5253 tensor(int64), tensor(int64),
5354 tensor(uint32), tensor(uint32),
5455 tensor(uint64) tensor(uint64)
5556 ): ):
5657 Constrain input and output types to float/int tensors. Constrain input and output types to float/int tensors.
.. _l-onnx-op-gemm-11: Gemm - 11 ========= **Version** * **name**: `Gemm (GitHub) `_ * **domain**: **main** * **since_version**: **11** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 11**. **Summary** General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 A' = transpose(A) if transA else A B' = transpose(B) if transB else B Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check `Broadcasting in ONNX `_. This operator has **optional** inputs/outputs. See `ONNX `_ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted. **Attributes** * **alpha**: Scalar multiplier for the product of input tensors A * B. Default value is ``1.0``. * **beta**: Scalar multiplier for input tensor C. Default value is ``1.0``. * **transA**: Whether A should be transposed Default value is ``0``. * **transB**: Whether B should be transposed Default value is ``0``. **Inputs** Between 2 and 3 inputs. * **A** (heterogeneous) - **T**: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero. * **B** (heterogeneous) - **T**: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero. * **C** (optional, heterogeneous) - **T**: Optional input tensor C. If not specified, the computation is done as if C is a scalar 0. The shape of C should be unidirectional broadcastable to (M, N). **Outputs** * **Y** (heterogeneous) - **T**: Output tensor of shape (M, N). **Type Constraints** * **T** in ( tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64) ): Constrain input and output types to float/int tensors. **Differences** .. raw:: html
00General Matrix multiplication:General Matrix multiplication:
11https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3
22
33A' = transpose(A) if transA else AA' = transpose(A) if transA else A
44
55B' = transpose(B) if transB else BB' = transpose(B) if transB else B
66
77Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),
88input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),
99and output tensor Y has shape (M, N). A will be transposed before doing theand output tensor Y has shape (M, N). A will be transposed before doing the
1010computation if attribute transA is non-zero, same for B and transB.computation if attribute transA is non-zero, same for B and transB.
1111This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.
12This operator has **optional** inputs/outputs. See ONNX _ for more details about the representation of optional arguments. An empty string may be used in the place of an actual argument's name to indicate a missing argument. Trailing optional arguments (those not followed by an argument that is present) may also be simply omitted.
1213
1314**Attributes****Attributes**
1415
1516* **alpha**:* **alpha**:
1617 Scalar multiplier for the product of input tensors A * B. Default value is 1.0. Scalar multiplier for the product of input tensors A * B. Default value is 1.0.
1718* **beta**:* **beta**:
1819 Scalar multiplier for input tensor C. Default value is 1.0. Scalar multiplier for input tensor C. Default value is 1.0.
1920* **transA**:* **transA**:
2021 Whether A should be transposed Default value is 0. Whether A should be transposed Default value is 0.
2122* **transB**:* **transB**:
2223 Whether B should be transposed Default value is 0. Whether B should be transposed Default value is 0.
2324
2425**Inputs****Inputs**
2526
27Between 2 and 3 inputs.
28
2629* **A** (heterogeneous) - **T**:* **A** (heterogeneous) - **T**:
2730 Input tensor A. The shape of A should be (M, K) if transA is 0, or Input tensor A. The shape of A should be (M, K) if transA is 0, or
2831 (K, M) if transA is non-zero. (K, M) if transA is non-zero.
2932* **B** (heterogeneous) - **T**:* **B** (heterogeneous) - **T**:
3033 Input tensor B. The shape of B should be (K, N) if transB is 0, or Input tensor B. The shape of B should be (K, N) if transB is 0, or
3134 (N, K) if transB is non-zero. (N, K) if transB is non-zero.
35* **C** (optional, heterogeneous) - **T**:
3236* **C** (heterogeneous) - **T**: Optional input tensor C. If not specified, the computation is done
3337 Input tensor C. The shape of C should be unidirectional as if C is a scalar 0. The shape of C should be unidirectional
3438 broadcastable to (M, N). broadcastable to (M, N).
3539
3640**Outputs****Outputs**
3741
3842* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
3943 Output tensor of shape (M, N). Output tensor of shape (M, N).
4044
4145**Type Constraints****Type Constraints**
4246
4347* **T** in (* **T** in (
4448 tensor(double), tensor(double),
4549 tensor(float), tensor(float),
4650 tensor(float16), tensor(float16),
4751 tensor(int32), tensor(int32),
4852 tensor(int64), tensor(int64),
4953 tensor(uint32), tensor(uint32),
5054 tensor(uint64) tensor(uint64)
5155 ): ):
5256 Constrain input and output types to float/int tensors. Constrain input and output types to float/int tensors.
.. _l-onnx-op-gemm-9: Gemm - 9 ======== **Version** * **name**: `Gemm (GitHub) `_ * **domain**: **main** * **since_version**: **9** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 9**. **Summary** General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 A' = transpose(A) if transA else A B' = transpose(B) if transB else B Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check `Broadcasting in ONNX `_. **Attributes** * **alpha**: Scalar multiplier for the product of input tensors A * B. Default value is ``1.0``. * **beta**: Scalar multiplier for input tensor C. Default value is ``1.0``. * **transA**: Whether A should be transposed Default value is ``0``. * **transB**: Whether B should be transposed Default value is ``0``. **Inputs** * **A** (heterogeneous) - **T**: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero. * **B** (heterogeneous) - **T**: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero. * **C** (heterogeneous) - **T**: Input tensor C. The shape of C should be unidirectional broadcastable to (M, N). **Outputs** * **Y** (heterogeneous) - **T**: Output tensor of shape (M, N). **Type Constraints** * **T** in ( tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64) ): Constrain input and output types to float/int tensors. **Differences** .. raw:: html
00General Matrix multiplication:General Matrix multiplication:
11https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3
22
33A' = transpose(A) if transA else AA' = transpose(A) if transA else A
44
55B' = transpose(B) if transB else BB' = transpose(B) if transB else B
66
77Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),
88input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),
99and output tensor Y has shape (M, N). A will be transposed before doing theand output tensor Y has shape (M, N). A will be transposed before doing the
1010computation if attribute transA is non-zero, same for B and transB.computation if attribute transA is non-zero, same for B and transB.
1111This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX _.
1212
1313**Attributes****Attributes**
1414
1515* **alpha**:* **alpha**:
1616 Scalar multiplier for the product of input tensors A * B. Default value is 1.0. Scalar multiplier for the product of input tensors A * B. Default value is 1.0.
1717* **beta**:* **beta**:
1818 Scalar multiplier for input tensor C. Default value is 1.0. Scalar multiplier for input tensor C. Default value is 1.0.
1919* **transA**:* **transA**:
2020 Whether A should be transposed Default value is 0. Whether A should be transposed Default value is 0.
2121* **transB**:* **transB**:
2222 Whether B should be transposed Default value is 0. Whether B should be transposed Default value is 0.
2323
2424**Inputs****Inputs**
2525
2626* **A** (heterogeneous) - **T**:* **A** (heterogeneous) - **T**:
2727 Input tensor A. The shape of A should be (M, K) if transA is 0, or Input tensor A. The shape of A should be (M, K) if transA is 0, or
2828 (K, M) if transA is non-zero. (K, M) if transA is non-zero.
2929* **B** (heterogeneous) - **T**:* **B** (heterogeneous) - **T**:
3030 Input tensor B. The shape of B should be (K, N) if transB is 0, or Input tensor B. The shape of B should be (K, N) if transB is 0, or
3131 (N, K) if transB is non-zero. (N, K) if transB is non-zero.
3232* **C** (heterogeneous) - **T**:* **C** (heterogeneous) - **T**:
3333 Input tensor C. The shape of C should be unidirectional Input tensor C. The shape of C should be unidirectional
3434 broadcastable to (M, N). broadcastable to (M, N).
3535
3636**Outputs****Outputs**
3737
3838* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
3939 Output tensor of shape (M, N). Output tensor of shape (M, N).
4040
4141**Type Constraints****Type Constraints**
4242
4343* **T** in (* **T** in (
4444 tensor(double), tensor(double),
4545 tensor(float), tensor(float),
4646 tensor(float16) tensor(float16),
47 tensor(int32),
48 tensor(int64),
49 tensor(uint32),
50 tensor(uint64)
4751 ): ):
4852 Constrain input and output types to float tensors. Constrain input and output types to float/int tensors.
.. _l-onnx-op-gemm-7: Gemm - 7 ======== **Version** * **name**: `Gemm (GitHub) `_ * **domain**: **main** * **since_version**: **7** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 7**. **Summary** General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 A' = transpose(A) if transA else A B' = transpose(B) if transB else B Compute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M), input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N), and output tensor Y has shape (M, N). A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. This operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check `Broadcasting in ONNX `_. **Attributes** * **alpha**: Scalar multiplier for the product of input tensors A * B. Default value is ``1.0``. * **beta**: Scalar multiplier for input tensor C. Default value is ``1.0``. * **transA**: Whether A should be transposed Default value is ``0``. * **transB**: Whether B should be transposed Default value is ``0``. **Inputs** * **A** (heterogeneous) - **T**: Input tensor A. The shape of A should be (M, K) if transA is 0, or (K, M) if transA is non-zero. * **B** (heterogeneous) - **T**: Input tensor B. The shape of B should be (K, N) if transB is 0, or (N, K) if transB is non-zero. * **C** (heterogeneous) - **T**: Input tensor C. The shape of C should be unidirectional broadcastable to (M, N). **Outputs** * **Y** (heterogeneous) - **T**: Output tensor of shape (M, N). **Type Constraints** * **T** in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors. **Differences** .. raw:: html
00General Matrix multiplication:General Matrix multiplication:
11https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3
2
3A' = transpose(A) if transA else A
4
5B' = transpose(B) if transB else B
6
27Compute Y = alpha * A * B + beta * C, where input tensor A hasCompute Y = alpha * A' * B' + beta * C, where input tensor A has shape (M, K) or (K, M),
3dimension (M X K), input tensor B has dimension (K X N), input tensor C and
48output tensor Y have dimension (M X N).input tensor B has shape (K, N) or (N, K), input tensor C is broadcastable to shape (M, N),
9and output tensor Y has shape (M, N). A will be transposed before doing the
510If attribute broadcast is non-zero, input tensor C will be broadcasted to matchcomputation if attribute transA is non-zero, same for B and transB.
611the dimension requirement. A will be transposed before doing the computationThis operator supports **unidirectional broadcasting** (tensor C should be unidirectional broadcastable to tensor A * B); for more details please check Broadcasting in ONNX <https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md>_.
7if attribute transA is non-zero, same for B and transB.
812
913**Attributes****Attributes**
1014
1115* **alpha**:* **alpha**:
1216 Scalar multiplier for the product of input tensors A * B, the Scalar multiplier for the product of input tensors A * B. Default value is 1.0.
13 default value is 1.0. Default value is 1.0.
1417* **beta**:* **beta**:
1518 Scalar multiplier for input tensor C, the default value is 1.0. Default value is 1.0. Scalar multiplier for input tensor C. Default value is 1.0.
16* **broadcast**:
17 Whether C should be broadcasted Default value is 0.
1819* **transA**:* **transA**:
1920 Whether A should be transposed Default value is 0. Whether A should be transposed Default value is 0.
2021* **transB**:* **transB**:
2122 Whether B should be transposed Default value is 0. Whether B should be transposed Default value is 0.
2223
2324**Inputs****Inputs**
2425
2526* **A** (heterogeneous) - **T**:* **A** (heterogeneous) - **T**:
2627 Input tensor A Input tensor A. The shape of A should be (M, K) if transA is 0, or
28 (K, M) if transA is non-zero.
2729* **B** (heterogeneous) - **T**:* **B** (heterogeneous) - **T**:
2830 Input tensor B Input tensor B. The shape of B should be (K, N) if transB is 0, or
31 (N, K) if transB is non-zero.
2932* **C** (heterogeneous) - **T**:* **C** (heterogeneous) - **T**:
3033 Input tensor C Input tensor C. The shape of C should be unidirectional
34 broadcastable to (M, N).
3135
3236**Outputs****Outputs**
3337
3438* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
3539 Output tensor. Output tensor of shape (M, N).
3640
3741**Type Constraints****Type Constraints**
3842
3943* **T** in (* **T** in (
4044 tensor(double), tensor(double),
4145 tensor(float), tensor(float),
4246 tensor(float16) tensor(float16)
4347 ): ):
4448 Constrain input and output types to float tensors. Constrain input and output types to float tensors.
.. _l-onnx-op-gemm-6: Gemm - 6 ======== **Version** * **name**: `Gemm (GitHub) `_ * **domain**: **main** * **since_version**: **6** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: True This version of the operator has been available **since version 6**. **Summary** General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 Compute Y = alpha * A * B + beta * C, where input tensor A has dimension (M X K), input tensor B has dimension (K X N), input tensor C and output tensor Y have dimension (M X N). If attribute broadcast is non-zero, input tensor C will be broadcasted to match the dimension requirement. A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. **Attributes** * **alpha**: Scalar multiplier for the product of input tensors A * B, the default value is 1.0. Default value is ``1.0``. * **beta**: Scalar multiplier for input tensor C, the default value is 1.0. Default value is ``1.0``. * **broadcast**: Whether C should be broadcasted Default value is ``0``. * **transA**: Whether A should be transposed Default value is ``0``. * **transB**: Whether B should be transposed Default value is ``0``. **Inputs** * **A** (heterogeneous) - **T**: Input tensor A * **B** (heterogeneous) - **T**: Input tensor B * **C** (heterogeneous) - **T**: Input tensor C **Outputs** * **Y** (heterogeneous) - **T**: Output tensor. **Type Constraints** * **T** in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors. **Differences** .. raw:: html
00General Matrix multiplication:General Matrix multiplication:
11https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3
22Compute Y = alpha * A * B + beta * C, where input tensor A hasCompute Y = alpha * A * B + beta * C, where input tensor A has
33dimension (M X K), input tensor B has dimension (K X N), input tensor C anddimension (M X K), input tensor B has dimension (K X N), input tensor C and
44output tensor Y have dimension (M X N).output tensor Y have dimension (M X N).
55If attribute broadcast is non-zero, input tensor C will be broadcasted to matchIf attribute broadcast is non-zero, input tensor C will be broadcasted to match
66the dimension requirement. A will be transposed before doing the computationthe dimension requirement. A will be transposed before doing the computation
77if attribute transA is non-zero, same for B and transB.if attribute transA is non-zero, same for B and transB.
88
99**Attributes****Attributes**
1010
1111* **alpha**:* **alpha**:
1212 Scalar multiplier for the product of input tensors A * B, the Scalar multiplier for the product of input tensors A * B, the
1313 default value is 1.0. Default value is 1.0. default value is 1.0. Default value is 1.0.
1414* **beta**:* **beta**:
1515 Scalar multiplier for input tensor C, the default value is 1.0. Default value is 1.0. Scalar multiplier for input tensor C, the default value is 1.0. Default value is 1.0.
1616* **broadcast**:* **broadcast**:
1717 Whether C should be broadcasted Default value is 0. Whether C should be broadcasted Default value is 0.
1818* **transA**:* **transA**:
1919 Whether A should be transposed Default value is 0. Whether A should be transposed Default value is 0.
2020* **transB**:* **transB**:
2121 Whether B should be transposed Default value is 0. Whether B should be transposed Default value is 0.
2222
2323**Inputs****Inputs**
2424
2525* **A** (heterogeneous) - **T**:* **A** (heterogeneous) - **T**:
2626 Input tensor A Input tensor A
2727* **B** (heterogeneous) - **T**:* **B** (heterogeneous) - **T**:
2828 Input tensor B Input tensor B
2929* **C** (heterogeneous) - **T**:* **C** (heterogeneous) - **T**:
3030 Input tensor C, can be inplace. Input tensor C
3131
3232**Outputs****Outputs**
3333
3434* **Y** (heterogeneous) - **T**:* **Y** (heterogeneous) - **T**:
3535 Output tensor. Output tensor.
3636
3737**Type Constraints****Type Constraints**
3838
3939* **T** in (* **T** in (
4040 tensor(double), tensor(double),
4141 tensor(float), tensor(float),
4242 tensor(float16) tensor(float16)
4343 ): ):
4444 Constrain input and output types to float tensors. Constrain input and output types to float tensors.
.. _l-onnx-op-gemm-1: Gemm - 1 ======== **Version** * **name**: `Gemm (GitHub) `_ * **domain**: **main** * **since_version**: **1** * **function**: False * **support_level**: SupportType.COMMON * **shape inference**: False This version of the operator has been available **since version 1**. **Summary** General Matrix multiplication: https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms#Level_3 Compute Y = alpha * A * B + beta * C, where input tensor A has dimension (M X K), input tensor B has dimension (K X N), input tensor C and output tensor Y have dimension (M X N). If attribute broadcast is non-zero, input tensor C will be broadcasted to match the dimension requirement. A will be transposed before doing the computation if attribute transA is non-zero, same for B and transB. **Attributes** * **alpha**: Scalar multiplier for the product of input tensors A * B, the default value is 1.0. Default value is ``1.0``. * **beta**: Scalar multiplier for input tensor C, the default value is 1.0. Default value is ``1.0``. * **broadcast**: Whether C should be broadcasted Default value is ``0``. * **transA**: Whether A should be transposed Default value is ``0``. * **transB**: Whether B should be transposed Default value is ``0``. **Inputs** * **A** (heterogeneous) - **T**: Input tensor A * **B** (heterogeneous) - **T**: Input tensor B * **C** (heterogeneous) - **T**: Input tensor C, can be inplace. **Outputs** * **Y** (heterogeneous) - **T**: Output tensor. **Type Constraints** * **T** in ( tensor(double), tensor(float), tensor(float16) ): Constrain input and output types to float tensors.