[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:
89 files changed
+944
-639
No files matched your search
@@ -125,7 +125,7 @@ def _extract_images(output: OmniRequestOutput) -> list:
|
||||
return output.images
|
||||
# When the output comes from the orchestrator pipeline, images may be
|
||||
# nested inside request_output.
|
||||
inner = getattr(output, "request_output", None)
|
||||
inner = output
|
||||
if inner is not None and hasattr(inner, "images") and inner.images:
|
||||
return inner.images
|
||||
return []
|
||||
|
||||
+2
-2
@@ -56,10 +56,10 @@ def test_teacache(model_name: str):
|
||||
# Extract images from request_output['images']
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "image"
|
||||
if not hasattr(first_output, "request_output") or not first_output.request_output:
|
||||
if not isinstance(first_output, OmniRequestOutput) or not first_output:
|
||||
raise ValueError("No request_output found in OmniRequestOutput")
|
||||
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
if not isinstance(req_out, OmniRequestOutput) or not hasattr(req_out, "images"):
|
||||
raise ValueError("Invalid request_output structure or missing 'images' key")
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ def _run_inference(
|
||||
elapsed_ms = (time.time() - start) * 1000
|
||||
|
||||
return InferenceResult(
|
||||
images=outputs[0].request_output.images,
|
||||
images=outputs[0].images,
|
||||
elapsed_ms=elapsed_ms,
|
||||
)
|
||||
finally:
|
||||
|
||||
@@ -49,10 +49,10 @@ def _diff_metrics(a: Image.Image, b: Image.Image) -> tuple[float, float]:
|
||||
def _extract_single_image(outputs) -> Image.Image:
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "image"
|
||||
if not hasattr(first_output, "request_output") or not first_output.request_output:
|
||||
if not isinstance(first_output, OmniRequestOutput) or not first_output:
|
||||
raise ValueError("No request_output found in OmniRequestOutput")
|
||||
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
if not isinstance(req_out, OmniRequestOutput) or not hasattr(req_out, "images"):
|
||||
raise ValueError("Invalid request_output structure or missing 'images' key")
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ def test_diffusion_model(tmp_path: Path, omni_runner):
|
||||
raise ValueError("Empty outputs from Omni.generate()")
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "image"
|
||||
if not hasattr(first_output, "request_output") or not first_output.request_output:
|
||||
if not isinstance(first_output, OmniRequestOutput) or not first_output:
|
||||
raise ValueError("No request_output found in OmniRequestOutput")
|
||||
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
if not isinstance(req_out, OmniRequestOutput) or not hasattr(req_out, "images"):
|
||||
raise ValueError("Invalid request_output structure or missing 'images' key")
|
||||
return req_out.images
|
||||
|
||||
@@ -122,8 +122,8 @@ def test_cpu_offload_diffusion_model(model_name: str):
|
||||
print(f"No offload peak memory: {no_offload_peak_memory} MB")
|
||||
|
||||
if model_name == "stabilityai/stable-audio-open-1.0":
|
||||
audio_offload = output_offload[0].request_output.multimodal_output.get("audio")
|
||||
audio_no_offload = output_no_offload[0].request_output.multimodal_output.get("audio")
|
||||
audio_offload = output_offload[0].multimodal_output.get("audio")
|
||||
audio_no_offload = output_no_offload[0].multimodal_output.get("audio")
|
||||
check_audio_determinism(audio_offload, audio_no_offload, atol=1e-2)
|
||||
|
||||
# Set platform-specific VRAM saving thresholds to account
|
||||
|
||||
@@ -20,18 +20,10 @@ IMAGE_VIDEO_MODELS = {
|
||||
|
||||
MODELS = {**AUDIO_MODEL, **IMAGE_VIDEO_MODELS}
|
||||
|
||||
LAYERWISE_MODEL_CASES = [
|
||||
pytest.param(
|
||||
"stabilityai/stable-audio-open-1.0",
|
||||
marks=[pytest.mark.full_model, pytest.mark.diffusion],
|
||||
id="stable_audio",
|
||||
),
|
||||
pytest.param(
|
||||
"riverclouds/qwen_image_random",
|
||||
marks=[pytest.mark.core_model, pytest.mark.diffusion],
|
||||
id="qwen_image_random",
|
||||
),
|
||||
]
|
||||
MODEL_MARKS = {
|
||||
"riverclouds/qwen_image_random": pytest.mark.core_model,
|
||||
"stabilityai/stable-audio-open-1.0": pytest.mark.full_model,
|
||||
}
|
||||
|
||||
AUDIO_MODEL_PARAMS = {
|
||||
"runner_params": {},
|
||||
@@ -101,8 +93,9 @@ def run_inference(
|
||||
return peak, output
|
||||
|
||||
|
||||
@pytest.mark.diffusion
|
||||
@hardware_test(res={"cuda": "L4", "rocm": "MI325"})
|
||||
@pytest.mark.parametrize("model_name", LAYERWISE_MODEL_CASES)
|
||||
@pytest.mark.parametrize("model_name", list(MODELS.keys()))
|
||||
def test_layerwise_offload_diffusion_model(model_name: str):
|
||||
"""Test that layerwise offloading reduces GPU memory usage.
|
||||
|
||||
@@ -134,8 +127,8 @@ def test_layerwise_offload_diffusion_model(model_name: str):
|
||||
print(f"No offload peak memory: {no_offload_peak_memory} MB")
|
||||
|
||||
if model_name == "stabilityai/stable-audio-open-1.0":
|
||||
audio_offload = output_offload[0].request_output.multimodal_output.get("audio")
|
||||
audio_no_offload = output_no_offload[0].request_output.multimodal_output.get("audio")
|
||||
audio_offload = output_offload[0].multimodal_output.get("audio")
|
||||
audio_no_offload = output_no_offload[0].multimodal_output.get("audio")
|
||||
# Match the sibling cpu-offload test's tolerance: layerwise offload moves
|
||||
# blocks across the PCIe bus on a side stream, which can perturb cuBLAS
|
||||
# algorithm selection and produce ~ULP-level drift larger than 1e-3.
|
||||
|
||||
@@ -94,8 +94,8 @@ def _generate_single_stage_image(
|
||||
if hasattr(first_output, "images") and first_output.images:
|
||||
images = first_output.images
|
||||
else:
|
||||
assert hasattr(first_output, "request_output") and first_output.request_output
|
||||
request_output = first_output.request_output
|
||||
assert isinstance(first_output, OmniRequestOutput) and first_output
|
||||
request_output = first_output
|
||||
if isinstance(request_output, list):
|
||||
req_out = request_output[0]
|
||||
else:
|
||||
|
||||
@@ -88,8 +88,8 @@ def _generate_single_stage_image(
|
||||
if hasattr(first_output, "images") and first_output.images:
|
||||
images = first_output.images
|
||||
else:
|
||||
assert hasattr(first_output, "request_output") and first_output.request_output
|
||||
request_output = first_output.request_output
|
||||
assert isinstance(first_output, OmniRequestOutput) and first_output
|
||||
request_output = first_output
|
||||
if isinstance(request_output, list):
|
||||
req_out = request_output[0]
|
||||
else:
|
||||
@@ -147,10 +147,10 @@ def _generate_single_stage_video(
|
||||
|
||||
first = outputs[0]
|
||||
|
||||
# Unwrap pipeline-style outputs (multi-stage / OmniRequestOutput.request_output).
|
||||
# Unwrap pipeline-style outputs (multi-stage / OmniRequestOutput).
|
||||
frames: Any = None
|
||||
if hasattr(first, "request_output") and isinstance(first.request_output, list):
|
||||
inner = first.request_output[0]
|
||||
if isinstance(first, OmniRequestOutput) and isinstance(first, list):
|
||||
inner = first[0]
|
||||
if isinstance(inner, OmniRequestOutput) and inner.images:
|
||||
frames = inner.images[0]
|
||||
if frames is None and hasattr(first, "images") and first.images:
|
||||
@@ -234,8 +234,8 @@ def _generate_bagel_image(
|
||||
if images := getattr(req_output, "images", None):
|
||||
generated_image = images[0]
|
||||
break
|
||||
if hasattr(req_output, "request_output") and req_output.request_output:
|
||||
stage_outputs = req_output.request_output
|
||||
if isinstance(req_output, OmniRequestOutput) and req_output:
|
||||
stage_outputs = req_output
|
||||
if not isinstance(stage_outputs, list):
|
||||
stage_outputs = [stage_outputs]
|
||||
for stage_out in stage_outputs:
|
||||
@@ -250,8 +250,8 @@ def _generate_bagel_image(
|
||||
|
||||
# Check LLM stage output — should have finish_reason=stop (not length)
|
||||
for req_output in omni_outputs:
|
||||
if hasattr(req_output, "request_output") and req_output.request_output:
|
||||
stage_outputs = req_output.request_output
|
||||
if isinstance(req_output, OmniRequestOutput) and req_output:
|
||||
stage_outputs = req_output
|
||||
if not isinstance(stage_outputs, list):
|
||||
stage_outputs = [stage_outputs]
|
||||
for stage_out in stage_outputs:
|
||||
|
||||
@@ -310,7 +310,7 @@ def _generate_image(omni, config: QualityTestConfig):
|
||||
first = outputs[0]
|
||||
if hasattr(first, "images") and first.images:
|
||||
return first.images[0], peak_mem
|
||||
inner = first.request_output
|
||||
inner = first
|
||||
if inner is not None and hasattr(inner, "images") and inner.images:
|
||||
return inner.images[0], peak_mem
|
||||
raise ValueError("Could not extract image from output.")
|
||||
@@ -341,15 +341,15 @@ def _generate_video(omni, config: QualityTestConfig):
|
||||
)
|
||||
|
||||
peak_mem = torch.accelerator.max_memory_allocated() / (1024**3)
|
||||
first = outputs[0]
|
||||
if hasattr(first, "request_output") and isinstance(first.request_output, list):
|
||||
inner = first.request_output[0]
|
||||
if isinstance(inner, OmniRequestOutput) and hasattr(inner, "images"):
|
||||
frames = inner.images[0] if inner.images else None
|
||||
else:
|
||||
frames = inner
|
||||
elif hasattr(first, "images") and first.images:
|
||||
frames = first.images[0]
|
||||
if isinstance(outputs, list) and isinstance(outputs[0], OmniRequestOutput):
|
||||
first = outputs[0]
|
||||
elif isinstance(outputs, OmniRequestOutput):
|
||||
first = outputs
|
||||
else:
|
||||
raise ValueError("Could not extract video frames from output.")
|
||||
|
||||
if hasattr(first, "images"):
|
||||
frames = first.images[0] if first.images else None
|
||||
else:
|
||||
raise ValueError("Could not extract video frames from output.")
|
||||
|
||||
@@ -444,11 +444,11 @@ def test_benchmark_generate_image_unwraps_nested_omni_request_output(monkeypatch
|
||||
|
||||
image = Image.new("RGB", (2, 2))
|
||||
inner = OmniRequestOutput.from_diffusion(request_id="req", images=[image])
|
||||
outer = OmniRequestOutput(
|
||||
outer = OmniRequestOutput.from_stage_output(
|
||||
inner,
|
||||
request_id="req",
|
||||
stage_id=0,
|
||||
final_output_type="image",
|
||||
request_output=inner,
|
||||
finished=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -73,11 +73,9 @@ def test_run_summary_reports_worker_peak_memory():
|
||||
assert summary["per_run_peak_memory_mb"] == [100.0, 150.0]
|
||||
|
||||
|
||||
def test_request_peak_memory_prefers_inner_diffusion_output():
|
||||
inner = type("InnerOutput", (), {"peak_memory_mb": 321.0})()
|
||||
outer = type("OuterOutput", (), {"request_output": inner, "peak_memory_mb": 123.0})()
|
||||
|
||||
assert _request_peak_memory_mb(outer) == 321.0
|
||||
def test_request_peak_memory_reads_peak_memory_mb_directly():
|
||||
result = type("Output", (), {"peak_memory_mb": 123.0})()
|
||||
assert _request_peak_memory_mb(result) == 123.0
|
||||
|
||||
|
||||
def test_metric_guidance_describes_thresholds():
|
||||
|
||||
@@ -273,7 +273,7 @@ class TestPipelineStreamingOutputToEntrypoint:
|
||||
await _wait_for(lambda: len(pipeline.requests) == 1)
|
||||
assert pipeline.requests[0].request_id.startswith("req-omni-")
|
||||
assert [output.multimodal_output["metadata"]["stream"]["chunk"] for output in outputs] == [0, 1]
|
||||
assert [getattr(output.request_output, "finished", output.finished) for output in outputs] == [False, True]
|
||||
assert [output.finished for output in outputs] == [False, True]
|
||||
finally:
|
||||
await self._shutdown_pipeline_omni_harness(omni, fixture, inline_client)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ from tests.helpers.mark import hardware_test
|
||||
from tests.helpers.runtime import OmniRunner
|
||||
from tests.helpers.stage_config import get_deploy_config_path, modify_stage_config
|
||||
from vllm_omni.entrypoints.omni import Omni
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
pytestmark = [pytest.mark.usefixtures("clean_gpu_memory_between_tests")]
|
||||
|
||||
@@ -95,8 +96,8 @@ def _extract_generated_image(omni_outputs: list) -> Image.Image | None:
|
||||
for req_output in omni_outputs:
|
||||
if images := getattr(req_output, "images", None):
|
||||
return images[0]
|
||||
if hasattr(req_output, "request_output") and req_output.request_output:
|
||||
stage_out = req_output.request_output
|
||||
if isinstance(req_output, OmniRequestOutput) and req_output:
|
||||
stage_out = req_output
|
||||
if hasattr(stage_out, "images") and stage_out.images:
|
||||
return stage_out.images[0]
|
||||
return None
|
||||
|
||||
@@ -24,6 +24,7 @@ from tests.helpers.mark import hardware_test
|
||||
from tests.helpers.runtime import OmniRunner
|
||||
from tests.helpers.stage_config import get_deploy_config_path, modify_stage_config
|
||||
from vllm_omni.entrypoints.omni import Omni
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
pytestmark = [pytest.mark.usefixtures("clean_gpu_memory_between_tests")]
|
||||
|
||||
@@ -122,8 +123,8 @@ def _extract_generated_image(omni_outputs: list) -> Image.Image | None:
|
||||
for req_output in omni_outputs:
|
||||
if images := getattr(req_output, "images", None):
|
||||
return images[0]
|
||||
if hasattr(req_output, "request_output") and req_output.request_output:
|
||||
stage_out = req_output.request_output
|
||||
if isinstance(req_output, OmniRequestOutput) and req_output:
|
||||
stage_out = req_output
|
||||
if hasattr(stage_out, "images") and stage_out.images:
|
||||
return stage_out.images[0]
|
||||
return None
|
||||
|
||||
@@ -328,7 +328,7 @@ def _run_offline(deploy_config_path: str, output_path: Path) -> tuple[Image.Imag
|
||||
images = None
|
||||
cot_text = ""
|
||||
for out in outputs:
|
||||
ro = getattr(out, "request_output", None)
|
||||
ro = out
|
||||
if ro and getattr(ro, "outputs", None):
|
||||
cot_text = "".join(getattr(o, "text", "") or "" for o in ro.outputs)
|
||||
if not cot_text:
|
||||
@@ -467,7 +467,7 @@ def _extract_image(outputs) -> Image.Image:
|
||||
assert outputs, "Pipeline produced no outputs"
|
||||
for output in outputs:
|
||||
images = getattr(output, "images", None)
|
||||
request_output = getattr(output, "request_output", None)
|
||||
request_output = output
|
||||
if not images and request_output is not None:
|
||||
images = getattr(request_output, "images", None)
|
||||
if images:
|
||||
|
||||
@@ -141,8 +141,8 @@ def _extract_frames(result) -> list[Image.Image]:
|
||||
|
||||
if isinstance(result, list):
|
||||
result = result[0] if result else None
|
||||
if isinstance(result, OmniRequestOutput) and result.is_pipeline_output and result.request_output is not None:
|
||||
result = result.request_output
|
||||
if isinstance(result, OmniRequestOutput) and result.is_pipeline_output and result is not None:
|
||||
result = result
|
||||
images = getattr(result, "images", None)
|
||||
if not images:
|
||||
raise AssertionError("Pipeline output had no images")
|
||||
|
||||
@@ -171,11 +171,11 @@ def _build_text_output(text: str = "This is a test response.") -> OmniRequestOut
|
||||
metrics=None,
|
||||
lora_request=None,
|
||||
)
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
request_output,
|
||||
request_id="test_req_text",
|
||||
finished=True,
|
||||
final_output_type="text",
|
||||
request_output=request_output,
|
||||
)
|
||||
|
||||
|
||||
@@ -200,11 +200,11 @@ def _build_audio_chat_output(num_samples: int = 24000) -> OmniRequestOutput:
|
||||
metrics=None,
|
||||
lora_request=None,
|
||||
)
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
request_output,
|
||||
request_id="test_req_audio_chat",
|
||||
finished=True,
|
||||
final_output_type="audio",
|
||||
request_output=request_output,
|
||||
)
|
||||
|
||||
|
||||
@@ -240,11 +240,11 @@ def _build_diffusion_image_output_for_chat_endpoint() -> OmniRequestOutput:
|
||||
images=[_build_image_output(color="blue")],
|
||||
finished=True,
|
||||
)
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
request_output,
|
||||
request_id="test_req_img_chat",
|
||||
finished=True,
|
||||
images=[_build_image_output(color="blue")],
|
||||
final_output_type="image",
|
||||
request_output=request_output,
|
||||
)
|
||||
|
||||
|
||||
@@ -515,8 +515,19 @@ def mock_async_omni(
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_server(unused_tcp_port_factory, server_case: ServerCase, mock_async_omni):
|
||||
def api_server(unused_tcp_port_factory, server_case: ServerCase, mock_async_omni, tmp_path):
|
||||
"""Set up a API server in background process from command line with parametrized model name and mocked AsyncOmni."""
|
||||
# Override the STORAGE_MANAGER path to a writable temp directory before
|
||||
# forking the server subprocess. The default /tmp/storage may be owned
|
||||
# by a different user (e.g. from a previous CI run) and cause
|
||||
# PermissionError when the server tries to save generated video files.
|
||||
from vllm_omni.entrypoints.openai.storage import STORAGE_MANAGER
|
||||
|
||||
old_storage_path = STORAGE_MANAGER.storage_path
|
||||
new_storage_path = tmp_path / "omni_storage"
|
||||
new_storage_path.mkdir(exist_ok=True)
|
||||
STORAGE_MANAGER.storage_path = str(new_storage_path)
|
||||
|
||||
parser = TrackingArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
cmd = OmniServeCommand()
|
||||
@@ -555,6 +566,9 @@ def api_server(unused_tcp_port_factory, server_case: ServerCase, mock_async_omni
|
||||
|
||||
yield f"http://127.0.0.1:{port}/v1"
|
||||
|
||||
# Restore the original storage path after the test.
|
||||
STORAGE_MANAGER.storage_path = old_storage_path
|
||||
|
||||
if server_process.is_alive():
|
||||
server_process.terminate()
|
||||
server_process.join(timeout=10)
|
||||
|
||||
@@ -294,7 +294,7 @@ class vLLMOmniHttpServerLocal:
|
||||
"global_steps": self.global_steps,
|
||||
}
|
||||
|
||||
req_output = final_res.request_output
|
||||
req_output = final_res
|
||||
if req_output is not None and hasattr(req_output, "finish_reason"):
|
||||
finish_reason = req_output.finish_reason or "stop"
|
||||
else:
|
||||
|
||||
@@ -53,9 +53,9 @@ def test_audiox_model(omni_runner: OmniRunner) -> None:
|
||||
assert outputs is not None
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "audio"
|
||||
assert hasattr(first_output, "request_output") and first_output.request_output
|
||||
assert isinstance(first_output, OmniRequestOutput) and first_output
|
||||
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
assert isinstance(req_out, OmniRequestOutput)
|
||||
assert req_out.final_output_type == "audio"
|
||||
assert hasattr(req_out, "multimodal_output") and req_out.multimodal_output
|
||||
|
||||
@@ -55,7 +55,7 @@ pytestmark = [
|
||||
def _extract_text(omni_outputs: list) -> str:
|
||||
"""Extract generated text from OmniRequestOutput list."""
|
||||
for req_output in omni_outputs:
|
||||
ro = getattr(req_output, "request_output", None)
|
||||
ro = req_output
|
||||
if ro and getattr(ro, "outputs", None):
|
||||
return "".join(getattr(o, "text", "") or "" for o in ro.outputs)
|
||||
return ""
|
||||
|
||||
@@ -28,7 +28,6 @@ from tests.helpers.media import get_asset_path
|
||||
from tests.helpers.runtime import OmniRunner
|
||||
from tests.helpers.stage_config import get_deploy_config_path
|
||||
from vllm_omni.model_executor.models.cosyvoice3.tokenizer import get_qwen_tokenizer
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
from vllm_omni.transformers_utils.configs.cosyvoice3 import CosyVoice3Config
|
||||
|
||||
MODEL = "FunAudioLLM/Fun-CosyVoice3-0.5B-2512"
|
||||
@@ -176,12 +175,12 @@ def test_cosyvoice3_offline_reference_zero_shot(omni_runner: OmniRunner) -> None
|
||||
assert 2.8 <= duration_s <= 8.8, f"Unexpected duration={duration_s:.3f}s (samples={audio.size}, sr={sr})"
|
||||
|
||||
# Code2wav is ``final_output`` (stage 1); ``Omni.generate`` yields its ``request_output`` / completions.
|
||||
pipeline_out = OmniRequestOutput.unwrap_result(outputs[0])
|
||||
pipeline_out = outputs[0]
|
||||
assert pipeline_out.stage_id == 1, f"expected final stage 1, got {pipeline_out.stage_id}"
|
||||
assert pipeline_out.final_output_type == "audio", (
|
||||
f"expected audio final_output_type, got {pipeline_out.final_output_type!r}"
|
||||
)
|
||||
ro = pipeline_out.request_output
|
||||
ro = pipeline_out
|
||||
assert ro is not None, "stage 1 should include request_output"
|
||||
completions = getattr(ro, "outputs", None) or []
|
||||
assert completions, "stage 1 request_output should include at least one completion"
|
||||
|
||||
@@ -175,7 +175,7 @@ def _find_stage_output(outputs: list[Any], output_type: str) -> Any | None:
|
||||
|
||||
# Prefer the latest finished chunk to avoid picking an intermediate stream output.
|
||||
for stage_output in reversed(matched):
|
||||
if _is_finished_request_output(getattr(stage_output, "request_output", None)):
|
||||
if _is_finished_request_output(stage_output):
|
||||
return stage_output
|
||||
return matched[-1]
|
||||
|
||||
@@ -205,7 +205,7 @@ def _to_token_list(value: Any) -> list[int]:
|
||||
|
||||
|
||||
def _extract_text(stage_output: Any, tokenizer: Any | None = None) -> str:
|
||||
request_output = getattr(stage_output, "request_output", None)
|
||||
request_output = stage_output
|
||||
if request_output is None:
|
||||
return ""
|
||||
req_list = request_output if isinstance(request_output, list) else [request_output]
|
||||
@@ -240,7 +240,7 @@ def _extract_text(stage_output: Any, tokenizer: Any | None = None) -> str:
|
||||
|
||||
|
||||
def _extract_audio(stage_output: Any) -> Any | None:
|
||||
request_output = getattr(stage_output, "request_output", None)
|
||||
request_output = stage_output
|
||||
if request_output is None:
|
||||
return None
|
||||
req_list = request_output if isinstance(request_output, list) else [request_output]
|
||||
@@ -256,7 +256,7 @@ def _extract_audio(stage_output: Any) -> Any | None:
|
||||
|
||||
|
||||
def _extract_image(stage_output: Any) -> Any | None:
|
||||
request_output = getattr(stage_output, "request_output", None)
|
||||
request_output = stage_output
|
||||
if request_output is None:
|
||||
return None
|
||||
req_list = request_output if isinstance(request_output, list) else [request_output]
|
||||
|
||||
@@ -54,7 +54,7 @@ def _sampling_params() -> OmniDiffusionSamplingParams:
|
||||
def _first_request_images(outputs) -> list:
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "image"
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
assert isinstance(req_out, OmniRequestOutput) and hasattr(req_out, "images")
|
||||
return req_out.images
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ def test_glm_image_autoround_w4a16_generates_image(omni_runner_handler: OmniRunn
|
||||
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "image"
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
assert isinstance(req_out, OmniRequestOutput) and hasattr(req_out, "images")
|
||||
images = req_out.images
|
||||
|
||||
@@ -224,7 +224,7 @@ def test_glm_image_autoround_w4a16_image_to_image(omni_runner_handler: OmniRunne
|
||||
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "image"
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
assert isinstance(req_out, OmniRequestOutput) and hasattr(req_out, "images")
|
||||
images = req_out.images
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ def _extract_generated_image(outputs: list[object]) -> Image.Image:
|
||||
if images := getattr(first_output, "images", None):
|
||||
return images[0]
|
||||
|
||||
request_output = getattr(first_output, "request_output", None)
|
||||
request_output = first_output
|
||||
if request_output is not None and (images := getattr(request_output, "images", None)):
|
||||
return images[0]
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ def test_i2t_generates_text(omni: Omni) -> None:
|
||||
outputs = omni.generate(prompts=[prompt_dict])
|
||||
assert outputs, "No outputs returned from Omni.generate()"
|
||||
|
||||
request_output = outputs[0].request_output
|
||||
request_output = outputs[0]
|
||||
assert request_output.outputs, "No completion outputs"
|
||||
|
||||
completion = request_output.outputs[0]
|
||||
|
||||
@@ -172,7 +172,7 @@ def test_mammothmoda2_t2i_e2e(omni_runner: OmniRunner):
|
||||
|
||||
found_image = False
|
||||
for out in outputs:
|
||||
ro_list = getattr(out, "request_output", out)
|
||||
ro_list = out
|
||||
if not isinstance(ro_list, list):
|
||||
ro_list = [ro_list]
|
||||
for ro in ro_list:
|
||||
|
||||
@@ -137,14 +137,11 @@ def _extract_final_audio_outputs(outputs):
|
||||
if getattr(item, "final_output_type", None) == "audio":
|
||||
final_outputs.append(item)
|
||||
continue
|
||||
request_output = getattr(item, "request_output", None)
|
||||
if request_output is None:
|
||||
continue
|
||||
multimodal_output = getattr(request_output, "multimodal_output", None)
|
||||
multimodal_output = getattr(item, "multimodal_output", None)
|
||||
if isinstance(multimodal_output, Mapping):
|
||||
final_outputs.append(item)
|
||||
continue
|
||||
completions = getattr(request_output, "outputs", None) or []
|
||||
completions = getattr(item, "outputs", None) or []
|
||||
if any(isinstance(getattr(completion, "multimodal_output", None), Mapping) for completion in completions):
|
||||
final_outputs.append(item)
|
||||
return final_outputs
|
||||
@@ -155,16 +152,11 @@ def _extract_multimodal_output(output) -> Mapping[str, Any]:
|
||||
if isinstance(multimodal_output, Mapping):
|
||||
return multimodal_output
|
||||
|
||||
request_output = getattr(output, "request_output", None)
|
||||
if request_output is not None:
|
||||
multimodal_output = getattr(request_output, "multimodal_output", None)
|
||||
completions = getattr(output, "outputs", None) or []
|
||||
for completion in completions:
|
||||
multimodal_output = getattr(completion, "multimodal_output", None)
|
||||
if isinstance(multimodal_output, Mapping):
|
||||
return multimodal_output
|
||||
completions = getattr(request_output, "outputs", None) or []
|
||||
for completion in completions:
|
||||
multimodal_output = getattr(completion, "multimodal_output", None)
|
||||
if isinstance(multimodal_output, Mapping):
|
||||
return multimodal_output
|
||||
|
||||
raise AssertionError("No multimodal audio output found in Ming generate results")
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ def _build_request(
|
||||
def _collect_audio(omni: Omni, request: dict) -> tuple[torch.Tensor, int]:
|
||||
"""Run a single request and return (waveform, sample_rate)."""
|
||||
for stage_outputs in omni.generate(request, DEFAULT_SAMPLING):
|
||||
req_output = stage_outputs.request_output
|
||||
req_output = stage_outputs
|
||||
if req_output is not None:
|
||||
mm = req_output.outputs[0].multimodal_output
|
||||
assert mm is not None, "Expected multimodal_output to be non-None"
|
||||
@@ -167,7 +167,7 @@ def test_moss_tts_nano_batch(omni_runner: OmniRunner, ref_audio_path) -> None:
|
||||
results = []
|
||||
# Single-stage model (num_stages=1): one sampling param for all requests.
|
||||
for stage_outputs in omni_runner.omni.generate(requests, [DEFAULT_SAMPLING]):
|
||||
req_output = stage_outputs.request_output
|
||||
req_output = stage_outputs
|
||||
if req_output is not None:
|
||||
mm = req_output.outputs[0].multimodal_output
|
||||
assert mm is not None
|
||||
|
||||
@@ -58,7 +58,7 @@ def test_omnivoice_text_to_audio(omni_runner: OmniRunner) -> None:
|
||||
|
||||
# Check final output has audio
|
||||
final_output = outputs[-1]
|
||||
ro = final_output.request_output
|
||||
ro = final_output
|
||||
assert ro is not None, "No request_output"
|
||||
|
||||
mm = getattr(ro, "multimodal_output", None)
|
||||
|
||||
@@ -42,7 +42,7 @@ def _sampling_params() -> OmniDiffusionSamplingParams:
|
||||
def _first_request_images(outputs) -> list:
|
||||
first_output = outputs[0]
|
||||
assert first_output.final_output_type == "image"
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
assert isinstance(req_out, OmniRequestOutput) and hasattr(req_out, "images")
|
||||
return req_out.images
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@ def generate_stable_audio_short_clip(
|
||||
# Audio-output diffusion pipelines (those with ``support_audio_output = True``) now have
|
||||
# ``final_output_type="audio"`` set on the outer stage metadata as well as the inner request.
|
||||
assert first_output.final_output_type == "audio"
|
||||
assert hasattr(first_output, "request_output") and first_output.request_output
|
||||
assert isinstance(first_output, OmniRequestOutput) and first_output
|
||||
|
||||
req_out = first_output.request_output
|
||||
req_out = first_output
|
||||
assert isinstance(req_out, OmniRequestOutput)
|
||||
assert req_out.final_output_type == "audio"
|
||||
assert hasattr(req_out, "multimodal_output") and req_out.multimodal_output
|
||||
|
||||
@@ -63,8 +63,8 @@ def _assert_non_empty_text_output(outputs: list[OmniRequestOutput]) -> None:
|
||||
|
||||
text_output = next((o for o in outputs if o.final_output_type == "text"), None)
|
||||
assert text_output is not None
|
||||
assert text_output.request_output is not None
|
||||
text_content = text_output.request_output.outputs[0].text
|
||||
assert text_output is not None
|
||||
text_content = text_output.outputs[0].text
|
||||
assert text_content is not None
|
||||
assert len(text_content.strip()) > 0
|
||||
|
||||
@@ -81,8 +81,8 @@ def test_audio_to_text_and_audio(omni_runner: OmniRunner) -> None:
|
||||
|
||||
audio_output = next((o for o in outputs if o.final_output_type == "audio"), None)
|
||||
if audio_output is not None:
|
||||
assert audio_output.request_output is not None
|
||||
audio_tensor = audio_output.request_output.outputs[0].multimodal_output.get("audio")
|
||||
assert audio_output is not None
|
||||
audio_tensor = audio_output.outputs[0].multimodal_output.get("audio")
|
||||
if audio_tensor is not None:
|
||||
assert audio_tensor.numel() > 0
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_realtime_duplex_multi_session_script_is_directly_executable():
|
||||
cwd=MULTI_DEMO_PATH.parents[3],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=20,
|
||||
timeout=60,
|
||||
check=False,
|
||||
)
|
||||
|
||||
@@ -78,7 +78,7 @@ def test_realtime_duplex_demo_pair_script_is_directly_executable():
|
||||
cwd=PAIR_DEMO_PATH.parents[3],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=20,
|
||||
timeout=60,
|
||||
check=False,
|
||||
)
|
||||
|
||||
@@ -91,7 +91,7 @@ def test_realtime_duplex_soft_interrupt_script_is_directly_executable():
|
||||
cwd=SOFT_INTERRUPT_DEMO_PATH.parents[3],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=20,
|
||||
timeout=60,
|
||||
check=False,
|
||||
)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ async def generate(
|
||||
output_modalities=["text"],
|
||||
):
|
||||
stage_id = omni_output.stage_id
|
||||
out = omni_output.request_output
|
||||
out = omni_output
|
||||
if stage_id == 0:
|
||||
num_tokens = sum(len(output.token_ids) for output in out.outputs)
|
||||
count = num_tokens
|
||||
|
||||
@@ -4,171 +4,269 @@
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
from pytest_mock import MockerFixture
|
||||
from vllm.outputs import CompletionOutput, RequestOutput
|
||||
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
class TestOmniRequestOutput:
|
||||
"""Tests for OmniRequestOutput class."""
|
||||
# ── helpers ────────────────────────────────────────────────────────────────
|
||||
|
||||
def test_from_diffusion(self):
|
||||
"""Test creating output from diffusion model."""
|
||||
images = [Image.new("RGB", (64, 64), color="red")]
|
||||
output = OmniRequestOutput.from_diffusion(
|
||||
request_id="test-123",
|
||||
images=images,
|
||||
prompt="a cat",
|
||||
|
||||
def _make_text_request_output(
|
||||
request_id: str = "req-1",
|
||||
text: str = "hello world",
|
||||
token_ids: list[int] | None = None,
|
||||
finished: bool = True,
|
||||
) -> RequestOutput:
|
||||
"""Build a minimal vLLM RequestOutput for testing."""
|
||||
return RequestOutput(
|
||||
request_id=request_id,
|
||||
prompt="test prompt",
|
||||
prompt_token_ids=[1, 2, 3],
|
||||
prompt_logprobs=None,
|
||||
outputs=[
|
||||
CompletionOutput(
|
||||
index=0,
|
||||
text=text,
|
||||
token_ids=token_ids or [10, 11, 12],
|
||||
cumulative_logprob=-1.0,
|
||||
logprobs=None,
|
||||
finish_reason="stop" if finished else None,
|
||||
stop_reason=None,
|
||||
)
|
||||
],
|
||||
finished=finished,
|
||||
metrics=None,
|
||||
lora_request=None,
|
||||
)
|
||||
|
||||
|
||||
# ── from_stage_output ──────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestFromStageOutput:
|
||||
"""Tests for OmniRequestOutput.from_stage_output()."""
|
||||
|
||||
def test_copies_request_output_content(self):
|
||||
"""Content from a vLLM RequestOutput is flattened onto the new object."""
|
||||
source = _make_text_request_output(text="copied text")
|
||||
out = OmniRequestOutput.from_stage_output(source, request_id="req-1", stage_id=0, final_output_type="text")
|
||||
|
||||
assert out.prompt == "test prompt"
|
||||
assert out.prompt_token_ids == [1, 2, 3]
|
||||
assert len(out.outputs) == 1
|
||||
assert out.outputs[0].text == "copied text"
|
||||
assert out.finished is True
|
||||
assert out.stage_id == 0
|
||||
assert out.final_output_type == "text"
|
||||
|
||||
def test_copies_omni_content(self):
|
||||
"""Diffusion fields are copied when source is another OmniRequestOutput."""
|
||||
image = Image.new("RGB", (64, 64), color="blue")
|
||||
inner = OmniRequestOutput.from_diffusion(request_id="req-diff", images=[image], prompt="a cat")
|
||||
outer = OmniRequestOutput.from_stage_output(inner, request_id="req-diff", stage_id=0, final_output_type="image")
|
||||
|
||||
assert len(outer.images) == 1
|
||||
assert outer.images[0] is image
|
||||
assert outer.prompt == "a cat"
|
||||
assert outer.is_diffusion_output
|
||||
|
||||
def test_with_duck_typed_source(self):
|
||||
"""A duck-typed source (SimpleNamespace-style) copies correctly."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
source = SimpleNamespace(
|
||||
outputs=[],
|
||||
prompt="duck prompt",
|
||||
prompt_token_ids=[7, 8, 9],
|
||||
finished=False,
|
||||
)
|
||||
out = OmniRequestOutput.from_stage_output(source, request_id="duck-1", stage_id=2)
|
||||
|
||||
assert out.prompt == "duck prompt"
|
||||
assert out.prompt_token_ids == [7, 8, 9]
|
||||
assert out.finished is False
|
||||
assert out.stage_id == 2
|
||||
|
||||
def test_request_id_always_copied_from_source(self):
|
||||
"""request_id is always copied from source, even when passed in kwargs."""
|
||||
source = _make_text_request_output(request_id="source-id")
|
||||
out = OmniRequestOutput.from_stage_output(source, request_id="kwargs-id", stage_id=1)
|
||||
# Source wins — request_id is content, not a control field.
|
||||
assert out.request_id == "source-id"
|
||||
|
||||
def test_passes_control_fields(self):
|
||||
"""Control fields (metrics, stage_durations, peak_memory_mb) are set."""
|
||||
source = _make_text_request_output()
|
||||
out = OmniRequestOutput.from_stage_output(
|
||||
source,
|
||||
request_id="r1",
|
||||
stage_id=3,
|
||||
metrics={"ttft": 0.5},
|
||||
stage_durations={"prefill": 0.12},
|
||||
peak_memory_mb=1024.0,
|
||||
)
|
||||
|
||||
assert out.metrics == {"ttft": 0.5}
|
||||
assert out.stage_durations == {"prefill": 0.12}
|
||||
assert out.peak_memory_mb == 1024.0
|
||||
|
||||
def test_finished_field_copied(self):
|
||||
"""The *finished* flag is copied from the source when present."""
|
||||
source = _make_text_request_output(finished=False)
|
||||
out = OmniRequestOutput.from_stage_output(source, request_id="r1")
|
||||
assert out.finished is False
|
||||
|
||||
source2 = _make_text_request_output(finished=True)
|
||||
out2 = OmniRequestOutput.from_stage_output(source2, request_id="r2")
|
||||
assert out2.finished is True
|
||||
|
||||
def test_outputs_field_copied(self):
|
||||
"""The *outputs* list is copied from the source."""
|
||||
source = _make_text_request_output(text="hello", token_ids=[1, 2, 3])
|
||||
out = OmniRequestOutput.from_stage_output(source, request_id="r1")
|
||||
|
||||
assert len(out.outputs) == 1
|
||||
assert out.outputs[0].text == "hello"
|
||||
assert out.outputs[0].token_ids == [1, 2, 3]
|
||||
|
||||
|
||||
# ── dataclass safety ────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestDataclassSafety:
|
||||
def test_from_stage_output_is_classmethod(self):
|
||||
"""from_stage_output must be a classmethod."""
|
||||
assert callable(OmniRequestOutput.from_stage_output)
|
||||
|
||||
|
||||
# ── msgpack round-trip ─────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestMsgpackRoundTrip:
|
||||
"""Tests that OmniRequestOutput survives msgpack encode → decode without
|
||||
infinite recursion or data loss."""
|
||||
|
||||
def test_round_trip_pipeline_output(self):
|
||||
"""A pipeline output round-trips without data loss."""
|
||||
from vllm_omni.distributed.omni_connectors.utils.serialization import (
|
||||
OmniMsgpackDecoder,
|
||||
OmniMsgpackEncoder,
|
||||
)
|
||||
|
||||
source = _make_text_request_output(text="round trip")
|
||||
out = OmniRequestOutput.from_stage_output(
|
||||
source,
|
||||
request_id="rt-1",
|
||||
stage_id=0,
|
||||
final_output_type="text",
|
||||
)
|
||||
|
||||
encoder = OmniMsgpackEncoder()
|
||||
decoder = OmniMsgpackDecoder()
|
||||
|
||||
encoded = encoder.encode(out)
|
||||
decoded = decoder.decode(encoded)
|
||||
|
||||
assert isinstance(decoded, OmniRequestOutput)
|
||||
assert decoded.request_id == "req-1"
|
||||
assert decoded.stage_id == 0
|
||||
assert decoded.final_output_type == "text"
|
||||
assert decoded.finished is True
|
||||
assert decoded.outputs[0].text == "round trip"
|
||||
assert decoded.prompt == "test prompt"
|
||||
assert decoded.prompt_token_ids == [1, 2, 3]
|
||||
|
||||
def test_round_trip_diffusion_output(self):
|
||||
"""A diffusion output round-trips without data loss."""
|
||||
from vllm_omni.distributed.omni_connectors.utils.serialization import (
|
||||
OmniMsgpackDecoder,
|
||||
OmniMsgpackEncoder,
|
||||
)
|
||||
|
||||
image = Image.new("RGB", (64, 64), color="red")
|
||||
out = OmniRequestOutput.from_diffusion(
|
||||
request_id="diff-1",
|
||||
images=[image],
|
||||
prompt="a red image",
|
||||
metrics={"steps": 50},
|
||||
)
|
||||
assert output.request_id == "test-123"
|
||||
assert output.images == images
|
||||
assert output.prompt == "a cat"
|
||||
assert output.metrics == {"steps": 50}
|
||||
assert output.is_diffusion_output
|
||||
assert output.num_images == 1
|
||||
|
||||
def test_from_pipeline(self, mocker: MockerFixture):
|
||||
"""Test creating output from pipeline stage."""
|
||||
mock_request_output = mocker.Mock()
|
||||
mock_request_output.request_id = "pipeline-123"
|
||||
mock_request_output.prompt_token_ids = [1, 2, 3]
|
||||
mock_request_output.outputs = [mocker.Mock()]
|
||||
mock_request_output.encoder_prompt_token_ids = None
|
||||
mock_request_output.prompt_logprobs = None
|
||||
mock_request_output.num_cached_tokens = 10
|
||||
mock_request_output.kv_transfer_params = None
|
||||
mock_request_output.multimodal_output = {"image": mocker.Mock()}
|
||||
|
||||
output = OmniRequestOutput.from_pipeline(
|
||||
stage_id=0,
|
||||
final_output_type="text",
|
||||
request_output=mock_request_output,
|
||||
multimodal_output={"audio": None},
|
||||
)
|
||||
|
||||
assert output.request_id == "pipeline-123"
|
||||
assert output.stage_id == 0
|
||||
assert output.final_output_type == "text"
|
||||
assert output.is_pipeline_output
|
||||
encoder = OmniMsgpackEncoder()
|
||||
decoder = OmniMsgpackDecoder()
|
||||
|
||||
def test_prompt_token_ids_property(self, mocker: MockerFixture):
|
||||
"""Test prompt_token_ids property for streaming compatibility."""
|
||||
mock_request_output = mocker.Mock()
|
||||
mock_request_output.prompt_token_ids = [1, 2, 3, 4, 5]
|
||||
encoded = encoder.encode(out)
|
||||
decoded = decoder.decode(encoded)
|
||||
|
||||
output = OmniRequestOutput.from_pipeline(
|
||||
stage_id=0,
|
||||
final_output_type="text",
|
||||
request_output=mock_request_output,
|
||||
assert isinstance(decoded, OmniRequestOutput)
|
||||
assert decoded.request_id == "diff-1"
|
||||
assert decoded.prompt == "a red image"
|
||||
assert decoded.num_images == 1
|
||||
assert decoded.images[0].size == (64, 64)
|
||||
assert decoded.metrics == {"steps": 50}
|
||||
|
||||
def test_round_trip_does_not_recurse(self):
|
||||
"""Encoding a pipeline output must not trigger infinite recursion."""
|
||||
from vllm_omni.distributed.omni_connectors.utils.serialization import (
|
||||
OmniMsgpackEncoder,
|
||||
)
|
||||
|
||||
assert output.prompt_token_ids == [1, 2, 3, 4, 5]
|
||||
source = _make_text_request_output(text="no recursion")
|
||||
out = OmniRequestOutput.from_stage_output(source, request_id="rec-1", stage_id=0)
|
||||
|
||||
def test_prompt_token_ids_none_when_no_request_output(self):
|
||||
"""Test prompt_token_ids returns None when no request_output."""
|
||||
output = OmniRequestOutput.from_diffusion(
|
||||
request_id="test-123",
|
||||
images=[],
|
||||
prompt="a cat",
|
||||
)
|
||||
assert output.prompt_token_ids is None
|
||||
encoder = OmniMsgpackEncoder()
|
||||
encoded = encoder.encode(out)
|
||||
assert isinstance(encoded, bytes)
|
||||
assert len(encoded) > 0
|
||||
|
||||
def test_outputs_property(self, mocker: MockerFixture):
|
||||
"""Test outputs property for chat completion compatibility."""
|
||||
mock_output = mocker.Mock()
|
||||
mock_request_output = mocker.Mock()
|
||||
mock_request_output.outputs = [mock_output]
|
||||
|
||||
output = OmniRequestOutput.from_pipeline(
|
||||
stage_id=0,
|
||||
final_output_type="text",
|
||||
request_output=mock_request_output,
|
||||
def test_legacy_wire_format_deserialized(self):
|
||||
"""When the wire format contains a nested ``request_output`` key
|
||||
(pre-inheritance legacy), it is merged via _copy_content_from."""
|
||||
from vllm_omni.distributed.omni_connectors.utils.serialization import (
|
||||
OmniMsgpackDecoder,
|
||||
)
|
||||
|
||||
assert output.outputs == [mock_output]
|
||||
# Build a legacy-style dict: OmniRequestOutput fields + a nested
|
||||
# request_output dict containing RequestOutput-like content.
|
||||
legacy_dict = {
|
||||
"request_id": "legacy-1",
|
||||
"finished": True,
|
||||
"stage_id": 1,
|
||||
"final_output_type": "text",
|
||||
"images": [],
|
||||
"_multimodal_output": {},
|
||||
"_custom_output": {},
|
||||
"stage_durations": {},
|
||||
"peak_memory_mb": 0.0,
|
||||
# --- nested request_output key (legacy) ---
|
||||
"request_output": {
|
||||
"request_id": "legacy-1",
|
||||
"prompt": "legacy prompt",
|
||||
"prompt_token_ids": [1, 2],
|
||||
"prompt_logprobs": None,
|
||||
"outputs": [],
|
||||
"finished": True,
|
||||
"metrics": {},
|
||||
"lora_request": None,
|
||||
"encoder_prompt": None,
|
||||
"encoder_prompt_token_ids": None,
|
||||
"num_cached_tokens": None,
|
||||
"kv_transfer_params": None,
|
||||
},
|
||||
}
|
||||
|
||||
def test_outputs_empty_when_no_request_output(self):
|
||||
"""Test outputs returns empty list when no request_output."""
|
||||
output = OmniRequestOutput.from_diffusion(
|
||||
request_id="test-123",
|
||||
images=[],
|
||||
prompt="a cat",
|
||||
)
|
||||
assert output.outputs == []
|
||||
# Manually run the decoder's post_process to test legacy path.
|
||||
# The decoder's _decode_omni_request_output pops "request_output"
|
||||
# and merges it via _copy_content_from.
|
||||
decoder = OmniMsgpackDecoder()
|
||||
result = decoder._post_process(legacy_dict)
|
||||
|
||||
def test_encoder_prompt_token_ids_property(self, mocker: MockerFixture):
|
||||
"""Test encoder_prompt_token_ids property."""
|
||||
mock_request_output = mocker.Mock()
|
||||
mock_request_output.encoder_prompt_token_ids = [10, 20, 30]
|
||||
|
||||
output = OmniRequestOutput.from_pipeline(
|
||||
stage_id=0,
|
||||
final_output_type="text",
|
||||
request_output=mock_request_output,
|
||||
)
|
||||
|
||||
assert output.encoder_prompt_token_ids == [10, 20, 30]
|
||||
|
||||
def test_num_cached_tokens_property(self, mocker: MockerFixture):
|
||||
"""Test num_cached_tokens property."""
|
||||
mock_request_output = mocker.Mock()
|
||||
mock_request_output.num_cached_tokens = 42
|
||||
|
||||
output = OmniRequestOutput.from_pipeline(
|
||||
stage_id=0,
|
||||
final_output_type="text",
|
||||
request_output=mock_request_output,
|
||||
)
|
||||
|
||||
assert output.num_cached_tokens == 42
|
||||
|
||||
def test_multimodal_output_property(self, mocker: MockerFixture):
|
||||
"""Test multimodal_output property."""
|
||||
mock_request_output = mocker.Mock()
|
||||
mock_audio = mocker.Mock()
|
||||
expected_output = {"audio": mock_audio}
|
||||
mock_request_output.outputs = []
|
||||
mock_request_output.multimodal_output = expected_output
|
||||
|
||||
output = OmniRequestOutput.from_pipeline(
|
||||
stage_id=0,
|
||||
final_output_type="audio",
|
||||
request_output=mock_request_output,
|
||||
)
|
||||
|
||||
assert output.multimodal_output is expected_output
|
||||
|
||||
def test_to_dict_diffusion(self):
|
||||
"""Test to_dict for diffusion output."""
|
||||
output = OmniRequestOutput.from_diffusion(
|
||||
request_id="test-123",
|
||||
images=[Image.new("RGB", (64, 64), color="red")],
|
||||
prompt="a cat",
|
||||
metrics={"steps": 50},
|
||||
)
|
||||
result = output.to_dict()
|
||||
|
||||
assert result["request_id"] == "test-123"
|
||||
assert result["finished"] is True
|
||||
assert result["final_output_type"] == "image"
|
||||
assert result["num_images"] == 1
|
||||
assert result["prompt"] == "a cat"
|
||||
|
||||
def test_to_dict_pipeline(self, mocker: MockerFixture):
|
||||
"""Test to_dict for pipeline output."""
|
||||
mock_request_output = mocker.Mock()
|
||||
mock_request_output.request_id = "pipeline-123"
|
||||
|
||||
output = OmniRequestOutput.from_pipeline(
|
||||
stage_id=0,
|
||||
final_output_type="text",
|
||||
request_output=mock_request_output,
|
||||
)
|
||||
result = output.to_dict()
|
||||
|
||||
assert result["request_id"] == "pipeline-123"
|
||||
assert result["finished"] is True
|
||||
assert result["final_output_type"] == "text"
|
||||
assert result["stage_id"] == 0
|
||||
assert isinstance(result, OmniRequestOutput)
|
||||
assert result.request_id == "legacy-1"
|
||||
assert result.finished is True
|
||||
# Content merged from legacy nested key
|
||||
assert result.prompt == "legacy prompt"
|
||||
assert result.prompt_token_ids == [1, 2]
|
||||
@@ -2156,12 +2156,12 @@ def test_direct_listen_decision_survives_inner_completion_metadata():
|
||||
)
|
||||
assert decision is not None
|
||||
output = attach_duplex_output_decision(
|
||||
OmniRequestOutput(
|
||||
OmniRequestOutput.from_stage_output(
|
||||
inner_output,
|
||||
request_id="duplex-direct-listen",
|
||||
finished=True,
|
||||
stage_id=0,
|
||||
final_output_type=decision.final_output_type,
|
||||
request_output=inner_output,
|
||||
metrics={
|
||||
"stage_metrics": {
|
||||
"0": {
|
||||
@@ -3049,12 +3049,12 @@ async def test_minicpmo_auto_response_listen_without_response_does_not_defer_com
|
||||
)
|
||||
assert decision is not None
|
||||
listen_output = attach_duplex_output_decision(
|
||||
OmniRequestOutput(
|
||||
OmniRequestOutput.from_stage_output(
|
||||
inner_output,
|
||||
request_id=request_id,
|
||||
finished=True,
|
||||
stage_id=0,
|
||||
final_output_type=decision.final_output_type,
|
||||
request_output=inner_output,
|
||||
),
|
||||
decision,
|
||||
)
|
||||
|
||||
@@ -119,7 +119,6 @@ class MockGenerationResult:
|
||||
|
||||
def __init__(self, images):
|
||||
self.images = images
|
||||
self.request_output = SimpleNamespace(images=images)
|
||||
self.stage_durations = {}
|
||||
self.peak_memory_mb = 0.0
|
||||
|
||||
@@ -137,10 +136,7 @@ class MockStageResult:
|
||||
outputs = [SimpleNamespace(text=text, index=0)]
|
||||
else:
|
||||
outputs = []
|
||||
self.request_output = SimpleNamespace(
|
||||
outputs=outputs,
|
||||
images=self.images,
|
||||
)
|
||||
self.outputs = outputs
|
||||
self.stage_durations = {}
|
||||
self.peak_memory_mb = 0.0
|
||||
|
||||
@@ -2080,22 +2076,20 @@ def test_extract_images_from_result():
|
||||
assert all(isinstance(img, Image.Image) for img in images)
|
||||
assert all(img.size == (64, 64) for img in images)
|
||||
|
||||
# Test dict path: result.request_output["images"]
|
||||
# Test result with "images" attribute set in __init__
|
||||
class DictRequestOutput:
|
||||
def __init__(self):
|
||||
self.request_output = {"images": [np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8)]}
|
||||
self.images = [np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8)]
|
||||
|
||||
result = DictRequestOutput()
|
||||
images = _extract_images_from_result(result)
|
||||
assert len(images) == 1
|
||||
assert isinstance(images[0], Image.Image)
|
||||
|
||||
# Test attribute path: result.request_output.images
|
||||
# Test result with "images" attribute from an inner object
|
||||
class AttrRequestOutput:
|
||||
def __init__(self):
|
||||
self.request_output = type(
|
||||
"obj", (), {"images": [np.random.randint(0, 255, (32, 32, 3), dtype=np.uint8)]}
|
||||
)()
|
||||
self.images = [np.random.randint(0, 255, (32, 32, 3), dtype=np.uint8)]
|
||||
|
||||
result = AttrRequestOutput()
|
||||
images = _extract_images_from_result(result)
|
||||
|
||||
@@ -180,10 +180,10 @@ def create_mock_audio_output_for_test(
|
||||
audio_tensor = torch.sin(torch.linspace(0, 440 * 2 * torch.pi, num_samples))
|
||||
mock_request_output = MockRequestOutput(request_id=request_id, audio_tensor=audio_tensor)
|
||||
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
mock_request_output,
|
||||
stage_id=0,
|
||||
final_output_type="audio",
|
||||
request_output=mock_request_output,
|
||||
)
|
||||
|
||||
|
||||
@@ -2292,10 +2292,10 @@ class TestStreamingResponse:
|
||||
self.prompt_logprobs = None
|
||||
self.kv_transfer_params = None
|
||||
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
MockRequestOutput(audio_tensor=chunk),
|
||||
stage_id=0,
|
||||
final_output_type="audio",
|
||||
request_output=MockRequestOutput(audio_tensor=chunk),
|
||||
finished=finished,
|
||||
)
|
||||
|
||||
@@ -3441,10 +3441,10 @@ class TestWAVStreaming:
|
||||
self.prompt_logprobs = None
|
||||
self.kv_transfer_params = None
|
||||
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
MockRequestOutput(audio_tensor=chunk),
|
||||
stage_id=0,
|
||||
final_output_type="audio",
|
||||
request_output=MockRequestOutput(audio_tensor=chunk),
|
||||
finished=finished,
|
||||
)
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ def _text_result(text: str) -> OmniRequestOutput:
|
||||
output.text = text
|
||||
request_output = RequestOutput()
|
||||
request_output.outputs = [output]
|
||||
return OmniRequestOutput(final_output_type="text", request_output=request_output)
|
||||
return OmniRequestOutput.from_stage_output(request_output, final_output_type="text")
|
||||
|
||||
|
||||
def _audio_result(audio_data: Any) -> OmniRequestOutput:
|
||||
@@ -61,7 +61,7 @@ def _audio_result(audio_data: Any) -> OmniRequestOutput:
|
||||
output.multimodal_output = {"audio": audio_data}
|
||||
request_output = RequestOutput()
|
||||
request_output.outputs = [output]
|
||||
return OmniRequestOutput(final_output_type="audio", request_output=request_output)
|
||||
return OmniRequestOutput.from_stage_output(request_output, final_output_type="audio")
|
||||
|
||||
|
||||
class MockWebSocket:
|
||||
|
||||
@@ -480,11 +480,9 @@ def test_async_omni_duplex_direct_output_prefers_outer_control_metadata():
|
||||
OmniRequestOutput(
|
||||
request_id="duplex-sid-e0-stage0",
|
||||
stage_id=0,
|
||||
request_output=SimpleNamespace(
|
||||
outputs=[],
|
||||
multimodal_output=SimpleNamespace(kind="processed-payload"),
|
||||
_custom_output={"inner": "completion"},
|
||||
),
|
||||
outputs=[],
|
||||
_multimodal_output={"kind": "processed-payload"},
|
||||
_custom_output={"inner": "completion"},
|
||||
),
|
||||
decision,
|
||||
)
|
||||
@@ -557,7 +555,7 @@ async def test_async_omni_duplex_collect_wraps_raw_response_stage_output():
|
||||
assert outputs[0].finished is False
|
||||
assert outputs[0].stage_id == 1
|
||||
assert outputs[0].final_output_type == "audio"
|
||||
assert outputs[0].request_output is raw_stage1_output
|
||||
assert outputs[0].peak_memory_mb == raw_stage1_output.peak_memory_mb
|
||||
|
||||
|
||||
def test_async_omni_duplex_request_info_includes_response_stage():
|
||||
|
||||
@@ -72,8 +72,8 @@ def make_output_msg(
|
||||
final_output_type=final_output_type,
|
||||
images=images or [],
|
||||
stage_durations={},
|
||||
outputs=[SimpleNamespace(text=payload, index=0)],
|
||||
)
|
||||
engine_output.payload = payload
|
||||
return OutputMessage(
|
||||
request_id=request_id,
|
||||
stage_id=stage_id,
|
||||
@@ -474,7 +474,7 @@ async def test_async_omni_yields_only_final_stage_outputs(monkeypatch: pytest.Mo
|
||||
app.shutdown()
|
||||
|
||||
assert [output.stage_id for output in outputs] == [2]
|
||||
assert [output.request_output.payload for output in outputs] == ["final"]
|
||||
assert [output.outputs[0].text for output in outputs] == ["final"]
|
||||
assert "req-1" not in app.request_states
|
||||
|
||||
|
||||
@@ -492,7 +492,7 @@ async def test_async_omni_accepts_multiple_final_stage_streams(monkeypatch: pyte
|
||||
app.shutdown()
|
||||
|
||||
assert [output.stage_id for output in outputs] == [0, 0, 0, 2, 2, 2]
|
||||
assert [output.request_output.payload for output in outputs] == [
|
||||
assert [output.outputs[0].text for output in outputs] == [
|
||||
"req-1-stage0-0",
|
||||
"req-1-stage0-1",
|
||||
"req-1-stage0-2",
|
||||
@@ -517,7 +517,7 @@ async def test_async_omni_stops_on_final_stage_finished(monkeypatch: pytest.Monk
|
||||
finally:
|
||||
app.shutdown()
|
||||
|
||||
assert [output.request_output.payload for output in outputs] == [
|
||||
assert [output.outputs[0].text for output in outputs] == [
|
||||
"req-1-stage0",
|
||||
"req-1-stage2-final",
|
||||
]
|
||||
@@ -544,7 +544,7 @@ async def test_async_omni_diffusion_only_yields_single_image_output(monkeypatch:
|
||||
assert outputs[0].stage_id == 0
|
||||
assert outputs[0].final_output_type == "image"
|
||||
assert outputs[0].images == ["req-1-image"]
|
||||
assert outputs[0].request_output.payload == "req-1-diffusion-final"
|
||||
assert outputs[0].outputs[0].text == "req-1-diffusion-final"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -565,7 +565,7 @@ async def test_async_omni_llm_diffusion_yields_text_stream_then_image(monkeypatc
|
||||
|
||||
assert [output.stage_id for output in outputs] == [0, 0, 0, 1]
|
||||
assert [output.final_output_type for output in outputs] == ["text", "text", "text", "image"]
|
||||
assert [output.request_output.payload for output in outputs] == [
|
||||
assert [output.outputs[0].text for output in outputs] == [
|
||||
"req-1-text-0",
|
||||
"req-1-text-1",
|
||||
"req-1-text-2",
|
||||
@@ -695,7 +695,7 @@ def test_omni_generate_py_generator_yields_final_outputs_for_each_request(monkey
|
||||
|
||||
assert len(outputs) == 4
|
||||
assert [output.stage_id for output in outputs] == [0, 2, 0, 2]
|
||||
assert [output.request_output.payload for output in outputs] == [
|
||||
assert [output.outputs[0].text for output in outputs] == [
|
||||
f"{engine.submitted[0]['request_id']}-stage0-0",
|
||||
f"{engine.submitted[0]['request_id']}-stage2-final",
|
||||
f"{engine.submitted[1]['request_id']}-stage0-0",
|
||||
@@ -739,7 +739,7 @@ def test_omni_generate_diffusion_only_yields_single_image_per_request(monkeypatc
|
||||
assert len(outputs) == 2
|
||||
assert [output.stage_id for output in outputs] == [0, 0]
|
||||
assert [output.final_output_type for output in outputs] == ["image", "image"]
|
||||
assert [output.request_output.payload for output in outputs] == [
|
||||
assert [output.outputs[0].text for output in outputs] == [
|
||||
f"{engine.submitted[0]['request_id']}-diffusion-final",
|
||||
f"{engine.submitted[1]['request_id']}-diffusion-final",
|
||||
]
|
||||
@@ -767,7 +767,7 @@ def test_omni_generate_llm_diffusion_yields_final_text_then_image_per_request(
|
||||
assert len(outputs) == 4
|
||||
assert [output.stage_id for output in outputs] == [0, 1, 0, 1]
|
||||
assert [output.final_output_type for output in outputs] == ["text", "image", "text", "image"]
|
||||
assert [output.request_output.payload for output in outputs] == [
|
||||
assert [output.outputs[0].text for output in outputs] == [
|
||||
f"{engine.submitted[0]['request_id']}-text-0",
|
||||
f"{engine.submitted[0]['request_id']}-image-final",
|
||||
f"{engine.submitted[1]['request_id']}-text-0",
|
||||
@@ -1046,7 +1046,6 @@ def _enqueue_stage_error(
|
||||
if kill_engine:
|
||||
engine._alive = False
|
||||
engine_output = OmniRequestOutput.from_error(msg["request_id"], error_text)
|
||||
engine_output.payload = ""
|
||||
engine.output_q.put_nowait(
|
||||
OutputMessage(
|
||||
request_id=msg["request_id"],
|
||||
|
||||
@@ -69,10 +69,10 @@ def _make_text_omni_output(
|
||||
],
|
||||
finished=finish_reason is not None,
|
||||
)
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
res,
|
||||
request_id=request_id,
|
||||
final_output_type="text",
|
||||
request_output=res,
|
||||
finished=finish_reason is not None,
|
||||
)
|
||||
|
||||
@@ -108,12 +108,12 @@ def _make_audio_omni_output(
|
||||
outputs=[completion],
|
||||
finished=True,
|
||||
)
|
||||
return OmniRequestOutput(
|
||||
return OmniRequestOutput.from_stage_output(
|
||||
res,
|
||||
request_id=request_id,
|
||||
stage_id=stage_id,
|
||||
replica_id=replica_id,
|
||||
final_output_type="audio",
|
||||
request_output=res,
|
||||
finished=True,
|
||||
)
|
||||
|
||||
@@ -151,7 +151,7 @@ def _build_serving_chat():
|
||||
)
|
||||
instance._create_audio_choice = MagicMock(
|
||||
side_effect=lambda omni_res, role, request, stream=False: _mock_audio_choices(
|
||||
index=omni_res.request_output.outputs[0].index,
|
||||
index=omni_res.outputs[0].index,
|
||||
role=role,
|
||||
)
|
||||
)
|
||||
@@ -489,7 +489,7 @@ async def test_audio_chunk_without_waveform_keeps_stream_alive():
|
||||
request = _make_request(modalities=["text", "audio"])
|
||||
|
||||
empty_audio = _make_audio_omni_output()
|
||||
empty_audio.request_output.outputs[0].multimodal_output = {"audio": []}
|
||||
empty_audio.outputs[0].multimodal_output = {"audio": []}
|
||||
|
||||
def create_audio_choice(omni_res, role, request, stream=False):
|
||||
return OmniOpenAIServingChat._create_audio_choice(serving_chat, omni_res, role, request, stream=stream)
|
||||
|
||||
+19
-1
@@ -26,10 +26,28 @@ from PIL import Image
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
_synthetic_media_fallback_dir: Path | None = None
|
||||
|
||||
|
||||
def _resolve_synthetic_media_cache_dir(cache_dir: Path | str | None) -> Path:
|
||||
if cache_dir is not None:
|
||||
return Path(cache_dir).expanduser().resolve()
|
||||
return Path(tempfile.gettempdir()) / "vllm_omni_test_synthetic_media"
|
||||
|
||||
default = Path(tempfile.gettempdir()) / "vllm_omni_test_synthetic_media"
|
||||
try:
|
||||
default.mkdir(parents=True, exist_ok=True)
|
||||
# Verify write access: the directory may exist but belong to
|
||||
# another user (e.g. a previous CI job), causing PermissionError
|
||||
# later when individual files are saved.
|
||||
canary = default / ".write_test"
|
||||
canary.touch()
|
||||
canary.unlink()
|
||||
return default
|
||||
except (PermissionError, OSError):
|
||||
global _synthetic_media_fallback_dir
|
||||
if _synthetic_media_fallback_dir is None:
|
||||
_synthetic_media_fallback_dir = Path(tempfile.mkdtemp(prefix="vllm_omni_test_synthetic_media_"))
|
||||
return _synthetic_media_fallback_dir
|
||||
|
||||
|
||||
def _np_array_from_mp4_bytes(video_bytes: bytes) -> np.ndarray:
|
||||
|
||||
@@ -2938,9 +2938,9 @@ class OmniRunnerHandler:
|
||||
audio_content = None
|
||||
for stage_output in outputs:
|
||||
if getattr(stage_output, "final_output_type", None) == "text":
|
||||
text_content = stage_output.request_output.outputs[0].text
|
||||
text_content = stage_output.outputs[0].text
|
||||
if getattr(stage_output, "final_output_type", None) == "audio":
|
||||
audio_content = stage_output.request_output.outputs[0].multimodal_output["audio"]
|
||||
audio_content = stage_output.outputs[0].multimodal_output["audio"]
|
||||
result.audio_content = audio_content
|
||||
result.text_content = text_content
|
||||
result.success = True
|
||||
@@ -3080,7 +3080,7 @@ class OmniRunnerHandler:
|
||||
mm_out: dict[str, Any] | None = None
|
||||
for stage_out in outputs:
|
||||
if getattr(stage_out, "final_output_type", None) == "audio":
|
||||
mm_out = stage_out.request_output.outputs[0].multimodal_output
|
||||
mm_out = stage_out.outputs[0].multimodal_output
|
||||
break
|
||||
if mm_out is None:
|
||||
raise AssertionError("No audio output from pipeline")
|
||||
|
||||
Reference in new issue
Block a user