[CI][MiniCPM-o] Add MiniCPM-o 4.5 accuracy and performance coverage (#5524)
Signed-off-by: R2-Y <ruiruyang2@gmail.com> Signed-off-by: psv666 <2693925048@qq.com> Co-authored-by: psv666 <2693925048@qq.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: amy-why-3459 <wuhaiyan17@huawei.com>
This commit is contained in:
59 files changed
+1908
-155
No files matched your search
@@ -55,6 +55,16 @@ class SeedTTSSampleRequest(SampleRequest):
|
||||
seed_tts_system_prompt: str = ""
|
||||
#: Local path to reference prompt WAV (for SIM vs. synthesized PCM in ``seed_tts_eval``).
|
||||
seed_tts_ref_wav_path: str = ""
|
||||
#: Ordered text targets evaluated as turns in one Realtime session.
|
||||
seed_tts_turns: tuple[SeedTTSTurn, ...] = ()
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SeedTTSTurn:
|
||||
"""One target utterance within a grouped Realtime Seed-TTS session."""
|
||||
|
||||
utterance_id: str
|
||||
target_text: str
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -216,24 +226,39 @@ class SeedTTSDataset(BenchmarkDataset):
|
||||
) -> list[SampleRequest]:
|
||||
if output_len is None:
|
||||
output_len = self.DEFAULT_OUTPUT_LEN
|
||||
turns_per_session = int(kwargs.pop("turns_per_session", 1))
|
||||
if turns_per_session < 1:
|
||||
raise ValueError("turns_per_session must be at least 1")
|
||||
|
||||
tok = get_cached_tokenizer(tokenizer)
|
||||
out: list[SampleRequest] = []
|
||||
for i, row in enumerate(self._rows):
|
||||
if len(out) >= num_requests:
|
||||
break
|
||||
valid_rows: list[tuple[_SeedTTSRow, Path]] = []
|
||||
for row in self._rows:
|
||||
wav_path = (self._root / self.locale / row.prompt_wav_rel).resolve()
|
||||
if not wav_path.is_file():
|
||||
logger.warning("Missing prompt wav for %s: %s", row.utterance_id, wav_path)
|
||||
continue
|
||||
valid_rows.append((row, wav_path))
|
||||
|
||||
target = row.target_text
|
||||
prompt_len = len(tok.encode(f"{self._system_prompt}\n{target}"))
|
||||
for session_index in range(num_requests):
|
||||
offset = session_index * turns_per_session
|
||||
group = valid_rows[offset : offset + turns_per_session]
|
||||
if len(group) < turns_per_session:
|
||||
break
|
||||
reference_row, reference_wav_path = group[0]
|
||||
turns = tuple(
|
||||
SeedTTSTurn(
|
||||
utterance_id=row.utterance_id,
|
||||
target_text=row.target_text,
|
||||
)
|
||||
for row, _ in group
|
||||
)
|
||||
prompt_len = sum(len(tok.encode(f"{self._system_prompt}\n{turn.target_text}")) for turn in turns)
|
||||
lang = "English" if self.locale == "en" else "Chinese"
|
||||
ref_uri = _ref_audio_payload(wav_path, inline=self.inline_ref_audio)
|
||||
ref_uri = _ref_audio_payload(reference_wav_path, inline=self.inline_ref_audio)
|
||||
speech_extra: dict[str, Any] = {
|
||||
"ref_audio": ref_uri,
|
||||
"ref_text": row.ref_text,
|
||||
"ref_text": reference_row.ref_text,
|
||||
"task_type": "Base",
|
||||
"language": lang,
|
||||
"max_new_tokens": output_len,
|
||||
@@ -241,20 +266,26 @@ class SeedTTSDataset(BenchmarkDataset):
|
||||
|
||||
out.append(
|
||||
SeedTTSSampleRequest(
|
||||
prompt=target,
|
||||
prompt=turns[0].target_text,
|
||||
prompt_len=prompt_len,
|
||||
expected_output_len=output_len,
|
||||
multi_modal_data=None,
|
||||
request_id=f"{request_id_prefix}{i}",
|
||||
request_id=f"{request_id_prefix}{session_index}",
|
||||
seed_tts_speech_extra=speech_extra,
|
||||
seed_tts_utterance_id=row.utterance_id,
|
||||
seed_tts_utterance_id=turns[0].utterance_id,
|
||||
seed_tts_locale=self.locale,
|
||||
seed_tts_system_prompt=self._system_prompt,
|
||||
seed_tts_ref_wav_path=str(wav_path),
|
||||
seed_tts_ref_wav_path=str(reference_wav_path),
|
||||
seed_tts_turns=turns,
|
||||
)
|
||||
)
|
||||
|
||||
logger.info("Seed-TTS: built %d requests (asked %d)", len(out), num_requests)
|
||||
logger.info(
|
||||
"Seed-TTS: built %d sessions (asked %d, turns_per_session=%d)",
|
||||
len(out),
|
||||
num_requests,
|
||||
turns_per_session,
|
||||
)
|
||||
self.maybe_oversample_requests(out, num_requests, request_id_prefix, no_oversample)
|
||||
return out
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ import string
|
||||
import tempfile
|
||||
import threading
|
||||
import wave
|
||||
from copy import copy
|
||||
from dataclasses import replace
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -123,11 +125,25 @@ def _get_eval_device() -> str:
|
||||
return explicit
|
||||
try:
|
||||
import torch
|
||||
|
||||
return "cuda:0" if torch.cuda.is_available() else "cpu"
|
||||
except ImportError:
|
||||
return "cpu"
|
||||
|
||||
if torch.cuda.is_available():
|
||||
return "cuda:0"
|
||||
|
||||
# Ascend: ``torch.npu`` only exists once ``torch_npu`` has been imported, which does
|
||||
# not necessarily happen in the benchmark client process. Without this branch the
|
||||
# eval silently lands on CPU, where Whisper-large-v3 needs hours for a full Seed-TTS
|
||||
# run and the CI job is killed by its timeout instead of reporting a WER.
|
||||
try:
|
||||
import torch_npu # noqa: F401
|
||||
except ImportError:
|
||||
pass
|
||||
if hasattr(torch, "npu") and torch.npu.is_available():
|
||||
return "npu:0"
|
||||
|
||||
return "cpu"
|
||||
|
||||
|
||||
def _punctuation_all() -> str:
|
||||
from zhon.hanzi import punctuation
|
||||
@@ -512,6 +528,42 @@ def _missing_deps_message(lang: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _expand_seed_tts_turn_outputs(
|
||||
input_requests: list[SeedTTSSampleRequest],
|
||||
outputs: list[Any],
|
||||
) -> tuple[list[SeedTTSSampleRequest], list[Any]]:
|
||||
"""Expand grouped Realtime sessions into one request/output pair per turn."""
|
||||
expanded_requests: list[SeedTTSSampleRequest] = []
|
||||
expanded_outputs: list[Any] = []
|
||||
for request, output in zip(input_requests, outputs, strict=True):
|
||||
turns = request.seed_tts_turns
|
||||
if not turns:
|
||||
expanded_requests.append(request)
|
||||
expanded_outputs.append(output)
|
||||
continue
|
||||
turn_pcm = getattr(output, "tts_turn_pcm_bytes", None)
|
||||
session_pcm = getattr(output, "tts_output_pcm_bytes", None)
|
||||
for turn_index, turn in enumerate(turns):
|
||||
expanded_requests.append(
|
||||
replace(
|
||||
request,
|
||||
prompt=turn.target_text,
|
||||
seed_tts_utterance_id=turn.utterance_id,
|
||||
seed_tts_turns=(),
|
||||
)
|
||||
)
|
||||
turn_output = copy(output)
|
||||
if isinstance(turn_pcm, list) and turn_index < len(turn_pcm):
|
||||
turn_output.tts_output_pcm_bytes = turn_pcm[turn_index]
|
||||
elif len(turns) == 1:
|
||||
# openai-chat-omni Seed-TTS only fills the session-level PCM field.
|
||||
turn_output.tts_output_pcm_bytes = session_pcm
|
||||
else:
|
||||
turn_output.tts_output_pcm_bytes = None
|
||||
expanded_outputs.append(turn_output)
|
||||
return expanded_requests, expanded_outputs
|
||||
|
||||
|
||||
def compute_seed_tts_wer_metrics(
|
||||
input_requests: list[SampleRequest],
|
||||
outputs: list[Any],
|
||||
@@ -524,6 +576,8 @@ def compute_seed_tts_wer_metrics(
|
||||
return None
|
||||
if not all(isinstance(r, SeedTTSSampleRequest) for r in input_requests):
|
||||
return None
|
||||
session_count = len(input_requests)
|
||||
input_requests, outputs = _expand_seed_tts_turn_outputs(input_requests, outputs)
|
||||
|
||||
first = input_requests[0]
|
||||
assert isinstance(first, SeedTTSSampleRequest)
|
||||
@@ -759,6 +813,8 @@ def compute_seed_tts_wer_metrics(
|
||||
|
||||
result: dict[str, Any] = {
|
||||
"seed_tts_eval_protocol": "seed-tts-eval",
|
||||
"seed_tts_session_count": session_count,
|
||||
"seed_tts_turn_count": len(input_requests),
|
||||
"seed_tts_content_evaluated": len(errs),
|
||||
"seed_tts_content_error_mean": statistics.fmean(errs) if errs else None,
|
||||
"seed_tts_content_error_median": statistics.median(errs) if errs else None,
|
||||
|
||||
@@ -9,11 +9,13 @@ import ssl
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
import uuid
|
||||
import wave
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Any, Literal
|
||||
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
|
||||
|
||||
import aiohttp
|
||||
import numpy as np
|
||||
@@ -47,6 +49,11 @@ from vllm_omni.benchmarks.data_modules.seed_tts_dataset import (
|
||||
)
|
||||
from vllm_omni.benchmarks.data_modules.sound_effect_dataset import SoundEffectDataset
|
||||
from vllm_omni.benchmarks.data_modules.ttsd_dataset import TTSDDataset
|
||||
from vllm_omni.experimental.fullduplex.client import (
|
||||
RealtimeDuplexClient,
|
||||
summarize_session_request_metrics,
|
||||
wait_for,
|
||||
)
|
||||
from vllm_omni.metrics import definitions as defs
|
||||
from vllm_omni.metrics.utils import coerce_positive_int_scalar
|
||||
|
||||
@@ -188,6 +195,9 @@ def _attach_seed_tts_to_request_func_input(sample: SampleRequest, rfi: RequestFu
|
||||
# Mark for PCM capture (WER / UTMOS eval) regardless of extra body presence.
|
||||
setattr(rfi, "seed_tts_row", True)
|
||||
sys_prompt = (sample.seed_tts_system_prompt or "").strip() or SEED_TTS_DEFAULT_OMNI_SYSTEM_PROMPT
|
||||
setattr(rfi, "seed_tts_system_prompt", sys_prompt)
|
||||
setattr(rfi, "seed_tts_speech_extra", sample.seed_tts_speech_extra)
|
||||
setattr(rfi, "seed_tts_turns", sample.seed_tts_turns)
|
||||
setattr(
|
||||
rfi,
|
||||
"omni_chat_messages",
|
||||
@@ -235,7 +245,12 @@ def get_samples(args, tokenizer):
|
||||
)
|
||||
|
||||
# Check if we need to handle omni-related backends/datasets
|
||||
is_omni_backend = args.backend in ["openai-chat-omni", "openai-audio-speech", "daily-omni"]
|
||||
is_omni_backend = args.backend in [
|
||||
"openai-chat-omni",
|
||||
"openai-audio-speech",
|
||||
"openai-realtime-duplex",
|
||||
"daily-omni",
|
||||
]
|
||||
is_omni_dataset = is_daily_omni or is_seed_tts or args.dataset_name == "random-mm"
|
||||
|
||||
if not is_omni_backend and not is_omni_dataset:
|
||||
@@ -334,10 +349,17 @@ def get_samples(args, tokenizer):
|
||||
return input_requests
|
||||
|
||||
if is_seed_tts:
|
||||
if args.backend not in ("openai-audio-speech", "openai-chat-omni"):
|
||||
if args.backend not in (
|
||||
"openai-audio-speech",
|
||||
"openai-chat-omni",
|
||||
"openai-realtime-duplex",
|
||||
"openai-realtime-tts",
|
||||
):
|
||||
raise ValueError(
|
||||
"Seed-TTS requires --backend openai-audio-speech (POST /v1/audio/speech) or "
|
||||
"--backend openai-chat-omni (POST /v1/chat/completions with ref_audio/ref_text). "
|
||||
"--backend openai-chat-omni (POST /v1/chat/completions with ref_audio/ref_text), or "
|
||||
"--backend openai-realtime-duplex or openai-realtime-tts "
|
||||
"(WebSocket /v1/realtime). "
|
||||
f"Got backend={args.backend!r}."
|
||||
)
|
||||
repo_id = getattr(args, "dataset_path", None) or getattr(args, "hf_name", None)
|
||||
@@ -346,6 +368,14 @@ def get_samples(args, tokenizer):
|
||||
"Seed-TTS requires --dataset-path (HF dataset repo id or local directory) or "
|
||||
"--hf-name for the Hub dataset id."
|
||||
)
|
||||
turns_per_session = int(getattr(args, "seed_tts_turns_per_session", 1))
|
||||
if turns_per_session > 1 and args.backend not in {
|
||||
"openai-realtime-duplex",
|
||||
"openai-realtime-tts",
|
||||
}:
|
||||
raise ValueError(
|
||||
f"--seed-tts-turns-per-session > 1 requires a Realtime Seed-TTS backend. Got backend={args.backend!r}."
|
||||
)
|
||||
|
||||
_cls_map = {
|
||||
"seed-tts": SeedTTSDataset,
|
||||
@@ -375,6 +405,7 @@ def get_samples(args, tokenizer):
|
||||
output_len=out_len,
|
||||
request_id_prefix=args.request_id_prefix,
|
||||
no_oversample=args.no_oversample,
|
||||
turns_per_session=turns_per_session,
|
||||
)
|
||||
|
||||
# Handle random-mm dataset (Omni's synthetic multimodal dataset)
|
||||
@@ -430,10 +461,14 @@ class MixRequestFuncOutput(RequestFuncOutput):
|
||||
#: Raw PCM s16le mono at 24 kHz for Seed-TTS WER: from ``/v1/audio/speech`` stream or
|
||||
#: resampled export after ``openai-chat-omni`` audio deltas.
|
||||
tts_output_pcm_bytes: bytes | None = None
|
||||
#: Per-turn 24 kHz mono PCM for grouped Realtime Seed-TTS WER.
|
||||
tts_turn_pcm_bytes: list[bytes] | None = None
|
||||
#: Per-stage snapshot from orchestrator ``metrics["stage_metrics"]`` (merged across SSE chunks).
|
||||
stage_metrics: dict[str, dict] | None = None
|
||||
stage_id: int | None = None
|
||||
final_output_type: str | None = None
|
||||
duplex_request_metrics: list[dict[str, object]] | None = None
|
||||
duplex_session_metrics: dict[str, object] | None = None
|
||||
|
||||
|
||||
_IMAGE_EDITS_EXTRA_BODY_FORM_FIELDS = (
|
||||
@@ -1249,6 +1284,180 @@ async def async_request_openai_audio_speech(
|
||||
return output
|
||||
|
||||
|
||||
def _realtime_websocket_url(api_url: str) -> str:
|
||||
parts = urlsplit(api_url)
|
||||
scheme = "wss" if parts.scheme == "https" else "ws"
|
||||
query = dict(parse_qsl(parts.query, keep_blank_values=True))
|
||||
query.setdefault("duplex", "1")
|
||||
return urlunsplit((scheme, parts.netloc, parts.path, urlencode(query), parts.fragment))
|
||||
|
||||
|
||||
async def async_request_openai_realtime_duplex(
|
||||
request_func_input: RequestFuncInput,
|
||||
session: aiohttp.ClientSession,
|
||||
pbar: tqdm | None = None,
|
||||
) -> MixRequestFuncOutput:
|
||||
"""Run one or more Seed-TTS turns through one explicit Realtime TTS session."""
|
||||
del session
|
||||
output = MixRequestFuncOutput()
|
||||
output.prompt_len = request_func_input.prompt_len
|
||||
output.start_time = time.perf_counter()
|
||||
speech_extra = getattr(request_func_input, "seed_tts_speech_extra", None)
|
||||
if not isinstance(speech_extra, dict):
|
||||
speech_extra = {}
|
||||
configured_turns = getattr(request_func_input, "seed_tts_turns", ())
|
||||
turn_prompts = [
|
||||
(
|
||||
str(getattr(turn, "utterance_id", "") or ""),
|
||||
str(getattr(turn, "target_text", "") or ""),
|
||||
)
|
||||
for turn in configured_turns
|
||||
if str(getattr(turn, "target_text", "") or "").strip()
|
||||
]
|
||||
if not turn_prompts:
|
||||
turn_prompts = [("", request_func_input.prompt)]
|
||||
session_id = f"seed-tts-{request_func_input.request_id or uuid.uuid4().hex}"
|
||||
try:
|
||||
async with RealtimeDuplexClient(_realtime_websocket_url(request_func_input.api_url)) as client:
|
||||
await client.configure(
|
||||
request_func_input.model_name or request_func_input.model,
|
||||
output_audio_format="pcm16",
|
||||
instructions=getattr(
|
||||
request_func_input,
|
||||
"seed_tts_system_prompt",
|
||||
SEED_TTS_DEFAULT_OMNI_SYSTEM_PROMPT,
|
||||
),
|
||||
native_duplex=False,
|
||||
auto_response=False,
|
||||
extra_body=speech_extra,
|
||||
session_id=session_id,
|
||||
timeout_s=120.0,
|
||||
)
|
||||
turn_metrics: list[dict[str, object]] = []
|
||||
turn_timings: list[dict[str, object]] = []
|
||||
turn_pcm_bytes: list[bytes] = []
|
||||
turn_transcripts: list[str] = []
|
||||
measurement_origin = {
|
||||
"ttft": "conversation.item.create client send to first non-empty text delta",
|
||||
"ttfp": "conversation.item.create client send to first audio packet",
|
||||
"rtf": "request-start-to-last-audio receive time divided by emitted audio duration",
|
||||
}
|
||||
for request_index, (utterance_id, target_text) in enumerate(turn_prompts):
|
||||
response_offset = len(client.events.response_ids)
|
||||
done_before = client.events.count("response.done")
|
||||
errors_before = len(client.events.errors())
|
||||
turn_started_at_s = time.monotonic()
|
||||
await client.send(
|
||||
{
|
||||
"type": "conversation.item.create",
|
||||
"item": {
|
||||
"type": "message",
|
||||
"role": "user",
|
||||
"content": [{"type": "input_text", "text": target_text}],
|
||||
},
|
||||
}
|
||||
)
|
||||
await client.send({"type": "response.create"})
|
||||
await wait_for(
|
||||
lambda: client.events.count("response.done") > done_before
|
||||
or len(client.events.errors()) > errors_before,
|
||||
timeout_s=180.0,
|
||||
label=f"Seed-TTS Realtime TTS turn {request_index} response.done",
|
||||
)
|
||||
errors = client.events.errors()
|
||||
if len(errors) > errors_before:
|
||||
raise RuntimeError(f"Seed-TTS Realtime TTS server error: {errors[-1]}")
|
||||
new_audio_response_ids = [
|
||||
response_id
|
||||
for response_id in client.events.response_ids[response_offset:]
|
||||
if client.events.audio_bytes(response_id)
|
||||
]
|
||||
if len(new_audio_response_ids) != 1:
|
||||
raise RuntimeError(
|
||||
f"Seed-TTS Realtime TTS turn {request_index} expected one audio response, "
|
||||
f"got {len(new_audio_response_ids)}"
|
||||
)
|
||||
response_id = new_audio_response_ids[0]
|
||||
timing = client.events.timing_summary(
|
||||
after_s=turn_started_at_s,
|
||||
input_committed_at_s=turn_started_at_s,
|
||||
response_id=response_id,
|
||||
measurement_origin=measurement_origin,
|
||||
)
|
||||
request_metrics = timing.get("request_metrics")
|
||||
if not isinstance(request_metrics, dict):
|
||||
raise RuntimeError(f"Seed-TTS duplex audio turn {response_id} omitted per-request metrics")
|
||||
turn_timings.append(timing)
|
||||
turn_metrics.append(
|
||||
{
|
||||
"session_id": session_id,
|
||||
"request_index": request_index,
|
||||
"utterance_id": utterance_id or None,
|
||||
"response_id": response_id,
|
||||
**request_metrics,
|
||||
}
|
||||
)
|
||||
response_audio = client.events.audio_bytes(response_id)
|
||||
turn_pcm_bytes.append(
|
||||
_pcm_s16le_to_seed_tts_wer_bytes(
|
||||
response_audio,
|
||||
sample_rate=client.events.output_sample_rate_hz,
|
||||
channels=1,
|
||||
)
|
||||
)
|
||||
turn_transcripts.append(
|
||||
"".join(
|
||||
str(event.get("delta") or "")
|
||||
for event in client.events.events
|
||||
if client.events.response_id(event) == response_id
|
||||
and event.get("type")
|
||||
in {
|
||||
"response.audio_transcript.delta",
|
||||
"response.output_text.delta",
|
||||
"response.text.delta",
|
||||
}
|
||||
)
|
||||
)
|
||||
await client.acknowledge_playback()
|
||||
request_finished_at = time.perf_counter()
|
||||
session_metrics = summarize_session_request_metrics(
|
||||
turn_metrics,
|
||||
session_id=session_id,
|
||||
)
|
||||
await client.close_session(timeout_s=30.0)
|
||||
|
||||
output.generated_text = " ".join(filter(None, turn_transcripts))
|
||||
output.ttft = float(session_metrics.get("mean_ttft_ms") or 0.0) / 1000.0
|
||||
output.audio_ttfp = float(session_metrics.get("mean_ttfp_ms") or 0.0) / 1000.0
|
||||
output.audio_rtf = float(session_metrics.get("mean_rtf") or 0.0)
|
||||
output.audio_duration = (
|
||||
sum(float(metric.get("audio_duration_ms") or 0.0) for metric in turn_metrics) / 1000.0
|
||||
)
|
||||
output.audio_frames = int(output.audio_duration * client.events.output_sample_rate_hz)
|
||||
output.latency = request_finished_at - output.start_time
|
||||
output.tts_turn_pcm_bytes = turn_pcm_bytes
|
||||
output.tts_output_pcm_bytes = b"".join(turn_pcm_bytes)
|
||||
if bool((request_func_input.extra_body or {}).get("save_duplex_request_metrics")):
|
||||
output.duplex_request_metrics = turn_metrics
|
||||
output.duplex_session_metrics = session_metrics
|
||||
output.output_tokens = sum(
|
||||
int(stage0.get("output_token_count") or 0)
|
||||
for timing in turn_timings
|
||||
if isinstance((stage0 := timing.get("stage0_tokens")), dict)
|
||||
)
|
||||
output.success = True
|
||||
except Exception:
|
||||
output.success = False
|
||||
output.error = traceback.format_exc()
|
||||
logger.error(
|
||||
"Seed-TTS Realtime TTS request failed: %s",
|
||||
output.error,
|
||||
)
|
||||
if pbar:
|
||||
pbar.update(1)
|
||||
return output
|
||||
|
||||
|
||||
ASYNC_REQUEST_FUNCS["openai-chat-omni"] = async_request_openai_chat_omni_completions
|
||||
if "openai-chat-omni" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("openai-chat-omni")
|
||||
@@ -1257,6 +1466,13 @@ ASYNC_REQUEST_FUNCS["openai-audio-speech"] = async_request_openai_audio_speech
|
||||
if "openai-audio-speech" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("openai-audio-speech")
|
||||
|
||||
ASYNC_REQUEST_FUNCS["openai-realtime-duplex"] = async_request_openai_realtime_duplex
|
||||
if "openai-realtime-duplex" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("openai-realtime-duplex")
|
||||
ASYNC_REQUEST_FUNCS["openai-realtime-tts"] = async_request_openai_realtime_duplex
|
||||
if "openai-realtime-tts" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("openai-realtime-tts")
|
||||
|
||||
ASYNC_REQUEST_FUNCS["openai-image-edits-omni"] = async_request_openai_image_edits_omni
|
||||
if "openai-image-edits-omni" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("openai-image-edits-omni")
|
||||
@@ -1603,6 +1819,14 @@ async def benchmark(
|
||||
"input_lens": [output.prompt_len for output in outputs],
|
||||
"errors": [output.error for output in outputs],
|
||||
}
|
||||
duplex_request_metrics = [metric for output in outputs for metric in (output.duplex_request_metrics or [])]
|
||||
if duplex_request_metrics:
|
||||
result["duplex_request_metrics"] = duplex_request_metrics
|
||||
duplex_session_metrics = [
|
||||
output.duplex_session_metrics for output in outputs if output.duplex_session_metrics is not None
|
||||
]
|
||||
if duplex_session_metrics:
|
||||
result["duplex_session_metrics"] = duplex_session_metrics
|
||||
|
||||
from vllm_omni.benchmarks.data_modules.daily_omni_eval import (
|
||||
compute_daily_omni_accuracy_metrics,
|
||||
|
||||
@@ -94,6 +94,8 @@ class _ModelEngineOverrides(TypedDict, total=False):
|
||||
moe_backend: str
|
||||
hf_overrides: Any
|
||||
limit_mm_per_prompt: dict[str, Any]
|
||||
interleave_mm_strings: bool
|
||||
media_io_kwargs: dict[str, Any]
|
||||
active_stream_window: int
|
||||
enable_sleep_mode: bool
|
||||
subtalker_sampling_params: dict[str, Any]
|
||||
@@ -322,6 +324,9 @@ class OmniStageModelConfig:
|
||||
moe_backend: str = "auto"
|
||||
hf_overrides: Any = None
|
||||
limit_mm_per_prompt: dict[str, Any] | None = None
|
||||
# MiniCPM interleaved AV packing and media decode knobs (Daily-Omni).
|
||||
interleave_mm_strings: bool | None = None
|
||||
media_io_kwargs: dict[str, Any] | None = None
|
||||
active_stream_window: int = Field(default=0, ge=0)
|
||||
duplex_max_sessions: int = Field(default=1, ge=1)
|
||||
enable_sleep_mode: bool = False
|
||||
|
||||
@@ -23,11 +23,19 @@ connectors:
|
||||
stages:
|
||||
- stage_id: 0
|
||||
max_num_seqs: 4
|
||||
# Leave headroom on the shared GPU for Talker KV + concurrent Code2Wav.
|
||||
gpu_memory_utilization: 0.55
|
||||
enforce_eager: false
|
||||
tensor_parallel_size: 1
|
||||
max_num_batched_tokens: 16384
|
||||
devices: "0"
|
||||
# Required for MiniCPM interleaved image/audio Daily-Omni packs (~78% recipe).
|
||||
# Keep these in YAML so they survive both --deploy-config and --stage-configs-path.
|
||||
interleave_mm_strings: true
|
||||
media_io_kwargs:
|
||||
video:
|
||||
fps: 1
|
||||
num_frames: 128
|
||||
limit_mm_per_prompt:
|
||||
# Daily-Omni MiniCPM pack: up to 64 interleaved image/audio pairs (1fps).
|
||||
image: 64
|
||||
@@ -49,6 +57,8 @@ stages:
|
||||
gpu_memory_utilization: 0.15
|
||||
enforce_eager: false
|
||||
max_num_batched_tokens: 8192
|
||||
# Talker context is 4096 (tts_config.max_position_embeddings).
|
||||
max_model_len: 4096
|
||||
devices: "0"
|
||||
output_connectors:
|
||||
to_stage_2: connector_of_shared_memory
|
||||
@@ -66,7 +76,7 @@ stages:
|
||||
|
||||
- stage_id: 2
|
||||
max_num_seqs: 4
|
||||
gpu_memory_utilization: 0.15
|
||||
gpu_memory_utilization: 0.18
|
||||
enforce_eager: true
|
||||
enable_chunked_prefill: false
|
||||
max_num_batched_tokens: 65536
|
||||
|
||||
@@ -31,6 +31,11 @@ stages:
|
||||
tensor_parallel_size: 1
|
||||
max_num_batched_tokens: 16384
|
||||
devices: "0"
|
||||
interleave_mm_strings: true
|
||||
media_io_kwargs:
|
||||
video:
|
||||
fps: 1
|
||||
num_frames: 128
|
||||
limit_mm_per_prompt:
|
||||
video: 1
|
||||
default_sampling_params:
|
||||
|
||||
@@ -43,6 +43,11 @@ stages:
|
||||
max_model_len: 4096
|
||||
max_num_batched_tokens: 4096
|
||||
devices: "0,1,2,3"
|
||||
interleave_mm_strings: true
|
||||
media_io_kwargs:
|
||||
video:
|
||||
fps: 1
|
||||
num_frames: 128
|
||||
limit_mm_per_prompt:
|
||||
video: 1
|
||||
default_sampling_params:
|
||||
|
||||
@@ -27,6 +27,8 @@ stages:
|
||||
- stage_id: 1
|
||||
max_num_seqs: 2
|
||||
async_scheduling: false
|
||||
# Talker context is 4096 (tts_config.max_position_embeddings).
|
||||
max_model_len: 4096
|
||||
# The split Talker exposes a binary continue/stop vocabulary; native
|
||||
# segment and turn boundaries travel as explicit output metadata.
|
||||
default_sampling_params:
|
||||
|
||||
@@ -69,6 +69,7 @@ from vllm_omni.engine.stage_runtime import (
|
||||
)
|
||||
from vllm_omni.entrypoints.pd_utils import PDDisaggregationMixin
|
||||
from vllm_omni.entrypoints.utils import (
|
||||
is_new_format_deploy_config,
|
||||
load_and_resolve_stage_configs,
|
||||
parse_stage_overrides,
|
||||
)
|
||||
@@ -1193,7 +1194,12 @@ class AsyncOmniEngine:
|
||||
"Ignoring it and resolving stages from stage_configs_path/model factory."
|
||||
)
|
||||
|
||||
if stage_configs_path is not None:
|
||||
# Legacy ``stage_args`` YAMLs own per-stage EngineArgs completely, so
|
||||
# strip parent CLI fields. New-format deploy YAMLs (also accepted via
|
||||
# ``--stage-configs-path``) merge CLI overrides the same way as
|
||||
# ``--deploy-config`` — do not strip, or flags like
|
||||
# ``interleave_mm_strings`` / ``media_io_kwargs`` are silently dropped.
|
||||
if stage_configs_path is not None and not is_new_format_deploy_config(stage_configs_path):
|
||||
base_kwargs = self._strip_single_engine_args(kwargs)
|
||||
else:
|
||||
base_kwargs = kwargs
|
||||
|
||||
@@ -132,6 +132,13 @@ def add_seed_tts_cli_args(parser: argparse.ArgumentParser) -> None:
|
||||
default="en",
|
||||
help="Which Seed-TTS split to load: en/meta.lst or zh/meta.lst under the dataset root.",
|
||||
)
|
||||
group.add_argument(
|
||||
"--seed-tts-turns-per-session",
|
||||
type=int,
|
||||
default=1,
|
||||
help="Group this many Seed-TTS target texts into one Realtime session. "
|
||||
"The first row's reference audio and transcript are reused for every turn.",
|
||||
)
|
||||
group.add_argument(
|
||||
"--seed-tts-root",
|
||||
type=str,
|
||||
|
||||
@@ -30,6 +30,15 @@ PROJECT_ROOT = Path(__file__).parent.parent.parent
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def is_new_format_deploy_config(path: str | None) -> bool:
|
||||
"""Return True when *path* is a deploy YAML (``stages:`` without legacy ``stage_args:``)."""
|
||||
if not path or not os.path.exists(path):
|
||||
return False
|
||||
with open(path, encoding="utf-8") as f:
|
||||
peek = yaml.safe_load(f) or {}
|
||||
return isinstance(peek, dict) and "stages" in peek and "stage_args" not in peek
|
||||
|
||||
|
||||
_DIFFUSERS_CLASS_TO_CONFIG: dict[str, str] = {
|
||||
"GlmImagePipeline": "glm_image",
|
||||
}
|
||||
@@ -642,9 +651,7 @@ def load_and_resolve_stage_configs(
|
||||
"Legacy `stage_configs/` yamls were replaced by `vllm_omni/deploy/<model>.yaml`; "
|
||||
"use --deploy-config. See docs/configuration/stage_configs.md."
|
||||
)
|
||||
with open(stage_configs_path, encoding="utf-8") as f:
|
||||
_peek = yaml.safe_load(f) or {}
|
||||
if "stages" in _peek and "stage_args" not in _peek:
|
||||
if is_new_format_deploy_config(stage_configs_path):
|
||||
deploy_config_path = stage_configs_path
|
||||
stage_configs_path = None
|
||||
else:
|
||||
|
||||
@@ -14,6 +14,8 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
|
||||
|
||||
from vllm_omni.metrics.definitions import compute_audio_rtf
|
||||
|
||||
try:
|
||||
import websockets
|
||||
from websockets.exceptions import ConnectionClosed
|
||||
@@ -46,6 +48,30 @@ def _interval_summary(values: list[float]) -> dict[str, float | int]:
|
||||
}
|
||||
|
||||
|
||||
def summarize_session_request_metrics(
|
||||
request_metrics: list[dict[str, object]],
|
||||
*,
|
||||
session_id: str | None,
|
||||
) -> dict[str, object]:
|
||||
"""Average client-observed metrics across turns that emitted audio."""
|
||||
|
||||
def mean(metric: str, *, digits: int = 3) -> float | None:
|
||||
values = [
|
||||
float(request[metric])
|
||||
for request in request_metrics
|
||||
if isinstance(request.get(metric), int | float) and math.isfinite(float(request[metric]))
|
||||
]
|
||||
return round(sum(values) / len(values), digits) if values else None
|
||||
|
||||
return {
|
||||
"session_id": session_id,
|
||||
"audio_turn_count": len(request_metrics),
|
||||
"mean_ttft_ms": mean("ttft_ms"),
|
||||
"mean_ttfp_ms": mean("ttfp_ms"),
|
||||
"mean_rtf": mean("rtf", digits=6),
|
||||
}
|
||||
|
||||
|
||||
def _event_stage_metrics(event: dict[str, object]) -> dict[str, object] | None:
|
||||
candidates: list[object] = [event.get("vllm_omni")]
|
||||
metadata = event.get("metadata")
|
||||
@@ -205,10 +231,12 @@ class RealtimeEventCollector:
|
||||
after_s: float,
|
||||
input_committed_at_s: float | None = None,
|
||||
response_id: str | None = None,
|
||||
measurement_origin: dict[str, str] | None = None,
|
||||
) -> dict[str, object]:
|
||||
"""Summarize engine token metrics and client-observed audio cadence."""
|
||||
stage0_metrics: dict[str, object] | None = None
|
||||
response_created_at_s: float | None = None
|
||||
first_text_received_at_s: float | None = None
|
||||
audio_received_at_s: list[float] = []
|
||||
cumulative_audio_ms: list[float] = []
|
||||
for event, received_at_s in zip(self.events, self.event_received_at_s, strict=True):
|
||||
@@ -219,6 +247,18 @@ class RealtimeEventCollector:
|
||||
continue
|
||||
if event.get("type") == "response.created" and response_created_at_s is None:
|
||||
response_created_at_s = received_at_s
|
||||
if (
|
||||
event.get("type")
|
||||
in {
|
||||
"response.audio_transcript.delta",
|
||||
"response.output_text.delta",
|
||||
"response.text.delta",
|
||||
}
|
||||
and isinstance(event.get("delta"), str)
|
||||
and bool(event["delta"])
|
||||
and first_text_received_at_s is None
|
||||
):
|
||||
first_text_received_at_s = received_at_s
|
||||
|
||||
stage_metrics = _event_stage_metrics(event)
|
||||
stage0 = stage_metrics.get("0") if isinstance(stage_metrics, dict) else None
|
||||
@@ -283,6 +323,45 @@ class RealtimeEventCollector:
|
||||
"chunk_duration_ms": _interval_summary(chunk_durations_ms),
|
||||
"max_chunk_gap_ms": interval_summary["max"],
|
||||
}
|
||||
request_started_at_s = input_committed_at_s if input_committed_at_s is not None else response_created_at_s
|
||||
if request_started_at_s is not None:
|
||||
audio_duration_ms = (
|
||||
max(cumulative_audio_ms)
|
||||
if cumulative_audio_ms
|
||||
else len(self.audio_bytes(response_id))
|
||||
* 1000.0
|
||||
/ (self.output_sample_rate_hz * PCM16_BYTES_PER_SAMPLE)
|
||||
)
|
||||
audio_generation_ms = max(
|
||||
0.0,
|
||||
(audio_received_at_s[-1] - request_started_at_s) * 1000.0,
|
||||
)
|
||||
result["request_metrics"] = {
|
||||
"source": "client_monotonic_receive",
|
||||
"measurement_origin": measurement_origin
|
||||
or {
|
||||
"ttft": "input_audio_buffer.commit client send to first non-empty text delta",
|
||||
"ttfp": "input_audio_buffer.commit client send to first audio packet",
|
||||
"rtf": "commit-to-last-audio receive time divided by emitted audio duration",
|
||||
},
|
||||
"ttft_ms": (
|
||||
_rounded_ms((first_text_received_at_s - request_started_at_s) * 1000.0)
|
||||
if first_text_received_at_s is not None
|
||||
else None
|
||||
),
|
||||
"ttfp_ms": _rounded_ms((audio_received_at_s[0] - request_started_at_s) * 1000.0),
|
||||
"rtf": round(
|
||||
compute_audio_rtf(
|
||||
audio_generation_ms / 1000.0,
|
||||
audio_duration_ms / 1000.0,
|
||||
),
|
||||
6,
|
||||
)
|
||||
if audio_duration_ms > 0
|
||||
else None,
|
||||
"audio_generation_ms": _rounded_ms(audio_generation_ms),
|
||||
"audio_duration_ms": _rounded_ms(audio_duration_ms),
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
@@ -332,9 +411,26 @@ class RealtimeDuplexClient:
|
||||
*,
|
||||
output_audio_format: str = "pcm16",
|
||||
ref_audio: str | None = None,
|
||||
instructions: str | None = None,
|
||||
initial_user_text: str | None = None,
|
||||
native_duplex: bool = True,
|
||||
auto_response: bool = True,
|
||||
temperature: float | None = None,
|
||||
extra_body: dict[str, object] | None = None,
|
||||
session_id: str | None = None,
|
||||
timeout_s: float = 20.0,
|
||||
) -> None:
|
||||
session_extra_body = dict(extra_body or {})
|
||||
if native_duplex:
|
||||
session_extra_body.update(
|
||||
{
|
||||
"auto_response": auto_response,
|
||||
"minicpmo45_native_duplex": True,
|
||||
"force_listen_count": 0,
|
||||
}
|
||||
)
|
||||
else:
|
||||
session_extra_body["minicpmo45_native_duplex"] = False
|
||||
session: dict[str, object] = {
|
||||
"model": model,
|
||||
"modalities": ["audio", "text"],
|
||||
@@ -343,14 +439,18 @@ class RealtimeDuplexClient:
|
||||
"turn_detection": None,
|
||||
"overlap_policy": "listen_only",
|
||||
"playback_commit_policy": "ack_only",
|
||||
"extra_body": {
|
||||
"auto_response": True,
|
||||
"minicpmo45_native_duplex": True,
|
||||
"force_listen_count": 0,
|
||||
},
|
||||
"extra_body": session_extra_body,
|
||||
}
|
||||
if temperature is not None:
|
||||
session["temperature"] = float(temperature)
|
||||
if ref_audio is not None:
|
||||
session["ref_audio"] = ref_audio
|
||||
if instructions is not None:
|
||||
session["instructions"] = instructions
|
||||
if initial_user_text is not None:
|
||||
extra_body = session["extra_body"]
|
||||
assert isinstance(extra_body, dict)
|
||||
extra_body["duplex_initial_user_text"] = initial_user_text
|
||||
if session_id:
|
||||
session["session_id"] = session_id
|
||||
await self.send({"type": "session.update", "session": session})
|
||||
|
||||
@@ -37,6 +37,7 @@ class MiniCPMO45NativeDuplexServingAdapter:
|
||||
"ref_audio_data",
|
||||
"ref_audio_format",
|
||||
"ref_audio_sample_rate_hz",
|
||||
"initial_user_text",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -90,6 +91,9 @@ class MiniCPMO45NativeDuplexServingAdapter:
|
||||
raise ValueError("ref_audio_path is not accepted by native duplex; use ref_audio URI instead")
|
||||
cls.validate_client_config(config)
|
||||
runtime_config: dict[str, object] = {"instructions": config.instructions}
|
||||
initial_user_text = extra_body.pop("duplex_initial_user_text", None)
|
||||
if isinstance(initial_user_text, str) and initial_user_text:
|
||||
runtime_config["initial_user_text"] = initial_user_text
|
||||
cls._apply_default_scheduler_policy(runtime_config, config=config, model_config=model_config)
|
||||
|
||||
ref_audio = config.ref_audio
|
||||
@@ -108,6 +112,7 @@ class MiniCPMO45NativeDuplexServingAdapter:
|
||||
runtime_config,
|
||||
model_config=model_config,
|
||||
instructions=config.instructions,
|
||||
initial_user_text=initial_user_text,
|
||||
ref_sample_count=None,
|
||||
)
|
||||
config.extra_body = extra_body
|
||||
@@ -130,6 +135,7 @@ class MiniCPMO45NativeDuplexServingAdapter:
|
||||
runtime_config,
|
||||
model_config=model_config,
|
||||
instructions=config.instructions,
|
||||
initial_user_text=initial_user_text,
|
||||
ref_sample_count=len(wav_np),
|
||||
)
|
||||
config.extra_body = extra_body
|
||||
@@ -167,6 +173,7 @@ class MiniCPMO45NativeDuplexServingAdapter:
|
||||
*,
|
||||
model_config: Any,
|
||||
instructions: object,
|
||||
initial_user_text: object,
|
||||
ref_sample_count: int | None,
|
||||
) -> None:
|
||||
"""Precompute the exact session-context token count for the engine.
|
||||
@@ -186,6 +193,7 @@ class MiniCPMO45NativeDuplexServingAdapter:
|
||||
prefix, suffix = MiniCPMO45DuplexPolicy.session_context_texts(
|
||||
instructions,
|
||||
ref_sample_count is not None,
|
||||
initial_user_text,
|
||||
)
|
||||
try:
|
||||
prefix_ids = tokenizer.encode(prefix, add_special_tokens=False)
|
||||
|
||||
@@ -43,7 +43,11 @@ class MiniCPMO45DuplexPolicy:
|
||||
return max(0, int(sample_count) // cls.SAMPLES_PER_AUDIO_TOKEN)
|
||||
|
||||
@staticmethod
|
||||
def session_context_texts(instructions: object, has_ref_audio: bool) -> tuple[str, str]:
|
||||
def session_context_texts(
|
||||
instructions: object,
|
||||
has_ref_audio: bool,
|
||||
initial_user_text: object = None,
|
||||
) -> tuple[str, str]:
|
||||
"""System-context prefix/suffix, matching MiniCPMODuplex.prepare()."""
|
||||
system_prompt = (
|
||||
instructions if isinstance(instructions, str) and instructions else "Streaming Omni Conversation."
|
||||
@@ -53,6 +57,8 @@ class MiniCPMO45DuplexPolicy:
|
||||
if has_ref_audio:
|
||||
prefix += "\n<|audio_start|>"
|
||||
suffix = "<|audio_end|>" + suffix
|
||||
if isinstance(initial_user_text, str) and initial_user_text:
|
||||
suffix += f"\n<|im_start|>user\n{initial_user_text}<|im_end|>\n<|im_start|>assistant\n"
|
||||
return prefix, suffix
|
||||
|
||||
SPECIAL_TOKEN_FIELDS: dict[str, str] = {
|
||||
|
||||
@@ -128,6 +128,7 @@ class MiniCPMO45Stage0DuplexRuntime:
|
||||
prefix, suffix = MiniCPMO45DuplexPolicy.session_context_texts(
|
||||
session_config.get("instructions"),
|
||||
ref_audio is not None,
|
||||
(runtime_config or {}).get("initial_user_text"),
|
||||
)
|
||||
for token_id in self._encode_text(prefix):
|
||||
state.context_embeds.append(self._embed_token(token_id))
|
||||
|
||||
@@ -89,6 +89,7 @@ class ChatFallbackProjectorMixin:
|
||||
if response_config.max_tokens is not None:
|
||||
kwargs["max_tokens"] = response_config.max_tokens
|
||||
model_extra = dict(response_config.extra_body)
|
||||
model_extra.pop("minicpmo45_native_duplex", None)
|
||||
tools = model_extra.pop("realtime_response_tools", model_extra.pop("realtime_tools", None))
|
||||
tool_choice = model_extra.pop(
|
||||
"realtime_response_tool_choice",
|
||||
|
||||
@@ -1172,6 +1172,7 @@ class OmniDuplexSessionHandler(
|
||||
return (
|
||||
session.capabilities.implementation_level == "model_native_duplex"
|
||||
and session.capabilities.supports_input_append
|
||||
and session.config.extra_body.get("minicpmo45_native_duplex") is not False
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in new issue
Block a user