# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import asyncio from abc import ABC, abstractmethod from collections import defaultdict from collections.abc import Awaitable, Callable from functools import cached_property, partial from typing import TYPE_CHECKING, Any, Final import torch from PIL import Image from typing_extensions import override from vllm import envs from vllm.config import ModelConfig from vllm.exceptions import VLLMValidationError from vllm.multimodal.media import MEDIA_CONNECTOR_REGISTRY, MediaConnector from vllm.renderers.embed_utils import ( safe_load_prompt_embeds, safe_load_prompt_embeds_async, ) from .types import InputAudio, ModalityStr, MultiModalEmbedsPayload if TYPE_CHECKING: from .item_tracker import AsyncMultiModalItemTracker, MultiModalItemTracker MODALITY_PLACEHOLDERS_MAP = { "image": "<##IMAGE##>", "audio": "<##AUDIO##>", "video": "<##VIDEO##>", "prompt_embeds": "<##PROMPT_EMBEDS##>", } PROMPT_EMBEDS_PLACEHOLDER_TOKEN: Final[str] = "" """The special token used as a placeholder for each embedding position during chat template rendering. Registered as an additional special token when `--enable-prompt-embeds` is set. See `_ensure_prompt_embeds_placeholder_token` in `vllm/renderers/hf.py`. """ _ENABLE_PROMPT_EMBEDS_ERROR: Final[str] = ( "You must set `--enable-prompt-embeds` to input `prompt_embeds`" ) class BaseMultiModalContentParser(ABC): def __init__(self) -> None: super().__init__() # stores model placeholders list with corresponding # general MM placeholder: # { # "<##IMAGE##>": ["", "", ""], # "<##AUDIO##>": ["