feat(hf): reuse the prompt KV cache across turns to keep time to first token flat
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- ai, performance
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 14.6k
- Fork
- 3.9k
- Merge medio
- 2g 9h
- PR unite (30g)
- 159
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di livekit/agents
-
BM25SearchStrategy (the default) never matches underscore-joined terms in tool descriptions or param descriptionsForse già presa @BlueX888 l’ha presa 2 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
livekit/agents#7727 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Assistant markup is stripped from chat history when expressive mode is offForse già presa @ShivamSharma43 l’ha presa 5 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hostsForse di nuovo libera @AbarnaaSree l’ha presa 45 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
livekit/agents#7022 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
elevenlabs: text-to-dialogue (v3/v4) alignment timestamps are chunk-relative, breaking synced transcriptsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di livekit/agents
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
topoteretes/cognee#5773 ·
I maintainer di solito rispondono entro 1 giorno
-
MiKTeX: a failed build reports no errors because texify --quiet switches the log to file:line: styleAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
SublimeText/LaTeXTools#1718 ·