Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Enable onednn GRUSequence in specific case of dynamic model (#32515)

Wilson Seok5005b19ef55c
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp
index 5a4f7503e32..f2b78fbe0dc 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/concat_input_order.cpp
@@ -144,8 +144,8 @@ void concat_input_order::run(program& p) {
std::vector<tensor::value_type> feature_sizes;
feature_sizes.reserve(inputs_count);
for (size_t input_idx = 0; input_idx < inputs_count; ++input_idx) {
- auto& dep = concat_node.get_dependency(input_idx);
- auto dep_layout = dep.get_output_layout();
+ const auto dep = concat_node.get_dependency_with_port(input_idx);
+ auto dep_layout = dep.first->get_output_layout(false, dep.second);
single_format &= dep_layout.format == out_format;
feature_sizes.push_back(dep_layout.feature());
}
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index 7f2327f611f..8a21f747502 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -875,31 +875,37 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
};
// 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
+ // Real sequence_lengths is not supported in all onednn Sequences, so if is_seq_len_provided() == true, we
// should always convert to TensorIterator.
- // RNN/GRU Sequences are not supported in GPU plugin
+ // (WA) We can ignore real sequence_lengths input for batch_size == 1 case when seq_length in first input is dynamic.
+ // This WA applies to GRUSequence only.
+ // RNN Sequence is not supported in GPU plugin and is always converted to TensorIterator
// LSTM Sequence supported with clip == 0, and activations have default values (sigmoid, tanh, tanh)
+ // GRU Sequence supported with clip == 0, and activations have default values (sigmoid, tanh)
auto isSequencePrimitiveSupported = [](const_node_ptr &node) -> bool {
const auto& data = node->input(0);
const auto& data_pshape = data.get_partial_shape();
auto max_seq_len = data_pshape[1];
- if (data_pshape.rank().is_static() && data_pshape.rank().get_length() > 1 && !data_pshape[1].is_static())
- return false;
+
if (ov::as_type_ptr<const ov::op::v5::RNNSequence>(node)) {
return false;
} else if (const auto &gru_seq = ov::as_type_ptr<const ov::op::v5::GRUSequence>(node)) {
+ bool is_batch_one_with_dynamic_seq_len = data_pshape[0] == 1 && !data_pshape[1].is_static();
return gru_seq->get_clip() == 0.0f &&
gru_seq->get_activations() == std::vector<std::string>{"sigmoid", "tanh"} &&
max_seq_len != 1 &&
- !ov::op::util::is_seq_len_provided(gru_seq->get_input_node_shared_ptr(0),
- gru_seq->get_input_node_shared_ptr(2)) &&
+ (!ov::op::util::is_seq_len_provided(gru_seq->get_input_node_shared_ptr(0),
+ gru_seq->get_input_node_shared_ptr(2)) ||
+ is_batch_one_with_dynamic_seq_len) &&
gru_seq->get_linear_before_reset();
} else if (const auto &lstm_seq = ov::as_type_ptr<const ov::op::v5::LSTMSequence>(node)) {
- return lstm_seq->get_clip() == 0.0f &&
- lstm_seq->get_activations() == std::vector<std::string>{"sigmoid", "tanh", "tanh"} &&
- max_seq_len != 1 &&
- !ov::op::util::is_seq_len_provided(lstm_seq->get_input_node_shared_ptr(0),
- lstm_seq->get_input_node_shared_ptr(3));
+ if (!data_pshape[1].is_static())
+ return false;
+ return (lstm_seq->get_clip() == 0.0f &&
+ lstm_seq->get_activations() == std::vector<std::string>{"sigmoid", "tanh", "tanh"} &&
+ max_seq_len != 1 &&
+ !ov::op::util::is_seq_len_provided(lstm_seq->get_input_node_shared_ptr(0),
+ lstm_seq->get_input_node_shared_ptr(3)));
}
return false;
};
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp
index aef67add02d..e809e244a58 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/gru_sequence.cpp
@@ -8,6 +8,7 @@
#include "common_test_utils/test_enums.hpp"
using ov::test::GRUSequenceTest;
+using ov::test::InputShape;
using ov::test::utils::InputLayerType;
using ov::test::utils::SequenceTestsMode;
@@ -37,6 +38,20 @@ namespace {
{{ 10, 20, 1}, { 10, 2, 1 }, { 10 }},
{{ 10, 20, 1}, { 10, 2, 10 }, { 10 }},
};
+
+ // Test case for GRUSequence onednn primitive
+ std::vector<SequenceTestsMode> mode_onednn {SequenceTestsMode::PURE_SEQ};
+ // Dynamic seq_length
+ const std::vector<InputShape> input_shapes_b1 = {
+ {{1, -1, 1}, {{1, 5, 1}}},
+ {{1, 1, 1}, {{1, 1, 1}}},
+ {{1}, {{1}}},
+ };
+ const std::vector<InputShape> input_shapes_bidirect_b1 = {
+ {{1, -1, 1}, {{1, 5, 1}}},
+ {{1, 2, 1}, {{1, 2, 1}}},
+ {{1}, {{1}}},
+ };
std::vector<size_t> seq_lengths_zero_clip{2};
std::vector<size_t> seq_lengths_clip_non_zero{20};
std::vector<size_t> batch{10};
@@ -47,6 +62,8 @@ namespace {
std::vector<bool> linear_before_reset = {true, false};
std::vector<float> clip{0.f};
std::vector<float> clip_non_zeros{0.7f};
+ std::vector<std::vector<std::string>> activations_onednn = {{"sigmoid", "tanh"}};
+ std::vector<bool> linear_before_reset_onednn = {true};
std::vector<ov::op::RecurrentSequenceDirection> direction = {ov::op::RecurrentSequenceDirection::FORWARD,
ov::op::RecurrentSequenceDirection::REVERSE};
std::vector<ov::op::RecurrentSequenceDirection> direction_bi = {ov::op::RecurrentSequenceDirection::BIDIRECTIONAL};
@@ -110,4 +127,32 @@ namespace {
::testing::Values(ov::test::utils::DEVICE_GPU)),
GRUSequenceTest::getTestCaseName);
+ INSTANTIATE_TEST_SUITE_P(smoke_GRUSequenceCommonZeroClip_B1, GRUSequenceTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(mode_onednn),
+ ::testing::Values(input_shapes_b1),
+ // ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args
+ ::testing::ValuesIn(activations_onednn),
+ ::testing::ValuesIn(clip),
+ ::testing::ValuesIn(linear_before_reset_onednn),
+ ::testing::ValuesIn(direction),
+ ::testing::Values(InputLayerType::CONSTANT),
+ ::testing::ValuesIn(netPrecisions),
+ ::testing::Values(ov::test::utils::DEVICE_GPU)),
+ GRUSequenceTest::getTestCaseName);
+
+ INSTANTIATE_TEST_SUITE_P(smoke_GRUSequenceCommonZeroClipBidirect_B1, GRUSequenceTest,
+ ::testing::Combine(
+ ::testing::ValuesIn(mode_onednn),
+ ::testing::Values(input_shapes_bidirect_b1),
+ // ::testing::ValuesIn(input_size), // hardcoded to 10 due to Combine supports up to 10 args
+ ::testing::ValuesIn(activations_onednn),
+ ::testing::ValuesIn(clip),
+ ::testing::ValuesIn(linear_before_reset_onednn),
+ ::testing::ValuesIn(direction_bi),
+ ::testing::Values(InputLayerType::CONSTANT),
+ ::testing::ValuesIn(netPrecisions),
+ ::testing::Values(ov::test::utils::DEVICE_GPU)),
+ GRUSequenceTest::getTestCaseName);
+
} // namespace