Skip to content

Commit 4b22bc7

Browse files
committed
[None][fix] Size the cross-attention KV cache from the encoder's declared length, not max_input_len
For encoder-decoder models the cross KV pool was sized from llm_args.max_input_len (default 1024), which overwrote the engine length unconditionally; the config-derived encoder limit was then applied with min() and could only shrink it further. Whisper's encoder emits max_source_positions=1500 frames, so every request failed in prepare_cross_metadata with "max KV cache length of input sequences (1500) exceeds the KV cache manager's maximum supported length (1024)". Treat the encoder's declared position limit (now including max_source_positions) as authoritative for the cross pool and fall back to max_input_len only when the model declares no encoder length. Fixes #19514. Verified on RTX 5070 Ti (sm_120) with openai/whisper-large-v3 (release 1.3.0rc25 + #19450): the default-argument reproduction from #18609 transcribes.
1 parent 129655f commit 4b22bc7

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎tensorrt_llm/_torch/pyexecutor/_util.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,18 +2210,26 @@ def _get_cross_kv_cache_layout(
22102210
head_dim = encoder_hidden_size // encoder_num_heads
22112211

22122212
max_seq_len = fallback_max_seq_len or self._max_seq_len
2213-
max_input_len = getattr(self._llm_args, "max_input_len", None)
2214-
if isinstance(max_input_len, int) and max_input_len > 0:
2215-
max_seq_len = max_input_len
22162213
encoder_limit = self._get_config_int_attr(
22172214
config,
22182215
("max_encoder_input_len", "encoder_max_input_length",
22192216
"max_encoder_position_embeddings",
2220-
"encoder_max_position_embeddings", "max_position_embeddings",
2221-
"n_positions"),
2217+
"encoder_max_position_embeddings", "max_source_positions",
2218+
"max_position_embeddings", "n_positions"),
22222219
)
22232220
if encoder_limit is not None:
2224-
max_seq_len = min(max_seq_len, encoder_limit)
2221+
# The cross pool holds the encoder output, so the encoder's own
2222+
# position limit is the authoritative length. Do not let
2223+
# max_input_len (a decoder-side prompt limit, default 1024)
2224+
# shrink it below that: Whisper's encoder emits
2225+
# max_source_positions=1500 frames for every clip, and the
2226+
# request would fail in prepare_cross_metadata with "max KV cache
2227+
# length of input sequences (1500) exceeds ... (1024)".
2228+
max_seq_len = encoder_limit
2229+
else:
2230+
max_input_len = getattr(self._llm_args, "max_input_len", None)
2231+
if isinstance(max_input_len, int) and max_input_len > 0:
2232+
max_seq_len = max_input_len
22252233

22262234
return num_layers, num_kv_heads, head_dim, max_seq_len
22272235

0 commit comments

Comments
 (0)