fix: disambiguate multimodal prefix cache keys (#36708)

Signed-off-by: tianshu.yu <tianshuyu.formal@gmail.com>
This commit is contained in:
tianshu-Michael-yu
2026-03-20 10:33:20 +08:00
committed by GitHub
parent e5a77a5015
commit 269bf46d99
3 changed files with 29 additions and 16 deletions
+7 -4
View File
@@ -413,7 +413,7 @@ def _gen_mm_extra_hash_keys(
# We do not need to check all mm inputs if the start token index is out of
# range. This usually happens in the late prefill phase and decoding phase.
last_pos = mm_features[-1].mm_position
if last_pos.offset + last_pos.length < start_token_idx:
if last_pos.offset + last_pos.length <= start_token_idx:
return extra_keys, start_mm_idx
# Support start_mm_idx == -1 to indicate the last mm input.
@@ -428,13 +428,16 @@ def _gen_mm_extra_hash_keys(
offset = mm_feature.mm_position.offset
length = mm_feature.mm_position.length
if end_token_idx > offset:
if start_token_idx > offset + length:
if start_token_idx >= offset + length:
# This block has passed the current mm input.
curr_mm_idx += 1
continue
# The block contains the current mm input.
extra_keys.append(mm_feature.identifier)
# The block contains the current mm input. Include its offset
# relative to the start of the block so prefix-cache keys stay
# distinct when the same MM item appears at different positions
# within otherwise-identical placeholder blocks.
extra_keys.append((mm_feature.identifier, offset - start_token_idx))
if end_token_idx >= offset + length:
# If this block contains the end of the current mm input,