[Feature]: Report the cross-attention KV cache pool in the Triton backend metrics and in the JSON iteration stats
The feature, motivation and pitch
For an encoder-decoder engine the executor creates two paged KV cache pools, one for self-attention and one for cross-attention (trtGptModelInflightBatching.cpp, the useCrossAttention() branch of the constructor). For those engines getCurrentIterationStats fills the optional IterationStats::crossKvCacheStats next to kvCacheStats. For a decoder-only engine there is no cross-attention pool and the field stays empty.
The Python bindings expose the field (cross_kv_cache_stats). The two paths that leave the process do not:
- Triton backend. The stats loop in
triton_backend/inflight_batcher_llm/src/model_instance_state.ccreadsstat.kvCacheStatsonly. Sonv_trt_llm_kv_cache_block_metricsdescribes the self-attention pool alone, and nothing describes the cross-attention pool. - JSON iteration stats. The
IterationStatsserializer incpp/tensorrt_llm/executor/jsonSerialization.cpplistskvCacheStatsand notcrossKvCacheStats. Soto_json_str()and the/metricsroute oftrtllm-servedo not carry it.
Why it matters for an encoder-decoder engine:
- A request holds its encoder output in the cross-attention pool for its whole life. That pool can be the one that runs out first. When it does, the only exported cache metric describes the other pool and can read nearly empty.
- Each pool is sized as the smaller of
max_tokens_in_paged_kv_cacheand its share of free GPU memory at load. The cross-attention pool can come out smaller than configured, and its capacity is not reported anywhere.
Request: when crossKvCacheStats has a value, report it on both paths.
A sketch, not compiled:
- In
model_instance_state.cc, next to the existingkvCacheStatsblock, append the same fields fromstat.crossKvCacheStatsunder distinct keys. - In
custom_metrics_reporter.{h,cc}, add a metric family for them with the samekv_cache_block_typelabel values. A separate family leaves the existing one unchanged, and it is simply absent for decoder-only engines. - In
jsonSerialization.cpp, addcrossKvCacheStatsto theIterationStatsserializer.
Alternatives
- Reading
cross_kv_cache_statsthrough the Python bindings. That works only for code inside the process that owns the executor, so not for a Triton deployment. - Inferring a full cross-attention pool from the request metrics (
activeagainstscheduled). That shows a symptom and not which pool caused it. - Adding the cross-attention values as extra
kv_cache_block_typelabel values on the existing family. That changes what the existing family means for anyone who aggregates it.
Additional context
- Code references are to v1.2.1. The backend's stats loop is the same in v1.3.0rc1.
Hi, I'd like to work on this issue.
I'll look into exposing crossKvCacheStats in the JSON iteration stats and adding a separate cross-attention KV cache metric series to the Triton backend, while keeping the existing self-attention metrics unchanged.
I'll also add targeted tests for both encoder-decoder and decoder-only cases where feasible.
Please let me know if there are any preferred metric names or compatibility constraints I should follow. Thanks!
For context, I currently have #20682 and #21720 open in this repository, both awaiting CI. To keep the work focused and ensure quality, I'd prefer to start on this once at least one of those PRs is resolved, unless there's a reason to prioritize this issue sooner.