LSTMCell/Sequence v1, reference implementations and decompose transformations for LSTM/GRU/RNN Cells (#2000)

* validate_and_infer_types() implementation

* input parameter validation for LSTM, GRU and RNN

* style-check applied

* Add LSTMSequence dynamic shape validation and test props for RNNCell, GRUCell, LSTMCell and LSTMSequence.

* recurrent_sequence.hpp moved to ngraph/core/include/ngraph/op/util/

* style check applied

* removed unused variable from LSTMSequence::validate_and_infer_types

* Add missing newline mark at the end of file.

* Add supression macro for FusedOp deprecation.

* Add element type initialization

* transpose,rnn cell reference implementations

* Apply PR review remarks

* reference implementations for cells op, single layer tests, align lstm cell/sequence according to the spec

* lstm/gru/rnn cell decompostion transformations

* ngraph codestyle

* clean up

* ngraph code style

* change inheritance of Cells, fix build

* fix build

* fix build again

* remove Peepholes from LSTMSeq, fix copy_runtime_info in transformations

* Rewrite tests to use gtest exception assertions.

* resolve tests issues

* ngraph codestyle

* add missed files

* fix typeprop tests

* fix lstm sequence checks

* fix arm build

* fix arm again

* delete unnecessary file

* add convert weghts format function, enable lstm test, resolve review comments

* add ngraph builders

* ngraph codestyle

* fix unit tests

* revert transpose reference implementation

* revert LSTM Cell v0, add LSTMCell v1, update transformation lstm_cell_to_cell_ie

* v1 version of LSTMCell op

* LSTMSequence v1 operation, exclude LSTMSeq from opset4

* fix python api tests

* resolve review comments, tests for decomposition transformations, switch lstm cell to opset4 in mo

Co-authored-by: Szymon Durawa <szymon.durawa@intel.com>
This commit is contained in:
Ivan Tikhonov
2020-09-04 09:04:36 +03:00
committed by GitHub
parent 28eed7708e
commit 2f5a28d44f
65 changed files with 4695 additions and 1248 deletions

View File

@@ -389,5 +389,31 @@ std::shared_ptr<ngraph::Node> makePad(const ngraph::Output<Node>& data,
std::shared_ptr<ngraph::Node> makeBatchNormInference(const ngraph::Output<Node>& data,
double epsilon);
std::shared_ptr<ngraph::Node> makeLSTMCell(const OutputVector& in,
const std::vector<ngraph::Shape>& WRB,
std::size_t hidden_size,
const std::vector<std::string>& activations =
std::vector<std::string>{"sigmoid", "tanh", "tanh"},
const std::vector<float>& activations_alpha = {},
const std::vector<float>& activations_beta = {},
float clip = 0.f);
std::shared_ptr<ngraph::Node> makeGRUCell(const OutputVector& in,
const std::vector<ngraph::Shape>& WRB,
std::size_t hidden_size,
const std::vector<std::string>& activations =
std::vector<std::string>{"sigmoid", "tanh"},
const std::vector<float>& activations_alpha = {},
const std::vector<float>& activations_beta = {},
float clip = 0.f,
bool linear_before_reset = false);
std::shared_ptr<ngraph::Node> makeRNNCell(const OutputVector& in,
const std::vector<ngraph::Shape>& WRB,
std::size_t hidden_size,
const std::vector<std::string>& activations = std::vector<std::string>{"tanh"},
const std::vector<float>& activations_alpha = {},
const std::vector<float>& activations_beta = {},
float clip = 0.f);
} // namespace builder
} // namespace ngraph

View File

@@ -130,7 +130,7 @@ static std::shared_ptr<ngraph::Function> makeTIwithLSTMcell(InferenceEngine::Pre
inShape = {N, I};
auto constantX = std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64, ngraph::Shape{2}, inShape);
auto LSTM_cell =
std::make_shared<ngraph::opset1::LSTMCell>(std::make_shared<ngraph::opset1::Reshape>(X, constantX, false),
std::make_shared<ngraph::opset4::LSTMCell>(std::make_shared<ngraph::opset1::Reshape>(X, constantX, false),
std::make_shared<ngraph::opset1::Reshape>(H_t, constantH, false),
std::make_shared<ngraph::opset1::Reshape>(C_t, constantH, false),
W_body,

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include <memory>
#include "ngraph_functions/builders.hpp"
namespace ngraph {
namespace builder {
std::shared_ptr<ngraph::Node> makeGRUCell(const OutputVector& in,
const std::vector<ngraph::Shape>& WRB,
std::size_t hidden_size,
const std::vector<std::string>& activations,
const std::vector<float>& activations_alpha,
const std::vector<float>& activations_beta,
float clip,
bool linear_before_reset) {
std::vector<float> empty;
auto W = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[0], empty, true);
auto R = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[1], empty, true);
auto B = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[2], empty, true);
return std::make_shared<ngraph::opset4::GRUCell>(in[0], in[1], W, R, B, hidden_size, activations,
activations_alpha, activations_beta, clip, linear_before_reset);
}
} // namespace builder
} // namespace ngraph

View File

@@ -0,0 +1,29 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include <memory>
#include "ngraph_functions/builders.hpp"
namespace ngraph {
namespace builder {
std::shared_ptr<ngraph::Node> makeLSTMCell(const std::vector<ngraph::Output<Node>>& in,
const std::vector<ngraph::Shape>& WRB,
std::size_t hidden_size,
const std::vector<std::string>& activations,
const std::vector<float>& activations_alpha,
const std::vector<float>& activations_beta,
float clip) {
std::vector<float> empty;
auto W = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[0], empty, true);
auto R = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[1], empty, true);
auto B = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[2], empty, true);
return std::make_shared<ngraph::opset4::LSTMCell>(in[0], in[1], in[2], W, R, B, hidden_size, activations,
activations_alpha, activations_beta, clip);
}
} // namespace builder
} // namespace ngraph

View File

@@ -0,0 +1,29 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include <memory>
#include "ngraph_functions/builders.hpp"
namespace ngraph {
namespace builder {
std::shared_ptr<ngraph::Node> makeRNNCell(const OutputVector& in,
const std::vector<ngraph::Shape>& WRB,
std::size_t hidden_size,
const std::vector<std::string>& activations,
const std::vector<float>& activations_alpha,
const std::vector<float>& activations_beta,
float clip) {
std::vector<float> empty;
auto W = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[0], empty, true);
auto R = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[1], empty, true);
auto B = ngraph::builder::makeConstant(in[0].get_element_type(), WRB[2], empty, true);
return std::make_shared<ngraph::opset4::RNNCell>(in[0], in[1], W, R, B, hidden_size, activations,
activations_alpha, activations_beta, clip);
}
} // namespace builder
} // namespace ngraph