[Bugfix][Multimodal] Handle prefix-covered items in SHM worker cache (#54994)

Signed-off-by: waizuichougou <2082431897@qq.com>
Signed-off-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
waizuichougou
2026-09-03 06:39:34 +00:00
committed by GitHub
co-authored by Nick Hill
parent 27a94d1ce4
commit 3f1af35e01
4 changed files with 115 additions and 4 deletions
+9 -4
View File
@@ -221,15 +221,20 @@ def strip_covered_mm_data(
"""Drop the tensor data of mm items whose placeholder span is fully inside
a prefix-cache-covered region: no encoder run can be scheduled for them,
so the workers never consume the payload fields. M-RoPE and XD-RoPE models
are the exception: the worker computes positions for the whole prompt from
the CPU-side metadata fields (e.g. grid dims), so those are kept. The
keep CPU-side metadata fields used to compute positions. SHM address items
are also kept so workers can balance the sender's reference count. The
scheduler-side ``Request`` keeps the full features."""
if not mm_features or num_computed_tokens == 0:
return mm_features
def maybe_strip(f: MultiModalFeatureSpec) -> MultiModalFeatureSpec:
if f.data is None or (
f.mm_position.offset + f.mm_position.length > num_computed_tokens
if (
f.data is None
# SHM address items must reach the worker so it can acknowledge
# the sender's reference count before the item is evicted. This
# mirrors how the SHM receiver identifies them ("address" in item).
or "address" in f.data
or (f.mm_position.offset + f.mm_position.length > num_computed_tokens)
):
return f