Skip to content

apply GPU transformation to avoid KV cache broadcast#36775

Open
nazanin-beheshti wants to merge 14 commits into
openvinotoolkit:masterfrom
nazanin-beheshti:naz/broadcast-kv-cache-fusion
Open

apply GPU transformation to avoid KV cache broadcast#36775
nazanin-beheshti wants to merge 14 commits into
openvinotoolkit:masterfrom
nazanin-beheshti:naz/broadcast-kv-cache-fusion

Conversation

@nazanin-beheshti

Copy link
Copy Markdown
Contributor

Details:

transformation-before-after transformation-2

Tickets:

AI Assistance:

  • AI assistance used: yes
  • *If yes, writing a draft transformation for me and then I clean it and debug it for better functionality.

@nazanin-beheshti nazanin-beheshti requested review from a team as code owners July 8, 2026 17:40
@github-actions github-actions Bot added the category: GPU OpenVINO GPU plugin label Jul 8, 2026
@Kotomi-Du Kotomi-Du requested a review from ZackyLake July 8, 2026 19:46
Comment thread src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp Outdated
Comment thread src/plugins/intel_gpu/src/plugin/transformations/GQA_decomposition_fusion.cpp Outdated
@nazanin-beheshti

Copy link
Copy Markdown
Contributor Author

@Lyamin-Roman Would you please review one more time?

Comment thread src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp Outdated
auto sdpa = std::make_shared<ov::intel_gpu::op::SDPA>(inputs, is_causal, in0_order, in1_order, in2_order, out_order);

model_ref = std::make_shared<ov::Model>(ov::OutputVector{ sdpa }, ov::ParameterVector{ input_q, input_k, input_v });
comparator.enable(FunctionsComparator::ATTRIBUTES);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add accuracy check too
comparator.enable(FunctionsComparator::CmpValues::ACCURACY);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an exception Exception from src\inference\src\cpp\infer_request.cpp:224:
Check 'it != map.end()' failed at src\plugins\template\backend\int_executable.cpp:225:
Interpreter backend doesn't implement evaluate method for OP SDPA

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lyamin-Roman the current transformation is similar with https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_gpu/tests/unit/transformations/unsqueeze_broadcast_reshape_sdpa_fusion_test.cpp which doesn't include comparator.enable(FunctionsComparator::CmpValues::ACCURACY); in the unit test as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kotomi-Du, Yes, ok, it looks like there is a reference only for PA, but accuracy test is still needed, and I suggest expanding the src/plugins/intel_gpu/tests/functional/subgraph_tests/sdpa.cpp test, which also tests the aforementioned UnsqueezeBroadcastReshapeSDPAFusion under is_complex_gqa flag

auto reshape1_pattern_key_m = any_input();
auto reshape_4d_to_5d_key_m = wrap_type<ov::op::v1::Reshape>({ in_key, reshape1_pattern_key_m }, reshape_4d_to_5d);

auto concat_key_m = wrap_type<ov::op::v0::Concat>({ reshape_4d_to_5d_key_m, reshape_4d_to_5d_key_m, reshape_4d_to_5d_key_m, reshape_4d_to_5d_key_m });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a hard code for GQA specifically q_head/k_head=4. Please refine the match pattern

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: GPU OpenVINO GPU plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants