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

オープン
#23,132 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
54/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
Python
スター
15.2k
フォーク
3k
平均マージ
2日 21時間
マージ済み PR(30日)
477

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/TensorRT-LLM のほかの issue

NVIDIA/TensorRT-LLM の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。