Files
vllm-omni/vllm_omni/request.py
T
+20 eb4e60ee64 [Rebase] Rebase to vllm v0.21.0 (#3530)
Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
Signed-off-by: Zhou Taichang <tzhouam@connect.ust.hk>
Signed-off-by: NumberWan <wantszkin2003@gmail.com>
Signed-off-by: Divyansh Singhvi <divyanshsinghvi@gmail.com>
Signed-off-by: dsinghvi <divyanshsinghvi@gmail.com>
Signed-off-by: Dnoob <dxpouo@gmail.com>
Signed-off-by: Yueqian Lin <70319226+linyueqian@users.noreply.github.com>
Signed-off-by: knlnguyen1802 <knlnguyen1802@gmail.com>
Signed-off-by: rein yang <ruiruyang2@gmail.com>
Signed-off-by: Nick Cao <ncao@redhat.com>
Signed-off-by: zhumingjue <zhumingjue@huawei.com>
Signed-off-by: Ricardo Noriega De Soto <rnoriega@redhat.com>
Signed-off-by: lyj-jjj <liuyingjun5@huawei.com>
Signed-off-by: gcanlin <canlinguosdu@gmail.com>
Signed-off-by: wangyu <410167048@qq.com>
Signed-off-by: weizhoublue <weizhoublue@github.com>
Signed-off-by: weizhou.lan@daocloud.io <weizhou.lan@daocloud.io>
Signed-off-by: dengyunyang <584797741@qq.com>
Signed-off-by: 汪志鹏 <wangzhipeng628@gmail.com>
Signed-off-by: David Chen <530634352@qq.com>
Signed-off-by: Jie Liu <33612777+keeper-jie@users.noreply.github.com>
Signed-off-by: Yueqian Lin <linyueqian@outlook.com>
Signed-off-by: princepride <wangzhipeng628@gmail.com>
Signed-off-by: natureofnature <wzliu@connect.hku.hk>
Signed-off-by: bjf-frz <frz123db@gmail.com>
Signed-off-by: amy-why-3459 <wuhaiyan17@huawei.com>
Signed-off-by: KexiongYu <yukexiong1@huawei.com>
Signed-off-by: Huang, Zeyu <11222265+fhfuih@users.noreply.github.com>
Signed-off-by: Zeyu Huang | 黃澤宇 <11222265+fhfuih@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: NumberWan <wantszkin2003@gmail.com>
Co-authored-by: dsinghvi <divyanshsinghvi@gmail.com>
Co-authored-by: Dnoob <dxpouo@gmail.com>
Co-authored-by: Yueqian Lin <70319226+linyueqian@users.noreply.github.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
Co-authored-by: knlnguyen1802 <knlnguyen1802@gmail.com>
Co-authored-by: Samit <285365963@qq.com>
Co-authored-by: rein yang <73573651+R2-Y@users.noreply.github.com>
Co-authored-by: Nick Cao <ncao@redhat.com>
Co-authored-by: zhumingjue138 <zhumingjue@huawei.com>
Co-authored-by: Ricardo Noriega <rnoriega@redhat.com>
Co-authored-by: lyj-jjj <liuyingjun5@huawei.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: gcanlin <canlinguosdu@gmail.com>
Co-authored-by: wangyu <53896905+yenuo26@users.noreply.github.com>
Co-authored-by: weizhoublue <45163302+weizhoublue@users.noreply.github.com>
Co-authored-by: weizhoublue <weizhoublue@github.com>
Co-authored-by: dengyunyang <584797741@qq.com>
Co-authored-by: 汪志鹏 <wangzhipeng628@gmail.com>
Co-authored-by: WeiQing Chen <40507679+david6666666@users.noreply.github.com>
Co-authored-by: Jie Liu <33612777+keeper-jie@users.noreply.github.com>
Co-authored-by: Yueqian Lin <linyueqian@outlook.com>
Co-authored-by: NATURE <wzliu@connect.hku.hk>
Co-authored-by: bjf-frz <frz123db@gmail.com>
Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com>
Co-authored-by: Y. Fisher <yukexiong1@huawei.com>
Co-authored-by: Zeyu Huang | 黃澤宇 <11222265+fhfuih@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-16 18:18:43 +08:00

132 lines
5.0 KiB
Python

from collections.abc import Callable
from dataclasses import dataclass
from typing import TYPE_CHECKING
import numpy as np
import torch
from vllm.multimodal.inputs import MultiModalFeatureSpec
from vllm.sampling_params import SamplingParams
from vllm.v1.request import Request
if TYPE_CHECKING:
from vllm.v1.core.kv_cache_utils import BlockHash
from vllm_omni.engine import AdditionalInformationPayload, OmniEngineCoreRequest, PromptEmbedsPayload
class OmniRequest(Request):
"""Request class for omni models, extending the base Request.
This class extends the base vLLM Request with support for prompt
embeddings and additional information payloads, enabling direct
transfer of pre-computed embeddings between stages.
Args:
prompt_embeds: Optional serialized prompt embeddings payload.
Used for direct transfer of embeddings between stages.
additional_information: Optional additional information payload
containing tensors or lists to be passed along with the request.
"""
def __init__(
self,
prompt_embeds: PromptEmbedsPayload | torch.Tensor | None = None,
# Optional external request ID for tracking
external_req_id: str | None = None,
additional_information: AdditionalInformationPayload | None = None,
*args,
**kwargs,
):
prompt_embeds_tensor = self._maybe_decode_prompt_embeds(prompt_embeds)
super().__init__(prompt_embeds=prompt_embeds_tensor, *args, **kwargs)
# Preserve serialized prompt embeddings payload (optional)
self.prompt_embeds_payload: PromptEmbedsPayload | None = (
prompt_embeds if isinstance(prompt_embeds, PromptEmbedsPayload) else None
)
# Optional external request ID for tracking
self.external_req_id: str | None = external_req_id
# Serialized additional information payload (optional)
self.additional_information: AdditionalInformationPayload | None = additional_information
@staticmethod
def _maybe_decode_prompt_embeds(
prompt_embeds: PromptEmbedsPayload | torch.Tensor | None,
) -> torch.Tensor | None:
if isinstance(prompt_embeds, PromptEmbedsPayload):
dtype = getattr(np, prompt_embeds.dtype)
arr = np.frombuffer(prompt_embeds.data, dtype=dtype)
arr = arr.reshape(prompt_embeds.shape)
return torch.from_numpy(arr)
return prompt_embeds
@classmethod
def from_engine_core_request(
cls,
request: OmniEngineCoreRequest,
block_hasher: Callable[["Request"], list["BlockHash"]] | None,
) -> "Request":
"""Create an OmniRequest from an OmniEngineCoreRequest.
Args:
request: The OmniEngineCoreRequest to convert
block_hasher: Optional function to compute block hashes for
prefix caching
Returns:
OmniRequest instance created from the engine core request
"""
return cls(
request_id=request.request_id,
# Optional external request ID for tracking
external_req_id=request.external_req_id,
client_index=request.client_index,
prompt_token_ids=request.prompt_token_ids,
prompt_embeds=request.prompt_embeds,
prompt_is_token_ids=request.prompt_is_token_ids,
mm_features=request.mm_features,
sampling_params=request.sampling_params,
pooling_params=request.pooling_params,
arrival_time=request.arrival_time,
lora_request=request.lora_request,
cache_salt=request.cache_salt,
priority=request.priority,
trace_headers=request.trace_headers,
block_hasher=block_hasher,
additional_information=request.additional_information,
resumable=request.resumable,
reasoning_ended=request.reasoning_ended,
reasoning_parser_kwargs=request.reasoning_parser_kwargs,
abort_immediately=request.abort_immediately,
)
@dataclass
class OmniStreamingUpdate:
"""
Override: add additional information
Lightweight data for streaming session continuation.
Contains only the fields needed to update an existing streaming session
with new input data.
"""
mm_features: list[MultiModalFeatureSpec] | None
prompt_token_ids: list[int] | None
max_tokens: int
arrival_time: float
sampling_params: SamplingParams | None
additional_information: AdditionalInformationPayload | None = None
@classmethod
def from_request(cls, request: "Request") -> "OmniStreamingUpdate | None":
if not request.resumable:
return None
return cls(
mm_features=request.mm_features,
prompt_token_ids=request.prompt_token_ids,
max_tokens=request.max_tokens,
arrival_time=request.arrival_time,
sampling_params=request.sampling_params,
additional_information=request.additional_information,
)