2025-09-11 14:32:51 +08:00
|
|
|
"""
|
2025-11-29 04:42:39 -08:00
|
|
|
Engine components for vLLM-Omni.
|
2025-09-11 14:32:51 +08:00
|
|
|
"""
|
|
|
|
|
|
2025-12-16 15:19:40 +08:00
|
|
|
from typing import Any
|
2025-10-24 16:49:19 +08:00
|
|
|
|
|
|
|
|
import msgspec
|
2025-11-30 04:44:01 +08:00
|
|
|
import torch
|
|
|
|
|
from vllm.v1.engine import (
|
2026-01-21 00:25:25 +08:00
|
|
|
EngineCoreOutput,
|
|
|
|
|
EngineCoreOutputs,
|
2025-11-30 04:44:01 +08:00
|
|
|
EngineCoreRequest,
|
|
|
|
|
)
|
2025-10-24 16:49:19 +08:00
|
|
|
|
2025-09-11 14:32:51 +08:00
|
|
|
|
2025-10-22 15:16:25 +08:00
|
|
|
class PromptEmbedsPayload(msgspec.Struct):
|
|
|
|
|
"""Serialized prompt embeddings payload for direct transfer.
|
|
|
|
|
|
|
|
|
|
data: raw bytes of the tensor in row-major order
|
|
|
|
|
shape: [seq_len, hidden_size]
|
|
|
|
|
dtype: torch dtype name (e.g., "float16", "float32")
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
data: bytes
|
|
|
|
|
shape: list[int]
|
|
|
|
|
dtype: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AdditionalInformationEntry(msgspec.Struct):
|
|
|
|
|
"""One entry of additional_information.
|
|
|
|
|
|
2026-03-24 10:29:38 -04:00
|
|
|
Three supported forms are encoded:
|
2025-10-22 15:16:25 +08:00
|
|
|
- tensor: data/shape/dtype
|
|
|
|
|
- list: a Python list (msgspec-serializable)
|
2026-03-24 10:29:38 -04:00
|
|
|
- scalar: a Python scalar (msgspec-serializable)
|
|
|
|
|
Exactly one of (tensor_data, list_data, scalar_data) should be non-None.
|
2025-10-22 15:16:25 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# Tensor form
|
2025-12-16 15:19:40 +08:00
|
|
|
tensor_data: bytes | None = None
|
|
|
|
|
tensor_shape: list[int] | None = None
|
|
|
|
|
tensor_dtype: str | None = None
|
2025-10-22 15:16:25 +08:00
|
|
|
|
|
|
|
|
# List form
|
2025-12-16 15:19:40 +08:00
|
|
|
list_data: list[Any] | None = None
|
2025-10-22 15:16:25 +08:00
|
|
|
|
2026-03-24 10:29:38 -04:00
|
|
|
# Scalar form
|
|
|
|
|
scalar_data: Any | None = None
|
|
|
|
|
|
2025-10-22 15:16:25 +08:00
|
|
|
|
|
|
|
|
class AdditionalInformationPayload(msgspec.Struct):
|
|
|
|
|
"""Serialized dictionary payload for additional_information.
|
|
|
|
|
|
|
|
|
|
Keys are strings; values are encoded as AdditionalInformationEntry.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
entries: dict[str, AdditionalInformationEntry]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OmniEngineCoreRequest(EngineCoreRequest):
|
2025-11-28 11:03:52 +08:00
|
|
|
"""Engine core request for omni models with embeddings support.
|
|
|
|
|
|
2026-03-09 17:29:38 +08:00
|
|
|
Extends the base EngineCoreRequest with support for additional
|
|
|
|
|
information payloads, enabling direct transfer of pre-computed data
|
|
|
|
|
between pipeline stages.
|
|
|
|
|
|
|
|
|
|
Note: prompt_embeds is inherited from EngineCoreRequest
|
|
|
|
|
(torch.Tensor | None). PromptEmbedsPayload should be decoded to
|
|
|
|
|
torch.Tensor before constructing this request.
|
2025-11-28 11:03:52 +08:00
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
additional_information: Optional serialized additional information
|
|
|
|
|
dictionary containing tensors or lists to pass along with the request
|
|
|
|
|
"""
|
|
|
|
|
|
2025-10-22 15:16:25 +08:00
|
|
|
# Optional additional information dictionary (serialized)
|
2025-12-16 15:19:40 +08:00
|
|
|
additional_information: AdditionalInformationPayload | None = None
|
2025-11-30 04:44:01 +08:00
|
|
|
|
|
|
|
|
|
2026-01-21 00:25:25 +08:00
|
|
|
class OmniEngineCoreOutput(EngineCoreOutput):
|
2025-12-16 15:19:40 +08:00
|
|
|
pooling_output: dict[str, torch.Tensor] | None = None
|
2026-04-18 15:42:41 +08:00
|
|
|
# Finished flag for streaming input segment
|
|
|
|
|
is_segment_finished: bool | None = False
|
|
|
|
|
# Streaming update prompt length
|
|
|
|
|
new_prompt_len_snapshot: int | None = None
|
2025-11-30 04:44:01 +08:00
|
|
|
|
|
|
|
|
|
2026-01-21 00:25:25 +08:00
|
|
|
class OmniEngineCoreOutputs(EngineCoreOutputs):
|
2025-11-30 04:44:01 +08:00
|
|
|
outputs: list[OmniEngineCoreOutput] = []
|