[Perf] Improve multimodal item handling from O(n) to O(log n) per step (#44212)
Signed-off-by: Andy Lo <andy@mistral.ai>
This commit is contained in:
@@ -104,7 +104,7 @@ from vllm.multimodal.inputs import (
|
||||
MultiModalKwargsItem,
|
||||
PlaceholderRange,
|
||||
)
|
||||
from vllm.multimodal.utils import group_and_batch_mm_kwargs
|
||||
from vllm.multimodal.utils import get_mm_features_in_window, group_and_batch_mm_kwargs
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.pooling_params import PoolingParams
|
||||
from vllm.sampling_params import SamplingType
|
||||
@@ -3100,23 +3100,18 @@ class GPUModelRunner(
|
||||
req_state = self.requests[req_id]
|
||||
num_computed_tokens = req_state.num_computed_tokens + shift_computed_tokens
|
||||
|
||||
for mm_feature in req_state.mm_features:
|
||||
mm_features = req_state.mm_features
|
||||
lo, hi = get_mm_features_in_window(
|
||||
mm_features,
|
||||
start=num_computed_tokens,
|
||||
end=num_computed_tokens + num_scheduled_tokens,
|
||||
)
|
||||
for i in range(lo, hi):
|
||||
mm_feature = mm_features[i]
|
||||
pos_info = mm_feature.mm_position
|
||||
start_pos = pos_info.offset
|
||||
num_encoder_tokens = pos_info.length
|
||||
|
||||
# The encoder output is needed if the two ranges overlap:
|
||||
# [num_computed_tokens,
|
||||
# num_computed_tokens + num_scheduled_tokens) and
|
||||
# [start_pos, start_pos + num_encoder_tokens)
|
||||
if start_pos >= num_computed_tokens + num_scheduled_tokens:
|
||||
# The encoder output is not needed in this step.
|
||||
break
|
||||
if start_pos + num_encoder_tokens <= num_computed_tokens:
|
||||
# The encoder output is already processed and stored
|
||||
# in the decoder's KV cache.
|
||||
continue
|
||||
|
||||
start_idx = max(num_computed_tokens - start_pos, 0)
|
||||
end_idx = min(
|
||||
num_computed_tokens - start_pos + num_scheduled_tokens,
|
||||
|
||||
Reference in New Issue
Block a user