[MO IR Reader] Update *Sequence backend_attrs (#10041)

* Update LSTMSequence backend_attrs

* Add missed attribute clip

* Update backend_attrs for all *sequence operations

* Add extender for GRUSequence

* Add GRUSequence to custom ops list

* use has_and_set instead if direct acces to attributes
This commit is contained in:
Anton Chetverikov
2022-02-09 12:13:23 +03:00
committed by GitHub
parent 4fdf71cdc1
commit 25ca17e789
8 changed files with 52 additions and 20 deletions

View File

@@ -1058,6 +1058,7 @@ openvino/tools/mo/utils/ir_reader/extenders/experimental_extender.py
openvino/tools/mo/utils/ir_reader/extenders/ExtractImagePatches_extender.py
openvino/tools/mo/utils/ir_reader/extenders/fakequantize_extender.py
openvino/tools/mo/utils/ir_reader/extenders/GRUCell_extender.py
openvino/tools/mo/utils/ir_reader/extenders/GRUSequence_extender.py
openvino/tools/mo/utils/ir_reader/extenders/if_extender.py
openvino/tools/mo/utils/ir_reader/extenders/interpolate_extender.py
openvino/tools/mo/utils/ir_reader/extenders/loop_extender.py

View File

@@ -54,9 +54,11 @@ class GRU(Op):
'direction', # one of 'forward', 'reverse', or 'bidirectional'
'axis',
'activation_alpha',
'activation_beta',
('activations', lambda node: ','.join(node.activations) if node.activations is not None else None),
('activations', lambda node: ','.join(node['activations']) if node.has_and_set('activations') else None),
('activations_alpha', lambda node: ','.join(map(str, node['activations_alpha']))
if node.has_and_set('activations_alpha') else None),
('activations_beta', lambda node: ','.join(map(str, node['activations_beta']))
if node.has_and_set('activations_beta') else None),
'clip',
'linear_before_reset',
]

View File

@@ -51,9 +51,11 @@ class GRUCell(Op):
def backend_attrs(self):
return [
'hidden_size', # number of the elements in hidden cell size
('activations', lambda node: ','.join(node.activations) if node.activations is not None else None),
'activation_alpha',
'activation_beta',
('activations', lambda node: ','.join(node['activations']) if node.has_and_set('activations') else None),
('activations_alpha', lambda node: ','.join(map(str, node['activations_alpha']))
if node.has_and_set('activations_alpha') else None),
('activations_beta', lambda node: ','.join(map(str, node['activations_beta']))
if node.has_and_set('activations_beta') else None),
'clip',
('linear_before_reset', lambda node: bool_to_str(node, 'linear_before_reset')),
]

View File

@@ -54,9 +54,11 @@ class LSTM(Op):
'direction', # one of 'forward', 'reverse', or 'bidirectional'
'axis',
'activation_alpha',
'activation_beta',
('activations', lambda node: ','.join(node.activations) if node.activations is not None else None),
('activations', lambda node: ','.join(node['activations']) if node.has_and_set('activations') else None),
('activations_alpha', lambda node: ','.join(map(str, node['activations_alpha']))
if node.has_and_set('activations_alpha') else None),
('activations_beta', lambda node: ','.join(map(str, node['activations_beta']))
if node.has_and_set('activations_beta') else None),
'clip',
# 'input_forget', # Not supported yet
]

View File

@@ -50,9 +50,11 @@ class LSTMCell(Op):
def backend_attrs(self):
return [
'hidden_size', # number of the elements in hidden cell size
('activations', lambda node: ','.join(node.activations) if node.activations is not None else None),
'activation_alpha',
'activation_beta',
('activations', lambda node: ','.join(node['activations']) if node.has_and_set('activations') else None),
('activations_alpha', lambda node: ','.join(map(str, node['activations_alpha']))
if node.has_and_set('activations_alpha') else None),
('activations_beta', lambda node: ','.join(map(str, node['activations_beta']))
if node.has_and_set('activations_beta') else None),
'clip',
]

View File

@@ -60,6 +60,13 @@ class LSTMSequence(Op):
def backend_attrs(self):
return [
'hidden_size',
('activations', lambda node: ','.join(node['activations']) if node.has_and_set('activations') else None),
('activations_alpha', lambda node: ','.join(map(str, node['activations_alpha']))
if node.has_and_set('activations_alpha') else None),
('activations_beta', lambda node: ','.join(map(str, node['activations_beta']))
if node.has_and_set('activations_beta') else None),
'clip',
'direction',
]
@staticmethod

View File

@@ -0,0 +1,13 @@
# Copyright (C) 2018-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from openvino.tools.mo.utils.graph import Node
from openvino.tools.mo.utils.ir_reader.extender import Extender
class GRUSequence_extender(Extender):
op = 'GRUSequence'
@staticmethod
def extend(op: Node):
op['infer'] = Extender.use_shapes_from_ir

View File

@@ -8,24 +8,26 @@ import numpy as np
from openvino.tools.mo.back.MaxPool import MaxPool
from openvino.tools.mo.back.TopKNormalizer import TopKNormalizer
from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.graph.graph import Graph, Node
from openvino.tools.mo.ops.Cast import Cast
from openvino.tools.mo.ops.GRU import GRU
from openvino.tools.mo.ops.ReduceOps import ReduceOp
from openvino.tools.mo.ops.activation_ops import Activation
from openvino.tools.mo.ops.clamp import AttributedClamp
from openvino.tools.mo.ops.convolution import Convolution
from openvino.tools.mo.ops.deconvolution import Deconvolution
from openvino.tools.mo.ops.dft import FFTBase
from openvino.tools.mo.ops.elementwise import Elementwise, UnaryElementwise, LogicalElementwise, BiasAdd, Div, Mul, Pow, Sub
from openvino.tools.mo.ops.elementwise import Elementwise, UnaryElementwise, LogicalElementwise, BiasAdd, Div, Mul, Pow, \
Sub
from openvino.tools.mo.ops.embedding_bag import EmbeddingBagBase
from openvino.tools.mo.ops.loop import Loop
from openvino.tools.mo.ops.op import Op
from openvino.tools.mo.ops.pooling import Pooling
from openvino.tools.mo.ops.psroipooling import DeformablePSROIPoolingOp
from openvino.tools.mo.ops.scatter import Scatter
from openvino.tools.mo.ops.scatternd import ScatterNDBase
from openvino.tools.mo.ops.split import Split, VariadicSplit
from openvino.tools.mo.front.common.partial_infer.utils import int64_array
from openvino.tools.mo.graph.graph import Graph, Node
from openvino.tools.mo.ops.clamp import AttributedClamp
from openvino.tools.mo.ops.convolution import Convolution
from openvino.tools.mo.ops.deconvolution import Deconvolution
from openvino.tools.mo.ops.op import Op
from openvino.tools.mo.ops.pooling import Pooling
from openvino.tools.mo.utils.class_registration import update_registration
from openvino.tools.mo.utils.import_extensions import import_by_path
from openvino.tools.mo.utils.ir_reader.extender import Extender
@@ -40,6 +42,7 @@ custom_ops = {
'Divide': Div,
'GroupConvolution': Convolution,
'GroupConvolutionBackpropData': Deconvolution,
'GRUSequence': GRU,
'Loop': Loop,
'MaxPool': Pooling,
'Multiply': Mul,