Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

feat(hf): reuse the prompt KV cache across turns to keep time to first token flat

オープン
#7,765 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
ai, performance

調査の方向性

Start by reading the livekit-plugins-hf implementation introduced in #7731 and trace how it encodes ChatContext for each turn. Compare the tokenized prompt prefixes across turns and identify where past_key_values could be retained and invalidated. Done means safely reusing unchanged prefixes, falling back when history changes, and bounding cache memory per session and overall; coordinate this design with #5351.

索引モデルが issue の本文から書いたものです。

説明

Feature Type

Would make my life easier

Feature Description

livekit-plugins-hf (#7731) re-encodes the full prompt on every turn: system prompt, tools and the whole conversation so far. Earlier turns don't change between replies, but their attention keys and values are computed again each time. So time to first token grows with the length of the call.

Measured on Qwen2.5-0.5B-Instruct, Apple M4 (MPS), temperature=0, steady state (second pass, shapes warm):

conversation prompt tokens time to first token
first turn 36 52 ms
after 10 exchanges 846 257 ms
after 20 exchanges 1666 494 ms
after 40 exchanges 3306 1002 ms

A 20x slowdown over one call, on the smallest model. Larger models scale it further.

Proposal: keep each session's past_key_values between turns, and on the next turn feed only the tokens after the longest shared prefix.

  • Key the cache by session (or by ChatContext identity) and evict it when the session ends.
  • Fall back to a full re-encode when the prefix changes, e.g. history truncation or an edited system prompt.
  • Bound the memory per session and in total, since the cache trades memory for latency. This interacts with the KV cache compression proposed in #5351.

Hosted providers already do this: the openai, anthropic and google plugins all expose prompt caching.

Workarounds / Alternatives
  • Trim history aggressively, which loses context.
  • Use a server with prefix caching (vLLM, SGLang) through the openai plugin. That adds a separate service.
Additional Context
  • Follow-up to #7731 and related to #5351.
  • Prefix reuse pairs with batching (#7764): prefix caching cuts each turn's prefill; batching shares decode across sessions.
主要言語
Python
スター
14.6k
フォーク
3.9k
平均マージ
3日 3時間
マージ済み PR(30日)
171

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

livekit/agents のほかの issue

livekit/agents の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。