[Enhancement] Refactor OmniInputProcessor and related classes for improved prompt handling
- Updated OmniInputProcessor to streamline input processing, including enhanced handling of prompt embeddings and additional information. - Introduced OmniTextPrompt and OmniEmbedsInputs to support new input structures with optional metadata. - Modified input preprocessing methods to accommodate new prompt types and ensure compatibility with multimodal inputs. - Improved error handling and type checking for data parallel configurations. Signed-off-by: [Your Name] <your.email@example.com> Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
This commit is contained in:
1 parent
b26a9735e6
commit
52d0122fb5
5 files changed
+172
-177
No files matched your search
@@ -1,12 +1,20 @@
|
||||
from typing import Any
|
||||
|
||||
from typing_extensions import assert_never
|
||||
from vllm.inputs.data import SingletonInputs, SingletonPrompt, TextPrompt, TokensPrompt
|
||||
from vllm.inputs.data import SingletonInputs, SingletonPrompt
|
||||
from vllm.inputs.preprocess import InputPreprocessor
|
||||
from vllm.logger import init_logger
|
||||
from vllm.multimodal.inputs import MultiModalInputs, MultiModalUUIDDict
|
||||
|
||||
from vllm_omni.inputs.data import OmniTokenInputs, token_inputs_omni
|
||||
from vllm_omni.inputs.data import (
|
||||
OmniEmbedsInputs,
|
||||
OmniEmbedsPrompt,
|
||||
OmniTextPrompt,
|
||||
OmniTokenInputs,
|
||||
OmniTokensPrompt,
|
||||
embeds_inputs_omni,
|
||||
token_inputs_omni,
|
||||
)
|
||||
from vllm_omni.inputs.parse import parse_singleton_prompt_omni
|
||||
|
||||
logger = init_logger(__name__)
|
||||
@@ -22,7 +30,7 @@ class OmniInputPreprocessor(InputPreprocessor):
|
||||
|
||||
def _process_text(
|
||||
self,
|
||||
parsed_content: TextPrompt,
|
||||
parsed_content: OmniTextPrompt,
|
||||
tokenization_kwargs: dict[str, Any] | None = None,
|
||||
*,
|
||||
mm_uuids: MultiModalUUIDDict | None = None,
|
||||
@@ -62,7 +70,7 @@ class OmniInputPreprocessor(InputPreprocessor):
|
||||
|
||||
def _process_tokens(
|
||||
self,
|
||||
parsed_content: TokensPrompt,
|
||||
parsed_content: OmniTokensPrompt,
|
||||
tokenization_kwargs: dict[str, Any] | None = None,
|
||||
*,
|
||||
mm_uuids: MultiModalUUIDDict | None = None,
|
||||
@@ -80,6 +88,10 @@ class OmniInputPreprocessor(InputPreprocessor):
|
||||
tokenization_kwargs=tokenization_kwargs,
|
||||
mm_uuids=mm_uuids,
|
||||
)
|
||||
if prompt_embeds is not None:
|
||||
inputs["prompt_embeds"] = prompt_embeds
|
||||
if additional_information is not None:
|
||||
inputs["additional_information"] = additional_information
|
||||
else:
|
||||
inputs = token_inputs_omni(
|
||||
prompt_token_ids=prompt_token_ids,
|
||||
@@ -129,9 +141,20 @@ class OmniInputPreprocessor(InputPreprocessor):
|
||||
)
|
||||
if parsed["type"] == "str":
|
||||
return self._process_text(
|
||||
TextPrompt(prompt=parsed["content"]),
|
||||
OmniTextPrompt(prompt=parsed["content"]),
|
||||
tokenization_kwargs=tokenization_kwargs,
|
||||
mm_uuids=mm_uuids,
|
||||
)
|
||||
|
||||
assert_never(parsed)
|
||||
|
||||
def _process_embeds(self, parsed_content: OmniEmbedsPrompt) -> OmniEmbedsInputs:
|
||||
inputs = super()._process_embeds(parsed_content)
|
||||
additional_information = parsed_content.get("additional_information")
|
||||
if additional_information is not None:
|
||||
inputs = embeds_inputs_omni(
|
||||
prompt_embeds=inputs["prompt_embeds"],
|
||||
cache_salt=inputs.get("cache_salt"),
|
||||
additional_information=additional_information,
|
||||
)
|
||||
return inputs
|
||||
Reference in new issue
Block a user