[MO][nG] add Gather-8 to MO, layer tests, nG python api unit-tests and up/down-grading transformations (#6560)

* gather-8 upgrade/downgrade transforms

* bump to opset8

* add Gather-8 to MO

* fix permutation for Gather

* added TF layer tests, ONNX layer tests for negative indices, and nG python api unit-tests for negative indices

* typo fix, disable downgrading transformation

* disable downgrade in clDNN, line width style fix

* all Gathers are converted to 7th version, transformations will be enabled/disabled while op will be added into plugins

* disabled Gather8LayerTest on GPU

* added common function for Op replacement

* concretized meaning of negative indices, fixed some typos

* applied review comments: left only meaningful layer tests

* removed op replacing functions from common utils

* returned back transformations without subroutines

* corrected style, added comments to common_optimizations.cpp
This commit is contained in:
Pavel Esir authored and GitHub committed 2021-08-13 11:56:49 +03:00
1 parent f324ca7fcd
commit 4738bbd757
25 files changed
+503 -185

No files matched your search

+3 -3
View File
@@ -18,7 +18,7 @@ class Gather(Op):
super().__init__(graph, {
'op': self.op,
'type': self.op,
'version': 'opset7',
'version': 'opset8',
'batch_dims': 0,
'infer': self.infer,
'force_precision_in_ports': {1: 'int32', 2: 'int64'},
@@ -31,7 +31,7 @@ class Gather(Op):
def backend_attrs(self):
version = self.get_opset()
if version == 'opset7':
if version in ['opset7', 'opset8']:
return ['batch_dims']
elif version == 'opset1':
return []
@@ -75,7 +75,7 @@ class Gather(Op):
# we import PermuteInputs locally because it uses Gather inside and we have recursive imports
from mo.graph.perm_inputs import PermuteInputs
PermuteInputs().set_input_permutation(node.in_node(1), node, 'input:0', 'axis')
PermuteInputs().set_input_permutation(node.in_node(2), node, 'input:0', 'axis')
batch_dims_range = indices_shape[:batch_dims]
out_shape = np.concatenate((data_shape[:axis], indices_shape[batch_dims:], data_shape[axis + 1:]))
@@ -114,6 +114,12 @@ class TestGatherPartialInfer(unittest.TestCase):
indices=[0, 0, 4],
ref_value=[1, 1, 5])
def test_axis_0_batch_dims_0_negative_indices(self):
self.build_and_test_value_inference(axis=0, batch_dims=0,
data=[1, 2, 3, 4, 5],
indices=[-1, -2, -3],
ref_value=[5, 4, 3])
def test_axis_1_batch_dims_1(self):
self.build_and_test_value_inference(axis=1, batch_dims=1,
data=[[1, 2, 3, 4, 5],
@@ -155,6 +161,27 @@ class TestGatherPartialInfer(unittest.TestCase):
[33, 34, 35, 36],
[29, 30, 31, 32]]]])
def test_axis_2_batch_dims_1_with_negative_indices(self):
self.build_and_test_value_inference(axis=2, batch_dims=1,
data=[[[[ 1, 2, 3, 4], # <-- first batch
[ 5, 6, 7, 8],
[ 9, 10, 11, 12],
[13, 14, 15, 16],
[17, 18, 19, 20]]],
[[[21, 22, 23, 24], # < -- second batch
[25, 26, 27, 28],
[29, 30, 31, 32],
[33, 34, 35, 36],
[37, 38, 39, 40]]]], # data_shape = (2, 1, 5, 4)
indices=[[-4, -3, -1],
[-1, 3, 2]],
ref_value=[[[[ 5, 6, 7, 8],
[ 9, 10, 11, 12],
[17, 18, 19, 20]]],
[[[37, 38, 39, 40],
[33, 34, 35, 36],
[29, 30, 31, 32]]]])
def test_axis_2_batch_dims_mimus_1(self):
self.build_and_test_value_inference(axis=2, batch_dims=-1,
data=[[[[ 1, 2, 3, 4], # <-- first batch