feat(hf): reuse the prompt KV cache across turns to keep time to first token flat
メンテナーはふだん 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
ChatContextidentity) 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
openaiplugin. 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
livekit/agents のほかの issue
-
Assistant markup is stripped from chat history when expressive mode is off対応中かも @ShivamSharma43 が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hosts再び着手できるかも @AbarnaaSree が 46 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
livekit/agents#7022 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 22/100
livekit/agents#7843 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 40/100
メンテナーはふだん 1 日以内に返信
-
StreamPacerWrapper.end_input() sets _input_ended before buffered sentences reach _sentences; last sentence(s) silently never sent to TTS対応中かも @Hugo-DDT が今日担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
btclib-org/btclib-node#1955 ·
メンテナーはふだん 1 日以内に返信
-
documentation v0.9.2
難易度 2/5 半日 初心者へのやさしさ 72/100
khuisman/mcp-gee-sweet#1033 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ossf/cve-bin-tool#5966 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 2 日以内に返信
-
write_iceberg ignores the table's write.parquet.compression-codec property対応中かも @YuangGao が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Eventual-Inc/Daft#7606 ·
メンテナーはふだん 1 日以内に返信