[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
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user