Cache per-item token estimates across view_for_generation calls

Abierto
#1,831 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
45/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
performance

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
1.8k
Forks
161
Merge medio
4 d 3 h
PR fusionados (30 d)
45

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de generative-computing/mellea

Todos los issues de generative-computing/mellea

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.