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
[TRANSFORMATIONS] Set proper of VLM's "inputs_embeds" input (#28928)
Andrii Staikov873f532c4d94
diff --git a/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp b/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cppindex eb684282ce0..f3d3d699caf 100644--- a/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp+++ b/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp@@ -1219,7 +1219,7 @@ TEST_P(SDPAToPATest, SDPAToPA_nanoLLaVA_General) {auto past_lens = make_param(PartialShape{DYN}, element::i32, "past_lens");auto value_cache_0 = make_param(PartialShape{DYN, 2, 2}, element::f32, "value_cache_0");auto key_cache_0 = make_param(PartialShape{DYN, 2, 2}, element::f32, "key_cache_0");- auto inputs_embeds = make_param(PartialShape{DYN, DYN, 8}, element::f32, "inputs_embeds");+ auto inputs_embeds = make_param(PartialShape{DYN, DYN}, element::f32, "inputs_embeds");auto position_ids = make_param(PartialShape{DYN}, element::i64, "position_ids");ParameterVector params = nodes_to_params({max_context_len,@@ -1241,8 +1241,9 @@ TEST_P(SDPAToPATest, SDPAToPA_nanoLLaVA_General) {auto Constant_16153 = makeConst(element::f32,ov::Shape({1, 1, 1}),{2.000000f});+ auto unsqueezed_inputs_embeds = makeOP<opset1::Unsqueeze>({inputs_embeds, 1});auto __module_model_model_layers_0_input_layernorm_aten_pow_Power =- makeOP<opset1::Power>({inputs_embeds, Constant_16153}, {{"auto_broadcast", "numpy"}});+ makeOP<opset1::Power>({unsqueezed_inputs_embeds, Constant_16153}, {{"auto_broadcast", "numpy"}});auto __module_model_model_layers_0_input_layernorm_aten_mean_ReduceMean =makeOP<opset1::ReduceMean>({__module_model_model_layers_0_input_layernorm_aten_pow_Power, {-1}},{{"keep_dims", true}});@@ -1258,7 +1259,7 @@ TEST_P(SDPAToPATest, SDPAToPA_nanoLLaVA_General) {makeOP<opset1::Divide>({Constant_16155, __module_model_model_layers_0_input_layernorm_aten_rsqrt_Sqrt},{{"auto_broadcast", "numpy"}, {"m_pythondiv", true}});auto __module_model_model_layers_0_input_layernorm_aten_mul_Multiply =- makeOP<opset1::Multiply>({inputs_embeds, __module_model_model_layers_0_input_layernorm_aten_rsqrt_Divide},+ makeOP<opset1::Multiply>({unsqueezed_inputs_embeds, __module_model_model_layers_0_input_layernorm_aten_rsqrt_Divide},{{"auto_broadcast", "numpy"}});auto __module_model_model_layers_0_input_layernorm_aten_mul_Multiply_1 =makeOP<opset1::Multiply>({Constant_16156, __module_model_model_layers_0_input_layernorm_aten_mul_Multiply},@@ -1283,7 +1284,7 @@ TEST_P(SDPAToPATest, SDPAToPA_nanoLLaVA_General) {{{"output_type", "i64"}});auto Gather_16756 = makeOP<opset8::Gather>({ShapeOf_16753, 1, 0}, {{"batch_dims", 0}});auto Reshape_16764 = makeOP<opset1::Reshape>({Gather_16756, {-1}}, {{"special_zero", false}});- auto ShapeOf_52004 = makeOP<opset3::ShapeOf>({inputs_embeds}, {{"output_type", "i64"}});+ auto ShapeOf_52004 = makeOP<opset3::ShapeOf>({unsqueezed_inputs_embeds}, {{"output_type", "i64"}});auto Gather_52005 = makeOP<opset8::Gather>({ShapeOf_52004, 1, 0}, {{"batch_dims", 0}});auto Convert_52006 = makeOP<opset1::Convert>({Gather_52005}, {{"destination_type", "i32"}});auto Subtract_52007 = makeOP<opset1::Subtract>({max_context_len, Convert_52006}, {{"auto_broadcast", "numpy"}});diff --git a/src/core/src/pass/sdpa_to_paged_attention.cpp b/src/core/src/pass/sdpa_to_paged_attention.cppindex 3d70e7e713f..1049c6b1fe7 100644--- a/src/core/src/pass/sdpa_to_paged_attention.cpp+++ b/src/core/src/pass/sdpa_to_paged_attention.cpp@@ -61,7 +61,7 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::ModesetName(std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1}), "rotation_trig_lut");}- auto sliding_window = v0::Constant::create(element::i32, Shape{}, {0}); // sliding_window+ auto sliding_window = v0::Constant::create(element::i32, Shape{}, {0});auto get_parameter = [=](const std::shared_ptr<ov::Model>& model,const std::string& name) -> std::shared_ptr<v0::Parameter> {@@ -90,23 +90,17 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::ModeOPENVINO_ASSERT(input_ids_node, "The model doesn't contain input_ids or input_embeds input. Aborting.");- std::shared_ptr<ov::Node> processed_input_ids;if (input_ids_node->get_friendly_name() == "input_ids") {- auto input_ids_target_inputs = input_ids_node->get_output_target_inputs(0);input_ids_node->set_partial_shape(PartialShape{-1});- processed_input_ids =- std::make_shared<v0::Unsqueeze>(input_ids_node, v0::Constant::create(element::i32, Shape{}, {1}));- for (const auto& target : input_ids_target_inputs) {- target.replace_source_output(processed_input_ids);- }} else if (input_ids_node->get_friendly_name() == "inputs_embeds") {- // VLMs have the input_ids part + embeddings calculation- // served as "inputs_embeds" input, so there's no need- // for additional work on the input here as this is done- // for "input_ids"- processed_input_ids = input_ids_node;- } else {- OPENVINO_ASSERT(processed_input_ids, "Couldn't process neither input_ids, nor inputs_embeds.");+ input_ids_node->set_partial_shape(PartialShape{-1, -1});+ }++ auto input_ids_target_inputs = input_ids_node->get_output_target_inputs(0);+ auto processed_input_ids =+ std::make_shared<v0::Unsqueeze>(input_ids_node, v0::Constant::create(element::i32, Shape{}, {1}));+ for (const auto& target : input_ids_target_inputs) {+ target.replace_source_output(processed_input_ids);}ParameterVector kv_parameters;