Skip to content

[NPUW] Replacing longrope pattern with precalculated values#33011

Merged
dmatveev merged 7 commits intoopenvinotoolkit:masterfrom
AlexanderKalistratov:npu_longrope_support
Mar 4, 2026
Merged

[NPUW] Replacing longrope pattern with precalculated values#33011
dmatveev merged 7 commits intoopenvinotoolkit:masterfrom
AlexanderKalistratov:npu_longrope_support

Conversation

@AlexanderKalistratov
Copy link
Contributor

Depends on huggingface/optimum-intel#1504
Searching pattern would be updated to the actual pattern which would be generated after huggingface/optimum-intel#1504 get merged.

@github-actions github-actions bot added category: NPU OpenVINO NPU plugin category: NPUW NPUW plugin labels Nov 25, 2025
@dmatveev dmatveev added this to the 2026.1 milestone Jan 27, 2026
@AlexanderKalistratov AlexanderKalistratov marked this pull request as ready for review February 10, 2026 14:12
@AlexanderKalistratov AlexanderKalistratov requested review from a team as code owners February 10, 2026 14:12
auto* pos_ids_data = position_ids->data<int64_t>();
// assuming position_ids are constantly non-deacreasing.
// this potentially could be not true. Alternative is to find max value in position_ids
auto max_pos_id = pos_ids_data[position_ids->get_size() - 1];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check if attention mask is right padded

const std::shared_ptr<ov::Model>& model) {
auto rpe = std::make_shared<RopePatternLLama2>();
ov::npuw::patterns::pre_compute::LongRopePatternPhi::LongRopePatternPhi() : matcher("sin-cos-matcher") {
auto MakeConstant = []() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Run pass conditionally

// Step 2: Apply Gather for cos and sin
auto gather_cos = std::make_shared<ov::op::v8::Gather>(cache[0], rpe->matched_position_ids, axis);
auto gather_sin = std::make_shared<ov::op::v8::Gather>(cache[1], rpe->matched_position_ids, axis);
LOG_VERB("Created gather op facilitate LUT search: " << gather_cos->get_name() << ", " << gather_cos->get_shape());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need verbose for the sin also?

LOG_VERB("Rope sin detected at: " << rpe->matched_sin->get_name() << ", replacing by cache node: "
<< gather_sin->get_name() << ", " << gather_sin->get_shape());

// replacing sin with gather op
Copy link
Contributor

Choose a reason for hiding this comment

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

cos and sin

ov::replace_node(rpe->matched_cos, squeeze_cos);
ov::replace_node(rpe->matched_sin, squeeze_sin);

// disconnecting gather from rest or subgraph started from concat_1
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor comment: typo in of

return {Cos, Sin};
}

void replaceSinCosByCache(int max_prompt_len, const ov::OutputVector& cache, const pre_compute::RopePatternDesc* rpe) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be to align with makeCosSinCache we need to swap Sin and Cos in name by places?

@dmatveev dmatveev added this pull request to the merge queue Mar 4, 2026
Merged via the queue into openvinotoolkit:master with commit ce9f77e Mar 4, 2026
194 checks passed
mlukasze pushed a commit to mlukasze/openvino that referenced this pull request Mar 5, 2026
…toolkit#33011)

Depends on huggingface/optimum-intel#1504
Searching pattern would be updated to the actual pattern which would be
generated after huggingface/optimum-intel#1504
get merged.
Nishant-ZFYII pushed a commit to Nishant-ZFYII/openvino that referenced this pull request Mar 5, 2026
…toolkit#33011)

Depends on huggingface/optimum-intel#1504
Searching pattern would be updated to the actual pattern which would be
generated after huggingface/optimum-intel#1504
get merged.
atamas19 pushed a commit to atamas19/openvino that referenced this pull request Mar 6, 2026
…toolkit#33011)

Depends on huggingface/optimum-intel#1504
Searching pattern would be updated to the actual pattern which would be
generated after huggingface/optimum-intel#1504
get merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: NPU OpenVINO NPU plugin category: NPUW NPUW plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants