Handle sequence ops with non constant W, R, B inputs (#18138)

* Handle sequence ops with non constant W, R, B inputs

Ticket: CVS-49207

* fix tests

* tests

* fix gna tests

* add include

* change type for seqLenIdx

* rename is_constfoldable to is_on_constant_path

---------

Co-authored-by: Ivan Tikhonov <ivan.tikhonov@intel.com>
This commit is contained in:
Mateusz TabakaandIvan Tikhonov authored and GitHub committed 2023-07-20 14:48:41 +04:00
1 parent 3b8f58f1af
commit fe8b8a96ff
42 files changed
+623 -230

No files matched your search

+1 -1
View File
@@ -121,7 +121,6 @@ xfail_issue_39662 = xfail_test(reason="RuntimeError: 'ScatterElementsUpdate' lay
xfail_issue_37973 = xfail_test(reason="TF Inception V2 - AssertionError: zoo models results mismatch")
xfail_issue_47495 = xfail_test(reason="BertSquad-10 from MSFT - AssertionError: zoo models results mismatch")
xfail_issue_49207 = xfail_test(reason="Model references undeclared parameters")
xfail_issue_48145 = xfail_test(reason="BertSquad-8 - AssertionError: Items are not equal: ACTUAL: 4 "
"DESIRED: 3")
xfail_issue_48190 = xfail_test(reason="RobertaBase-11 - AssertionError: Items are not equal: "
@@ -155,3 +154,4 @@ xfail_issue_86911 = xfail_test(reason="LSTM_Seq_len_unpacked - AssertionError: z
xfail_issue_91151 = xfail_test(reason="RuntimeError: model input (shape={3,4}) and blob (shape=(1)) are incompatible")
xfail_issue_91490 = xfail_test(reason="y has zero dimension which is not allowed")
xfail_issue_101965 = xfail_test(reason="Mismatch with numpy-based expected results.")
xfail_issue_113506 = xfail_test(reason="Unsupported operation of type: LSTMSequence Node expects 7 inputs. Actual: 8")
@@ -30,7 +30,6 @@ from tests import (
xfail_issue_47323,
xfail_issue_73538,
xfail_issue_48052,
xfail_issue_49207,
xfail_issue_52463,
xfail_issue_58033,
xfail_issue_63033,
@@ -62,6 +61,7 @@ from tests import (
xfail_issue_99972,
xfail_issue_99973,
xfail_issue_101965,
xfail_issue_113506,
)
from tests.test_onnx.utils.onnx_backend import OpenVinoTestBackend
@@ -113,18 +113,6 @@ OnnxBackendPyTorchConvertedModelTest = None
globals().update(backend_test.enable_report().test_cases)
tests_expected_to_fail = [
(
xfail_issue_49207,
"OnnxBackendNodeModelTest.test_rnn_seq_length_cpu",
"OnnxBackendNodeModelTest.test_simple_rnn_defaults_cpu",
"OnnxBackendNodeModelTest.test_simple_rnn_with_initial_bias_cpu",
"OnnxBackendNodeModelTest.test_gru_defaults_cpu",
"OnnxBackendNodeModelTest.test_gru_seq_length_cpu",
"OnnxBackendNodeModelTest.test_gru_with_initial_bias_cpu",
"OnnxBackendNodeModelTest.test_lstm_defaults_cpu",
"OnnxBackendNodeModelTest.test_lstm_with_initial_bias_cpu",
"OnnxBackendNodeModelTest.test_lstm_with_peepholes_cpu",
),
(
xfail_issue_39658,
"OnnxBackendNodeModelTest.test_tile_cpu",
@@ -582,6 +570,10 @@ tests_expected_to_fail = [
"OnnxBackendNodeModelTest.test_dft_cpu",
"OnnxBackendNodeModelTest.test_dft_inverse_cpu",
),
(
xfail_issue_113506,
"OnnxBackendNodeModelTest.test_lstm_with_peepholes_cpu",
),
]
for test_group in tests_expected_to_fail:
@@ -127,7 +127,6 @@ xfail_issue_39662 = xfail_test(reason="RuntimeError: 'ScatterElementsUpdate' lay
xfail_issue_37973 = xfail_test(reason="TF Inception V2 - AssertionError: zoo models results mismatch")
xfail_issue_47430 = xfail_test(reason="FCN ResNet models - AssertionError: zoo models results mismatch")
xfail_issue_47495 = xfail_test(reason="BertSquad-10 from MSFT - AssertionError: zoo models results mismatch")
xfail_issue_49207 = xfail_test(reason="Model references undeclared parameters")
xfail_issue_48145 = xfail_test(reason="BertSquad-8 - AssertionError: Items are not equal: ACTUAL: 4 "
"DESIRED: 3")
xfail_issue_48190 = xfail_test(reason="RobertaBase-11 - AssertionError: Items are not equal: "
@@ -163,5 +162,6 @@ xfail_issue_90649 = xfail_test(reason="RuntimeError: OV does not support the fol
xfail_issue_91151 = xfail_test(reason="RuntimeError: model input (shape={3,4}) and blob (shape=(1)) are incompatible")
xfail_issue_91490 = xfail_test(reason="y has zero dimension which is not allowed")
xfail_issue_101965 = xfail_test(reason="Mismatch with numpy-based expected results.")
xfail_issue_113506 = xfail_test(reason="Unsupported operation of type: LSTMSequence Node expects 7 inputs. Actual: 8")
skip_dynamic_model = pytest.mark.skip(reason="CPU plug-in can't load a model with dynamic output shapes via legacy API")
@@ -31,7 +31,6 @@ from tests_compatibility import (
xfail_issue_47323,
xfail_issue_73538,
xfail_issue_48052,
xfail_issue_49207,
xfail_issue_52463,
xfail_issue_58033,
xfail_issue_63033,
@@ -64,6 +63,7 @@ from tests_compatibility import (
xfail_issue_99970,
xfail_issue_99972,
xfail_issue_99973,
xfail_issue_113506,
skip_dynamic_model,
)
from tests_compatibility.test_onnx.utils.onnx_backend import OpenVinoTestBackend
@@ -115,18 +115,6 @@ OnnxBackendPyTorchConvertedModelTest = None
globals().update(backend_test.enable_report().test_cases)
tests_expected_to_fail = [
(
xfail_issue_49207,
"OnnxBackendNodeModelTest.test_rnn_seq_length_cpu",
"OnnxBackendNodeModelTest.test_simple_rnn_defaults_cpu",
"OnnxBackendNodeModelTest.test_simple_rnn_with_initial_bias_cpu",
"OnnxBackendNodeModelTest.test_gru_defaults_cpu",
"OnnxBackendNodeModelTest.test_gru_seq_length_cpu",
"OnnxBackendNodeModelTest.test_gru_with_initial_bias_cpu",
"OnnxBackendNodeModelTest.test_lstm_defaults_cpu",
"OnnxBackendNodeModelTest.test_lstm_with_initial_bias_cpu",
"OnnxBackendNodeModelTest.test_lstm_with_peepholes_cpu",
),
(
xfail_issue_39658,
"OnnxBackendNodeModelTest.test_tile_cpu",
@@ -716,6 +704,10 @@ tests_expected_to_fail = [
"OnnxBackendNodeModelTest.test_split_zero_size_splits_opset13_cpu",
"OnnxBackendNodeModelTest.test_split_zero_size_splits_opset18_cpu",
),
(
xfail_issue_113506,
"OnnxBackendNodeModelTest.test_lstm_with_peepholes_cpu",
),
]
for test_group in tests_expected_to_fail:
@@ -221,7 +221,11 @@ TRANSFORMATIONS_API bool is_dequantization_subgraph(const Output<Node>& node);
TRANSFORMATIONS_API bool can_eliminate_eltwise_node(const std::shared_ptr<Node>& eltwise,
const Output<Node>& constant,
const Output<Node>& non_constant_input);
TRANSFORMATIONS_API bool is_constant_and_all_values_equal_int(const Output<Node>& output, const int64_t& v);
TRANSFORMATIONS_API bool is_on_constant_path(const ov::Output<ov::Node>& output);
} // namespace util
} // namespace op
} // namespace ov
@@ -9,27 +9,7 @@
#include <openvino/pass/pattern/op/wrap_type.hpp>
#include <transformations/rt_info/dequantization_node.hpp>
#include <transformations/rt_info/disable_constant_folding.hpp>
static bool is_constfoldable(const ov::Output<ov::Node>& output) {
auto status = true;
std::deque<ov::Node*> nodes_to_calculate = {output.get_node()};
while (status && !nodes_to_calculate.empty()) {
auto current_node = nodes_to_calculate.front();
nodes_to_calculate.pop_front();
if (current_node->get_input_size() == 0 && !ov::is_type<ov::op::v0::Constant>(current_node)) {
status = false;
} else {
// not a leaf, not a shape_of -- continue to search
for (const auto& input_value : current_node->input_values()) {
const auto& input_node = input_value.get_node();
nodes_to_calculate.push_front(input_node);
}
}
}
return status;
}
#include <transformations/utils/utils.hpp>
ov::pass::MarkDequantizationSubgraph::MarkDequantizationSubgraph(const element::TypeVector& precisions) {
// Dequantization subgraph may have two forms: with and without Subtract
@@ -74,7 +54,7 @@ ov::pass::MarkDequantizationSubgraph::MarkDequantizationSubgraph(const element::
return false;
}
if (is_constfoldable(input)) {
if (ov::op::util::is_on_constant_path(input)) {
// disable ConstantFolding if dequantization subgraph is on constant data
ov::disable_constant_folding(convert);
}
@@ -130,17 +130,29 @@ bool convert_sequence_to_ti(const std::shared_ptr<ngraph::Node>& sequence,
const auto squeezed_x = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(X_body_param, axis_1);
const auto squeezed_w = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(W, axis_0);
std::shared_ptr<ov::op::v0::Parameter> W_body_param;
if (!ov::is_type<ov::op::v0::Constant>(squeezed_w))
W_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_w->get_element_type(),
squeezed_w->get_output_partial_shape(0));
const auto squeezed_r = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(R, axis_0);
std::shared_ptr<ov::op::v0::Parameter> R_body_param;
if (!ov::is_type<ov::op::v0::Constant>(squeezed_r))
R_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_r->get_element_type(),
squeezed_r->get_output_partial_shape(0));
const auto squeezed_b = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(B, axis_0);
std::shared_ptr<ov::op::v0::Parameter> B_body_param;
if (!ov::is_type<ov::op::v0::Constant>(squeezed_b))
B_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_b->get_element_type(),
squeezed_b->get_output_partial_shape(0));
std::shared_ptr<ngraph::Node> cell;
if (const auto lstm_sequence = ngraph::as_type_ptr<ov::op::v5::LSTMSequence>(sequence)) {
cell = std::make_shared<ov::op::v4::LSTMCell>(squeezed_x,
H_body_param,
C_body_param,
squeezed_w,
squeezed_r,
squeezed_b,
W_body_param ? W_body_param : squeezed_w,
R_body_param ? R_body_param : squeezed_r,
B_body_param ? B_body_param : squeezed_b,
lstm_sequence->get_hidden_size(),
lstm_sequence->get_activations(),
lstm_sequence->get_activations_alpha(),
@@ -149,9 +161,9 @@ bool convert_sequence_to_ti(const std::shared_ptr<ngraph::Node>& sequence,
} else if (const auto rnn_sequence = ngraph::as_type_ptr<ov::op::v5::RNNSequence>(sequence)) {
cell = std::make_shared<ov::op::v0::RNNCell>(squeezed_x,
H_body_param,
squeezed_w,
squeezed_r,
squeezed_b,
W_body_param ? W_body_param : squeezed_w,
R_body_param ? R_body_param : squeezed_r,
B_body_param ? B_body_param : squeezed_b,
rnn_sequence->get_hidden_size(),
rnn_sequence->get_activations(),
rnn_sequence->get_activations_alpha(),
@@ -160,9 +172,9 @@ bool convert_sequence_to_ti(const std::shared_ptr<ngraph::Node>& sequence,
} else if (const auto gnn_sequence = ngraph::as_type_ptr<ov::op::v5::GRUSequence>(sequence)) {
cell = std::make_shared<ov::op::v3::GRUCell>(squeezed_x,
H_body_param,
squeezed_w,
squeezed_r,
squeezed_b,
W_body_param ? W_body_param : squeezed_w,
R_body_param ? R_body_param : squeezed_r,
B_body_param ? B_body_param : squeezed_b,
gnn_sequence->get_hidden_size(),
gnn_sequence->get_activations(),
gnn_sequence->get_activations_alpha(),
@@ -201,6 +213,12 @@ bool convert_sequence_to_ti(const std::shared_ptr<ngraph::Node>& sequence,
if (cell_state_defined)
body_params.push_back(C_body_param);
body_params.push_back(seq_body_param);
if (W_body_param)
body_params.push_back(W_body_param);
if (R_body_param)
body_params.push_back(R_body_param);
if (B_body_param)
body_params.push_back(B_body_param);
body_results.push_back(concat_res);
body_results.push_back(H_res);
@@ -230,6 +248,12 @@ bool convert_sequence_to_ti(const std::shared_ptr<ngraph::Node>& sequence,
if (cell_state_defined)
tensor_iterator->set_merged_input(C_body_param, squeezed_c, C_res);
tensor_iterator->set_invariant_input(seq_body_param, seq_lengths);
if (W_body_param)
tensor_iterator->set_invariant_input(W_body_param, squeezed_w);
if (R_body_param)
tensor_iterator->set_invariant_input(R_body_param, squeezed_r);
if (B_body_param)
tensor_iterator->set_invariant_input(B_body_param, squeezed_b);
ngraph::Output<ngraph::Node> H_out = H_res;
ngraph::Output<ngraph::Node> C_out = C_res;
@@ -366,6 +366,27 @@ bool is_constant_and_all_values_equal_int(const Output<Node>& output, const int6
return false;
}
bool is_on_constant_path(const ov::Output<ov::Node>& output) {
auto status = true;
std::deque<ov::Node*> nodes_to_calculate = {output.get_node()};
while (status && !nodes_to_calculate.empty()) {
auto current_node = nodes_to_calculate.front();
nodes_to_calculate.pop_front();
if (current_node->get_input_size() == 0 && !ov::is_type<ov::op::v0::Constant>(current_node)) {
status = false;
} else {
// not a leaf - continue to search
for (const auto& input_value : current_node->input_values()) {
const auto& input_node = input_value.get_node();
nodes_to_calculate.push_front(input_node);
}
}
}
return status;
}
} // namespace util
} // namespace op
} // namespace ov
@@ -19,7 +19,7 @@ namespace v5 {
/// \ingroup ov_ops_cpp_api
class OPENVINO_API GRUSequence : public util::RNNCellBase {
public:
OPENVINO_OP("GRUSequence", "opset5", op::Op);
OPENVINO_OP("GRUSequence", "opset5", util::RNNCellBase);
GRUSequence();
GRUSequence(const Output<Node>& X,
@@ -120,29 +120,6 @@ onnx_model_max_pool_dyn_rank_without_default_attrs
onnx_model_lp_norm_default_dynamic
onnx_instance_normalization_dynamic
# (Constant W, R inputs are required) Ticket: 49207
# Function references undeclared parameters
# LSTMSequence
IE_CPU.onnx_model_lstm_fwd_large_batch_no_clip
IE_CPU.onnx_model_lstm_fwd_mixed_seq
IE_CPU.onnx_model_lstm_mixed_seq_reverse
# GRUSequence
IE_CPU.onnx_model_gru_defaults_fwd
IE_CPU.onnx_model_gru_fwd_mixed_seq_len
IE_CPU.onnx_model_gru_rev_clip
IE_CPU.onnx_model_gru_reverse
IE_CPU.onnx_model_gru_fwd_bias_initial_h
IE_CPU.onnx_model_gru_bidirectional
IE_CPU.onnx_model_gru_fwd_linear_before_reset
# RNNSequence
IE_CPU.onnx_model_rnn_defaults_fwd
IE_CPU.onnx_model_rnn_fwd_activations
IE_CPU.onnx_model_rnn_fwd_mixed_seq_len
IE_CPU.onnx_model_rnn_rev_clip
IE_CPU.onnx_model_rnn_reverse
IE_CPU.onnx_model_rnn_fwd_bias_initial_h
IE_CPU.onnx_model_rnn_bidirectional
# Legacy tests with unsupported features from opset4 LSTM/GRU/RNN
# Peepholes input unsupported
onnx_model_lstm_fwd_with_clip_peepholes
+70 -21
View File
@@ -14,6 +14,7 @@
#include <common/primitive_hashing_utils.hpp>
#include <memory>
#include <utils/shape_inference/shape_inference_ngraph.hpp>
#include "transformations/utils/utils.hpp"
#include "ov_ops/augru_cell.hpp"
#include "ov_ops/augru_sequence.hpp"
@@ -216,9 +217,9 @@ bool RNN::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::s
if (one_of(op->get_type_info(), ov::op::v0::RNNCell::get_type_info_static(), ov::op::v3::GRUCell::get_type_info_static())) {
// Plug-in does not support dynamism on weights.
if (!ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(2)) ||
!ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(3)) ||
(op->get_input_size() > 4 && !ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(4)))) {
if (!ov::op::util::is_on_constant_path(op->input_value(2)) ||
!ov::op::util::is_on_constant_path(op->input_value(3)) ||
(op->get_input_size() > 4 && !ov::op::util::is_on_constant_path(op->input_value(4)))) {
errorMessage = "Node expects constants as W, R, B inputs.";
return false;
}
@@ -228,9 +229,9 @@ bool RNN::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::s
ov::op::v5::GRUSequence::get_type_info_static(),
ov::op::v5::RNNSequence::get_type_info_static())) {
// Plug-in does not support dynamism on weights.
if (!ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(3)) ||
!ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(4)) ||
(op->get_input_size() > 5 && !ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(5)))) {
if (!ov::op::util::is_on_constant_path(op->input_value(3)) ||
!ov::op::util::is_on_constant_path(op->input_value(4)) ||
(op->get_input_size() > 5 && !ov::op::util::is_on_constant_path(op->input_value(5)))) {
errorMessage = "Node expects constants as W, R, B inputs.";
return false;
}
@@ -246,34 +247,82 @@ bool RNN::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::s
return false;
}
// Plug-in does not support dynamism on weights.
if (!ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(4)) ||
!ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(5)) ||
!ov::is_type<ov::op::v0::Constant>(op->get_input_node_ptr(6))) {
errorMessage = "Node expects constants as W, R, B inputs.";
if (!ov::op::util::is_on_constant_path(op->input_value(4)) ||
!ov::op::util::is_on_constant_path(op->input_value(5)) ||
!ov::op::util::is_on_constant_path(op->input_value(6))) {
errorMessage = "Node expects static shaped W, R, B inputs.";
return false;
}
}
auto rnnCellBase = ov::as_type_ptr<const ov::op::util::RNNCellBase>(op);
if (rnnCellBase && rnnCellBase->get_clip() != 0.f) {
errorMessage = "Clipping is not supported for RNN primitive.";
return false;
if (rnnCellBase) {
if (rnnCellBase->get_clip() != 0.f) {
errorMessage = "Clipping is not supported for RNN primitive.";
return false;
}
if (one_of(rnnCellBase->get_type_info(),
ov::op::v0::LSTMCell::get_type_info_static(),
ov::op::v4::LSTMCell::get_type_info_static(),
ov::op::v5::LSTMSequence::get_type_info_static())) {
if (rnnCellBase->get_activations() != std::vector<std::string>{"sigmoid", "tanh", "tanh"}) {
errorMessage = "Not supported activation functions";
return false;
}
} else if (!ov::is_type<ov::op::v5::RNNSequence>(op) && rnnCellBase->get_activations() != std::vector<std::string>{"sigmoid", "tanh"}) {
errorMessage = "Not supported activation functions";
return false;
}
}
ov::op::RecurrentSequenceDirection direction = ov::op::RecurrentSequenceDirection::FORWARD;
if (ov::is_type<ov::op::v5::GRUSequence>(op)) {
direction = ov::as_type_ptr<const ov::op::v5::GRUSequence>(op)->get_direction();
} else if (ov::is_type<ov::op::v0::LSTMSequence>(op)) {
direction = ov::as_type_ptr<const ov::op::v0::LSTMSequence>(op)->get_direction();
} else if (ov::is_type<ov::op::v5::LSTMSequence>(op)) {
direction = ov::as_type_ptr<const ov::op::v5::LSTMSequence>(op)->get_direction();
} else if (ov::is_type<ov::op::v5::RNNSequence>(op)) {
direction = ov::as_type_ptr<const ov::op::v5::RNNSequence>(op)->get_direction();
int64_t seqLenIdx = -1;
if (auto gru_seq = ov::as_type_ptr<const ov::op::v5::GRUSequence>(op)) {
direction = gru_seq->get_direction();
seqLenIdx = 2;
} else if (auto lstm_seq = ov::as_type_ptr<const ov::op::v0::LSTMSequence>(op)) {
if (lstm_seq->get_activations() != std::vector<std::string>{"sigmoid", "tanh", "tanh"}) {
errorMessage = "Not supported activation functions";
return false;
}
direction = lstm_seq->get_direction();
seqLenIdx = 3;
} else if (auto lstm_seq = ov::as_type_ptr<const ov::op::v5::LSTMSequence>(op)) {
direction = lstm_seq->get_direction();
seqLenIdx = 3;
} else if (auto augru_seq = ov::as_type_ptr<const ov::op::internal::AUGRUSequence>(op)) {
direction = augru_seq->get_direction();
seqLenIdx = 2;
} else if (auto rnn_seq = ov::as_type_ptr<const ov::op::v5::RNNSequence>(op)) {
direction = rnn_seq->get_direction();
seqLenIdx = 2;
}
if (!one_of(direction, ov::op::RecurrentSequenceDirection::FORWARD, ov::op::RecurrentSequenceDirection::REVERSE)) {
errorMessage = "Unsupported sequence direction.";
return false;
}
if (seqLenIdx > 0) {
const auto& data_pshape = op->get_input_partial_shape(0);
// WA: dynamic shapes make impossible to check seq_len due to shapeOf subgraphs
// but the sequence is still supported in CPU and doesn't need to be decomposed
if (data_pshape.is_dynamic())
return true;
const int64_t maxSeqLenDimIdx = 1;
if (data_pshape.rank().is_static() && data_pshape.rank().get_length() > maxSeqLenDimIdx && !data_pshape[maxSeqLenDimIdx].is_static()) {
errorMessage = "Max sequence length dimension is dynamic";
return false;
}
auto maxSeqLen = data_pshape[maxSeqLenDimIdx].get_length();
if (ov::op::util::is_seq_len_provided(op->get_input_node_shared_ptr(seqLenIdx), maxSeqLen)) {
errorMessage = "Unsupported sequence length.";
return false;
}
}
} catch (...) {
return false;
}
@@ -120,6 +120,7 @@
#include "nodes/normalize.h"
#include "nodes/fake_quantize.h"
#include "nodes/mha.h"
#include "nodes/rnn.h"
#include "dnnl.hpp"
#include <cpu/x64/cpu_isa_traits.hpp>
@@ -295,80 +296,19 @@ void Transformations::PreLpt(const std::vector<ov::element::Type>& defaultPrecis
},
ov::pass::ConvertBatchToSpace, ov::pass::ConvertSpaceToBatch);
auto isCellPrimitiveSupported = [](const_node_ptr &node) -> bool {
if (const auto &rnn_cell = std::dynamic_pointer_cast<const ov::opset4::RNNCell>(node)) {
return rnn_cell->get_clip() == 0.0f;
} else if (const auto &gru_cell = std::dynamic_pointer_cast<const ov::opset4::GRUCell>(
node)) {
return gru_cell->get_clip() == 0.0f
&& gru_cell->get_activations() == std::vector<std::string>{"sigmoid", "tanh"};
} else if (const auto &augru_cell = std::dynamic_pointer_cast<const ov::op::internal::AUGRUCell>(
node)) {
return augru_cell->get_clip() == 0.0f
&& augru_cell->get_activations() == std::vector<std::string>{"sigmoid", "tanh"};
} else if (const auto &lstm_cell = std::dynamic_pointer_cast<const ov::opset4::LSTMCell>(
node)) {
return lstm_cell->get_clip() == 0.0f &&
lstm_cell->get_activations() == std::vector<std::string>{"sigmoid", "tanh", "tanh"};
} else if (const auto &lstm_cell_v1 = std::dynamic_pointer_cast<const ov::opset1::LSTMCell>(
node)) {
return lstm_cell_v1->get_clip() == 0.0f &&
lstm_cell_v1->get_activations() == std::vector<std::string>{"sigmoid", "tanh", "tanh"};
}
return false;
};
// Sequences supported by the plugin shouldn't be converted to TensorIterator.
// sequence_length input is not supported in all Sequences, so if is_seq_len_provided() == true, we
// should always convert to TensorIterator.
// RNN/GRU/LSTM Sequences are supported with clip == 0, and with default activations.
auto isSequencePrimitiveSupported = [](const_node_ptr &node) -> bool {
const auto& data = node->input(0);
const auto& data_pshape = data.get_partial_shape();
// WA: dynamic shapes make impossible to check seq_len due to shapeOf subgraphs
// but the sequence is still supported in CPU and doesn't need to be decomposed
if (data_pshape.is_dynamic())
return true;
if (data_pshape.rank().is_static() && data_pshape.rank().get_length() > 1 && !data_pshape[1].is_static())
return false;
auto max_seq_len = data.get_shape().at(1);
if (const auto &rnn_seq = std::dynamic_pointer_cast<const ov::opset6::RNNSequence>(node)) {
return rnn_seq->get_clip() == 0.0f &&
!ov::op::util::is_seq_len_provided(rnn_seq->get_input_node_shared_ptr(2),
max_seq_len);
} else if (const auto &gru_seq = std::dynamic_pointer_cast<const ov::opset6::GRUSequence>(
node)) {
return gru_seq->get_clip() == 0.0f &&
gru_seq->get_activations() == std::vector<std::string>{"sigmoid", "tanh"} &&
!ov::op::util::is_seq_len_provided(gru_seq->get_input_node_shared_ptr(2),
max_seq_len);
} else if (const auto &augru_seq = std::dynamic_pointer_cast<const ov::op::internal::AUGRUSequence>(
node)) {
return augru_seq->get_clip() == 0.0f &&
augru_seq->get_activations() == std::vector<std::string>{"sigmoid", "tanh"} &&
!ov::op::util::is_seq_len_provided(augru_seq->get_input_node_shared_ptr(2),
max_seq_len);
} else if (const auto &lstm_seq = std::dynamic_pointer_cast<const ov::opset6::LSTMSequence>(
node)) {
return lstm_seq->get_clip() == 0.0f &&
lstm_seq->get_activations() == std::vector<std::string>{"sigmoid", "tanh", "tanh"} &&
!ov::op::util::is_seq_len_provided(lstm_seq->get_input_node_shared_ptr(3),
max_seq_len);
}
return false;
};
CPU_SET_CALLBACK_COMMON(manager,
[isSequencePrimitiveSupported](const_node_ptr &node) -> bool {
return isSequencePrimitiveSupported(node);
[](const_node_ptr &node) -> bool {
std::string msg;
return node::RNN::isSupportedOperation(node, msg);
},
ov::pass::ConvertRNNSequenceToTensorIterator,
ov::pass::ConvertGRUSequenceToTensorIterator,
ov::pass::ConvertLSTMSequenceToTensorIterator);
CPU_SET_CALLBACK_COMMON(manager,
[isCellPrimitiveSupported](const_node_ptr &node) -> bool {
return isCellPrimitiveSupported(node);
[](const_node_ptr &node) -> bool {
std::string msg;
return node::RNN::isSupportedOperation(node, msg);
},
ov::pass::RNNCellDecomposition,
ov::pass::GRUCellDecomposition,
@@ -18,6 +18,10 @@ namespace {
{"tanh", "relu"}};
std::vector<float> clip = {0.0f, 0.7f};
std::vector<bool> linear_before_reset = {true, false};
std::vector<ngraph::helpers::InputLayerType> layer_types = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER
};
std::vector<InferenceEngine::Precision> netPrecisions = {InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16};
@@ -30,6 +34,9 @@ namespace {
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GRUCellTest::getTestCaseName);
@@ -45,6 +45,23 @@ namespace {
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GRUSequenceTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_GRUSequenceCommonZeroClipNonConstantWRB, GRUSequenceTest,
::testing::Combine(
::testing::Values(ngraph::helpers::SequenceTestsMode::PURE_SEQ),
::testing::ValuesIn(seq_lengths_zero_clip),
::testing::ValuesIn(batch),
::testing::ValuesIn(hidden_size),
// ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::PARAMETER),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GRUSequenceTest::getTestCaseName);
@@ -60,6 +77,7 @@ namespace {
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
GRUSequenceTest::getTestCaseName);
@@ -18,6 +18,10 @@ namespace {
{"tanh", "relu", "sigmoid"}, {"sigmoid", "sigmoid", "sigmoid"},
{"tanh", "tanh", "tanh"}, {"relu", "relu", "relu"}};
std::vector<float> clip{0.f, 0.7f};
std::vector<ngraph::helpers::InputLayerType> layer_types = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER
};
std::vector<InferenceEngine::Precision> netPrecisions = {InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16};
@@ -29,6 +33,9 @@ namespace {
::testing::ValuesIn(input_size),
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
LSTMCellTest::getTestCaseName);
@@ -44,6 +44,22 @@ namespace {
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
LSTMSequenceTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonZeroClipNonconstantWRB, LSTMSequenceTest,
::testing::Combine(
::testing::Values(ngraph::helpers::SequenceTestsMode::PURE_SEQ),
::testing::ValuesIn(seq_lengths_zero_clip),
::testing::ValuesIn(batch),
::testing::ValuesIn(hidden_size),
::testing::ValuesIn(input_size),
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::PARAMETER),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
LSTMSequenceTest::getTestCaseName);
@@ -58,6 +74,7 @@ namespace {
::testing::ValuesIn(activations),
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
LSTMSequenceTest::getTestCaseName);
@@ -16,6 +16,10 @@ namespace {
std::vector<size_t> input_size{1, 30};
std::vector<std::vector<std::string>> activations = {{"relu"}, {"sigmoid"}, {"tanh"}};
std::vector<float> clip = {0.f, 0.7f};
std::vector<ngraph::helpers::InputLayerType> layer_types = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER
};
std::vector<InferenceEngine::Precision> netPrecisions = {InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16};
@@ -27,6 +31,9 @@ namespace {
::testing::ValuesIn(input_size),
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
RNNCellTest::getTestCaseName);
@@ -41,6 +41,7 @@ namespace {
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
RNNSequenceTest::getTestCaseName);
@@ -55,6 +56,7 @@ namespace {
::testing::ValuesIn(activations),
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
RNNSequenceTest::getTestCaseName);
@@ -273,10 +273,6 @@ TEST_P(SequenceCPUTest, CompareWithRefs) {
CheckNumberOfNodesWithType(compiledModel, "Transpose", 0);
}
const std::vector<SEQ_TYPE> nodeType = {
SEQ_TYPE::GRU, SEQ_TYPE::LSTM, SEQ_TYPE::RNN
};
const std::vector<size_t> hiddenSizes = {
1, 10
};
@@ -317,8 +313,8 @@ std::vector<bool> linearBeforeReset = {true, false};
std::vector<ElementType> netPrecisions = { ElementType::f32 };
INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_dynamic, SequenceCPUTest,
::testing::Combine(::testing::ValuesIn(nodeType),
INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_dynamic_lstm_rnn, SequenceCPUTest,
::testing::Combine(::testing::ValuesIn({SEQ_TYPE::LSTM, SEQ_TYPE::RNN}),
::testing::ValuesIn(hiddenSizes),
::testing::ValuesIn(inputSizes),
::testing::ValuesIn(inShapeParams_dynamic),
@@ -330,6 +326,19 @@ INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_dynamic, SequenceCPUTest,
::testing::Values(ngraph::helpers::InputLayerType::PARAMETER)),
SequenceCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_dynamic_gru, SequenceCPUTest,
::testing::Combine(::testing::Values(SEQ_TYPE::GRU),
::testing::ValuesIn(hiddenSizes),
::testing::ValuesIn(inputSizes),
::testing::ValuesIn(inShapeParams_dynamic),
::testing::ValuesIn(activations_gru_support),
::testing::ValuesIn(clip),
::testing::ValuesIn(linearBeforeReset),
::testing::ValuesIn(direction),
::testing::ValuesIn(netPrecisions),
::testing::Values(ngraph::helpers::InputLayerType::PARAMETER)),
SequenceCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_SequenceCPUTest_static_gru, SequenceCPUTest,
::testing::Combine(::testing::Values(SEQ_TYPE::GRU),
::testing::ValuesIn(hiddenSizes),
@@ -11,6 +11,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
class GRUCellGNATest : public GRUCellTest {
protected:
void SetUp() override {
@@ -23,6 +25,9 @@ protected:
std::vector<float> activations_beta;
float clip;
bool linear_before_reset;
InputLayerType WType;
InputLayerType RType;
InputLayerType BType;
InferenceEngine::Precision netPrecision;
std::tie(should_decompose,
batch,
@@ -31,6 +36,9 @@ protected:
activations,
clip,
linear_before_reset,
WType,
RType,
BType,
netPrecision,
targetDevice) = this->GetParam();
@@ -42,6 +50,10 @@ protected:
{(linear_before_reset ? 4 : 3) * hidden_size}},
};
ASSERT_EQ(InputLayerType::CONSTANT, WType);
ASSERT_EQ(InputLayerType::CONSTANT, RType);
ASSERT_EQ(InputLayerType::CONSTANT, BType);
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]});
std::vector<ngraph::Shape> WRB = {inputShapes[2], inputShapes[3], inputShapes[4]};
@@ -121,6 +133,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_GRUCellCommon,
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::Values(InputLayerType::CONSTANT),
::testing::Values(InputLayerType::CONSTANT),
::testing::Values(InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA)),
GRUCellTest::getTestCaseName);
@@ -13,6 +13,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
class GRUSequenceGNATest : public GRUSequenceTest {
protected:
void SetUp() override {
@@ -27,6 +29,7 @@ protected:
std::vector<float> activations_beta;
float clip;
bool linear_before_reset;
InputLayerType WRBType;
ngraph::op::RecurrentSequenceDirection direction;
InferenceEngine::Precision netPrecision;
std::tie(m_mode,
@@ -37,9 +40,12 @@ protected:
clip,
linear_before_reset,
direction,
WRBType,
netPrecision,
targetDevice) = this->GetParam();
ASSERT_EQ(InputLayerType::CONSTANT, WRBType);
size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1;
std::vector<std::vector<size_t>> inputShapes = {
{{batch, seq_lengths, input_size},
@@ -160,6 +166,7 @@ INSTANTIATE_TEST_SUITE_P(
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA)),
GRUSequenceTest::getTestCaseName);
@@ -176,6 +183,7 @@ INSTANTIATE_TEST_SUITE_P(
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA)),
GRUSequenceTest::getTestCaseName);
@@ -13,6 +13,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
class LSTMSequenceGNATest : public LSTMSequenceTest {
protected:
void SetUp() override {
@@ -27,6 +29,7 @@ protected:
std::vector<float> activations_beta;
float clip;
ngraph::op::RecurrentSequenceDirection direction;
InputLayerType WRBType;
InferenceEngine::Precision netPrecision;
std::tie(m_mode,
seq_lengths,
@@ -36,9 +39,12 @@ protected:
activations,
clip,
direction,
WRBType,
netPrecision,
targetDevice) = this->GetParam();
ASSERT_EQ(InputLayerType::CONSTANT, WRBType);
size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1;
std::vector<std::vector<size_t>> inputShapes = {
{{batch, seq_lengths, input_size},
@@ -156,6 +162,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonZeroClip,
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(direction),
::testing::Values(InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA)),
LSTMSequenceTest::getTestCaseName);
@@ -170,6 +177,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonClip,
::testing::ValuesIn(activations),
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(direction),
::testing::Values(InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA)),
LSTMSequenceTest::getTestCaseName);
@@ -18,6 +18,10 @@ namespace {
{"tanh", "relu"}};
std::vector<float> clip = {0.0f, 0.7f};
std::vector<bool> linear_before_reset = {true, false};
std::vector<ngraph::helpers::InputLayerType> layer_types = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER
};
std::vector<InferenceEngine::Precision> netPrecisions = {InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16};
@@ -30,6 +34,9 @@ namespace {
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
GRUCellTest::getTestCaseName);
@@ -45,6 +45,23 @@ namespace {
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
GRUSequenceTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(GRUSequenceCommonZeroClipNonConstantWRB, GRUSequenceTest,
::testing::Combine(
::testing::Values(ngraph::helpers::SequenceTestsMode::PURE_SEQ),
::testing::ValuesIn(seq_lengths_zero_clip),
::testing::ValuesIn(batch),
::testing::ValuesIn(hidden_size),
// ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::PARAMETER),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
GRUSequenceTest::getTestCaseName);
@@ -60,6 +77,7 @@ namespace {
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(linear_before_reset),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
GRUSequenceTest::getTestCaseName);
@@ -20,6 +20,10 @@ std::vector<std::vector<std::string>> activations = {{"relu", "sigmoid", "tanh"}
{"tanh", "relu", "sigmoid"}, {"sigmoid", "sigmoid", "sigmoid"},
{"tanh", "tanh", "tanh"}, {"relu", "relu", "relu"}};
std::vector<float> clip{0.f, 0.7f};
std::vector<ngraph::helpers::InputLayerType> layer_types = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER
};
std::vector<InferenceEngine::Precision> netPrecisions = {InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16};
@@ -31,6 +35,9 @@ INSTANTIATE_TEST_SUITE_P(LSTMCellCommon, LSTMCellTest,
::testing::ValuesIn(input_size),
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
LSTMCellTest::getTestCaseName);
@@ -43,6 +50,9 @@ INSTANTIATE_TEST_SUITE_P(smoke_LSTMCellCommon, LSTMCellTest,
::testing::ValuesIn(input_size),
::testing::ValuesIn(activations_smoke),
::testing::ValuesIn(clip),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
LSTMCellTest::getTestCaseName);
@@ -46,6 +46,22 @@ INSTANTIATE_TEST_SUITE_P(LSTMSequenceCommonZeroClip, LSTMSequenceTest,
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
LSTMSequenceTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(LSTMSequenceCommonZeroClipNonConstantWRB, LSTMSequenceTest,
::testing::Combine(
::testing::Values(ngraph::helpers::SequenceTestsMode::PURE_SEQ),
::testing::ValuesIn(seq_lengths_zero_clip),
::testing::ValuesIn(batch),
::testing::ValuesIn(hidden_size),
::testing::ValuesIn(input_size),
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::PARAMETER),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
LSTMSequenceTest::getTestCaseName);
@@ -60,6 +76,7 @@ INSTANTIATE_TEST_SUITE_P(LSTMSequenceCommonClip, LSTMSequenceTest,
::testing::ValuesIn(activations),
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
LSTMSequenceTest::getTestCaseName);
@@ -74,6 +91,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_LSTMSequenceCommonClip, LSTMSequenceTest,
::testing::ValuesIn(activations_smoke),
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
LSTMSequenceTest::getTestCaseName);
@@ -16,6 +16,10 @@ namespace {
std::vector<size_t> input_size{1, 30};
std::vector<std::vector<std::string>> activations = {{"relu"}, {"sigmoid"}, {"tanh"}};
std::vector<float> clip = {0.f, 0.7f};
std::vector<ngraph::helpers::InputLayerType> layer_types = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER
};
std::vector<InferenceEngine::Precision> netPrecisions = {InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16};
@@ -27,6 +31,9 @@ namespace {
::testing::ValuesIn(input_size),
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(layer_types),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
RNNCellTest::getTestCaseName);
@@ -41,6 +41,7 @@ INSTANTIATE_TEST_SUITE_P(RNNSequenceCommonZeroClip, RNNSequenceTest,
::testing::ValuesIn(activations),
::testing::ValuesIn(clip),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
RNNSequenceTest::getTestCaseName);
@@ -55,6 +56,7 @@ INSTANTIATE_TEST_SUITE_P(RNNSequenceCommonClip, RNNSequenceTest,
::testing::ValuesIn(activations),
::testing::ValuesIn(clip_non_zeros),
::testing::ValuesIn(direction),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
RNNSequenceTest::getTestCaseName);
@@ -62,6 +62,8 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*OVCompiledModelBaseTest.*CanSetConfigToExecNetAndCheckConfigAndCheck.*)",
// TODO: Issue 67408
R"(.*smoke_LSTMSequenceCommonClip.*LSTMSequenceTest.*CompareWithRefs.*)",
// TODO: Issue 114262
R"(LSTMSequenceCommonZeroClipNonConstantWRB/LSTMSequenceTest.CompareWithRefs/mode=PURE_SEQ_seq_lengths=2_batch=10_hidden_size=1_.*relu.*)",
// Expected behavior. GPU plugin doesn't support i64 for eltwise power operation.
R"(.*EltwiseLayerTest.*OpType=Pow.*NetType=i64.*)",
// TODO: Issue: 68712
@@ -1740,6 +1740,25 @@ std::shared_ptr<ov::Model> generateRNNCellBase(const std::shared_ptr<ov::op::Op>
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(RNNCellBaseNode->output(0)),
std::make_shared<ov::op::v0::Result>(RNNCellBaseNode->output(1))};;
return std::make_shared<ov::Model>(results, params, "LSTMCell4BaseGraph");
} else if (ov::is_type<ov::op::v5::GRUSequence>(node)) {
const auto params =
ngraph::builder::makeDynamicParams({ov::element::f32, ov::element::f32, ov::element::i64},
{{5, 10, 10}, {5, 1, 10}, {5}});
const auto W = ngraph::builder::makeConstant<float>(ov::element::f32, {1, 30, 10}, {}, true);
const auto R = ngraph::builder::makeConstant<float>(ov::element::f32, {1, 30, 10}, {}, true);
const auto B = ngraph::builder::makeConstant<float>(ov::element::f32, {1, 30}, {}, true);
const size_t hidden_size = 10;
const auto gru_sequence =
std::make_shared<ov::op::v5::GRUSequence>(params[0],
params[1],
params[2],
W,
R,
B,
hidden_size,
ov::op::RecurrentSequenceDirection::FORWARD);
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(gru_sequence)};
return std::make_shared<ov::Model>(results, params, "GRUSequence");
} else if (ov::is_type<ov::op::v0::LSTMSequence>(node)) {
const auto params = ngraph::builder::makeDynamicParams({ov::element::f32, ov::element::f32, ov::element::f32, ov::element::i64},
{{5, 10, 10}, {5, 1, 10}, {5, 1, 10}, {5}});
@@ -23,6 +23,9 @@ using GRUCellParams = typename std::tuple<
std::vector<std::string>, // activations
float, // clip
bool, // linear_before_reset
ngraph::helpers::InputLayerType, // W input type (Constant or Parameter)
ngraph::helpers::InputLayerType, // R input type (Constant or Parameter)
ngraph::helpers::InputLayerType, // B input type (Constant or Parameter)
InferenceEngine::Precision, // Network precision
std::string>; // Device name
@@ -26,6 +26,7 @@ using GRUSequenceParams = typename std::tuple<
float, // clip
bool, // linear_before_reset
ngraph::op::RecurrentSequenceDirection, // direction
ngraph::helpers::InputLayerType, // WRB input type (Constant or Parameter)
InferenceEngine::Precision, // Network precision
std::string>; // Device name
@@ -23,6 +23,9 @@ using LSTMCellParams = typename std::tuple<
size_t, // input size
std::vector<std::string>, // activations
float, // clip
ngraph::helpers::InputLayerType, // W input type (Constant or Parameter)
ngraph::helpers::InputLayerType, // R input type (Constant or Parameter)
ngraph::helpers::InputLayerType, // B input type (Constant or Parameter)
InferenceEngine::Precision, // Network precision
std::string>; // Device name
@@ -24,9 +24,11 @@ using LSTMSequenceParams = typename std::tuple<
std::vector<std::string>, // activations
float, // clip
ngraph::op::RecurrentSequenceDirection, // direction
ngraph::helpers::InputLayerType, // WRB input type (Constant or Parameter)
InferenceEngine::Precision, // Network precision
std::string>; // Device name
class LSTMSequenceTest : public testing::WithParamInterface<LSTMSequenceParams>,
virtual public LayerTestsUtils::LayerTestsCommon {
public:
@@ -22,6 +22,9 @@ using RNNCellParams = typename std::tuple<
size_t, // input size
std::vector<std::string>, // activations
float, // clip
ngraph::helpers::InputLayerType, // W input type (Constant or Parameter)
ngraph::helpers::InputLayerType, // R input type (Constant or Parameter)
ngraph::helpers::InputLayerType, // B input type (Constant or Parameter)
InferenceEngine::Precision, // Network precision
std::string>; // Device name
@@ -24,6 +24,7 @@ using RNNSequenceParams = typename std::tuple<
std::vector<std::string>, // activations
float, // clip
ngraph::op::RecurrentSequenceDirection, // direction
ngraph::helpers::InputLayerType, // WRB input type (Constant or Parameter)
InferenceEngine::Precision, // Network precision
std::string>; // Device name
@@ -7,6 +7,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
std::string GRUCellTest::getTestCaseName(const testing::TestParamInfo<GRUCellParams> &obj) {
bool should_decompose;
size_t batch;
@@ -18,10 +20,13 @@ std::string GRUCellTest::getTestCaseName(const testing::TestParamInfo<GRUCellPar
float clip;
bool linear_before_reset;
std::vector<std::vector<size_t>> inputShapes;
InputLayerType WType;
InputLayerType RType;
InputLayerType BType;
InferenceEngine::Precision netPrecision;
std::string targetDevice;
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip,
linear_before_reset, netPrecision, targetDevice) = obj.param;
linear_before_reset, WType, RType, BType, netPrecision, targetDevice) = obj.param;
inputShapes = {
{{batch, input_size}, {batch, hidden_size}, {3 * hidden_size, input_size},
{3 * hidden_size, hidden_size}, {(linear_before_reset? 4 : 3) * hidden_size}},
@@ -35,6 +40,9 @@ std::string GRUCellTest::getTestCaseName(const testing::TestParamInfo<GRUCellPar
result << "activations=" << CommonTestUtils::vec2str(activations) << "_";
result << "clip=" << clip << "_";
result << "linear_before_reset=" << linear_before_reset << "_";
result << "WType=" << WType << "_";
result << "RType=" << RType << "_";
result << "BType=" << BType << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "targetDevice=" << targetDevice << "_";
return result.str();
@@ -50,21 +58,52 @@ void GRUCellTest::SetUp() {
std::vector<float> activations_beta;
float clip;
bool linear_before_reset;
InputLayerType WType;
InputLayerType RType;
InputLayerType BType;
InferenceEngine::Precision netPrecision;
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, linear_before_reset,
netPrecision, targetDevice) = this->GetParam();
WType, RType, BType, netPrecision, targetDevice) = this->GetParam();
std::vector<std::vector<size_t>> inputShapes = {
{{batch, input_size}, {batch, hidden_size}, {3 * hidden_size, input_size},
{3 * hidden_size, hidden_size}, {(linear_before_reset? 4 : 3) * hidden_size}},
};
std::vector<ngraph::Shape> WRB = {inputShapes[2], inputShapes[3], inputShapes[4]};
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]});
std::vector<ngraph::Shape> WRB = {inputShapes[2], inputShapes[3], inputShapes[4]};
auto gru_cell = ngraph::builder::makeGRU(
ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)),
WRB, hidden_size, activations, {}, {}, clip, linear_before_reset);
std::shared_ptr<ov::Node> W;
if (WType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[0]);
W = param;
params.push_back(param);
} else {
W = ngraph::builder::makeConstant<float>(ngPrc, WRB[0], {}, true);
}
std::shared_ptr<ov::Node> R;
if (RType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[1]);
R = param;
params.push_back(param);
} else {
R = ngraph::builder::makeConstant<float>(ngPrc, WRB[1], {}, true);
}
std::shared_ptr<ov::Node> B;
if (BType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[2]);
B = param;
params.push_back(param);
} else {
B = ngraph::builder::makeConstant<float>(ngPrc, WRB[2], {}, true);
}
auto gru_cell = std::make_shared<ov::op::v3::GRUCell>(params[0], params[1], W, R, B, hidden_size, activations,
activations_alpha, activations_beta, clip,
linear_before_reset);
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(gru_cell->output(0))};
function = std::make_shared<ngraph::Function>(results, params, "gru_cell");
if (should_decompose) {
@@ -8,6 +8,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
std::string GRUSequenceTest::getTestCaseName(const testing::TestParamInfo<GRUSequenceParams> &obj) {
ngraph::helpers::SequenceTestsMode mode;
size_t seq_lengths;
@@ -20,10 +22,11 @@ namespace LayerTestsDefinitions {
float clip;
bool linear_before_reset;
ngraph::op::RecurrentSequenceDirection direction;
InputLayerType WRBType;
InferenceEngine::Precision netPrecision;
std::string targetDevice;
std::tie(mode, seq_lengths, batch, hidden_size, activations, clip, linear_before_reset, direction, netPrecision,
targetDevice) = obj.param;
std::tie(mode, seq_lengths, batch, hidden_size, activations, clip, linear_before_reset, direction, WRBType,
netPrecision, targetDevice) = obj.param;
std::vector<std::vector<size_t>> inputShapes = {
{{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {3 * hidden_size, input_size},
{3 * hidden_size, hidden_size}, {(linear_before_reset ? 4 : 3) * hidden_size}},
@@ -55,11 +58,12 @@ namespace LayerTestsDefinitions {
float clip;
bool linear_before_reset;
ngraph::op::RecurrentSequenceDirection direction;
InputLayerType WRBType;
InferenceEngine::Precision netPrecision;
std::tie(m_mode, seq_lengths, batch, hidden_size, activations, clip, linear_before_reset, direction, netPrecision,
targetDevice) = this->GetParam();
std::tie(m_mode, seq_lengths, batch, hidden_size, activations, clip, linear_before_reset, direction, WRBType,
netPrecision, targetDevice) = this->GetParam();
size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1;
std::vector<std::vector<size_t>> inputShapes = {
std::vector<ov::Shape> inputShapes = {
{{batch, seq_lengths, input_size}, {batch, num_directions, hidden_size}, {batch},
{num_directions, 3 * hidden_size, input_size}, {num_directions, 3 * hidden_size, hidden_size},
{num_directions, (linear_before_reset ? 4 : 3) * hidden_size}},
@@ -67,17 +71,47 @@ namespace LayerTestsDefinitions {
m_max_seq_len = seq_lengths;
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]});
const auto& W_shape = inputShapes[3];
const auto& R_shape = inputShapes[4];
const auto& B_shape = inputShapes[5];
std::shared_ptr<ov::Node> seq_lengths_node;
if (m_mode == SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM ||
m_mode == SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM ||
m_mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM) {
auto seq_lengths = ngraph::builder::makeParams(ngraph::element::i64, {inputShapes[2]}).at(0);
seq_lengths->set_friendly_name("seq_lengths");
params.push_back(seq_lengths);
auto param = ngraph::builder::makeParams(ov::element::i64, {inputShapes[2]}).at(0);
param->set_friendly_name("seq_lengths");
params.push_back(param);
seq_lengths_node = param;
} else if (m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_CONST ||
m_mode == ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_CONST) {
seq_lengths_node = ngraph::builder::makeConstant<int64_t>(ov::element::i64, inputShapes[2], {}, true,
static_cast<int64_t>(seq_lengths), 0.f);
} else {
std::vector<int64_t> lengths(batch, seq_lengths);
seq_lengths_node = ngraph::builder::makeConstant(ov::element::i64, inputShapes[2], lengths, false);
}
std::vector<ngraph::Shape> WRB = {inputShapes[3], inputShapes[4], inputShapes[5], inputShapes[2]};
auto gru_sequence = ngraph::builder::makeGRU(ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)),
WRB, hidden_size, activations, {}, {}, clip, linear_before_reset, true, direction,
m_mode);
std::shared_ptr<ov::Node> W, R, B;
if (WRBType == InputLayerType::PARAMETER) {
const auto W_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, W_shape);
const auto R_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, R_shape);
const auto B_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, B_shape);
W = W_param;
R = R_param;
B = B_param;
params.push_back(W_param);
params.push_back(R_param);
params.push_back(B_param);
} else {
W = ngraph::builder::makeConstant<float>(ngPrc, W_shape, {}, true);
R = ngraph::builder::makeConstant<float>(ngPrc, R_shape, {}, true);
B = ngraph::builder::makeConstant<float>(ngPrc, B_shape, {}, true);
}
auto gru_sequence = std::make_shared<ov::op::v5::GRUSequence>(params[0], params[1], seq_lengths_node, W, R, B, hidden_size, direction,
activations, activations_alpha, activations_beta, clip, linear_before_reset);
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(gru_sequence->output(0)),
std::make_shared<ngraph::opset1::Result>(gru_sequence->output(1))};
function = std::make_shared<ngraph::Function>(results, params, "gru_sequence");
@@ -7,6 +7,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
std::string LSTMCellTest::getTestCaseName(const testing::TestParamInfo<LSTMCellParams> &obj) {
bool should_decompose;
size_t batch;
@@ -16,10 +18,13 @@ std::string LSTMCellTest::getTestCaseName(const testing::TestParamInfo<LSTMCellP
std::vector<float> activations_alpha;
std::vector<float> activations_beta;
float clip;
InputLayerType WType;
InputLayerType RType;
InputLayerType BType;
InferenceEngine::Precision netPrecision;
std::string targetDevice;
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, netPrecision,
targetDevice) = obj.param;
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, WType, RType, BType,
netPrecision, targetDevice) = obj.param;
std::vector<std::vector<size_t>> inputShapes = {
{{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {4 * hidden_size, input_size},
{4 * hidden_size, hidden_size}, {4 * hidden_size}},
@@ -32,6 +37,9 @@ std::string LSTMCellTest::getTestCaseName(const testing::TestParamInfo<LSTMCellP
result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_";
result << "activations=" << CommonTestUtils::vec2str(activations) << "_";
result << "clip=" << clip << "_";
result << "WType=" << WType << "_";
result << "RType=" << RType << "_";
result << "BType=" << BType << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "targetDevice=" << targetDevice << "_";
return result.str();
@@ -46,18 +54,50 @@ void LSTMCellTest::SetUp() {
std::vector<float> activations_alpha;
std::vector<float> activations_beta;
float clip;
InputLayerType WType;
InputLayerType RType;
InputLayerType BType;
InferenceEngine::Precision netPrecision;
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, netPrecision,
targetDevice) = this->GetParam();
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, WType, RType, BType,
netPrecision, targetDevice) = this->GetParam();
std::vector<std::vector<size_t>> inputShapes = {
{{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {4 * hidden_size, input_size},
{4 * hidden_size, hidden_size}, {4 * hidden_size}},
};
std::vector<ngraph::Shape> WRB = {inputShapes[3], inputShapes[4], inputShapes[5]};
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1], inputShapes[2]});
std::vector<ngraph::Shape> WRB = {inputShapes[3], inputShapes[4], inputShapes[5]};
auto lstm_cell = ngraph::builder::makeLSTM(ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)),
WRB, hidden_size, activations, {}, {}, clip);
std::shared_ptr<ov::Node> W;
if (WType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[0]);
W = param;
params.push_back(param);
} else {
W = ngraph::builder::makeConstant<float>(ngPrc, WRB[0], {}, true);
}
std::shared_ptr<ov::Node> R;
if (RType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[1]);
R = param;
params.push_back(param);
} else {
R = ngraph::builder::makeConstant<float>(ngPrc, WRB[1], {}, true);
}
std::shared_ptr<ov::Node> B;
if (BType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[2]);
B = param;
params.push_back(param);
} else {
B = ngraph::builder::makeConstant<float>(ngPrc, WRB[2], {}, true);
}
auto lstm_cell = std::make_shared<ov::op::v4::LSTMCell>(params[0], params[1], params[2], W, R, B, hidden_size, activations,
activations_alpha, activations_beta, clip);
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(lstm_cell->output(0)),
std::make_shared<ngraph::opset1::Result>(lstm_cell->output(1))};
function = std::make_shared<ngraph::Function>(results, params, "lstm_cell");
@@ -9,6 +9,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
std::string LSTMSequenceTest::getTestCaseName(const testing::TestParamInfo<LSTMSequenceParams> &obj) {
ngraph::helpers::SequenceTestsMode mode;
size_t seq_lengths;
@@ -20,10 +22,11 @@ namespace LayerTestsDefinitions {
std::vector<float> activations_beta;
float clip;
ngraph::op::RecurrentSequenceDirection direction;
InputLayerType WRBType;
InferenceEngine::Precision netPrecision;
std::string targetDevice;
std::tie(mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, netPrecision,
targetDevice) = obj.param;
std::tie(mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction,
WRBType, netPrecision, targetDevice) = obj.param;
std::vector<std::vector<size_t>> inputShapes = {
{{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {4 * hidden_size, input_size},
{4 * hidden_size, hidden_size}, {4 * hidden_size}},
@@ -38,6 +41,7 @@ namespace LayerTestsDefinitions {
result << "activations=" << CommonTestUtils::vec2str(activations) << "_";
result << "direction=" << direction << "_";
result << "clip=" << clip << "_";
result << "WRBType=" << WRBType << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "targetDevice=" << targetDevice << "_";
return result.str();
@@ -56,27 +60,59 @@ namespace LayerTestsDefinitions {
std::vector<float> activations_beta;
float clip;
ngraph::op::RecurrentSequenceDirection direction;
InputLayerType WRBType;
InferenceEngine::Precision netPrecision;
std::tie(m_mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, netPrecision,
targetDevice) = this->GetParam();
std::tie(m_mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction,
WRBType, netPrecision, targetDevice) = this->GetParam();
size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1;
m_max_seq_len = seq_lengths;
std::vector<std::vector<size_t>> inputShapes = {
std::vector<ov::Shape> inputShapes = {
{{batch, seq_lengths, input_size}, {batch, num_directions, hidden_size}, {batch, num_directions, hidden_size},
{batch}, {num_directions, 4 * hidden_size, input_size}, {num_directions, 4 * hidden_size, hidden_size}, {num_directions, 4 * hidden_size}},
};
const auto& W_shape = inputShapes[4];
const auto& R_shape = inputShapes[5];
const auto& B_shape = inputShapes[6];
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = makeParams(ngPrc, {inputShapes[0], inputShapes[1], inputShapes[2]});
std::shared_ptr<ov::Node> seq_lengths_node;
if (m_mode == SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM ||
m_mode == SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM ||
m_mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM) {
auto seq_lengths = makeParams(ngraph::element::i64, {inputShapes[3]}).at(0);
seq_lengths->set_friendly_name("seq_lengths");
params.push_back(seq_lengths);
auto param = makeParams(ov::element::i64, {inputShapes[3]}).at(0);
seq_lengths_node = param;
seq_lengths_node->set_friendly_name("seq_lengths");
params.push_back(param);
} else if (m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_CONST ||
m_mode == ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_CONST) {
seq_lengths_node = ngraph::builder::makeConstant<int64_t>(ov::element::i64, inputShapes[3], {}, true,
static_cast<int64_t>(seq_lengths), 0.f);
} else {
std::vector<int64_t> lengths(inputShapes[3][0], seq_lengths);
seq_lengths_node = ngraph::builder::makeConstant(ov::element::i64, inputShapes[3], lengths, false);
}
std::vector<ngraph::Shape> WRB = {inputShapes[4], inputShapes[5], inputShapes[6], inputShapes[3]};
auto lstm_sequence = makeLSTM(convert2OutputVector(castOps2Nodes(params)), WRB, hidden_size, activations,
{}, {}, clip, true, direction, m_mode);
std::shared_ptr<ov::Node> W, R, B;
if (WRBType == InputLayerType::PARAMETER) {
const auto W_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, W_shape);
const auto R_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, R_shape);
const auto B_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, B_shape);
W = W_param;
R = R_param;
B = B_param;
params.push_back(W_param);
params.push_back(R_param);
params.push_back(B_param);
} else {
W = ngraph::builder::makeConstant<float>(ngPrc, W_shape, {}, true);
R = ngraph::builder::makeConstant<float>(ngPrc, R_shape, {}, true);
B = ngraph::builder::makeConstant<float>(ngPrc, B_shape, {}, true);
}
auto lstm_sequence = std::make_shared<ov::op::v5::LSTMSequence>(params[0], params[1], params[2], seq_lengths_node, W, R, B, hidden_size, direction,
std::vector<float>{}, std::vector<float>{}, activations, clip);
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(lstm_sequence->output(0)),
std::make_shared<ngraph::opset1::Result>(lstm_sequence->output(1)),
std::make_shared<ngraph::opset1::Result>(lstm_sequence->output(2))};
@@ -7,6 +7,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
std::string RNNCellTest::getTestCaseName(const testing::TestParamInfo<RNNCellParams> &obj) {
bool should_decompose;
size_t batch;
@@ -14,9 +16,12 @@ std::string RNNCellTest::getTestCaseName(const testing::TestParamInfo<RNNCellPar
size_t input_size;
std::vector<std::string> activations;
float clip;
InputLayerType WType;
InputLayerType RType;
InputLayerType BType;
InferenceEngine::Precision netPrecision;
std::string targetDevice;
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip,
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, WType, RType, BType,
netPrecision, targetDevice) = obj.param;
std::vector<std::vector<size_t>> inputShapes = {{batch, input_size}, {batch, hidden_size},
{hidden_size, input_size}, {hidden_size, hidden_size}, {hidden_size}};
@@ -28,6 +33,9 @@ std::string RNNCellTest::getTestCaseName(const testing::TestParamInfo<RNNCellPar
result << "IS=" << CommonTestUtils::vec2str(inputShapes) << "_";
result << "activations=" << CommonTestUtils::vec2str(activations) << "_";
result << "clip=" << clip << "_";
result << "WType=" << WType << "_";
result << "RType=" << RType << "_";
result << "BType=" << BType << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "targetDevice=" << targetDevice << "_";
return result.str();
@@ -42,17 +50,47 @@ void RNNCellTest::SetUp() {
std::vector<float> activations_alpha;
std::vector<float> activations_beta;
float clip;
InputLayerType WType;
InputLayerType RType;
InputLayerType BType;
InferenceEngine::Precision netPrecision;
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip,
std::tie(should_decompose, batch, hidden_size, input_size, activations, clip, WType, RType, BType,
netPrecision, targetDevice) = this->GetParam();
std::vector<std::vector<size_t>> inputShapes = {{batch, input_size}, {batch, hidden_size},
{hidden_size, input_size}, {hidden_size, hidden_size}, {hidden_size}};
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]});
std::vector<ngraph::Shape> WRB = {inputShapes[2], inputShapes[3], inputShapes[4]};
auto rnn_cell = ngraph::builder::makeRNN(
ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)),
WRB, hidden_size, activations, {}, {}, clip);
std::shared_ptr<ov::Node> W;
if (WType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[0]);
W = param;
params.push_back(param);
} else {
W = ngraph::builder::makeConstant<float>(ngPrc, WRB[0], {}, true);
}
std::shared_ptr<ov::Node> R;
if (RType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[1]);
R = param;
params.push_back(param);
} else {
R = ngraph::builder::makeConstant<float>(ngPrc, WRB[1], {}, true);
}
std::shared_ptr<ov::Node> B;
if (BType == InputLayerType::PARAMETER) {
const auto param = std::make_shared<ov::op::v0::Parameter>(ngPrc, WRB[2]);
B = param;
params.push_back(param);
} else {
B = ngraph::builder::makeConstant<float>(ngPrc, WRB[2], {}, true);
}
auto rnn_cell = std::make_shared<ov::op::v0::RNNCell>(params[0], params[1], W, R, B, hidden_size, activations,
activations_alpha, activations_beta, clip);
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(rnn_cell)};
function = std::make_shared<ngraph::Function>(results, params, "rnn_cell");
if (should_decompose) {
@@ -8,6 +8,8 @@
namespace LayerTestsDefinitions {
using ngraph::helpers::InputLayerType;
std::string RNNSequenceTest::getTestCaseName(const testing::TestParamInfo<RNNSequenceParams> &obj) {
ngraph::helpers::SequenceTestsMode mode;
size_t seq_lengths;
@@ -20,9 +22,10 @@ namespace LayerTestsDefinitions {
float clip;
ngraph::op::RecurrentSequenceDirection direction;
InferenceEngine::Precision netPrecision;
InputLayerType WRBType;
std::string targetDevice;
std::tie(mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, netPrecision,
targetDevice) = obj.param;
std::tie(mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, WRBType,
netPrecision, targetDevice) = obj.param;
std::vector<std::vector<size_t>> inputShapes = {
{{batch, input_size}, {batch, hidden_size}, {batch, hidden_size}, {hidden_size, input_size},
{hidden_size, hidden_size}, {hidden_size}},
@@ -53,11 +56,12 @@ namespace LayerTestsDefinitions {
std::vector<float> activations_beta;
float clip;
ngraph::op::RecurrentSequenceDirection direction;
InputLayerType WRBType;
InferenceEngine::Precision netPrecision;
std::tie(m_mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, netPrecision,
targetDevice) = this->GetParam();
std::tie(m_mode, seq_lengths, batch, hidden_size, input_size, activations, clip, direction, WRBType,
netPrecision, targetDevice) = this->GetParam();
size_t num_directions = direction == ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL ? 2 : 1;
std::vector<std::vector<size_t>> inputShapes = {
std::vector<ov::Shape> inputShapes = {
{{batch, seq_lengths, input_size}, {batch, num_directions, hidden_size}, {batch},
{num_directions, hidden_size, input_size}, {num_directions, hidden_size, hidden_size},
{num_directions, hidden_size}},
@@ -65,17 +69,46 @@ namespace LayerTestsDefinitions {
m_max_seq_len = seq_lengths;
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShapes[0], inputShapes[1]});
std::shared_ptr<ov::Node> seq_lengths_node;
if (m_mode == SequenceTestsMode::CONVERT_TO_TI_MAX_SEQ_LEN_PARAM ||
m_mode == SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_PARAM ||
m_mode == SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_PARAM) {
auto seq_lengths = ngraph::builder::makeParams(ngraph::element::i64, {inputShapes[2]}).at(0);
seq_lengths->set_friendly_name("seq_lengths");
params.push_back(seq_lengths);
auto param = ngraph::builder::makeParams(ngraph::element::i64, {inputShapes[2]}).at(0);
param->set_friendly_name("seq_lengths");
params.push_back(param);
seq_lengths_node = param;
} else if (m_mode == ngraph::helpers::SequenceTestsMode::CONVERT_TO_TI_RAND_SEQ_LEN_CONST ||
m_mode == ngraph::helpers::SequenceTestsMode::PURE_SEQ_RAND_SEQ_LEN_CONST) {
seq_lengths_node = ngraph::builder::makeConstant(ov::element::i64, inputShapes[2], {}, true,
static_cast<float>(seq_lengths), 0.f);
} else {
std::vector<float> lengths(batch, seq_lengths);
seq_lengths_node = ngraph::builder::makeConstant(ov::element::i64, inputShapes[2], lengths, false);
}
std::vector<ngraph::Shape> WRB = {inputShapes[3], inputShapes[4], inputShapes[5], inputShapes[2]};
auto rnn_sequence = ngraph::builder::makeRNN(ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(params)),
WRB, hidden_size, activations, {}, {}, clip, true, direction,
m_mode);
const auto& W_shape = inputShapes[3];
const auto& R_shape = inputShapes[4];
const auto& B_shape = inputShapes[5];
std::shared_ptr<ov::Node> W, R, B;
if (WRBType == InputLayerType::PARAMETER) {
const auto W_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, W_shape);
const auto R_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, R_shape);
const auto B_param = std::make_shared<ov::op::v0::Parameter>(ngPrc, B_shape);
W = W_param;
R = R_param;
B = B_param;
params.push_back(W_param);
params.push_back(R_param);
params.push_back(B_param);
} else {
W = ngraph::builder::makeConstant<float>(ngPrc, W_shape, {}, true);
R = ngraph::builder::makeConstant<float>(ngPrc, R_shape, {}, true);
B = ngraph::builder::makeConstant<float>(ngPrc, B_shape, {}, true);
}
auto rnn_sequence = std::make_shared<ov::op::v5::RNNSequence>(params[0], params[1], seq_lengths_node, W, R, B, hidden_size, direction,
activations, activations_alpha, activations_beta, clip);
ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(rnn_sequence->output(0)),
std::make_shared<ngraph::opset1::Result>(rnn_sequence->output(1))};
function = std::make_shared<ngraph::Function>(results, params, "rnn_sequence");