Cache per-item token estimates across view_for_generation calls

Aperta
#1,831 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
performance

Direzione di ricerca

Start with _as_list_token_budget in mellea/stdlib/context/chat.py and the per-call estimates dict, then trace how view_for_generation calls it. Decide whether the cache lives on the history thunk or is keyed by context version, since the issue leaves that open. Done means repeated views reuse the stored estimates without re-rendering or re-running json.dumps, which you can check with a timing or call-count test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement needs-design
What happened?

_as_list_token_budget (mellea/stdlib/context/chat.py, from #1760) renders
each history item through TemplateFormatter and, for tool-call replies,
re-serializes call args with json.dumps, to produce per-item token
estimates. The estimates dict only caches within a single call, but
view_for_generation runs 2–3× per generation (tool dispatch, backend
_generate_from_context, sampling retries), so a long tool-heavy history
re-renders the same spans and re-serializes the same tool calls repeatedly on
the generation hot path.

What did you expect to happen?

Since history items are immutable once added to the context, the per-item
estimate could be computed once — cached on the thunk, or memoized per
context version — making repeat views cheap.

Notes

Performance polish, not a correctness problem; only noticeable with long
tool-heavy histories. Follow-up from the #1760 review.

Lingua principale
Python
Stelle
1.8k
Fork
161
Merge medio
4g 3h
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di generative-computing/mellea

Tutte le issue di generative-computing/mellea

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.