Signed-off-by: Megha Agarwal <agarwalmegha1308@gmail.com> Signed-off-by: meghaagr13 <divyanshsinghvi@gmail.com> Signed-off-by: Taichang Zhou <tzhouam@connect.ust.hk> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com> Co-authored-by: meghaagr13 <divyanshsinghvi@gmail.com> Co-authored-by: Boao Shi <aoibosh@connect.hku.hk> Co-authored-by: Taichang Zhou <tzhouam@connect.ust.hk> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
49 files changed
+985
-327
No files matched your search
@@ -6,6 +6,7 @@ and also outputs sampled tokens.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from contextlib import nullcontext
|
||||
from copy import copy
|
||||
from dataclasses import replace
|
||||
@@ -46,6 +47,39 @@ from vllm_omni.worker.omni_connector_model_runner_mixin import OmniConnectorMode
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def _ensure_tensor_values(payload: dict[str, object]) -> dict[str, torch.Tensor]:
|
||||
"""Convert a flattened payload to strictly ``dict[str, torch.Tensor]``.
|
||||
|
||||
Non-tensor scalars (int, float) are wrapped with ``torch.tensor()``.
|
||||
Values that cannot be safely converted are dropped with a warning.
|
||||
This enforces the tensor-only invariant required by the
|
||||
``OmniEngineCoreOutput.multimodal_output`` wire field and msgspec
|
||||
serialization.
|
||||
"""
|
||||
result: dict[str, torch.Tensor] = {}
|
||||
for key, val in payload.items():
|
||||
if isinstance(val, torch.Tensor):
|
||||
result[key] = val
|
||||
elif isinstance(val, (int, float, bool)):
|
||||
result[key] = torch.tensor(val)
|
||||
elif isinstance(val, (list, tuple)):
|
||||
try:
|
||||
result[key] = torch.tensor(val)
|
||||
except (ValueError, TypeError, RuntimeError):
|
||||
logger.warning(
|
||||
"Dropping non-tensorizable multimodal output key '%s' (type=%s) from wire payload.",
|
||||
key,
|
||||
type(val).__name__,
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Dropping non-tensor multimodal output key '%s' (type=%s) from wire payload.",
|
||||
key,
|
||||
type(val).__name__,
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
class ExecuteModelState(NamedTuple):
|
||||
scheduler_output: SchedulerOutput
|
||||
logits: torch.Tensor | None
|
||||
@@ -329,7 +363,7 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
|
||||
if self.omni_prefix_cache is not None and is_last_pp_rank:
|
||||
# If this happens, it generally means the model is not following the correct
|
||||
# interface yet and is therefore currently not compatible with prefix cache.
|
||||
if multimodal_outputs is not None and not isinstance(multimodal_outputs, dict):
|
||||
if multimodal_outputs is not None and not isinstance(multimodal_outputs, Mapping):
|
||||
logger.warning_once(
|
||||
"prefix caching expects mm outputs to be a dict, but got %s",
|
||||
type(multimodal_outputs),
|
||||
@@ -835,21 +869,45 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
|
||||
|
||||
@staticmethod
|
||||
def _resolve_req_hidden_states(
|
||||
hidden_states_cpu: torch.Tensor,
|
||||
hidden_states_cpu: torch.Tensor | None,
|
||||
combined_hidden_states: dict[str, torch.Tensor] | None,
|
||||
rid: str,
|
||||
start: int,
|
||||
end: int,
|
||||
):
|
||||
) -> torch.Tensor | None:
|
||||
if combined_hidden_states is not None:
|
||||
# We always have all request IDs for prefix cache, even for
|
||||
# partial cache misses, so this should never happen.
|
||||
if rid not in combined_hidden_states:
|
||||
raise RuntimeError("Request IDs in the batch are missing from the merged states!")
|
||||
return combined_hidden_states[rid]
|
||||
# Prefix caching is disabled
|
||||
# Prefix caching is disabled. hidden_states_cpu may legitimately be
|
||||
# None (e.g. sparse audio output or no scheduled hidden payload);
|
||||
# callers must omit the "hidden" key in that case.
|
||||
if hidden_states_cpu is None:
|
||||
return None
|
||||
return hidden_states_cpu[start:end]
|
||||
|
||||
def _build_multimodal_outputs(
|
||||
self,
|
||||
per_req_payloads: list[dict[str, object]] | None,
|
||||
) -> list[dict[str, torch.Tensor]] | None:
|
||||
"""Build per-request multimodal output payloads (dedicated channel).
|
||||
|
||||
Reuses the per-request payloads assembled by the pooler-payload loop
|
||||
in sample_tokens() (which already handles prefix-cache merging,
|
||||
sparse audio output, and partial downstream batches) so the wire
|
||||
channel stays consistent with the full-payload accumulation path.
|
||||
Enforces the tensor-only invariant required by msgspec: scalars and
|
||||
lists are wrapped into tensors, and anything that cannot be safely
|
||||
converted is dropped.
|
||||
"""
|
||||
if self.vllm_config.model_config.engine_output_type == "text":
|
||||
return None
|
||||
if per_req_payloads is None:
|
||||
return None
|
||||
return [_ensure_tensor_values(payload) if payload else {} for payload in per_req_payloads]
|
||||
|
||||
@torch.inference_mode()
|
||||
def sample_tokens(
|
||||
self,
|
||||
@@ -1057,6 +1115,10 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
|
||||
deferred_mm_cache_keys=deferred_mm_cache_keys,
|
||||
)
|
||||
|
||||
# NOTE: pooler_output here is used only for the full-payload accumulation
|
||||
# path (accumulate_full_payload_output) and is NOT passed on the wire via
|
||||
# OmniModelRunnerOutput.pooler_output (which is set to None below).
|
||||
# The actual multimodal wire transport uses multimodal_outputs instead.
|
||||
pooler_output: list[dict[str, object]] | None = None
|
||||
if needs_pooler_payload:
|
||||
mm_cpu = None
|
||||
@@ -1112,7 +1174,8 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
|
||||
start,
|
||||
end,
|
||||
)
|
||||
payload["hidden"] = req_hidden_states
|
||||
if req_hidden_states is not None:
|
||||
payload["hidden"] = req_hidden_states
|
||||
|
||||
mm_payload: dict[str, object] = {}
|
||||
if combined_multimodal_outputs or mm_cpu:
|
||||
@@ -1127,7 +1190,6 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
|
||||
|
||||
for mm_key in combined_multimodal_outputs.keys():
|
||||
mm_payload[mm_key] = _unwrap_lists(combined_multimodal_outputs[mm_key][rid])
|
||||
|
||||
else:
|
||||
for mm_key, mm_val in mm_cpu.items():
|
||||
if mm_key in {"meta.req_id", "meta.sparse_audio"}:
|
||||
@@ -1166,6 +1228,7 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
|
||||
if req_state is not None and pooler_output[i]:
|
||||
self.accumulate_full_payload_output(rid, pooler_output[i], req_state)
|
||||
|
||||
multimodal_outputs = self._build_multimodal_outputs(pooler_output)
|
||||
with record_function_or_nullcontext("gpu_model_runner: ModelRunnerOutput"):
|
||||
routed_experts_lists = None
|
||||
if self.routed_experts_initialized:
|
||||
@@ -1176,7 +1239,8 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
|
||||
sampled_token_ids=valid_sampled_token_ids,
|
||||
logprobs=logprobs_lists,
|
||||
prompt_logprobs_dict=prompt_logprobs_dict,
|
||||
pooler_output=(pooler_output if engine_output_type != "text" and needs_pooler_payload else None),
|
||||
pooler_output=None,
|
||||
multimodal_outputs=multimodal_outputs,
|
||||
kv_connector_output=kv_connector_output,
|
||||
ec_connector_output=ec_connector_output if self.supports_mm_inputs else None,
|
||||
num_nans_in_logits=num_nans_in_logits,
|
||||
|
||||
Reference in new issue
Block a user