[Refactor][OutputProcessor 2/8]: OmniRequestOutput should inherit RequestOutput and no nested wrap-up (#5146)

Signed-off-by: Boao Shi <aoibosh@connect.hku.hk>
Signed-off-by: bowieshi <aoibosh@connect.hku.hk>
Signed-off-by: princepride <wangzhipeng628@gmail.com>
Signed-off-by: R2-Y <ruiruyang2@gmail.com>
Signed-off-by: amy-why-3459 <wuhaiyan17@huawei.com>
Signed-off-by: Shi Boao Bowie <aoibosh@connect.hku.hk>
Co-authored-by: 汪志鹏 <wangzhipeng628@gmail.com>
Co-authored-by: ruirui(rein) yang <73573651+R2-Y@users.noreply.github.com>
Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com>
Co-authored-by: Gao Han <hgaoaf@connect.ust.hk>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
authored and GitHub committed 2026-08-12 22:58:23 +08:00
1 parent 38a2500bdf
commit fcf1085395
89 files changed
+944 -639

No files matched your search

@@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from collections.abc import Mapping
from dataclasses import asdict, is_dataclass
from dataclasses import asdict, fields, is_dataclass
from typing import Any
import msgspec
@@ -59,7 +59,10 @@ class OmniMsgpackEncoder:
if isinstance(obj, Image.Image):
return self._encode_pil_image(obj)
# RequestOutput (not a dataclass, needs special handling)
# RequestOutput (not a dataclass, needs special handling).
# Note: OmniRequestOutput subclasses RequestOutput but is a dataclass,
# so msgspec encodes it natively (field map) and it never reaches
# this hook.
if isinstance(obj, RequestOutput):
return self._encode_request_output(obj)
@@ -148,7 +151,6 @@ class OmniMsgpackEncoder:
"encoder_prompt": obj.encoder_prompt,
"encoder_prompt_token_ids": obj.encoder_prompt_token_ids,
"num_cached_tokens": obj.num_cached_tokens,
"multi_modal_placeholders": getattr(obj, "multi_modal_placeholders", None),
"kv_transfer_params": obj.kv_transfer_params,
}
# Handle multimodal_output attribute (MultimodalPayload or dict)
@@ -252,23 +254,27 @@ class OmniMsgpackDecoder:
def _decode_omni_request_output(self, obj: dict[str, Any]) -> Any:
"""Decode dict to OmniRequestOutput.
OmniRequestOutput is a dataclass, so we can use msgspec.convert
or construct it directly.
By the time this runs, ``_post_process`` has already reconstructed
nested values bottom-up (CompletionOutput, tensors, images, ...), so
the object is built directly from the known dataclass fields.
"""
from vllm_omni.outputs import OmniRequestOutput
data = dict(obj)
# Legacy wire format (pre-inheritance): the stage output was nested
# under "request_output". Merge its content into the new object.
legacy_inner = data.pop("request_output", None)
field_names = {f.name for f in fields(OmniRequestOutput)}
known = {k: v for k, v in data.items() if k in field_names}
try:
# Use msgspec.convert for dataclass reconstruction
return msgspec.convert(obj, OmniRequestOutput)
out = OmniRequestOutput(**known)
except Exception:
try:
# Fallback: construct directly if msgspec.convert fails
# (e.g., if some fields are missing or have wrong types)
return OmniRequestOutput(**obj)
except Exception:
# If both attempts fail, return dict as-is (defensive fallback)
# This should rarely happen if _is_omni_request_output is correct
return obj
# Defensive fallback; should rarely happen if
# _is_omni_request_output is correct.
return obj
if legacy_inner is not None and not isinstance(legacy_inner, dict):
out._copy_content_from(legacy_inner)
return out
def _decode_tensor(self, obj: dict[str, Any]) -> torch.Tensor:
"""Decode dict to torch.Tensor."""
@@ -314,19 +320,16 @@ class OmniMsgpackDecoder:
We construct it manually using only the known __init__ parameters to
avoid triggering the "Ignoring extra arguments" warning in vllm.
Fields that are not part of RequestOutput.__init__ (e.g.
multi_modal_placeholders, multimodal_output) are extracted first and
multimodal_output) are extracted first and
then restored as dynamic attributes after construction.
"""
# Extract dynamically-added / non-init fields before constructing so
# they are not passed as unknown **kwargs to RequestOutput.__init__.
mm_output = obj.pop("multimodal_output", None)
multi_modal_placeholders = obj.pop("multi_modal_placeholders", None)
ro = RequestOutput(**obj)
# Restore dynamic attributes that are not part of __init__.
if multi_modal_placeholders is not None:
setattr(ro, "multi_modal_placeholders", multi_modal_placeholders)
if mm_output is not None:
setattr(ro, "multimodal_output", mm_output)
return ro