feat(hf): reuse the prompt KV cache across turns to keep time to first token flat
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- ai, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 14.6k
- Fork
- 3.9k
- Merge trung bình
- 2 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 177
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của livekit/agents
-
Assistant markup is stripped from chat history when expressive mode is offCó thể đã có người làm @ShivamSharma43 đã nhận 6 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
docs: openai.LLM vs openai.responses.LLM for HTTP OpenAI-compat hostsCó thể làm lại được @AbarnaaSree đã nhận 46 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
livekit/agents#7022 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Tool argument errors put the argument values in the log message body, outside `lk.pii.*`Có thể đã có người làm @Li-john1021 đã nhận hôm nay. Đang mở
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 25/100
livekit/agents#7801 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Google Realtime (Vertex AI): update_instructions() appends a model turn instead of replacing the system instructionCó thể đã có người làm @Li-john1021 đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
livekit/agents#7785 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
elevenlabs: text-to-dialogue (v3/v4) alignment timestamps are chunk-relative, breaking synced transcriptsCó thể đã có người làm @satheeshk50 đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
livekit/agents#7773 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của livekit/agents
Issue tương tự
-
customer-reported question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Azure/azure-sdk-for-python#49548 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
btclib-org/btclib-wallet#409 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Phase 2 PSA Capability & Career Profile
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bcgov/digital-journeys#2310 ·
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fastmachinelearning/hls4ml#1582 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Sort modelsĐang mởenhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày