Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unconditionally unroll sdpa layer for all models #1493

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/cpp/src/llm_pipeline_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ std::shared_ptr<ov::Model> cvt_value_tensors_layout(std::shared_ptr<ov::Model> m
return ppp.build();
}

void unroll_sdpa(std::shared_ptr<ov::Model> model) {
ov::pass::GraphRewrite rewr;
rewr.add_matcher<ScaledDotProductAttentionDecomposition>();
rewr.run_on_model(model);
ov::pass::Validate().run_on_model(model);
}

bool optimize_value_tensors(std::shared_ptr<ov::Model> model) {
ov::pass::GraphRewrite rewr;
rewr.add_matcher<ScaledDotProductAttentionDecomposition>();
Expand Down Expand Up @@ -1049,6 +1056,8 @@ void StatelessLLMPipeline::setupAndCompileModels(
m_kvcache_desc.v_tensors_transposed = true;
prefill_model = cvt_value_tensors_layout(prefill_model);
}
} else {
unroll_sdpa(kvcache_model);
}
// (7) Replace KV-cache tensors for the entire cache to tensors only for new token (before concat)
kvcache_model = redirect_new_kv_to_output(kvcache_model);
Expand Down
Loading