Skip to content

[Release] Cache Minja Template#4134

Open
apaniukov wants to merge 6 commits into
openvinotoolkit:releases/2026/3from
apaniukov:cache-minja-template
Open

[Release] Cache Minja Template#4134
apaniukov wants to merge 6 commits into
openvinotoolkit:releases/2026/3from
apaniukov:cache-minja-template

Conversation

@apaniukov

Copy link
Copy Markdown
Contributor

Description

Port #4133 to release.

CVS-###

Fixes #(issue)

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.

jkoniusz and others added 3 commits July 9, 2026 17:30
…encies group across 1 directory (openvinotoolkit#4107)

Bumps the npm-dependencies group with 1 update in the /src/js directory:
[@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node).

Updates `@types/node` from 24.13.2 to 24.13.3
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a
href="https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node">compare
view</a></li>
</ul>
</details>
<br />

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
<!-- Keep your pull requests (PRs) as atomic as possible. That increases
the likelihood that an individual PR won't be stuck because of adjacent
problems, merge conflicts, or code review.
Your merged PR is going to appear in the automatically generated release
notes on GitHub. So the clearer the title the better. -->
## Description
<!-- Please include a summary of the change. Also include relevant
motivation and context. -->

Skip NPU test failing in precommits:

https://github.com/openvinotoolkit/openvino.genai/actions/runs/29002476348/job/86068988266?pr=4119


https://github.com/openvinotoolkit/openvino.genai/actions/runs/29005199890/job/86079240639

## Checklist:
- [x] This PR follows [GenAI Contributing
guidelines](https://github.com/openvinotoolkit/openvino.genai?tab=contributing-ov-file#contributing).
<!-- Always follow them. If there are deviations, explain what and why.
-->
- [x] Tests have been updated or added to cover the new code. <!--
Specify exactly which tests were added or updated. If the change isn't
maintenance related, update the tests at
https://github.com/openvinotoolkit/openvino.genai/tree/master/tests or
explain in the description why the tests don't need an update. -->
- [x] This PR fully addresses the ticket. <!--- If not, explain clearly
what is covered and what is not. If follow-up pull requests are needed,
specify in the description. -->
- [NA] I have made corresponding changes to the documentation. <!-- Run
github.com/\<username>/openvino.genai/actions/workflows/deploy_gh_pages.yml
on your fork with your branch as a parameter to deploy a test version
with the updated content. Replace this comment with the link to the
built docs. If the documentation is updated in a separate PR, clearly
specify it. -->
Copilot AI review requested due to automatic review settings July 10, 2026 15:08
@apaniukov apaniukov requested a review from pavel-esir as a code owner July 10, 2026 15:08
@github-actions github-actions Bot added the category: tokenizers Tokenizer class or submodule update label Jul 10, 2026
@apaniukov apaniukov changed the title Cache minja template [Release] Cache Minja Template Jul 10, 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

Ports the “Cache Minja Chat Template” change to the release branch to avoid repeatedly parsing/constructing minja::chat_template objects during Tokenizer::apply_chat_template, significantly reducing chat-template application overhead in hot paths.

Changes:

  • Added a small, mutex-protected cache of parsed minja::chat_template objects keyed by the template string.
  • Updated apply_chat_template() to reuse cached templates and to synchronize reads/updates of chat template state (set_chat_template(), getters).
  • Cleared the cache when set_chat_template() updates the configured template to ensure correctness.

Reviewed changes

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

File Description
src/cpp/src/tokenizer/tokenizer_impl.hpp Adds mutex + in-memory cache fields and declares the cached-template accessor.
src/cpp/src/tokenizer/tokenizer_impl.cpp Implements the cache, switches apply_chat_template() to reuse cached templates, and synchronizes chat template state access.

Comment on lines +48 to +49
mutable std::mutex m_minja_chat_template_cache_mutex;
mutable std::unordered_map<std::string, std::shared_ptr<const minja::chat_template>> m_minja_chat_template_cache;

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 8 out of 9 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • src/js/package-lock.json: Generated file


@pytest.mark.parametrize("llm_model", MODELS_LIST, indirect=True)
@pytest.mark.parametrize("npu_config", PIPELINE_CONFIGS, indirect=True)
@pytest.mark.xfail(reason="Error: KV-Cache is full: num_stored_tokens=319 capacity=319. Ticket 190518")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: cmake / build Cmake scripts category: GGUF GGUF file reader category: GHA CI based on Github actions category: JS API GenAI JS API category: LLM LLM pipeline (stateful, static) category: samples dependencies category: tokenizers Tokenizer class or submodule update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants