Skip to content

Commit

Permalink
Add Einsum Opset 12 support (#773)
Browse files Browse the repository at this point in the history
1. Add opset 12 support for Einsum
2. Skip dropout, if and loop onnx-backend-test
3. Fix acosh, reduce_sum, split, squeeze and topk testcase in test_node.py
Signed-off-by: Winnie Tsang <[email protected]>
  • Loading branch information
winnietsang authored Oct 23, 2020
1 parent 6ed3bf2 commit 651c90f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
12 changes: 6 additions & 6 deletions doc/support_status.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ONNX-Tensorflow Support Status
|||
|-:|:-|
|ONNX-Tensorflow Version|Master ( commit id: 6f5c155247e28ae0ceb2ce2615ce1483ffa27c43 )|
|ONNX Version|Master ( commit id: b2ed660d0a065b8346816f2c3a95d79ca79b88c9 )|
|Tensorflow Version|v2.3.0|
|ONNX-Tensorflow Version|Master ( commit id: f64afb48034af7121341f4ba5d6f56e275c5aedb )|
|ONNX Version|Master ( commit id: a7a0fec7f25cae567429af62b7eaaee1c3f0e247 )|
|Tensorflow Version|v2.3.1|

Notes:
* Values that are new or updated from a previous opset version are in bold.
Expand Down Expand Up @@ -51,7 +51,7 @@ Notes:
|Div|**1**|1|1|1|1|**6**|**7**|7|7|7|7|7|**13**:small_red_triangle:|Div|
|Dropout|**1**|1|1|1|1|**6**|**7**|7|7|**10**|10|**12**|**13**|Dropout|
|DynamicQuantizeLinear|-|-|-|-|-|-|-|-|-|-|**11**|11|11|DynamicQuantizeLinear|
|Einsum|-|-|-|-|-|-|-|-|-|-|-|**12**:small_red_triangle:|12:small_red_triangle:|Einsum|
|Einsum|-|-|-|-|-|-|-|-|-|-|-|**12**|12|Einsum|
|Elu|**1**|1|1|1|1|**6**|6|6|6|6|6|6|6|Elu|
|Equal|**1**|1|1|1|1|1|**7**|7|7|7|**11**|11|**13**|Equal|
|Erf|-|-|-|-|-|-|-|-|**9**|9|9|9|**13**|Erf|
Expand Down Expand Up @@ -100,7 +100,7 @@ Notes:
|Mul|**1**|1|1|1|1|**6**|**7**|7|7|7|7|7|**13**|Mul|
|Multinomial|-|-|-|-|-|-|**7**:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|7:small_red_triangle:|Multinomial|
|Neg|**1**|1|1|1|1|**6**|6|6|6|6|6|6|**13**|Neg|
|NegativeLogLikelihoodLoss|-|-|-|-|-|-|-|-|-|-|-|**12**:small_red_triangle:|12:small_red_triangle:|NegativeLogLikelihoodLoss|
|NegativeLogLikelihoodLoss|-|-|-|-|-|-|-|-|-|-|-|**12**:small_red_triangle:|**13**:small_red_triangle:|NegativeLogLikelihoodLoss|
|NonMaxSuppression|-|-|-|-|-|-|-|-|-|**10**|**11**|11|11|NonMaxSuppression|
|NonZero|-|-|-|-|-|-|-|-|**9**|9|9|9|**13**:small_red_triangle:|NonZero|
|Not|**1**|1|1|1|1|1|1|1|1|1|1|1|1|Not|
Expand Down Expand Up @@ -179,7 +179,7 @@ Notes:
|Where|-|-|-|-|-|-|-|-|**9**|9|9|9|9|Where|
|Xor|**1**|1|1|1|1|1|**7**|7|7|7|7|7|7|Xor|

ONNX-TF Supported Operators / ONNX Operators: 113 / 162
ONNX-TF Supported Operators / ONNX Operators: 118 / 162

Notes:
1. Cast: Cast string to data types other than float32/float64/int32/int64 is not supported in Tensorflow
Expand Down
14 changes: 14 additions & 0 deletions onnx_tf/handlers/backend/einsum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import tensorflow as tf

from onnx_tf.handlers.backend_handler import BackendHandler
from onnx_tf.handlers.handler import onnx_op

@onnx_op("Einsum")

class Einsum(BackendHandler):

@classmethod
def version_12(cls, node, **kwargs):
equation = node.attrs.get("equation", "")
inputs = [kwargs["tensor_dict"][inp] for inp in node.inputs]
return [tf.einsum(equation, *inputs)]
2 changes: 1 addition & 1 deletion onnx_tf/opset_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'Div': [1, 6, 7],
'Dropout': [1, 6, 7, 10, 12, 13],
'DynamicQuantizeLinear': [11],
'Einsum': [],
'Einsum': [12],
'Elu': [1, 6],
'Equal': [1, 7, 11, 13],
'Erf': [9, 13],
Expand Down
13 changes: 13 additions & 0 deletions test/backend/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,19 @@ def test_dynamic_quantize_linear(self):
np.testing.assert_almost_equal(output["Y_Scale"], y_scale)
np.testing.assert_almost_equal(output["Y_Zero_Point"], y_zero_point)

def test_einsum(self):
if legacy_opset_pre_ver(12):
raise unittest.SkipTest(
"ONNX version {} doesn't support Einsum.".format(
defs.onnx_opset_version()))
equation = 'ij,jk->ik' #matmul
node_def = helper.make_node("Einsum", ["X", "Y"], ["Z"], equation=equation)
x = self._get_rnd_float32(shape=[3, 4])
y = self._get_rnd_float32(shape=[4, 5])
z = np.einsum(equation, x, y)
output = run_node(node_def, [x, y])
np.testing.assert_almost_equal(output["Z"], z)

def test_elu(self):
node_def = helper.make_node("Elu", ["X"], ["Y"])
x = self._get_rnd_float32(shape=[100])
Expand Down

0 comments on commit 651c90f

Please sign in to comment.