[MO]Fix Merge shape infer function (#7864)
* Update merge shape infer function * Update merge shape inference tests
This commit is contained in:
1 parent
b82cc125fa
commit
fb02aec976
2 files changed
+37
-7
No files matched your search
@@ -34,13 +34,15 @@ class Merge(Op):
|
||||
|
||||
inferred_and_executable = [n for n in node.in_nodes().values() if n['is_partial_inferred'] and
|
||||
'executable' in n and n['executable']]
|
||||
tensor = inferred_and_executable[0]
|
||||
if len(inferred_and_executable) > 0:
|
||||
tensor = inferred_and_executable[0]
|
||||
|
||||
if all([tensor.has_valid('value') and n.has_valid('value') and strict_compare_tensors(tensor.value, n.value)
|
||||
for n in inferred_and_executable]):
|
||||
node.out_node().value = tensor.value.copy()
|
||||
else:
|
||||
node.out_node().value = None
|
||||
if all([tensor.has_valid('value') and n.has_valid('value') and strict_compare_tensors(tensor.value,
|
||||
n.value)
|
||||
for n in inferred_and_executable]):
|
||||
node.out_node().value = tensor.value.copy()
|
||||
else:
|
||||
node.out_node().value = None
|
||||
|
||||
# do not use set_shape(tensor.shape) here because input port shape may be different from the calculated output
|
||||
# shape and `set_shape` will raise an error that shape has changed
|
||||
|
||||
@@ -58,7 +58,7 @@ class TestMerge(unittest.TestCase):
|
||||
edges_with_attrs=self.edges,
|
||||
update_nodes_attributes=[('second', {'executable': True}),
|
||||
('first', {'is_partial_inferred': False,
|
||||
'value': None}),
|
||||
'value': None}),
|
||||
('merge_output', {'shape': np.array([2, 2]),
|
||||
'value': None}),
|
||||
('merge', {'is_not_fully_inferred': True})])
|
||||
@@ -115,3 +115,31 @@ class TestMerge(unittest.TestCase):
|
||||
|
||||
(flag, resp) = compare_graphs(graph, ref_graph, 'merge_output', check_op_attrs=True)
|
||||
self.assertTrue(flag, resp)
|
||||
|
||||
def test_merge_infer_no_executable(self):
|
||||
graph = build_graph_with_attrs(
|
||||
nodes_with_attrs=self.nodes,
|
||||
edges_with_attrs=self.edges,
|
||||
update_nodes_attributes=[
|
||||
('first', {'executable': False, 'value': np.ones([2, 2]), 'shape': int64_array([2, 2])}),
|
||||
('second', {'executable': False, 'value': np.zeros([4, 4]), 'shape': int64_array([4, 4])})
|
||||
]
|
||||
)
|
||||
|
||||
ref_graph = build_graph_with_attrs(
|
||||
nodes_with_attrs=self.nodes,
|
||||
edges_with_attrs=self.edges,
|
||||
update_nodes_attributes=[
|
||||
('first', {'executable': False, 'value': np.ones([2, 2]), 'shape': int64_array([2, 2])}),
|
||||
('second', {'executable': False, 'value': np.zeros([4, 4]), 'shape': int64_array([4, 4])}),
|
||||
('merge', {'is_not_fully_inferred': False}),
|
||||
('merge_output', {'shape': int64_array([2, 2]), 'value': None})
|
||||
]
|
||||
)
|
||||
|
||||
tested_class = Merge(graph=graph, attrs={})
|
||||
node = Node(graph, 'merge')
|
||||
tested_class.merge_infer(node)
|
||||
|
||||
(flag, resp) = compare_graphs(graph, ref_graph, 'merge_output', check_op_attrs=True)
|
||||
self.assertTrue(flag, resp)
|
||||
Reference in new issue
Block a user