[Core] Skip broadcasting mm tensor data to workers for prefix-cache-covered items (#52041)
Signed-off-by: Xiaoan (Sean) Liu <shawnliu0327@gmail.com> Signed-off-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
co-authored by
Nick Hill
parent
2b7fcbf527
commit
db92053e97
@@ -5,6 +5,7 @@ import bisect
|
||||
import mimetypes
|
||||
from collections import defaultdict
|
||||
from collections.abc import Generator, Sequence
|
||||
from dataclasses import replace
|
||||
from itertools import groupby
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
@@ -212,6 +213,36 @@ def _batch_mm_items(
|
||||
}
|
||||
|
||||
|
||||
def strip_covered_mm_data(
|
||||
mm_features: list[MultiModalFeatureSpec],
|
||||
num_computed_tokens: int,
|
||||
uses_mrope: bool = False,
|
||||
) -> list[MultiModalFeatureSpec]:
|
||||
"""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 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
|
||||
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
|
||||
):
|
||||
return f
|
||||
|
||||
data = None
|
||||
if uses_mrope:
|
||||
data = MultiModalKwargsItem(
|
||||
{k: elem for k, elem in f.data.items() if elem.field.keep_on_cpu}
|
||||
)
|
||||
return replace(f, data=data)
|
||||
|
||||
return [maybe_strip(f) for f in mm_features]
|
||||
|
||||
|
||||
def group_and_batch_mm_items(
|
||||
items: Sequence[MultiModalKwargsItem],
|
||||
*,
|
||||
|
||||
@@ -6,6 +6,7 @@ from functools import cached_property
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from vllm.config.ec_manager_config import EncoderCacheManagerMetadata
|
||||
from vllm.multimodal.utils import strip_covered_mm_data
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import numpy as np
|
||||
@@ -53,11 +54,16 @@ class NewRequestData:
|
||||
request: Request,
|
||||
block_ids: tuple[list[int], ...],
|
||||
prefill_token_ids: list[int] | None = None,
|
||||
uses_mrope: bool = False,
|
||||
) -> "NewRequestData":
|
||||
return cls(
|
||||
req_id=request.request_id,
|
||||
prompt_token_ids=request.prompt_token_ids,
|
||||
mm_features=request.mm_features,
|
||||
mm_features=strip_covered_mm_data(
|
||||
request.mm_features,
|
||||
request.num_computed_tokens,
|
||||
uses_mrope=uses_mrope,
|
||||
),
|
||||
sampling_params=request.sampling_params,
|
||||
pooling_params=request.pooling_params,
|
||||
block_ids=block_ids,
|
||||
|
||||
@@ -82,6 +82,7 @@ class Scheduler(SchedulerInterface):
|
||||
self.scheduler_config = vllm_config.scheduler_config
|
||||
self.cache_config = vllm_config.cache_config
|
||||
self.lora_config = vllm_config.lora_config
|
||||
self.model_uses_mrope = vllm_config.model_config.uses_mrope
|
||||
self.kv_cache_config = kv_cache_config
|
||||
self.kv_events_config = vllm_config.kv_events_config
|
||||
self.parallel_config = vllm_config.parallel_config
|
||||
@@ -1199,13 +1200,16 @@ class Scheduler(SchedulerInterface):
|
||||
req,
|
||||
req_to_new_blocks[req.request_id].get_block_ids(),
|
||||
req._all_token_ids,
|
||||
uses_mrope=self.model_uses_mrope,
|
||||
)
|
||||
for req in scheduled_new_reqs
|
||||
]
|
||||
else:
|
||||
new_reqs_data = [
|
||||
NewRequestData.from_request(
|
||||
req, req_to_new_blocks[req.request_id].get_block_ids()
|
||||
req,
|
||||
req_to_new_blocks[req.request_id].get_block_ids(),
|
||||
uses_mrope=self.model_uses_mrope,
|
||||
)
|
||||
for req in scheduled_new_reqs
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user