OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[transformation][CPU][GPU] support 3D rope (#31949)
Yuan Huf412d66bfc4f
diff --git a/src/common/transformations/include/ov_ops/rotary_positional_embeddings.hpp b/src/common/transformations/include/ov_ops/rotary_positional_embeddings.hppindex 2a83ecc61c7..656649afd04 100644--- a/src/common/transformations/include/ov_ops/rotary_positional_embeddings.hpp+++ b/src/common/transformations/include/ov_ops/rotary_positional_embeddings.hpp@@ -32,6 +32,7 @@ public:// each head. change input order to [batch, head_cnt, 4608] to support 2d ropebool is_qwen = false; // Qwen is special which overrides other settingbool use_rope_cache = false; // use precomputed RoPE cache for trigonometric values (cosine and sine)+ bool support_3d_rope = false; // use same logic as RoPEFusionGPTNEOX(4), used by gpu pluginsize_t head_cnt = 0;size_t head_size = 0;int gather_position_arg_id =diff --git a/src/common/transformations/include/transformations/common_optimizations/fuse_rotary_positional_embeddings.hpp b/src/common/transformations/include/transformations/common_optimizations/fuse_rotary_positional_embeddings.hppindex 01f49149351..ec5191dca07 100644--- a/src/common/transformations/include/transformations/common_optimizations/fuse_rotary_positional_embeddings.hpp+++ b/src/common/transformations/include/transformations/common_optimizations/fuse_rotary_positional_embeddings.hpp@@ -28,7 +28,7 @@ class TRANSFORMATIONS_API RoPEShareCosSin;class ov::pass::RoPEFusionGPTNEOX : public ov::pass::MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("RoPEFusionGPTNEOX");- RoPEFusionGPTNEOX();+ RoPEFusionGPTNEOX(int rank);};class ov::pass::RoPEFusionFlux : public ov::pass::MatcherPass {diff --git a/src/common/transformations/src/ov_ops/rotary_positional_embeddings.cpp b/src/common/transformations/src/ov_ops/rotary_positional_embeddings.cppindex 87d5208af35..5adfa5bb7d7 100644--- a/src/common/transformations/src/ov_ops/rotary_positional_embeddings.cpp+++ b/src/common/transformations/src/ov_ops/rotary_positional_embeddings.cpp@@ -95,6 +95,7 @@ bool RoPE::visit_attributes(ov::AttributeVisitor& visitor) {visitor.on_attribute("rotary_ndims", m_config.rotary_ndims);visitor.on_attribute("is_chatglm", m_config.is_chatglm);visitor.on_attribute("support_2d_rope", m_config.support_2d_rope);+ visitor.on_attribute("support_3d_rope", m_config.support_3d_rope);visitor.on_attribute("is_qwen", m_config.is_qwen);visitor.on_attribute("use_rope_cache", m_config.use_rope_cache);visitor.on_attribute("head_cnt", m_config.head_cnt);diff --git a/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cpp b/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cppindex 19de411c4a3..ee9ba3cba02 100644--- a/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cpp@@ -58,7 +58,8 @@ bool ov::pass::RoPEFusion::run_on_model(const std::shared_ptr<ov::Model>& model)auto symbolic_ctx_manager = symbolic_optimizations.get_manager();symbolic_ctx_manager->register_pass<ov::pass::RoPEFusionFlux>();- symbolic_ctx_manager->register_pass<ov::pass::RoPEFusionGPTNEOX>();+ symbolic_ctx_manager->register_pass<ov::pass::RoPEFusionGPTNEOX>(4);+ symbolic_ctx_manager->register_pass<ov::pass::RoPEFusionGPTNEOX>(3);symbolic_ctx_manager->register_pass<ov::pass::RoPEFusionGPTJ>();// optional heads & tails are fused in separate matcher pass,// after RoPENode has been created.@@ -164,7 +165,7 @@ ov::pass::RoPEFusionFlux::RoPEFusionFlux() {this->register_matcher(m, callback);}-ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX() {+ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX(int rank) {using namespace ov::op::util;MATCHER_SCOPE(RoPEFusionGPTNEOX);@@ -177,19 +178,19 @@ ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX() {// branch.// so here we use a WA, only match the path of rotate_hal(x)*sin and check the x*cos path// in the callback- auto x = pattern::any_input(pattern::rank_equals(4));- auto x_or_cos1 = pattern::any_input(pattern::rank_equals(4));- auto x_or_cos2 = pattern::any_input(pattern::rank_equals(4));- auto t_sin = pattern::any_input(pattern::rank_equals(4));+ auto x = pattern::any_input(pattern::rank_equals(rank));+ auto x_or_cos1 = pattern::any_input(pattern::rank_equals(rank));+ auto x_or_cos2 = pattern::any_input(pattern::rank_equals(rank));+ auto t_sin = pattern::any_input(pattern::rank_equals(rank));- auto varsplit = pattern::wrap_type<v1::VariadicSplit>({x, 3, {"half_ndims", "?"}});+ auto varsplit = pattern::wrap_type<v1::VariadicSplit>({x, rank - 1, {"half_ndims", "?"}});varsplit->set_output_size(2);auto int32_max = std::numeric_limits<std::int32_t>::max();- auto x2 = NewGenSlice(x, "half_ndims", int32_max, 1, 3);+ auto x2 = NewGenSlice(x, "half_ndims", int32_max, 1, rank - 1);auto x2neg = pattern::wrap_type<v1::Multiply>({x2 | varsplit->output(1), -1.0f}, {{"auto_broadcast", "numpy"}});- auto x1 = NewGenSlice(x, 0, "half_ndims", 1, 3);+ auto x1 = NewGenSlice(x, 0, "half_ndims", 1, rank - 1);auto x_rotate_half = pattern::wrap_type<v0::Concat>({x2neg, x1 | varsplit->output(0)}, {{"axis", -1}});auto mul_cos = pattern::wrap_type<v1::Multiply>({x_or_cos1, x_or_cos2}, {{"auto_broadcast", "numpy"}});@@ -220,6 +221,9 @@ ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX() {op::internal::RoPE::Config config;OutputVector new_args;+ if (rank == 3) {+ config.support_3d_rope = true;+ }config.rotary_ndims = 2ul * static_cast<size_t>(half_ndims.i());new_args.push_back(pattern_map.at(x));diff --git a/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp b/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cppindex 0cbc6f8f55f..64b1f6be814 100644--- a/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp+++ b/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp@@ -154,6 +154,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_LLama2_no_gather) {{"config.is_interleaved", false},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", 0},@@ -192,6 +193,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_LLama2_with_gather) {{"config.is_interleaved", false},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", 0},@@ -204,13 +206,13 @@ TEST_F(TransformationTestsF, ConvertToROPE_LLama2_with_gather) {}}-static std::shared_ptr<ov::Model> buildROPE_GPTNEOX(const int batch,- const int seq_length,- const int max_position_embeddings,- const int ndims,- const int num_heads,- const int rotary_ndims,- bool sin_cos_preprocessing) {+static std::shared_ptr<ov::Model> buildROPE_GPTNEOX_4D(const int batch,+ const int seq_length,+ const int max_position_embeddings,+ const int ndims,+ const int num_heads,+ const int rotary_ndims,+ bool sin_cos_preprocessing) {auto batch_s = static_cast<size_t>(batch);auto seq_length_s = static_cast<size_t>(seq_length);auto ndims_s = static_cast<size_t>(ndims);@@ -307,6 +309,60 @@ static std::shared_ptr<ov::Model> buildROPE_GPTNEOX(const int batch,return std::make_shared<ov::Model>(ov::OutputVector{cat_Concat_458}, parameters);}+static std::shared_ptr<ov::Model> buildROPE_GPTNEOX_3D(const int seq_length,+ const int num_heads,+ const int rotary_ndims,+ std::string split_op_type) {+ auto seq_length_s = static_cast<size_t>(seq_length);+ auto rotary_ndims_s = static_cast<size_t>(rotary_ndims);+ auto num_heads_s = static_cast<size_t>(num_heads);+ auto input =+ std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{seq_length_s, num_heads_s, rotary_ndims_s});+ auto Constant_396096 = makeConst(ov::element::f32, ov::Shape({1, 1, 1}), {-1.000000f});++ auto param_cos =+ std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{seq_length_s, 1, rotary_ndims_s});+ auto param_sin =+ std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{seq_length_s, 1, rotary_ndims_s});+ ov::Output<ov::Node> cat_Concat;+ if (split_op_type == "VariadicSplit") {+ auto split = makeOP<ov::opset1::VariadicSplit>({input, {2}, {rotary_ndims / 2, rotary_ndims / 2}});+ auto neg_Multiply =+ makeOP<ov::opset1::Multiply>({split->output(1), Constant_396096}, {{"auto_broadcast", "numpy"}});+ cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, split->output(0)}, {{"axis", -1}});+ } else if (split_op_type == "Slice") {+ auto slice_right_part = makeOP<ov::opset8::Slice>({input, {rotary_ndims / 2}, {INT_MAX}, {1}, {2}});+ auto slice_left_part = makeOP<ov::opset8::Slice>({input, {0}, {rotary_ndims / 2}, {1}, {2}});+ auto neg_Multiply =+ makeOP<ov::opset1::Multiply>({slice_right_part, Constant_396096}, {{"auto_broadcast", "numpy"}});+ cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, slice_left_part}, {{"axis", -1}});+ } else if (split_op_type == "StridedSlice") {+ auto slice_right_part =+ makeOP<ov::opset1::StridedSlice>({input, {0, 0, rotary_ndims / 2}, {0, 0, INT_MAX}, {1, 1, 1}},+ {{"begin_mask", {1, 1, 0}},+ {"end_mask", {1, 1, 0}},+ {"new_axis_mask", {}},+ {"shrink_axis_mask", {}},+ {"ellipsis_mask", {}}});+ auto slice_left_part = makeOP<ov::opset1::StridedSlice>({input, {0, 0, 0}, {0, 0, rotary_ndims / 2}, {1, 1, 1}},+ {{"begin_mask", {1, 1, 0}},+ {"end_mask", {1, 1, 0}},+ {"new_axis_mask", {}},+ {"shrink_axis_mask", {}},+ {"ellipsis_mask", {}}});+ auto neg_Multiply =+ makeOP<ov::opset1::Multiply>({slice_right_part, Constant_396096}, {{"auto_broadcast", "numpy"}});+ cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, slice_left_part}, {{"axis", -1}});+ } else {+ return nullptr;+ }+ auto mul_sin_Multiply = makeOP<ov::opset1::Multiply>({cat_Concat, param_sin}, {{"auto_broadcast", "numpy"}});+ auto mul_cos_Multiply = makeOP<ov::opset1::Multiply>({input, param_cos}, {{"auto_broadcast", "numpy"}});+ auto add_Add = makeOP<ov::opset1::Add>({mul_cos_Multiply, mul_sin_Multiply}, {{"auto_broadcast", "numpy"}});+ ov::ParameterVector parameters = ov::ParameterVector{input, param_cos, param_sin};+ return std::make_shared<ov::Model>(ov::OutputVector{add_Add}, parameters);+}+TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_no_gather) {disable_rt_info_check();const int batch = 2;@@ -316,7 +372,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_no_gather) {const int rotary_ndims = 20;const int max_position_embeddings = 2048;- model = buildROPE_GPTNEOX(batch, seq_len, max_position_embeddings, ndims, num_heads, rotary_ndims, false);+ model = buildROPE_GPTNEOX_4D(batch, seq_len, max_position_embeddings, ndims, num_heads, rotary_ndims, false);manager.register_pass<ov::pass::RoPEFusion>();{auto input =@@ -333,6 +389,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_no_gather) {{"config.is_interleaved", false},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", 0},@@ -353,7 +410,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_with_gather) {const int num_heads = 32;const int max_position_embeddings = 2048;- model = buildROPE_GPTNEOX(batch, seq_len, max_position_embeddings, ndims, num_heads, rotary_ndims, true);+ model = buildROPE_GPTNEOX_4D(batch, seq_len, max_position_embeddings, ndims, num_heads, rotary_ndims, true);manager.register_pass<ov::pass::RoPEFusion>();{auto cos_sin = makeCosSinCache(max_position_embeddings, rotary_ndims);@@ -371,6 +428,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTNEOX_with_gather) {{"config.is_interleaved", false},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", 0},@@ -489,6 +547,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTJ) {{"config.is_interleaved", true},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", 0},@@ -611,6 +670,7 @@ TEST_P(ConvertToROPETest, ConvertToROPE_chatGLM) {{"config.rotary_ndims", rotary_ndims},{"config.is_chatglm", true},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", true},{"config.head_cnt", num_heads},@@ -698,6 +758,7 @@ TEST_P(ConvertToROPETest, ConvertToROPE_chatGLM_Slice) {{"config.rotary_ndims", rotary_ndims},{"config.is_chatglm", true},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", true},{"config.head_cnt", num_heads},@@ -711,6 +772,55 @@ TEST_P(ConvertToROPETest, ConvertToROPE_chatGLM_Slice) {INSTANTIATE_TEST_SUITE_P(TransformationTestsF, ConvertToROPETest, ::testing::ValuesIn({0, 1}));+class ConvertToROPETestGPTNEOX_3D : public TransformationTestsF, public ::testing::WithParamInterface<std::string> {+public:+ static std::string getTestCaseName(const testing::TestParamInfo<std::string>& obj) {+ const auto& split_op_type = obj.param;+ std::ostringstream result;+ result << "split_op_type=" << split_op_type;+ return result.str();+ }+};+TEST_P(ConvertToROPETestGPTNEOX_3D, ConvertToROPE_qwen) {+ disable_rt_info_check();+ const int seq_len = 16;+ const int num_heads = 32;+ const int rotary_ndims = 80;+ const std::string split_op_type = GetParam();+ model = buildROPE_GPTNEOX_3D(seq_len, num_heads, rotary_ndims, split_op_type);+ ASSERT_TRUE(model != nullptr);+ manager.register_pass<ov::pass::RoPEFusionGPTNEOX>(3);+ {+ auto input =+ std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{seq_len, num_heads, rotary_ndims});+ auto param_cos = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{seq_len, 1, rotary_ndims});+ auto param_sin = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{seq_len, 1, rotary_ndims});+ auto rope = makeOP<ov::op::internal::RoPE>({input, param_cos, param_sin},+ {{"config.slice_start", 0},+ {"config.slice_stop", 0},+ {"config.input_trans0213", false},+ {"config.output_trans0213", false},+ {"config.is_interleaved", false},+ {"config.is_chatglm", false},+ {"config.support_2d_rope", false},+ {"config.support_3d_rope", true},+ {"config.is_qwen", false},+ {"config.use_rope_cache", false},+ {"config.head_cnt", 0},+ {"config.head_size", 0},+ {"config.rotary_ndims", rotary_ndims},+ {"config.gather_position_arg_id", 0}});+ model_ref =+ std::make_shared<ov::Model>(ov::OutputVector{rope}, ov::ParameterVector{input, param_cos, param_sin});+ }+}++const std::vector<std::string> vit_param = {"VariadicSplit", "Slice", "StridedSlice"};+INSTANTIATE_TEST_SUITE_P(TransformationTestsF,+ ConvertToROPETestGPTNEOX_3D,+ ::testing::ValuesIn(vit_param),+ ConvertToROPETestGPTNEOX_3D::getTestCaseName);+TEST_F(TransformationTestsF, ConvertToROPE_GPTJ_Slice) {disable_rt_info_check();using namespace ov;@@ -784,6 +894,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTJ_Slice) {{"config.is_interleaved", true},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", 0},@@ -902,6 +1013,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_chatGLM_2d_rope) {{"config.rotary_ndims", rotary_ndims},{"config.is_chatglm", true},{"config.support_2d_rope", true},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", true},{"config.head_cnt", num_heads},@@ -1012,6 +1124,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_chatGLM_nano_2d_rope) {{"config.rotary_ndims", rotary_ndims},{"config.is_chatglm", true},{"config.support_2d_rope", true},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", true},{"config.head_cnt", num_heads},@@ -1104,6 +1217,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_chatGLMHF_2d_rope) {{"config.rotary_ndims", rotary_ndims},{"config.is_chatglm", true},{"config.support_2d_rope", true},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", num_heads},@@ -1347,6 +1461,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_chatGLM3_PagedAttention) {{"config.rotary_ndims", rotary_ndims},{"config.is_chatglm", true},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", true},{"config.head_cnt", num_heads},@@ -1426,6 +1541,7 @@ TEST_P(ConvertToROPETest, ConvertToROPE_Qwen_PagedAttention) {{"config.rotary_ndims", 128},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", true},{"config.use_rope_cache", false},{"config.head_cnt", head_cnt},@@ -1510,6 +1626,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_GPTJ_PagedAttention) {{"config.rotary_ndims", rotary_ndims},{"config.is_chatglm", false},{"config.support_2d_rope", false},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", false},{"config.head_cnt", 0},@@ -1584,6 +1701,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_chatGLM4_PagedAttention) {{"config.rotary_ndims", 64},{"config.is_chatglm", true},{"config.support_2d_rope", true},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", true},{"config.head_cnt", 32},@@ -1670,6 +1788,7 @@ TEST_F(TransformationTestsF, ConvertToROPE_chatGLM4_PagedAttention_GPU) {{"config.rotary_ndims", 64},{"config.is_chatglm", true},{"config.support_2d_rope", true},+ {"config.support_3d_rope", false},{"config.is_qwen", false},{"config.use_rope_cache", true},{"config.head_cnt", 32},diff --git a/src/plugins/intel_cpu/src/nodes/rope.cpp b/src/plugins/intel_cpu/src/nodes/rope.cppindex 3d0d781b8fb..50077b7c5de 100644--- a/src/plugins/intel_cpu/src/nodes/rope.cpp+++ b/src/plugins/intel_cpu/src/nodes/rope.cpp@@ -129,6 +129,11 @@ struct RoPE::RoPEExecutorRotateHalf : public RoPE::Executor {t_src = t_src.slice(3, m_config.slice_start, m_config.slice_stop);can_inplace = false;}+ if (t_src.m_rank == 3) {+ t_src = t_src.reshape({1, t_src.size(0), t_src.size(1), t_src.size(2)});+ t_dst = t_dst.reshape({1, t_dst.size(0), t_dst.size(1), t_dst.size(2)});+ }+if (m_config.input_trans0213) {t_src = t_src.permute({0, 2, 1, 3});can_inplace = false;@@ -139,9 +144,13 @@ struct RoPE::RoPEExecutorRotateHalf : public RoPE::Executor {if (t_cos.m_rank == 2) {t_cos = t_cos.reshape({1, 1, t_cos.size(0), t_cos.size(1)});+ } else if (t_cos.m_rank == 3) {+ t_cos = t_cos.reshape({1, t_cos.size(0), t_cos.size(1), t_cos.size(2)});}if (t_sin.m_rank == 2) {t_sin = t_sin.reshape({1, 1, t_sin.size(0), t_sin.size(1)});+ } else if (t_sin.m_rank == 3) {+ t_sin = t_sin.reshape({1, t_sin.size(0), t_sin.size(1), t_sin.size(2)});}auto batch_size = t_src.size(0);diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cppindex 8a2e88f9f71..733d4d24ecd 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp@@ -70,5 +70,14 @@ INSTANTIATE_TEST_SUITE_P(smoke_RoPETestChatGLM,::testing::Values(ov::test::utils::DEVICE_CPU)),RoPETestChatGLM2DRoPEStridedSlice::getTestCaseName);+const std::vector<std::string> vit_param = {"VariadicSplit", "Slice", "StridedSlice"};+INSTANTIATE_TEST_SUITE_P(smoke_RoPETestQwenVL,+ RoPETestQwenVL,+ ::testing::Combine(+ ::testing::Values(ov::element::f32),+ ::testing::Values(ov::test::utils::DEVICE_CPU),+ ::testing::ValuesIn(vit_param)),+ RoPETestQwenVL::getTestCaseName);+} // namespace test} // namespace ovdiff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.cl b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.clindex 7e7e2e41fcd..bf725d35711 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.cl+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.cl@@ -344,7 +344,6 @@ KERNEL(rope_opt)input_idx += SLICED_FROM_START;#endif#endif-uint cos_sin_p = p;#ifdef ENABLE_GATHERuint gather_b = b < INPUT3_BATCH_NUM ? b : 0;@@ -378,7 +377,7 @@ uint cos_sin_p = p;uint cos_sin_h = 0;cos_sin_p = cos_sin_p < INPUT1_BATCH_NUM ? cos_sin_p : 0;- #ifndef SIN_COS_HAVE_DYNAMIC_PADDINGS+#ifndef SIN_COS_HAVE_DYNAMIC_PADDINGSuint cos_sin_idx = INPUT1_GET_INDEX(cos_sin_p, 0, 0, 0);uint cos_idx = cos_sin_idx;@@ -387,8 +386,20 @@ uint cos_sin_p = p;uint cos_idx = INPUT1_GET_INDEX(cos_sin_p, 0, 0, 0);uint sin_idx = INPUT2_GET_INDEX(cos_sin_p, 0, 0, 0);#endif+#elif INPUT1_DIMS == 3 && INPUT2_DIMS == 3+ uint cos_sin_b = b < INPUT1_BATCH_NUM ? b : 0;+ uint cos_sin_h = h < INPUT1_FEATURE_NUM ? h : 0;+#ifndef SIN_COS_HAVE_DYNAMIC_PADDINGS+ uint cos_sin_idx = INPUT1_GET_INDEX(cos_sin_b, cos_sin_h, 0, 0);++ uint cos_idx = cos_sin_idx;+ uint sin_idx = cos_sin_idx;#else-# error "rope_opt.cl - 4 or 2 of INPUT1_DIMS/INPUT2_DIMS is supported only"+ uint cos_idx = INPUT1_GET_INDEX(cos_sin_b, cos_sin_h, 0, 0);+ uint sin_idx = INPUT2_GET_INDEX(cos_sin_b, cos_sin_h, 0, 0);+#endif+#else+# error "rope_opt.cl - 2, 3 or 4 of INPUT1_DIMS/INPUT2_DIMS is supported only"#endifuint output_idx = OUTPUT_GET_INDEX(b, h, p, 0);@@ -415,6 +426,7 @@ uint cos_sin_p = p;*(OUTPUT_VEC_TYPE*)(output + output_idx + r) = out1;*(OUTPUT_VEC_TYPE*)(output + output_idx + HALF_ROTARY_NDIMS + r) = out2;#endif+}#endifdiff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.cppindex 66768bae633..95fc69f0d3f 100644--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/rope_opt.cpp@@ -152,8 +152,10 @@ protected:auto b = extract_channel(ChannelName::BATCH, out_l);auto f = extract_channel(ChannelName::FEATURE, out_l);auto y = extract_channel(ChannelName::Y, out_l);-wgs.global = {b, f, y * cfg.rotary_ndims / 2ul / vec_size};+ if (cfg.support_3d_rope) {+ wgs.global = {b, f, cfg.rotary_ndims / 2ul / vec_size};+ }}wgs.local = ov::intel_gpu::get_optimal_lws(wgs.global, params.get_device_info(), in_l.format, out_l.format, dims_by_gws);diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cppindex 7c0a291b349..9a588184ff8 100644--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp@@ -14,6 +14,33 @@ INSTANTIATE_TEST_SUITE_P(smoke_RoPETestFlux,::testing::Values(ov::test::utils::DEVICE_GPU)),RoPETestFlux::getTestCaseName);+class GPURoPETestQwenVL : public RoPETestQwenVL {+protected:+ void SetUp() override {+ RoPETestQwenVL::SetUp();+ const auto& [element_type, _targetDevice, split_op_type] = this->GetParam();+ if (element_type == ov::element::f16) {+ abs_threshold = 0.015f;+ }+ }+};++TEST_P(GPURoPETestQwenVL, CompareWithRefs) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ run();+ auto function = compiledModel.get_runtime_model();+ CheckNumberOfNodesWithType(function, {"RoPE"}, 1);+};++const std::vector<std::string> vit_param = {"VariadicSplit", "Slice", "StridedSlice"};+INSTANTIATE_TEST_SUITE_P(smoke_RoPEQwenVL,+ GPURoPETestQwenVL,+ ::testing::Combine(+ ::testing::Values(ov::element::f16, ov::element::f32),+ ::testing::Values(ov::test::utils::DEVICE_GPU),+ ::testing::ValuesIn(vit_param)),+ GPURoPETestQwenVL::getTestCaseName);+INSTANTIATE_TEST_SUITE_P(smoke_RoPETestChatGLM,RoPETestChatGLMStridedSlice,::testing::Combine(diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/rotary_pos_emb.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/rotary_pos_emb.hppindex f9475a6c248..9baad69de96 100644--- a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/rotary_pos_emb.hpp+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/rotary_pos_emb.hpp@@ -11,6 +11,7 @@ namespace test {using rope_params = std::tuple<ov::element::Type, std::string>;using rope_params_2 = std::tuple<bool, ov::element::Type, std::string>;+using rope_params_qwenvit = std::tuple<ov::element::Type, std::string, std::string>;class RoPETestFlux : public SubgraphBaseTest, public testing::WithParamInterface<rope_params> {private:@@ -19,6 +20,7 @@ private:int num_head,int ndims,ov::element::Type element_type);+protected:void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;void SetUp() override;@@ -27,6 +29,21 @@ public:static std::string getTestCaseName(const testing::TestParamInfo<rope_params>& obj);};+class RoPETestQwenVL : public SubgraphBaseTest, public testing::WithParamInterface<rope_params_qwenvit> {+private:+ std::shared_ptr<ov::Model> buildROPE_QwenVL(ov::element::Type element_type,+ ov::PartialShape input_shape,+ ov::PartialShape cos_shape,+ ov::PartialShape sin_shape,+ std::string split_op_type);++protected:+ void SetUp() override;++public:+ static std::string getTestCaseName(const testing::TestParamInfo<rope_params_qwenvit>& obj);+};+class RoPETestLlama2StridedSlice : public SubgraphBaseTest, public testing::WithParamInterface<rope_params> {private:std::shared_ptr<ov::Model> buildROPE_Llama2(int batch,@@ -34,6 +51,7 @@ private:int max_position_embeddings,int num_head,int ndims);+protected:ov::Tensor create_i32_tensor(const ov::Shape& shape, int start, int step = 1);ov::OutputVector makeCosSinCache(int max_position_embeddings, int rotary_ndims);@@ -46,7 +64,11 @@ public:class RoPETestChatGLMStridedSlice : public SubgraphBaseTest, public testing::WithParamInterface<rope_params> {private:- std::shared_ptr<ov::Model> buildROPE_ChatGLM(int batch, int head_cnt, int rotary_dims, ov::element::Type element_type);+ std::shared_ptr<ov::Model> buildROPE_ChatGLM(int batch,+ int head_cnt,+ int rotary_dims,+ ov::element::Type element_type);+protected:ov::Tensor create_i32_tensor(const ov::Shape& shape, int start, int step = 1);void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;@@ -59,6 +81,7 @@ public:class RoPETestQwen7bStridedSlice : public SubgraphBaseTest, public testing::WithParamInterface<rope_params_2> {private:std::shared_ptr<ov::Model> buildROPE_QWen7b(bool specialReshape, ov::element::Type element_type);+protected:void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;void SetUp() override;@@ -74,6 +97,7 @@ private:int rotary_dims,bool hasShapeOf,ov::element::Type element_type);+protected:void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;void SetUp() override;@@ -91,6 +115,7 @@ private:int max_position_embeddings,int num_head,int ndims);+protected:void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;void SetUp() override;@@ -106,13 +131,18 @@ private:int max_position_embeddings,int num_head,int ndims);+protected:void SetUp() override;};class RoPETestChatGLMSlice : public RoPETestChatGLMStridedSlice {private:- std::shared_ptr<ov::Model> buildROPE_ChatGLM(int batch, int head_cnt, int rotary_dims, ov::element::Type element_type);+ std::shared_ptr<ov::Model> buildROPE_ChatGLM(int batch,+ int head_cnt,+ int rotary_dims,+ ov::element::Type element_type);+protected:void SetUp() override;};@@ -120,6 +150,7 @@ protected:class RoPETestQwen7bSlice : public RoPETestQwen7bStridedSlice {private:std::shared_ptr<ov::Model> buildROPE_Qwen7b(bool specialReshape, ov::element::Type element_type);+protected:void SetUp() override;};@@ -127,17 +158,22 @@ protected:class RoPETestGPTJSlice : public RoPETestGPTJStridedSlice {private:std::shared_ptr<ov::Model> buildROPE_GPTJ(int num_head,- int hidden_dims,- int rotary_dims,- bool hasShapeOf,- ov::element::Type element_type);+ int hidden_dims,+ int rotary_dims,+ bool hasShapeOf,+ ov::element::Type element_type);+protected:void SetUp() override;};class RoPETestChatGLM2DRoPEStridedSlice : public SubgraphBaseTest, public testing::WithParamInterface<rope_params> {private:- std::shared_ptr<ov::Model> buildROPE_ChatGLM(int batch, int head_cnt, int rotary_dims, ov::element::Type element_type);+ std::shared_ptr<ov::Model> buildROPE_ChatGLM(int batch,+ int head_cnt,+ int rotary_dims,+ ov::element::Type element_type);+protected:ov::Tensor create_i32_tensor(const ov::Shape& shape, int start, int step = 1);void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;@@ -153,6 +189,7 @@ private:int num_heads,int rotary_ndims,ov::element::Type element_type);+protected:void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;void SetUp() override;diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/rotary_pos_emb.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/rotary_pos_emb.hppindex e9677efd80f..8321ca43827 100644--- a/src/tests/functional/plugin/shared/include/subgraph_tests/rotary_pos_emb.hpp+++ b/src/tests/functional/plugin/shared/include/subgraph_tests/rotary_pos_emb.hpp@@ -31,6 +31,13 @@ TEST_P(RoPETestFlux, CompareWithRefs) {CheckNumberOfNodesWithType(function, {"RoPE"}, 1);};+TEST_P(RoPETestQwenVL, CompareWithRefs) {+ SKIP_IF_CURRENT_TEST_IS_DISABLED();+ run();+ auto function = compiledModel.get_runtime_model();+ CheckNumberOfNodesWithType(function, {"RoPE"}, 1);+};+TEST_P(RoPETestLlama2StridedSlice, CompareWithRefs) {SKIP_IF_CURRENT_TEST_IS_DISABLED();run();diff --git a/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cpp b/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cppindex 7b5a65ebe7c..0003bbc657f 100644--- a/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cpp+++ b/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cpp@@ -6,10 +6,6 @@#include "common_test_utils/ov_tensor_utils.hpp"#include "openvino/core/node_vector.hpp"-#include "transformations/utils/gen_pattern.hpp"-#include "openvino/opsets/opset1_decl.hpp"-#include "openvino/opsets/opset3_decl.hpp"-#include "openvino/opsets/opset8_decl.hpp"#include "openvino/op/add.hpp"#include "openvino/op/concat.hpp"#include "openvino/op/convert.hpp"@@ -27,6 +23,10 @@#include "openvino/op/transpose.hpp"#include "openvino/op/unsqueeze.hpp"#include "openvino/op/variadic_split.hpp"+#include "openvino/opsets/opset1_decl.hpp"+#include "openvino/opsets/opset3_decl.hpp"+#include "openvino/opsets/opset8_decl.hpp"+#include "transformations/utils/gen_pattern.hpp"using namespace ov::gen_pattern;using namespace ov;@@ -78,9 +78,12 @@ void RoPETestFlux::generate_inputs(const std::vector<ov::Shape>& targetInputStatauto sin_data = in_data;sin_data.seed = 20;- ov::Tensor t_input = utils::create_and_fill_tensor(funcInputs[0].get_element_type(), targetInputStaticShapes[0], in_data);- ov::Tensor t_cos = utils::create_and_fill_tensor(funcInputs[1].get_element_type(), targetInputStaticShapes[1], cos_data);- ov::Tensor t_sin = utils::create_and_fill_tensor(funcInputs[2].get_element_type(), targetInputStaticShapes[2], sin_data);+ ov::Tensor t_input =+ utils::create_and_fill_tensor(funcInputs[0].get_element_type(), targetInputStaticShapes[0], in_data);+ ov::Tensor t_cos =+ utils::create_and_fill_tensor(funcInputs[1].get_element_type(), targetInputStaticShapes[1], cos_data);+ ov::Tensor t_sin =+ utils::create_and_fill_tensor(funcInputs[2].get_element_type(), targetInputStaticShapes[2], sin_data);inputs.clear();inputs.insert({funcInputs[0].get_node_shared_ptr(), t_input});@@ -101,8 +104,7 @@ void RoPETestFlux::SetUp() {std::vector<InputShape> input_shapes = {{{batch, num_head, seq_length, ndims}, {{batch, num_head, seq_length, ndims}}},{{1, 1, seq_length, ndims}, {{1, 1, seq_length, ndims}}},- {{1, 1, seq_length, ndims}, {{1, 1, seq_length, ndims}}}- };+ {{1, 1, seq_length, ndims}, {{1, 1, seq_length, ndims}}}};init_input_shapes(input_shapes);function = build_rope_flux(batch, -1, num_head, ndims, element_type);}@@ -114,6 +116,80 @@ std::string RoPETestFlux::getTestCaseName(const testing::TestParamInfo<rope_parareturn result.str();}+std::shared_ptr<ov::Model> RoPETestQwenVL::buildROPE_QwenVL(ov::element::Type element_type,+ ov::PartialShape input_shape,+ ov::PartialShape cos_shape,+ ov::PartialShape sin_shape,+ std::string split_op_type) {+ auto input = std::make_shared<opset1::Parameter>(element_type, input_shape);+ auto cos_cache = std::make_shared<opset1::Parameter>(element_type, cos_shape);+ auto cos_mul = makeOP<opset1::Multiply>({input, cos_cache}, {{"auto_broadcast", "numpy"}});+ auto sin_cache = std::make_shared<opset1::Parameter>(element_type, sin_shape);+ const int rotary_ndims = input_shape[2].get_length();+ auto neg_constant = makeConst(element_type, ov::Shape({ 1, 1, 1}), {-1});+ ov::Output<ov::Node> cat_Concat;+ if (split_op_type == "VariadicSplit") {+ auto split = makeOP<ov::opset1::VariadicSplit>({input, {2}, {rotary_ndims / 2, rotary_ndims / 2}});+ auto neg_Multiply =+ makeOP<ov::opset1::Multiply>({split->output(1), neg_constant}, {{"auto_broadcast", "numpy"}});+ cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, split->output(0)}, {{"axis", -1}});+ } else if (split_op_type == "Slice") {+ auto slice_right_part = makeOP<ov::opset8::Slice>({input, {rotary_ndims / 2}, {INT_MAX}, {1}, {2}});+ auto slice_left_part = makeOP<ov::opset8::Slice>({input, {0}, {rotary_ndims / 2}, {1}, {2}});+ auto neg_Multiply =+ makeOP<ov::opset1::Multiply>({slice_right_part, neg_constant}, {{"auto_broadcast", "numpy"}});+ cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, slice_left_part}, {{"axis", -1}});+ } else if (split_op_type == "StridedSlice") {+ auto slice_right_part = makeOP<ov::opset1::StridedSlice>({input, {0, 0, rotary_ndims / 2},+ {0, 0, INT_MAX},+ {1, 1, 1}},+ {{"begin_mask", {1, 1, 0}},+ {"end_mask", {1, 1, 0}},+ {"new_axis_mask", {}},+ {"shrink_axis_mask", {}},+ {"ellipsis_mask", {}}});+ auto slice_left_part = makeOP<ov::opset1::StridedSlice>({input, {0, 0, 0},+ {0, 0, rotary_ndims / 2},+ {1, 1, 1}},+ {{"begin_mask", {1, 1, 0}},+ {"end_mask", {1, 1, 0}},+ {"new_axis_mask", {}},+ {"shrink_axis_mask", {}},+ {"ellipsis_mask", {}}});+ auto neg_Multiply =+ makeOP<ov::opset1::Multiply>({slice_right_part, neg_constant}, {{"auto_broadcast", "numpy"}});+ cat_Concat = makeOP<ov::opset1::Concat>({neg_Multiply, slice_left_part}, {{"axis", -1}});+ } else {+ return nullptr;+ }+ auto sin_mul = makeOP<ov::opset1::Multiply>({cat_Concat, sin_cache}, {{"auto_broadcast", "numpy"}});+ auto add_Add = makeOP<ov::opset1::Add>({cos_mul, sin_mul}, {{"auto_broadcast", "numpy"}});+ ov::ParameterVector parameters = ov::ParameterVector{input, cos_cache, sin_cache};+ return std::make_shared<ov::Model>(ov::OutputVector{add_Add}, parameters);+}++void RoPETestQwenVL::SetUp() {+ const auto& [element_type, _targetDevice, split_op_type] = this->GetParam();+ targetDevice = _targetDevice;+ ov::PartialShape input_shape = PartialShape({-1, 16, 80});+ ov::PartialShape cos_shape = PartialShape({-1, 1, 80});+ ov::PartialShape sin_shape = PartialShape({-1, 1, 80});+ InputShape input_shape_value = {input_shape, {Shape{80, 16, 80}}};+ InputShape cos_shape_value = {cos_shape, {Shape{80, 1, 80}}};+ InputShape sin_shape_value = {sin_shape, {Shape{80, 1, 80}}};+ init_input_shapes({input_shape_value, cos_shape_value, sin_shape_value});+ function = buildROPE_QwenVL(element_type, input_shape, cos_shape, sin_shape, split_op_type);+ ASSERT_TRUE(function != nullptr);+}++std::string RoPETestQwenVL::getTestCaseName(const testing::TestParamInfo<rope_params_qwenvit>& obj) {+ const auto& [element_type, targetDevice, split_op_type] = obj.param;+ std::ostringstream result;+ result << "targetDevice=" << targetDevice << ",element_type=" << element_type.to_string()+ << ",split_op_type=" << split_op_type;+ return result.str();+}+ov::OutputVector RoPETestLlama2StridedSlice::makeCosSinCache(int max_position_embeddings, int rotary_ndims) {std::vector<float> lut_sin(max_position_embeddings * rotary_ndims, 0.0f);std::vector<float> lut_cos(max_position_embeddings * rotary_ndims, 0.0f);@@ -271,7 +347,10 @@ std::string RoPETestLlama2StridedSlice::getTestCaseName(const testing::TestParamreturn result.str();}-std::shared_ptr<ov::Model> RoPETestChatGLMStridedSlice::buildROPE_ChatGLM(int batch, int head_cnt, int rotary_dims, ov::element::Type element_type) {+std::shared_ptr<ov::Model> RoPETestChatGLMStridedSlice::buildROPE_ChatGLM(int batch,+ int head_cnt,+ int rotary_dims,+ ov::element::Type element_type) {auto input = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{-1, batch, 4096 + 256 + 256});auto cos_sin_cache = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{32768, 32, 2});auto position_ids = std::make_shared<ov::opset1::Parameter>(ov::element::i32, PartialShape{-1, -1});@@ -413,7 +492,8 @@ std::string RoPETestChatGLMStridedSlice::getTestCaseName(const testing::TestParareturn result.str();}-std::shared_ptr<ov::Model> RoPETestQwen7bStridedSlice::buildROPE_QWen7b(bool specialReshape, ov::element::Type element_type) {+std::shared_ptr<ov::Model> RoPETestQwen7bStridedSlice::buildROPE_QWen7b(bool specialReshape,+ ov::element::Type element_type) {auto input = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{-1, -1, 4096 + 4096 + 4096});auto cos_cache = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{1, -1, 1, 128});auto sin_cache = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{1, -1, 1, 128});@@ -482,7 +562,8 @@ std::shared_ptr<ov::Model> RoPETestQwen7bStridedSlice::buildROPE_QWen7b(bool spe1,}),{-1});- auto Constant_296840 = makeOP<opset1::Convert>({Constant_296840_compressed}, {{"destination_type", element_type.to_string()}});+ auto Constant_296840 =+ makeOP<opset1::Convert>({Constant_296840_compressed}, {{"destination_type", element_type.to_string()}});auto neg_Multiply_499 =makeOP<opset1::Multiply>({ListUnpack_496_Squeeze_0, Constant_296840}, {{"auto_broadcast", "numpy"}});auto ListUnpack_496_Squeeze = makeOP<opset1::Squeeze>({ListUnpack_496_Split->output(0), -2});@@ -826,7 +907,7 @@ void RoPETestRotateHalfWithoutTranspose::SetUp() {std::string RoPETestRotateHalfWithoutTranspose::getTestCaseName(const testing::TestParamInfo<rope_params>& obj) {const auto& [element_type, targetDevice] = obj.param;std::ostringstream result;- result << "targetDevice=" << targetDevice <<"_element_type=" << element_type.to_string();+ result << "targetDevice=" << targetDevice << "_element_type=" << element_type.to_string();return result.str();}@@ -912,7 +993,10 @@ void RoPETestChatGLMSlice::SetUp() {function = RoPETestChatGLMSlice::buildROPE_ChatGLM(batch, num_head, rotary_dims, element_type);}-std::shared_ptr<ov::Model> RoPETestChatGLMSlice::buildROPE_ChatGLM(int batch, int head_cnt, int rotary_dims, ov::element::Type element_type) {+std::shared_ptr<ov::Model> RoPETestChatGLMSlice::buildROPE_ChatGLM(int batch,+ int head_cnt,+ int rotary_dims,+ ov::element::Type element_type) {auto input = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{-1, batch, 4096 + 256 + 256});auto cos_sin_cache = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{32768, 32, 2});auto position_ids = std::make_shared<ov::opset1::Parameter>(ov::element::i32, PartialShape{-1, -1});@@ -947,7 +1031,8 @@ std::shared_ptr<ov::Model> RoPETestChatGLMSlice::buildROPE_ChatGLM(int batch, inmakeOP<opset1::Reshape>({slice_Slice_357, ListConstruct_372_Concat}, {{"special_zero", false}});auto select_Gather_381 = makeOP<opset8::Gather>({reshape_Reshape_373, 0, -1}, {{"batch_dims", 0}});auto slice_Unsqueeze_367 = makeOP<opset1::Unsqueeze>({size_Gather_348, 0});- auto slice_Slice_369 = makeOP<opset8::Slice>({__module_transformer_transpose_Transpose, {0}, slice_Unsqueeze_367, {1}, {0}});+ auto slice_Slice_369 =+ makeOP<opset8::Slice>({__module_transformer_transpose_Transpose, {0}, slice_Unsqueeze_367, {1}, {0}});auto size_ShapeOf_374 = makeOP<opset3::ShapeOf>({reshape_Reshape_373}, {{"output_type", "i32"}});auto size_Gather_376 = makeOP<opset8::Gather>({size_ShapeOf_374, {3}, 0}, {{"batch_dims", 0}});auto ListConstruct_379_Concat =@@ -1034,7 +1119,8 @@ std::shared_ptr<ov::Model> RoPETestQwen7bSlice::buildROPE_Qwen7b(bool specialRes1,}),{-1});- auto Constant_296840 = makeOP<opset1::Convert>({Constant_296840_compressed}, {{"destination_type", element_type.to_string()}});+ auto Constant_296840 =+ makeOP<opset1::Convert>({Constant_296840_compressed}, {{"destination_type", element_type.to_string()}});auto neg_Multiply_499 =makeOP<opset1::Multiply>({ListUnpack_496_Squeeze_0, Constant_296840}, {{"auto_broadcast", "numpy"}});auto ListUnpack_496_Squeeze = makeOP<opset1::Squeeze>({ListUnpack_496_Split->output(0), -2});@@ -1129,7 +1215,10 @@ std::shared_ptr<ov::Model> RoPETestGPTJSlice::buildROPE_GPTJ(int num_head,return std::make_shared<ov::Model>(model_output, ov::ParameterVector{input, sincos});}-std::shared_ptr<ov::Model> RoPETestChatGLM2DRoPEStridedSlice::buildROPE_ChatGLM(int batch, int head_cnt, int rotary_dims, ov::element::Type element_type) {+std::shared_ptr<ov::Model> RoPETestChatGLM2DRoPEStridedSlice::buildROPE_ChatGLM(int batch,+ int head_cnt,+ int rotary_dims,+ ov::element::Type element_type) {auto input = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{batch, -1, 4096 + 256 + 256});auto cos_sin_cache = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{32768, 32, 2});auto position_ids = std::make_shared<ov::opset1::Parameter>(ov::element::i32, PartialShape{-1, -1});@@ -1142,15 +1231,15 @@ std::shared_ptr<ov::Model> RoPETestChatGLM2DRoPEStridedSlice::buildROPE_ChatGLM(auto permute_Transpose = makeOP<opset1::Transpose>({view_Reshape, {0, 2, 1, 3}}, {});- auto slice_Slice_357 =- makeOP<opset1::StridedSlice>({permute_Transpose, {0, 0, 0, 0}, {0, 0, 0, 64}, {1, 1, 1, 1}},- {{"begin_mask", {1, 1, 1, 0}},- {"end_mask", {1, 1, 1, 0}},- {"new_axis_mask", {}},- {"shrink_axis_mask", {}},- {"ellipsis_mask", {}}});+ auto slice_Slice_357 = makeOP<opset1::StridedSlice>({permute_Transpose, {0, 0, 0, 0}, {0, 0, 0, 64}, {1, 1, 1, 1}},+ {{"begin_mask", {1, 1, 1, 0}},+ {"end_mask", {1, 1, 1, 0}},+ {"new_axis_mask", {}},+ {"shrink_axis_mask", {}},+ {"ellipsis_mask", {}}});- auto aten_view_Reshape_1 = makeOP<opset1::Reshape>({ListUnpack_321->output(1), {0, 0, 2, 128}}, {{"special_zero", true}});+ auto aten_view_Reshape_1 =+ makeOP<opset1::Reshape>({ListUnpack_321->output(1), {0, 0, 2, 128}}, {{"special_zero", true}});auto aten_transpose_1 = makeOP<opset8::Transpose>({aten_view_Reshape_1, {0, 2, 1, 3}});auto shape_of_105249 = makeOP<opset8::ShapeOf>({aten_transpose_1}, {{"output_type", "i32"}});auto gather_105252 = makeOP<opset8::Gather>({shape_of_105249, {2}, {0}}, {{"batch_dims", 0}});@@ -1165,27 +1254,26 @@ std::shared_ptr<ov::Model> RoPETestChatGLM2DRoPEStridedSlice::buildROPE_ChatGLM({"ellipsis_mask", {}}});auto list_construct_concat_1 = makeOP<opset1::Concat>({{-1}, {1}, gather_105252, {32}, {2}}, {{"axis", 0}});- auto reshape_Reshape_373 =- makeOP<opset1::Reshape>({slice_Slice_357, {0, 32, 0, 32, 2}}, {{"special_zero", true}});- auto select_Gather_384 = makeOP<opset8::Gather>({reshape_Reshape_373, 0, -1}, {{"batch_dims", 0}});//x_even- auto select_Gather_381 = makeOP<opset8::Gather>({reshape_Reshape_373, 1, -1}, {{"batch_dims", 0}});//x_odd+ auto reshape_Reshape_373 = makeOP<opset1::Reshape>({slice_Slice_357, {0, 32, 0, 32, 2}}, {{"special_zero", true}});+ auto select_Gather_384 = makeOP<opset8::Gather>({reshape_Reshape_373, 0, -1}, {{"batch_dims", 0}}); // x_even+ auto select_Gather_381 = makeOP<opset8::Gather>({reshape_Reshape_373, 1, -1}, {{"batch_dims", 0}}); // x_oddauto view_Reshape_380 =makeOP<opset1::Reshape>({slice_Slice_369, list_construct_concat_1}, {{"special_zero", false}});- auto select_Gather_385 = makeOP<opset8::Gather>({view_Reshape_380, 0, -1}, {{"batch_dims", 0}});//cos_tab- auto select_Gather_382 = makeOP<opset8::Gather>({view_Reshape_380, 1, -1}, {{"batch_dims", 0}});//sin_tab+ auto select_Gather_385 = makeOP<opset8::Gather>({view_Reshape_380, 0, -1}, {{"batch_dims", 0}}); // cos_tab+ auto select_Gather_382 = makeOP<opset8::Gather>({view_Reshape_380, 1, -1}, {{"batch_dims", 0}}); // sin_tabauto mul_Multiply_386 =- makeOP<opset1::Multiply>({select_Gather_381, select_Gather_382}, {{"auto_broadcast", "numpy"}});//x_odd_sin+ makeOP<opset1::Multiply>({select_Gather_381, select_Gather_382}, {{"auto_broadcast", "numpy"}}); // x_odd_sinauto mul_Multiply_383 =- makeOP<opset1::Multiply>({select_Gather_384, select_Gather_385}, {{"auto_broadcast", "numpy"}});//x_even_cos+ makeOP<opset1::Multiply>({select_Gather_384, select_Gather_385}, {{"auto_broadcast", "numpy"}}); // x_even_cosauto sub_Subtract_389 =makeOP<opset1::Subtract>({mul_Multiply_383, mul_Multiply_386}, {{"auto_broadcast", "numpy"}});auto mul_Multiply_391 =- makeOP<opset1::Multiply>({select_Gather_381, select_Gather_385}, {{"auto_broadcast", "numpy"}});//x_odd_cos+ makeOP<opset1::Multiply>({select_Gather_381, select_Gather_385}, {{"auto_broadcast", "numpy"}}); // x_odd_cosauto mul_Multiply_393 =- makeOP<opset1::Multiply>({select_Gather_384, select_Gather_382}, {{"auto_broadcast", "numpy"}});//x_even_sin+ makeOP<opset1::Multiply>({select_Gather_384, select_Gather_382}, {{"auto_broadcast", "numpy"}}); // x_even_sinauto add_Add_396 = makeOP<opset1::Add>({mul_Multiply_391, mul_Multiply_393}, {{"auto_broadcast", "numpy"}});auto Unsqueeze_62716 = makeOP<opset1::Unsqueeze>({sub_Subtract_389, -1}, {});@@ -1254,10 +1342,15 @@ std::string RoPETestChatGLM2DRoPEStridedSlice::getTestCaseName(const testing::Tereturn result.str();}-std::shared_ptr<ov::Model> RoPETestChatGLMHF::buildROPE_ChatGLMHF(int seq_length, int num_heads, int rotary_ndims, ov::element::Type element_type) {+std::shared_ptr<ov::Model> RoPETestChatGLMHF::buildROPE_ChatGLMHF(int seq_length,+ int num_heads,+ int rotary_ndims,+ ov::element::Type element_type) {auto input = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{seq_length, 1, 4096});- auto cos = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{seq_length, 1, 1, (rotary_ndims / 2)});- auto sin = std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{seq_length, 1, 1, (rotary_ndims / 2)});+ auto cos =+ std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{seq_length, 1, 1, (rotary_ndims / 2)});+ auto sin =+ std::make_shared<ov::opset1::Parameter>(element_type, PartialShape{seq_length, 1, 1, (rotary_ndims / 2)});auto transpose = makeOP<ov::opset1::Reshape>({input, {-1, num_heads, 1, 128}}, {{"special_zero", false}});auto slice_1 = makeOP<ov::opset1::StridedSlice>({transpose, {0, 0, 0, 0}, {0, 0, 0, rotary_ndims}, {1, 1, 1, 1}},@@ -1286,28 +1379,30 @@ std::shared_ptr<ov::Model> RoPETestChatGLMHF::buildROPE_ChatGLMHF(int seq_length{"ellipsis_mask", {}}});auto minus_one = makeConst(element_type, ov::Shape({}), {-1.0f});auto neg = makeOP<ov::opset1::Multiply>({slice_2, minus_one}, {{"auto_broadcast", "numpy"}});- auto unsqueeze_1 = makeOP<ov::opset1::Reshape>({neg, {-1, num_heads, 1, (rotary_ndims / 2), 1}}, {{"special_zero", false}});+ auto unsqueeze_1 =+ makeOP<ov::opset1::Reshape>({neg, {-1, num_heads, 1, (rotary_ndims / 2), 1}}, {{"special_zero", false}});auto slice_3 = makeOP<ov::opset1::StridedSlice>({slice_1, {0, 0, 0, 0}, {0, 0, 0, INT_MAX}, {1, 1, 1, 2}},{{"begin_mask", {1, 1, 1, 0}},{"end_mask", {1, 1, 1, 0}},{"new_axis_mask", {}},{"shrink_axis_mask", {}},{"ellipsis_mask", {}}});- auto unsqueeze_2 = makeOP<ov::opset1::Reshape>({slice_3, {-1, num_heads, 1, (rotary_ndims / 2), 1}}, {{"special_zero", false}});+ auto unsqueeze_2 =+ makeOP<ov::opset1::Reshape>({slice_3, {-1, num_heads, 1, (rotary_ndims / 2), 1}}, {{"special_zero", false}});auto stack = makeOP<ov::opset1::Concat>({unsqueeze_1, unsqueeze_2}, {{"axis", -1}});auto flatten = makeOP<ov::opset1::Reshape>({stack, {0, num_heads, 0, rotary_ndims}}, {{"special_zero", true}});auto multiply_1 = makeOP<ov::opset1::Multiply>({flatten, repeat_interleave_sin}, {{"auto_broadcast", "numpy"}});auto add = makeOP<ov::opset1::Add>({multiply, multiply_1}, {{"auto_broadcast", "numpy"}});- auto slice_5 = makeOP<ov::opset1::StridedSlice>({transpose, {0, 0, 0, rotary_ndims}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}},- {{"begin_mask", {1, 1, 1, 0}},- {"end_mask", {1, 1, 1, 0}},- {"new_axis_mask", {}},- {"shrink_axis_mask", {}},- {"ellipsis_mask", {}}});+ auto slice_5 =+ makeOP<ov::opset1::StridedSlice>({transpose, {0, 0, 0, rotary_ndims}, {0, 0, 0, INT_MAX}, {1, 1, 1, 1}},+ {{"begin_mask", {1, 1, 1, 0}},+ {"end_mask", {1, 1, 1, 0}},+ {"new_axis_mask", {}},+ {"shrink_axis_mask", {}},+ {"ellipsis_mask", {}}});auto concat = makeOP<ov::opset1::Concat>({add, slice_5}, {{"axis", -1}});- return std::make_shared<ov::Model>(ov::OutputVector{concat},- ov::ParameterVector{input, cos, sin});+ return std::make_shared<ov::Model>(ov::OutputVector{concat}, ov::ParameterVector{input, cos, sin});}void RoPETestChatGLMHF::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {@@ -1327,9 +1422,12 @@ void RoPETestChatGLMHF::generate_inputs(const std::vector<ov::Shape>& targetInpuauto sin_data = in_data;sin_data.seed = 20;- ov::Tensor t_input = utils::create_and_fill_tensor(funcInputs[0].get_element_type(), targetInputStaticShapes[0], in_data);- ov::Tensor t_cos = utils::create_and_fill_tensor(funcInputs[1].get_element_type(), targetInputStaticShapes[1], cos_data);- ov::Tensor t_sin = utils::create_and_fill_tensor(funcInputs[2].get_element_type(), targetInputStaticShapes[2], sin_data);+ ov::Tensor t_input =+ utils::create_and_fill_tensor(funcInputs[0].get_element_type(), targetInputStaticShapes[0], in_data);+ ov::Tensor t_cos =+ utils::create_and_fill_tensor(funcInputs[1].get_element_type(), targetInputStaticShapes[1], cos_data);+ ov::Tensor t_sin =+ utils::create_and_fill_tensor(funcInputs[2].get_element_type(), targetInputStaticShapes[2], sin_data);inputs.clear();inputs.insert({funcInputs[0].get_node_shared_ptr(), t_input});@@ -1345,11 +1443,9 @@ void RoPETestChatGLMHF::SetUp() {const int num_heads = 32;const int rotary_ndims = 64;- std::vector<InputShape> input_shapes = {- {{-1, 1, 4096}, {{seq_length, 1, 4096}}},- {{-1, 1, 1, (rotary_ndims / 2)}, {{seq_length, 1, 1, (rotary_ndims / 2)}}},- {{-1, 1, 1, (rotary_ndims / 2)}, {{seq_length, 1, 1, (rotary_ndims / 2)}}}- };+ std::vector<InputShape> input_shapes = {{{-1, 1, 4096}, {{seq_length, 1, 4096}}},+ {{-1, 1, 1, (rotary_ndims / 2)}, {{seq_length, 1, 1, (rotary_ndims / 2)}}},+ {{-1, 1, 1, (rotary_ndims / 2)}, {{seq_length, 1, 1, (rotary_ndims / 2)}}}};init_input_shapes(input_shapes);function = buildROPE_ChatGLMHF(-1, num_heads, rotary_ndims, element_type);}