Skip to content

Adding kv-cache invalidation when generation hits short factor threshold#4117

Open
AlexanderKalistratov wants to merge 7 commits into
openvinotoolkit:masterfrom
AlexanderKalistratov:longrope_sdpa_kvcache_invalidation
Open

Adding kv-cache invalidation when generation hits short factor threshold#4117
AlexanderKalistratov wants to merge 7 commits into
openvinotoolkit:masterfrom
AlexanderKalistratov:longrope_sdpa_kvcache_invalidation

Conversation

@AlexanderKalistratov

@AlexanderKalistratov AlexanderKalistratov commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

Add support for short-factor to long-factor RoPe transition via cache invalidation for SDPA backend.
This is a functional support of the feature as cache-invalidation has performance impact.
Tested on CPU and NPU plugins.
Currently this functionality is enabled for NPU only, but can be extended to other plugins.

EISW-223126

Checklist:

  • This PR follows GenAI Contributing guidelines.
  • Tests have been updated or added to cover the new code.
  • This PR fully addresses the ticket.
  • I have made corresponding changes to the documentation.

Copilot AI review requested due to automatic review settings July 8, 2026 18:29
@AlexanderKalistratov AlexanderKalistratov added this to the 2026.3 milestone Jul 8, 2026
@github-actions github-actions Bot added category: visual language Visual language pipeline category: LLM LLM pipeline (stateful, static) labels Jul 8, 2026

Copilot AI left a comment

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.

Pull request overview

This PR adds LongRoPE “short-factor → long-factor” transition handling for the stateful LLM pipeline by detecting the model’s LongRoPE switch threshold from config.json and forcing KV-cache invalidation / reprefill when crossing that boundary (including a mid-generation split for SDPA).

Changes:

  • Detect LongRoPE usage + threshold from config.json and store it in StatefulLLMPipeline.
  • Force a one-off full-history resend + cache reset when a chat turn crosses the threshold; add a streamer-based mid-generation stop-and-rerun path.
  • Ensure LongRoPE threshold detection is invoked in stateful pipeline construction paths.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/cpp/src/lm_encoding.cpp Minor formatting/whitespace updates.
src/cpp/src/llm/pipeline.cpp Calls StatefulLLMPipeline::set_longrope_threshold(models_path) after construction to initialize LongRoPE behavior.
src/cpp/src/llm/pipeline_stateful.hpp Adds LongRoPE threshold state and “one-shot” reprefill flag declarations.
src/cpp/src/llm/pipeline_stateful.cpp Implements LongRoPE threshold detection and adds cache-reset + rerun logic when the boundary is reached.

Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp Outdated
Comment thread src/cpp/src/llm/pipeline_stateful.cpp Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 14:36

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp Outdated
Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.hpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Copilot AI review requested due to automatic review settings July 9, 2026 22:39

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Copilot AI review requested due to automatic review settings July 10, 2026 00:58
@AlexanderKalistratov AlexanderKalistratov force-pushed the longrope_sdpa_kvcache_invalidation branch from 4360de1 to 726a031 Compare July 10, 2026 01:01

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp Outdated
Comment thread src/cpp/src/llm/pipeline_stateful.hpp
Copilot AI review requested due to automatic review settings July 10, 2026 01:02

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp Outdated
Copilot AI review requested due to automatic review settings July 10, 2026 01:38

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/cpp/src/lm_encoding.cpp Outdated
Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Comment thread src/cpp/src/llm/pipeline_stateful.cpp Outdated
Copilot AI review requested due to automatic review settings July 10, 2026 02:41

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/cpp/src/llm/pipeline_stateful.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: LLM LLM pipeline (stateful, static) category: visual language Visual language pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants