[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
+40
-16
@@ -6,8 +6,23 @@ except ImportError:
|
||||
# Python < 3.11: use typing_extensions
|
||||
from typing_extensions import NotRequired
|
||||
|
||||
from typing import TypeAlias
|
||||
|
||||
import torch
|
||||
from vllm.inputs.data import EmbedsPrompt, TokenInputs, TokensPrompt
|
||||
from vllm.inputs.data import (
|
||||
EmbedsInputs,
|
||||
EmbedsPrompt,
|
||||
TextPrompt,
|
||||
TokenInputs,
|
||||
TokensPrompt,
|
||||
)
|
||||
|
||||
|
||||
class OmniTextPrompt(TextPrompt):
|
||||
"""Text prompt with optional embeddings and additional information."""
|
||||
|
||||
prompt_embeds: NotRequired[torch.Tensor]
|
||||
additional_information: NotRequired[dict[str, Any]]
|
||||
|
||||
|
||||
class OmniTokensPrompt(TokensPrompt):
|
||||
@@ -52,25 +67,20 @@ class OmniTokenInputs(TokenInputs):
|
||||
|
||||
|
||||
class OmniEmbedsPrompt(EmbedsPrompt):
|
||||
"""Embeddings prompt with optional additional information.
|
||||
"""Embeddings prompt with optional additional information."""
|
||||
|
||||
Extends EmbedsPrompt to support additional information payloads
|
||||
for direct transfer between pipeline stages.
|
||||
|
||||
Attributes:
|
||||
prompt_embeds: Optional tensor containing prompt embeddings
|
||||
additional_information: Optional dictionary containing additional
|
||||
information (tensors or lists) to pass along with the prompt
|
||||
"""
|
||||
|
||||
# New: optional prompt embeddings aligned with token ids
|
||||
prompt_embeds: NotRequired[torch.Tensor]
|
||||
|
||||
# New: optional additional information dictionary
|
||||
# Values may be torch.Tensor or list
|
||||
additional_information: NotRequired[dict[str, Any]]
|
||||
|
||||
|
||||
class OmniEmbedsInputs(EmbedsInputs):
|
||||
"""Embeddings inputs with optional additional information."""
|
||||
|
||||
additional_information: NotRequired[dict[str, Any]]
|
||||
|
||||
|
||||
OmniSingletonPrompt: TypeAlias = str | OmniTextPrompt | OmniTokensPrompt | OmniEmbedsPrompt
|
||||
|
||||
|
||||
def token_inputs_omni(
|
||||
prompt_token_ids: list[int],
|
||||
prompt: str | None = None,
|
||||
@@ -106,3 +116,17 @@ def token_inputs_omni(
|
||||
inputs["additional_information"] = additional_information
|
||||
|
||||
return inputs
|
||||
|
||||
|
||||
def embeds_inputs_omni(
|
||||
prompt_embeds: torch.Tensor,
|
||||
cache_salt: str | None = None,
|
||||
additional_information: dict[str, Any] | None = None,
|
||||
) -> OmniEmbedsInputs:
|
||||
"""Construct embeddings inputs with optional metadata."""
|
||||
inputs: OmniEmbedsInputs = OmniEmbedsInputs(type="embeds", prompt_embeds=prompt_embeds)
|
||||
if cache_salt is not None:
|
||||
inputs["cache_salt"] = cache_salt
|
||||
if additional_information is not None:
|
||||
inputs["additional_information"] = additional_information
|
||||
return inputs
|
||||
Reference in new issue
Block a user