[Feature]: Separate KV cache token caps for the self-attention and cross-attention pools

Abierto
#23,132 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
54/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Start with _split_kv_cache_budget_for_cross in tensorrt_llm/_torch/pyexecutor/_util.py and the V2 manager in kv_cache/kv_cache_manager_v2.py; trace how each pool applies its byte budget and token cap. Then check the V1 split for compatibility and find the relevant tests and KvCacheConfig.max_tokens description. Done when an optional cross-attention token cap limits that pool while the existing setting and behavior remain intact when it is unset.

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

Descripción

KV-Cache Management
The feature, motivation and pitch

An encoder-decoder model runs with two KV cache pools, one for decoder self-attention and one for cross-attention. KvCacheConfig.max_tokens is a single number and it caps both, under either KV cache manager. _split_kv_cache_budget_for_cross (tensorrt_llm/_torch/pyexecutor/_util.py) gives each pool a share of the memory budget and the same max_tokens. With V2, each pool's manager takes the smaller of its byte budget and the bytes that hold max_tokens (kv_cache/kv_cache_manager_v2.py). With V1, the split caps each pool's token count at the same value. The only setting that differs per pool is cross_kv_cache_fraction, which is a share of a memory budget and not a size.

The two pools need different token counts, and both needs are known in advance:

  • Cross-attention: a request holds its encoder output for its whole life. That is the encoder length, whatever the output length.
  • Self-attention: a request holds at most the decoder's maximum length, times the beam width.

Whisper is a clear case. Each request holds 1,500 tokens in the cross-attention pool and at most 448 in the self-attention pool. With greedy decoding and 64 concurrent requests, the pools need 96,000 and at most 28,672 tokens. max_tokens must be at least 96,000 to fit the cross-attention pool, so it cannot hold the self-attention pool to its real need. For whisper-large-v3-turbo in fp16, an even split then reserves about 1.8 GiB for a pool that can use at most about 0.55 GiB.

Request: an optional token cap for the cross-attention pool, for example cross_kv_cache_max_tokens.

  • When it is set, max_tokens caps the self-attention pool only.
  • When it is unset, behaviour stays as today.
  • Each pool holds the smaller of its own token cap and its share of the memory budget.
  • The max_tokens description says which pool it caps. Today it reads "The maximum number of tokens that should be stored in the KV cache" and does not say the cap applies to each pool.
Alternatives
  • max_gpu_total_bytes with cross_kv_cache_fraction. This gives each pool an absolute size, but in bytes and through a ratio. The user has to work out bytes per token for each pool, which depends on layer count, heads, dtype and KV quantization, and redo it when any of them changes. Token counts follow directly from the model and the concurrency.
  • free_gpu_memory_fraction with cross_kv_cache_fraction. The sizes then depend on the memory that is free at load, so they differ between replicas and with whatever else shares the GPU.
  • One max_tokens sized for the larger pool. This over-reserves the other pool, by about 3.3 times for Whisper.
Additional context
  • Code references are to main at 9f446f7.
  • V1 is deprecated as of 1.4, so the request is mainly for V2.
  • Related: #22105, which asks to report the cross-attention pool's statistics.
Before submitting a new issue...
  • Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
Lenguaje dominante
Python
Estrellas
15.2k
Forks
3k
Merge medio
2 d 21 h
PR fusionados (30 d)
477

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

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 NVIDIA/TensorRT-LLM

Todos los issues de NVIDIA/TensorRT-LLM

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.