[perf] Minicpm o4.5 optimization (#5228)
Signed-off-by: R2-Y <ruiruyang2@gmail.com> Co-authored-by: Sy03 <1370724210@qq.com>
This commit is contained in:
1 parent
acf941da4d
commit
ad3a162eb8
54 files changed
+3861
-3997
No files matched your search
@@ -99,19 +99,21 @@ def test_update_omni_help_updates_upstream_actions() -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("extra_body", "bot_task", "expected"),
|
||||
("backend", "extra_body", "bot_task", "expected"),
|
||||
[
|
||||
(None, "think", {"bot_task": "think"}),
|
||||
({"bot_task": "recaption"}, "think", {"bot_task": "recaption"}),
|
||||
({"custom": True}, None, {"custom": True}),
|
||||
("openai-chat-omni", None, "think", {}),
|
||||
("openai-image-edits-omni", None, "think", {"bot_task": "think"}),
|
||||
("openai-image-edits-omni", {"bot_task": "recaption"}, "think", {"bot_task": "recaption"}),
|
||||
("openai-image-edits-omni", {"custom": True}, None, {"custom": True}),
|
||||
],
|
||||
)
|
||||
def test_preprocess_serve_args_merges_bot_task_without_overriding_extra_body(
|
||||
backend: str,
|
||||
extra_body: dict | None,
|
||||
bot_task: str | None,
|
||||
expected: dict,
|
||||
) -> None:
|
||||
args = argparse.Namespace(extra_body=extra_body, bot_task=bot_task)
|
||||
args = argparse.Namespace(backend=backend, extra_body=extra_body, bot_task=bot_task)
|
||||
|
||||
preprocess_serve_args(args)
|
||||
|
||||
@@ -122,9 +124,15 @@ def test_preprocess_serve_args_merges_bot_task_without_overriding_extra_body(
|
||||
("argv", "expected_extra_body", "expected_explicit"),
|
||||
[
|
||||
(
|
||||
["--print-stage", "--image-edits-bot-task", "recaption"],
|
||||
[
|
||||
"--backend",
|
||||
"openai-image-edits-omni",
|
||||
"--print-stage",
|
||||
"--image-edits-bot-task",
|
||||
"recaption",
|
||||
],
|
||||
{"bot_task": "recaption"},
|
||||
{"print_stage", "bot_task"},
|
||||
{"backend", "print_stage", "bot_task"},
|
||||
),
|
||||
(
|
||||
["--extra-body", '{"bot_task":"vanilla"}'],
|
||||
@@ -140,6 +148,7 @@ def test_omni_args_parse_and_preprocess(
|
||||
) -> None:
|
||||
parser = TrackingArgumentParser()
|
||||
parser.add_argument("--extra-body", type=json.loads, default=None)
|
||||
parser.add_argument("--backend", default="openai-chat-omni")
|
||||
add_omni_args(parser)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
@@ -26,6 +26,7 @@ def _make_scheduler(*, stage_id: int = 0) -> OmniARScheduler:
|
||||
sched.num_waiting_for_streaming_input = 0
|
||||
sched.log_stats = False
|
||||
sched.chunk_transfer_adapter = None
|
||||
sched.skipped_waiting = set()
|
||||
return sched
|
||||
|
||||
|
||||
@@ -90,3 +91,24 @@ def test_stage0_streaming_update_keeps_all_computed_tokens_without_placeholder()
|
||||
assert session._output_token_ids == []
|
||||
assert session.num_prompt_tokens == 8
|
||||
assert sched._new_prompt_len_snapshot[session.request_id] == 2
|
||||
|
||||
|
||||
def test_explicit_streaming_payload_replaces_placeholder_prompt() -> None:
|
||||
sched = _make_scheduler(stage_id=1)
|
||||
sched.chunk_transfer_adapter = SimpleNamespace(
|
||||
receives_chunks=False,
|
||||
segment_finished_requests=set(),
|
||||
)
|
||||
session = _make_request()
|
||||
session.status = RequestStatus.WAITING_FOR_STREAMING_REQ
|
||||
update = _make_update([10, 20])
|
||||
update.additional_information = {
|
||||
"tts_token_ids": [10, 20],
|
||||
"meta": {"replace_streaming_prompt": True},
|
||||
}
|
||||
|
||||
sched._update_request_as_session(session, update)
|
||||
|
||||
assert session.prompt_token_ids == [10, 20]
|
||||
assert session.additional_information == update.additional_information
|
||||
assert session.status == RequestStatus.WAITING
|
||||
@@ -8,6 +8,7 @@ from vllm_omni.distributed.omni_connectors.adapter import try_recv_via_connector
|
||||
from vllm_omni.distributed.omni_connectors.connectors.shm_connector import SharedMemoryConnector
|
||||
from vllm_omni.distributed.omni_connectors.utils.config import ConnectorSpec, OmniTransferConfig
|
||||
from vllm_omni.distributed.omni_connectors.utils.initialization import get_connectors_config_for_stage
|
||||
from vllm_omni.engine.stage_init_utils import get_stage_connector_spec
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
@@ -217,6 +218,22 @@ def test_get_connectors_for_stage():
|
||||
assert stage_2_config["from_stage_1"]["spec"]["name"] == "C2"
|
||||
|
||||
|
||||
def test_outgoing_only_async_stage_uses_sender_connector_spec():
|
||||
config = OmniTransferConfig(
|
||||
connectors={
|
||||
("1", "2"): ConnectorSpec(
|
||||
name="SharedMemoryConnector",
|
||||
extra={"codec_chunk_frames": 25},
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
spec = get_stage_connector_spec(config, stage_id=1, async_chunk=True)
|
||||
|
||||
assert spec["name"] == "SharedMemoryConnector"
|
||||
assert spec["extra"] == {"codec_chunk_frames": 25, "role": "sender"}
|
||||
|
||||
|
||||
def test_recv_with_missing_metadata(mocker: MockerFixture):
|
||||
"""Test recv when queue payload is malformed (missing metadata)."""
|
||||
# Connector expects metadata but task doesn't have it
|
||||
|
||||
@@ -13,6 +13,7 @@ from vllm.v1.core.sched.scheduler import Scheduler as VLLMScheduler
|
||||
from vllm.v1.request import RequestStatus
|
||||
|
||||
from vllm_omni.data_entry_keys import CodesStruct, MetaStruct, OmniPayload, OmniPayloadStruct
|
||||
from vllm_omni.distributed.omni_connectors.adapter import construct_next_stage_streaming_input_prompt
|
||||
from vllm_omni.distributed.omni_connectors.transfer_adapter.base import OmniTransferAdapterBase
|
||||
from vllm_omni.distributed.omni_connectors.transfer_adapter.chunk_transfer_adapter import (
|
||||
OmniChunkTransferAdapter,
|
||||
@@ -43,6 +44,33 @@ def _req(req_id: str, status: RequestStatus, external_req_id: str | None = None)
|
||||
)
|
||||
|
||||
|
||||
def test_streaming_payload_can_replace_placeholder_prompt(mocker: MockerFixture) -> None:
|
||||
request = SimpleNamespace(
|
||||
_all_token_ids=[0, 0, 7, 8],
|
||||
_output_token_ids=[7, 8],
|
||||
prompt_token_ids=[0, 0],
|
||||
num_computed_tokens=4,
|
||||
num_prompt_tokens=2,
|
||||
update_block_hashes=mocker.Mock(),
|
||||
)
|
||||
payload = {
|
||||
"ids": {"prompt": [1, 2, 3]},
|
||||
"meta": {
|
||||
"replace_streaming_prompt": True,
|
||||
"next_stage_prompt_len": 7,
|
||||
},
|
||||
}
|
||||
|
||||
construct_next_stage_streaming_input_prompt(payload, request)
|
||||
|
||||
assert request.prompt_token_ids == [0] * 7
|
||||
assert request._all_token_ids == [0] * 7
|
||||
assert request._output_token_ids == []
|
||||
assert request.num_computed_tokens == 0
|
||||
assert request.num_prompt_tokens == 7
|
||||
request.update_block_hashes.assert_called_once_with()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def build_adapter(monkeypatch, mocker: MockerFixture):
|
||||
def _build(
|
||||
@@ -81,6 +109,10 @@ def build_adapter(monkeypatch, mocker: MockerFixture):
|
||||
worker_type=model_mode,
|
||||
max_num_seqs=max_num_seqs,
|
||||
active_stream_window=active_stream_window,
|
||||
stage_connector_config={
|
||||
"name": "SharedMemoryConnector",
|
||||
"extra": connector_extra or {},
|
||||
},
|
||||
)
|
||||
scheduler_config = SimpleNamespace(max_num_seqs=max_num_seqs)
|
||||
adapter = OmniChunkTransferAdapter(
|
||||
@@ -381,6 +413,26 @@ def test_load_poll_ar_request_additional_information_concats_tensors(build_adapt
|
||||
assert request.additional_information["meta"]["finished"].item() is True
|
||||
|
||||
|
||||
def test_sender_only_adapter_does_not_park_or_clear_requests(build_adapter):
|
||||
adapter, _ = build_adapter(stage_id=1, connector_extra={"role": "sender"})
|
||||
request = _req("req-1", RequestStatus.WAITING)
|
||||
request.additional_information = {"tts_token_ids": torch.tensor([1])}
|
||||
waiting_queue = DummyWaitingQueue([request])
|
||||
running_queue = []
|
||||
|
||||
adapter.load_async(request)
|
||||
adapter.process_pending_chunks(
|
||||
waiting_queue,
|
||||
running_queue,
|
||||
scheduler_requests={request.request_id: request},
|
||||
)
|
||||
|
||||
assert waiting_queue == [request]
|
||||
assert request.status == RequestStatus.WAITING
|
||||
assert request.additional_information["tts_token_ids"].item() == 1
|
||||
assert adapter._pending_load_reqs == deque()
|
||||
|
||||
|
||||
def test_process_and_restore_queues(build_adapter):
|
||||
adapter, _ = build_adapter(stage_id=1, max_num_seqs=8)
|
||||
waiting_req = _req("w1", RequestStatus.WAITING)
|
||||
|
||||
@@ -2,10 +2,15 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
# Use the new import path for initialization utilities
|
||||
from vllm_omni.distributed.omni_connectors.utils.config import (
|
||||
stage_receives_chunks,
|
||||
stage_sends_async_output,
|
||||
)
|
||||
from vllm_omni.distributed.omni_connectors.utils.initialization import load_omni_transfer_config
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
@@ -38,6 +43,26 @@ def get_config_files():
|
||||
config_files = get_config_files()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("role", "stage_id", "receives", "sends"),
|
||||
[
|
||||
("sender", 0, False, True),
|
||||
("receiver", 1, True, False),
|
||||
(None, 0, True, False),
|
||||
(None, None, True, True),
|
||||
],
|
||||
)
|
||||
def test_stage_chunk_direction_helpers(role, stage_id, receives, sends):
|
||||
extra = {} if role is None else {"role": role}
|
||||
model_config = SimpleNamespace(
|
||||
stage_id=stage_id,
|
||||
stage_connector_config={"extra": extra},
|
||||
)
|
||||
|
||||
assert stage_receives_chunks(model_config) is receives
|
||||
assert stage_sends_async_output(model_config) is sends
|
||||
|
||||
|
||||
@pytest.mark.skipif(len(config_files) == 0, reason="No config files found or directory missing")
|
||||
@pytest.mark.parametrize("yaml_file", config_files, ids=lambda p: p.name)
|
||||
def test_load_qwen_yaml_configs(yaml_file):
|
||||
|
||||
@@ -6,6 +6,7 @@ from __future__ import annotations
|
||||
import queue
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import janus
|
||||
import pytest
|
||||
@@ -91,6 +92,25 @@ class FakeInputProcessor:
|
||||
)
|
||||
|
||||
|
||||
class FakePrewarmPool:
|
||||
stage_type = "llm"
|
||||
|
||||
def __init__(self, role: str) -> None:
|
||||
self.stage_vllm_config = SimpleNamespace(
|
||||
model_config=SimpleNamespace(
|
||||
max_model_len=64,
|
||||
stage_connector_config={"extra": {"role": role}},
|
||||
)
|
||||
)
|
||||
self.submitted: list[Any] = []
|
||||
|
||||
async def submit_initial(self, _request_id, _req_state, request, prompt_text=None):
|
||||
self.submitted.append(request)
|
||||
|
||||
def get_bound_replica_id(self, _request_id):
|
||||
return 0
|
||||
|
||||
|
||||
def _request_output(request_id: str) -> RequestOutput:
|
||||
completion = CompletionOutput(
|
||||
index=0,
|
||||
@@ -168,3 +188,56 @@ async def test_forward_text_prompt_uses_target_stage_input_processor() -> None:
|
||||
submitted_request = stage1.add_request_calls[0][0]
|
||||
assert submitted_request.prompt_token_ids == [101, 102]
|
||||
assert submitted_request.external_req_id == "req-text"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_prewarm_skips_outgoing_only_stage() -> None:
|
||||
orchestrator = object.__new__(Orchestrator)
|
||||
stage0 = FakePrewarmPool("sender")
|
||||
stage1 = FakePrewarmPool("sender")
|
||||
stage2 = FakePrewarmPool("receiver")
|
||||
orchestrator.stage_pools = [stage0, stage1, stage2]
|
||||
orchestrator._emit_tx_edge = lambda **_kwargs: None
|
||||
req_state = OrchestratorRequestState(
|
||||
request_id="req-prewarm",
|
||||
prompt={"prompt_token_ids": [1, 2]},
|
||||
sampling_params_list=[SamplingParams(max_tokens=1) for _ in range(3)],
|
||||
final_stage_id=2,
|
||||
)
|
||||
|
||||
await orchestrator._prewarm_async_chunk_stages(
|
||||
"req-prewarm",
|
||||
SimpleNamespace(prompt_token_ids=[1, 2], resumable=True),
|
||||
req_state,
|
||||
)
|
||||
|
||||
assert stage1.submitted == []
|
||||
assert len(stage2.submitted) == 1
|
||||
assert 1 not in req_state.stage_submit_ts
|
||||
assert 2 in req_state.stage_submit_ts
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_route_forwards_to_outgoing_only_stage() -> None:
|
||||
orchestrator = object.__new__(Orchestrator)
|
||||
orchestrator.async_chunk = True
|
||||
orchestrator._pd_pair = None
|
||||
orchestrator._cfg_tracker = SimpleNamespace(
|
||||
is_companion=lambda _request_id: False,
|
||||
has_companions=lambda _request_id: False,
|
||||
)
|
||||
stage0 = SimpleNamespace(final_output=False)
|
||||
stage1 = FakePrewarmPool("sender")
|
||||
orchestrator.stage_pools = [stage0, stage1]
|
||||
orchestrator._forward_to_next_stage = AsyncMock()
|
||||
req_state = OrchestratorRequestState(
|
||||
request_id="req-route",
|
||||
sampling_params_list=[SamplingParams(max_tokens=1) for _ in range(2)],
|
||||
final_stage_id=1,
|
||||
)
|
||||
req_state.stage_submit_ts[0] = 1.0
|
||||
output = SimpleNamespace(request_id="req-route", finished=True)
|
||||
|
||||
await orchestrator._route_output(0, 0, output, req_state, None)
|
||||
|
||||
orchestrator._forward_to_next_stage.assert_awaited_once()
|
||||
@@ -0,0 +1,28 @@
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from vllm.v1.engine.core import EngineCoreProc
|
||||
|
||||
from vllm_omni.engine.stage_engine_core_proc import StageEngineCoreProc
|
||||
|
||||
|
||||
def test_preprocess_add_request_preserves_omni_fields():
|
||||
engine = StageEngineCoreProc.__new__(StageEngineCoreProc)
|
||||
request = SimpleNamespace(
|
||||
request_id="internal",
|
||||
external_req_id="external",
|
||||
additional_information={"conditioning": "payload"},
|
||||
)
|
||||
scheduler_request = SimpleNamespace()
|
||||
|
||||
with patch.object(
|
||||
EngineCoreProc,
|
||||
"preprocess_add_request",
|
||||
return_value=(scheduler_request, 3),
|
||||
):
|
||||
result, current_wave = engine.preprocess_add_request(request)
|
||||
|
||||
assert result is scheduler_request
|
||||
assert current_wave == 3
|
||||
assert result.external_req_id == "external"
|
||||
assert result.additional_information == {"conditioning": "payload"}
|
||||
@@ -0,0 +1,29 @@
|
||||
import base64
|
||||
import io
|
||||
import runpy
|
||||
import wave
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def test_append_wav_chunk_extracts_pcm_frames() -> None:
|
||||
example = Path(__file__).parents[3] / "examples" / "online_serving" / "minicpmo" / "streaming_chat_completion.py"
|
||||
append_wav_chunk = runpy.run_path(example)["append_wav_chunk"]
|
||||
encoded_buffer = io.BytesIO()
|
||||
with wave.open(encoded_buffer, "wb") as wav:
|
||||
wav.setnchannels(1)
|
||||
wav.setsampwidth(2)
|
||||
wav.setframerate(24000)
|
||||
wav.writeframes(b"\x01\x02\x03\x04")
|
||||
|
||||
pcm_parts: list[bytes] = []
|
||||
audio_format = append_wav_chunk(
|
||||
base64.b64encode(encoded_buffer.getvalue()).decode(),
|
||||
pcm_parts,
|
||||
)
|
||||
|
||||
assert audio_format == (1, 2, 24000)
|
||||
assert pcm_parts == [b"\x01\x02\x03\x04"]
|
||||
@@ -0,0 +1,431 @@
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.batched_token2wav import (
|
||||
BatchedToken2Wav,
|
||||
)
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_code2wav import (
|
||||
MiniCPMO45Code2Wav,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
class _FakeEncoder(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.calls: list[int] = []
|
||||
|
||||
def forward_chunk(self, xs, last_chunk=False, cnn_cache=None, att_cache=None):
|
||||
batch, length, _ = xs.shape
|
||||
self.calls.append(batch)
|
||||
old_length = 0 if att_cache is None else att_cache.shape[3]
|
||||
output = xs[:, : max(1, length - 1)]
|
||||
cnn = xs[:, :1, :].transpose(1, 2).contiguous()
|
||||
marker = xs[:, 0, 0].reshape(1, batch, 1, 1, 1)
|
||||
att = marker.expand(1, batch, 1, old_length + output.shape[1], 1).clone()
|
||||
return output, cnn, att
|
||||
|
||||
|
||||
class _FakeBlock:
|
||||
def __init__(self):
|
||||
conv1 = SimpleNamespace(causal_padding=(1, 0))
|
||||
self.conv = SimpleNamespace(
|
||||
in_channels=1,
|
||||
out_channels=1,
|
||||
block=[None, conv1],
|
||||
)
|
||||
self.attn = SimpleNamespace(num_heads=1, head_dim=1)
|
||||
|
||||
|
||||
class _FakeEstimator(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.blocks = [_FakeBlock()]
|
||||
self.cfg_batches: list[int] = []
|
||||
self.speaker_order: list[list[float]] = []
|
||||
|
||||
def t_embedder(self, time):
|
||||
return time[:, None]
|
||||
|
||||
def blocks_forward_chunk(
|
||||
self,
|
||||
inputs,
|
||||
time,
|
||||
mask,
|
||||
cnn_cache,
|
||||
att_cache,
|
||||
cnn_out,
|
||||
att_out,
|
||||
):
|
||||
del time, mask, cnn_cache, att_cache
|
||||
self.cfg_batches.append(inputs.shape[0])
|
||||
self.speaker_order.append(inputs[:, 2, 0].tolist())
|
||||
marker = inputs[:, 1, 0]
|
||||
cnn_out.copy_(marker.reshape(1, -1, 1, 1).expand_as(cnn_out))
|
||||
att_out.copy_(marker.reshape(1, -1, 1, 1, 1).expand_as(att_out))
|
||||
return inputs[:, 1:2]
|
||||
|
||||
|
||||
class _FakeDecoder(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.estimator = _FakeEstimator()
|
||||
self.inference_cfg_rate = 0.7
|
||||
self.register_buffer("rand_noise", torch.zeros(1, 1, 100), persistent=False)
|
||||
|
||||
|
||||
class _FakeFlow(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.encoder = _FakeEncoder()
|
||||
self.encoder_proj = nn.Identity()
|
||||
self.decoder = _FakeDecoder()
|
||||
self.spk_embed_affine_layer = nn.Identity()
|
||||
|
||||
def input_embedding(self, tokens):
|
||||
return tokens.to(torch.float32).unsqueeze(-1)
|
||||
|
||||
|
||||
class _FakeHiFT(nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.calls: list[int] = []
|
||||
|
||||
def forward(self, mel, source):
|
||||
del source
|
||||
self.calls.append(mel.shape[0])
|
||||
speech = mel[:, 0].repeat_interleave(3, dim=1)
|
||||
generated_source = speech[:, None]
|
||||
return speech, generated_source
|
||||
|
||||
|
||||
class _FakeToken2Wav:
|
||||
def __init__(self):
|
||||
self.flow = _FakeFlow()
|
||||
self.hift = _FakeHiFT()
|
||||
self.float16 = False
|
||||
self.n_timesteps = 2
|
||||
self.mel_cache_len = 1
|
||||
self.source_cache_len = 2
|
||||
self.speech_window = torch.hamming_window(4, periodic=False)
|
||||
self.prompt_calls = 0
|
||||
|
||||
def _prepare_prompt(self, prompt_wav):
|
||||
del prompt_wav
|
||||
self.prompt_calls += 1
|
||||
return (
|
||||
torch.tensor([[5, 6]], dtype=torch.long),
|
||||
torch.tensor([2], dtype=torch.int32),
|
||||
torch.ones(1, 1),
|
||||
torch.ones(1, 4, 1),
|
||||
torch.tensor([4], dtype=torch.int32),
|
||||
)
|
||||
|
||||
def stream(self, *args, **kwargs):
|
||||
raise AssertionError("sequential stream fallback must never be called")
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
raise AssertionError("sequential __call__ fallback must never be called")
|
||||
|
||||
|
||||
def _config(minimum: int = 1):
|
||||
return SimpleNamespace(
|
||||
model_config=SimpleNamespace(
|
||||
model="/fake/model",
|
||||
stage_connector_config={
|
||||
"extra": {
|
||||
"code2wav_min_batch_size": minimum,
|
||||
"prompt_cache_id": "shared",
|
||||
"prompt_wav": "/fake/prompt.wav",
|
||||
}
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _model():
|
||||
token2wav = _FakeToken2Wav()
|
||||
backend = BatchedToken2Wav(token2wav)
|
||||
model = MiniCPMO45Code2Wav(vllm_config=_config())
|
||||
model.backend = backend
|
||||
return model, token2wav
|
||||
|
||||
|
||||
def _info(
|
||||
request_id: str,
|
||||
chunk_seq: int,
|
||||
codes: list[int],
|
||||
*,
|
||||
last_chunk: bool = False,
|
||||
cache_epoch: int = 0,
|
||||
):
|
||||
return {
|
||||
"codes": {"audio": torch.tensor(codes, dtype=torch.long)},
|
||||
"meta": {
|
||||
"request_id": request_id,
|
||||
"chunk_seq": chunk_seq,
|
||||
"cache_epoch": cache_epoch,
|
||||
"last_chunk": last_chunk,
|
||||
"prompt_cache_id": "shared",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _forward(model, infos, placeholder_counts=None, request_ids=None):
|
||||
placeholder_counts = placeholder_counts or [1] * len(infos)
|
||||
input_ids = torch.zeros(sum(placeholder_counts), dtype=torch.long)
|
||||
return model(
|
||||
input_ids=input_ids,
|
||||
seq_token_counts=placeholder_counts,
|
||||
runtime_additional_information=infos,
|
||||
request_ids=request_ids,
|
||||
)
|
||||
|
||||
|
||||
def test_adapter_runs_true_batch_cfg_and_splits_request_caches():
|
||||
token2wav = _FakeToken2Wav()
|
||||
adapter = BatchedToken2Wav(token2wav)
|
||||
prompt = adapter.prepare_prompt("shared", "/fake/prompt.wav")
|
||||
states = adapter.setup_batch(prompt, 2)
|
||||
audios, states = adapter.decode_batch(
|
||||
torch.tensor([[10, 11], [20, 21]]),
|
||||
prompt,
|
||||
states,
|
||||
last_chunk=False,
|
||||
)
|
||||
|
||||
assert token2wav.prompt_calls == 1
|
||||
assert token2wav.flow.encoder.calls == [2, 2]
|
||||
assert token2wav.flow.decoder.estimator.cfg_batches == [4, 4, 4, 4]
|
||||
assert all(order == [1.0, 1.0, 0.0, 0.0] for order in token2wav.flow.decoder.estimator.speaker_order)
|
||||
assert token2wav.hift.calls == [2]
|
||||
assert len(audios) == 2
|
||||
cache0 = states[0].flow_cache["estimator_cnn_cache"]
|
||||
cache1 = states[1].flow_cache["estimator_cnn_cache"]
|
||||
assert cache0.data_ptr() != cache1.data_ptr()
|
||||
assert cache0[0, 0, 0, 0, 0].item() == 10
|
||||
assert cache1[0, 0, 0, 0, 0].item() == 20
|
||||
|
||||
|
||||
def test_estimator_cache_stack_split_round_trip_preserves_cfg_rows():
|
||||
token2wav = _FakeToken2Wav()
|
||||
adapter = BatchedToken2Wav(token2wav)
|
||||
prompt = adapter.prepare_prompt("shared", "/fake/prompt.wav")
|
||||
states = adapter.setup_batch(prompt, 2)
|
||||
_, states = adapter.decode_batch(
|
||||
torch.tensor([[10, 11], [20, 21]]),
|
||||
prompt,
|
||||
states,
|
||||
last_chunk=False,
|
||||
)
|
||||
|
||||
stacked = adapter._stack_flow_cache(states)
|
||||
assert stacked["estimator_cnn_cache"].shape[2] == 4
|
||||
assert stacked["estimator_att_cache"].shape[2] == 4
|
||||
restored = adapter._split_flow_cache(stacked, 2)
|
||||
for original, round_tripped in zip(states, restored, strict=True):
|
||||
torch.testing.assert_close(
|
||||
round_tripped["estimator_cnn_cache"],
|
||||
original.flow_cache["estimator_cnn_cache"],
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
round_tripped["estimator_att_cache"],
|
||||
original.flow_cache["estimator_att_cache"],
|
||||
)
|
||||
|
||||
|
||||
def test_model_preserves_output_slots_and_prefers_runtime_codes():
|
||||
model, token2wav = _model()
|
||||
output = _forward(
|
||||
model,
|
||||
[_info("a", 0, [10, 11]), _info("b", 0, [20, 21])],
|
||||
placeholder_counts=[3, 1],
|
||||
)
|
||||
|
||||
audios = output.multimodal_outputs["model_outputs"]
|
||||
assert len(audios) == 2
|
||||
assert len(output.multimodal_outputs["sr"]) == 2
|
||||
assert all(sr.item() == 24000 for sr in output.multimodal_outputs["sr"])
|
||||
assert all(audio.dtype == torch.float32 for audio in audios)
|
||||
# Fake CFM uses two Euler steps whose deltas sum to one. Its conditional
|
||||
# row is mu and its unconditional row is zero, so CFG produces 1.7 * mu.
|
||||
torch.testing.assert_close(audios[0][0], torch.tensor(1.7 * 10))
|
||||
torch.testing.assert_close(audios[1][0], torch.tensor(1.7 * 20))
|
||||
assert token2wav.flow.encoder.calls[-1] == 2
|
||||
|
||||
|
||||
def test_mixed_final_exact_buckets_keep_order_and_release_only_final_states():
|
||||
model, _ = _model()
|
||||
_forward(
|
||||
model,
|
||||
[_info(name, 0, [index + 1, index + 2]) for index, name in enumerate(("a", "b", "c", "d"))],
|
||||
)
|
||||
output = _forward(
|
||||
model,
|
||||
[
|
||||
_info("a", 1, [11, 12]),
|
||||
_info("c", 1, [31, 32, 33], last_chunk=True),
|
||||
_info("b", 1, [21, 22]),
|
||||
_info("d", 1, [41, 42, 43], last_chunk=True),
|
||||
],
|
||||
)
|
||||
|
||||
audios = output.multimodal_outputs["model_outputs"]
|
||||
window = torch.hamming_window(4, periodic=False)
|
||||
overlap_scale = 1.7 * (window[0] + window[2])
|
||||
expected = torch.tensor([1, 3, 2, 4], dtype=torch.float32) * overlap_scale
|
||||
actual = torch.stack([audio[0] for audio in audios])
|
||||
torch.testing.assert_close(actual, expected)
|
||||
assert set(model._states) == {"a", "b"}
|
||||
|
||||
|
||||
def test_empty_final_sentinel_emits_empty_and_releases_state_without_compute():
|
||||
model, token2wav = _model()
|
||||
_forward(model, [_info("a", 0, [1, 2]), _info("b", 0, [3, 4])])
|
||||
hift_calls = list(token2wav.hift.calls)
|
||||
output = _forward(
|
||||
model,
|
||||
[
|
||||
_info("a", 1, [], last_chunk=True),
|
||||
_info("b", 1, [], last_chunk=True),
|
||||
],
|
||||
)
|
||||
|
||||
assert [audio.numel() for audio in output.multimodal_outputs["model_outputs"]] == [0, 0]
|
||||
assert model._states == {}
|
||||
assert token2wav.hift.calls == hift_calls
|
||||
|
||||
|
||||
def test_empty_final_ignores_generation_scheduler_placeholder_token():
|
||||
model, _ = _model()
|
||||
_forward(model, [_info("a", 0, [1, 2]), _info("b", 0, [3, 4])])
|
||||
infos = [_info("a", 1, [], last_chunk=True), _info("b", 1, [], last_chunk=True)]
|
||||
for info in infos:
|
||||
info.pop("codes")
|
||||
info["meta"]["code_flat_numel"] = 0
|
||||
|
||||
output = _forward(model, infos, placeholder_counts=[1, 1])
|
||||
|
||||
assert [audio.numel() for audio in output.multimodal_outputs["model_outputs"]] == [0, 0]
|
||||
assert model._states == {}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("info", "reason"),
|
||||
[
|
||||
(_info("a", 0, [1, 2], cache_epoch=-1), "negative_stream_position"),
|
||||
(_info("a", 0, [1, 2]), "stale_or_reordered_chunk"),
|
||||
(_info("a", 2, [1, 2]), "stale_or_reordered_chunk"),
|
||||
],
|
||||
)
|
||||
def test_stale_epoch_and_reordered_chunks_are_rejected(info, reason):
|
||||
model, _ = _model()
|
||||
_forward(model, [_info("a", 0, [1, 2]), _info("b", 0, [3, 4])])
|
||||
|
||||
with pytest.raises(RuntimeError, match=reason):
|
||||
_forward(model, [info, _info("b", 1, [3, 4])])
|
||||
|
||||
|
||||
def test_singleton_and_mixed_shape_buckets_use_same_batched_backend_without_fallback():
|
||||
model, token2wav = _model()
|
||||
_forward(model, [_info("a", 0, [1, 2]), _info("b", 0, [3, 4])])
|
||||
output = _forward(model, [_info("a", 1, [5, 6]), _info("b", 1, [7, 8, 9])])
|
||||
|
||||
assert len(output.multimodal_outputs["model_outputs"]) == 2
|
||||
# Exact-shape buckets execute independently but both use the same vectorized
|
||||
# adapter; there is no Token2wav.stream/__call__ fallback.
|
||||
assert token2wav.hift.calls[-2:] == [1, 1]
|
||||
|
||||
|
||||
def test_backend_failure_does_not_commit_any_request_state(monkeypatch):
|
||||
model, _ = _model()
|
||||
_forward(
|
||||
model,
|
||||
[_info(name, 0, [index + 1, index + 2]) for index, name in enumerate(("a", "b", "c", "d"))],
|
||||
)
|
||||
before = dict(model._states)
|
||||
original = model.backend.decode_batch
|
||||
call_count = 0
|
||||
|
||||
def fail(*args, **kwargs):
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
if call_count == 2:
|
||||
raise RuntimeError("injected failure")
|
||||
return original(*args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(model.backend, "decode_batch", fail)
|
||||
with pytest.raises(RuntimeError, match="injected failure"):
|
||||
_forward(
|
||||
model,
|
||||
[
|
||||
_info("a", 1, [5, 6]),
|
||||
_info("b", 1, [7, 8]),
|
||||
_info("c", 1, [9, 10, 11]),
|
||||
_info("d", 1, [12, 13, 14]),
|
||||
],
|
||||
)
|
||||
assert call_count == 2
|
||||
assert model._states == before
|
||||
|
||||
|
||||
def test_cleanup_and_profile_output_are_aligned():
|
||||
model, _ = _model()
|
||||
_forward(model, [_info("a", 0, [1, 2]), _info("b", 0, [3, 4])])
|
||||
model.on_requests_finished(["a"])
|
||||
assert set(model._states) == {"b"}
|
||||
|
||||
profile = model(
|
||||
input_ids=torch.zeros(5, dtype=torch.long),
|
||||
seq_token_counts=[2, 3],
|
||||
)
|
||||
assert [audio.numel() for audio in profile.multimodal_outputs["model_outputs"]] == [0, 0]
|
||||
assert set(model._states) == {"b"}
|
||||
|
||||
|
||||
def test_cleanup_uses_generation_runner_internal_request_ids():
|
||||
model, _ = _model()
|
||||
_forward(
|
||||
model,
|
||||
[_info("external-a", 0, [1, 2]), _info("external-b", 0, [3, 4])],
|
||||
request_ids=["internal-a", "internal-b"],
|
||||
)
|
||||
|
||||
model.on_requests_finished(["internal-a"])
|
||||
|
||||
assert set(model._states) == {"internal-b"}
|
||||
|
||||
|
||||
def test_reference_voice_and_duplex_metadata_follow_request_lifecycle():
|
||||
model, _ = _model()
|
||||
first = _info("voice-a", 0, [1, 2])
|
||||
first["codes"]["ref"] = torch.linspace(-0.1, 0.1, 160)
|
||||
first["meta"].update(
|
||||
ref_audio_sr=16000,
|
||||
native_duplex_segment_text="hello",
|
||||
duplex_turn_id=7,
|
||||
duplex_epoch=3,
|
||||
)
|
||||
first["meta"].pop("prompt_cache_id")
|
||||
|
||||
output = _forward(model, [first])
|
||||
prompt_cache_id, prompt_wav = model._owned_prompt_wavs["voice-a"]
|
||||
assert prompt_cache_id.startswith("voice-a:")
|
||||
assert Path(prompt_wav).is_file()
|
||||
assert bytes(output.multimodal_outputs["meta.llm_output_text_utf8"][0].tolist()).decode() == "hello"
|
||||
assert output.multimodal_outputs["meta.duplex_turn_id"][0].item() == 7
|
||||
assert output.multimodal_outputs["meta.duplex_epoch"][0].item() == 3
|
||||
|
||||
final = _info("voice-a", 1, [3, 4], last_chunk=True)
|
||||
final["meta"].pop("prompt_cache_id")
|
||||
output = _forward(model, [final])
|
||||
|
||||
assert output.multimodal_outputs["meta.tts_is_last_chunk"][0].item() is True
|
||||
assert "voice-a" not in model._owned_prompt_wavs
|
||||
assert not Path(prompt_wav).exists()
|
||||
assert (prompt_cache_id, prompt_wav) not in model.backend._prompt_features
|
||||
@@ -1,74 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Regression test for HF model-ID resolution and path caching in MiniCPM-o 4.5 TTS."""
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
MiniCPMO45OmniTTSForConditionalGeneration,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
class _FakeMiniCPMTTS:
|
||||
def __init__(self, config, audio_tokenizer):
|
||||
self.config = config
|
||||
self.audio_tokenizer = audio_tokenizer
|
||||
self.emb_text = object()
|
||||
self.projector_semantic = object()
|
||||
|
||||
def generate(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def test_hf_model_id_path_caching(mocker, tmp_path):
|
||||
"""Verify the resolved HF path is cached and reused for default ref audio."""
|
||||
resolved_path = str(tmp_path / "resolved_hf_model")
|
||||
assets_dir = tmp_path / "resolved_hf_model" / "assets"
|
||||
assets_dir.mkdir(parents=True, exist_ok=True)
|
||||
ref_audio_file = assets_dir / "HT_ref_audio.wav"
|
||||
ref_audio_file.write_bytes(b"dummy wav content")
|
||||
|
||||
mock_download = mocker.patch(
|
||||
"vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts.download_weights_from_hf_specific",
|
||||
return_value=resolved_path,
|
||||
)
|
||||
|
||||
mocker.patch(
|
||||
"transformers.dynamic_module_utils.get_class_from_dynamic_module",
|
||||
return_value=_FakeMiniCPMTTS,
|
||||
)
|
||||
|
||||
# Build fake vllm_config with HF model ID
|
||||
model_id = "openbmb/MiniCPM-o-4_5"
|
||||
tts_cfg = SimpleNamespace(
|
||||
audio_bos_token_id=151687,
|
||||
text_eos_token_id=151692,
|
||||
num_audio_tokens=6562,
|
||||
hidden_size=768,
|
||||
normalize_projected_hidden=True,
|
||||
top_p=0.8,
|
||||
top_k=100,
|
||||
repetition_penalty=1.02,
|
||||
attn_implementation="sdpa",
|
||||
)
|
||||
hf_config = SimpleNamespace(tts_config=tts_cfg)
|
||||
vllm_config = SimpleNamespace(
|
||||
model_config=SimpleNamespace(
|
||||
model=model_id,
|
||||
hf_config=hf_config,
|
||||
)
|
||||
)
|
||||
|
||||
tts_model = MiniCPMO45OmniTTSForConditionalGeneration(vllm_config=vllm_config)
|
||||
|
||||
tts_model._lazy_init_tts()
|
||||
tts_model._lazy_init_tts()
|
||||
|
||||
mock_download.assert_called_once_with(model_id, None, ["*"])
|
||||
assert tts_model._model_path == resolved_path
|
||||
assert tts_model._assets_loaded is True
|
||||
assert tts_model._resolve_prompt_wav_path(None, None) == (str(ref_audio_file), None)
|
||||
@@ -10,7 +10,7 @@ Covers ``vllm_omni.model_executor.stage_input_processors.minicpmo_4_5_omni.llm2t
|
||||
- structured model_intermediate_buffer carries the thinker ids and text
|
||||
- scheduler prompt tokens follow the selected TTS region or output tokens
|
||||
- MiniCPM-o 4.5 TTS region detection on 151703 / 151704 tokens
|
||||
- No TTS markers present -> no ``tts_token_ids`` / ``tts_hidden_states`` keys
|
||||
- plain chat without TTS markers conditions on the generated assistant span
|
||||
- prompt arg is normalized to a list and ``multi_modal_data`` is gated by
|
||||
``requires_multimodal_data``
|
||||
"""
|
||||
@@ -33,6 +33,7 @@ pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
_HIDDEN_DIM = 4
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Legacy fused Talker metadata is replaced by separate Talker and Code2Wav stage payloads.")
|
||||
def test_native_duplex_talker_emits_empty_text_metadata_to_clear_previous_segment() -> None:
|
||||
class _Talker:
|
||||
_ar_last_chunk_flags = [True]
|
||||
@@ -91,13 +92,15 @@ def _make_thinker_output(
|
||||
latent: torch.Tensor | None = None,
|
||||
hidden_states: torch.Tensor | None = None,
|
||||
multimodal_output: dict[str, object] | None = None,
|
||||
request_multimodal_output: dict[str, object] | None = None,
|
||||
):
|
||||
"""Construct a minimal mock of a thinker engine output entry.
|
||||
|
||||
The real ``llm2tts`` only reads a tight slice of fields:
|
||||
- top-level: ``request_id``, ``prompt_token_ids``, ``outputs[0]``
|
||||
- per-output: ``multimodal_output`` (dict), ``hidden_states`` (opt),
|
||||
``text``, ``token_ids``
|
||||
- top-level: ``request_id``, ``prompt_token_ids``, optional
|
||||
``multimodal_output``, and ``outputs[0]``
|
||||
- per-output: fallback ``multimodal_output``, ``hidden_states`` (opt),
|
||||
``text``, and ``token_ids``
|
||||
"""
|
||||
mm_output = dict(multimodal_output or {})
|
||||
if latent is not None:
|
||||
@@ -109,11 +112,14 @@ def _make_thinker_output(
|
||||
)
|
||||
if hidden_states is not None:
|
||||
output.hidden_states = hidden_states
|
||||
return SimpleNamespace(
|
||||
request_output = SimpleNamespace(
|
||||
request_id=request_id,
|
||||
prompt_token_ids=prompt_token_ids,
|
||||
outputs=[output],
|
||||
)
|
||||
if request_multimodal_output is not None:
|
||||
request_output.multimodal_output = request_multimodal_output
|
||||
return request_output
|
||||
|
||||
|
||||
class TestInputValidation:
|
||||
@@ -131,6 +137,19 @@ class TestInputValidation:
|
||||
|
||||
|
||||
class TestBasicShape:
|
||||
def test_request_level_multimodal_output_feeds_orchestrator_bridge(self) -> None:
|
||||
hidden = torch.zeros((2, _HIDDEN_DIM))
|
||||
thinker_output = _make_thinker_output(
|
||||
prompt_token_ids=[10],
|
||||
output_token_ids=[20],
|
||||
request_multimodal_output={"latent": hidden},
|
||||
)
|
||||
|
||||
out = llm2tts([thinker_output], prompt=None)
|
||||
|
||||
assert out[0]["prompt_token_ids"] == [0, 0, 0]
|
||||
assert torch.equal(torch.tensor(out[0]["model_intermediate_buffer"]["hidden_states"]["tts"]), hidden[1:])
|
||||
|
||||
def test_returns_one_entry_per_input(self) -> None:
|
||||
hidden = torch.zeros((3, _HIDDEN_DIM))
|
||||
out = llm2tts(
|
||||
@@ -144,13 +163,13 @@ class TestBasicShape:
|
||||
)
|
||||
assert len(out) == 2
|
||||
|
||||
def test_talker_scheduler_prompt_uses_output_tokens(self) -> None:
|
||||
def test_talker_scheduler_prompt_matches_condition_length(self) -> None:
|
||||
hidden = torch.zeros((2, _HIDDEN_DIM))
|
||||
out = llm2tts(
|
||||
[_make_thinker_output(prompt_token_ids=[10], output_token_ids=[20], hidden_states=hidden)],
|
||||
prompt=None,
|
||||
)
|
||||
assert out[0]["prompt_token_ids"] == [20]
|
||||
assert out[0]["prompt_token_ids"] == [0, 0, 0]
|
||||
assert "stream_output" not in out[0]["model_intermediate_buffer"]
|
||||
|
||||
def test_model_intermediate_buffer_carries_thinker_outputs(self) -> None:
|
||||
@@ -174,6 +193,24 @@ class TestBasicShape:
|
||||
assert buffer["ids"]["output"] == out_ids
|
||||
assert buffer["llm_output_text"] == ["hello"]
|
||||
|
||||
def test_strict_talker_receives_canonical_nested_handoff(self) -> None:
|
||||
hidden = torch.arange(5 * _HIDDEN_DIM, dtype=torch.float32).reshape(5, _HIDDEN_DIM)
|
||||
result = llm2tts(
|
||||
[
|
||||
_make_thinker_output(
|
||||
prompt_token_ids=[10],
|
||||
output_token_ids=[151703, 20, 21, 151704],
|
||||
hidden_states=hidden,
|
||||
)
|
||||
],
|
||||
prompt=None,
|
||||
)[0]
|
||||
|
||||
buffer = result["model_intermediate_buffer"]
|
||||
assert result["prompt_token_ids"] == [0, 0, 0, 0]
|
||||
assert buffer["ids"]["tts"] == [20, 21]
|
||||
assert torch.equal(torch.tensor(buffer["hidden_states"]["tts"]), hidden[2:4])
|
||||
|
||||
def test_latent_in_multimodal_output_takes_precedence(self) -> None:
|
||||
# When both ``multimodal_output["latent"]`` and ``hidden_states`` are
|
||||
# present, the latent payload must win (this is the steady-state path
|
||||
@@ -241,13 +278,10 @@ class TestTtsRegionDetection:
|
||||
assert buffer["ids"]["tts"] == [30, 31]
|
||||
assert torch.equal(torch.tensor(buffer["hidden_states"]["tts"]), hidden[3:5])
|
||||
|
||||
def test_no_tts_markers_omits_slice_keys(self) -> None:
|
||||
# If neither marker pair is present, the bridge should NOT populate
|
||||
# ``tts_token_ids`` / ``tts_hidden_states`` — the talker should fall
|
||||
# through to the dummy path.
|
||||
buffer, _ = self._run([10, 11], [20, 21, 22])
|
||||
assert "tts" not in buffer["ids"]
|
||||
assert "tts" not in buffer.get("hidden_states", {})
|
||||
def test_plain_chat_without_tts_markers_uses_assistant_span(self) -> None:
|
||||
buffer, hidden = self._run([10, 11], [20, 21, 22])
|
||||
assert buffer["ids"]["tts"] == [20, 21, 22]
|
||||
assert torch.equal(torch.tensor(buffer["hidden_states"]["tts"]), hidden[2:5])
|
||||
|
||||
|
||||
class TestPromptAndMultiModal:
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
Covers:
|
||||
- pipeline declared in the central registry
|
||||
- lazy loader returns the expected ``PipelineConfig``
|
||||
- 2-stage topology (thinker LLM_AR + talker LLM_AR with audio output)
|
||||
- stage 1 routes through ``llm2tts`` custom input processor
|
||||
- split 3-stage topology with no fused compatibility registration
|
||||
- stage 1 routes through ``llm2tts`` and the async Code2Wav producer
|
||||
- ``hf_architectures`` covers both the shared ``MiniCPMO`` alias and the
|
||||
explicit 4.5 arch
|
||||
- ``hf_config_predicate`` selects MiniCPM-o 4.5 only and rejects 2.6
|
||||
@@ -15,6 +15,7 @@ Covers:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
@@ -23,20 +24,29 @@ from vllm_omni.config.pipeline_registry import OMNI_PIPELINES
|
||||
from vllm_omni.config.stage_config import (
|
||||
PipelineConfig,
|
||||
StageExecutionType,
|
||||
load_deploy_config,
|
||||
merge_pipeline_deploy,
|
||||
)
|
||||
from vllm_omni.model_executor.models.registry import _OMNI_MODELS
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
_PIPELINE_KEY = "minicpmo_4_5"
|
||||
_DEPLOY_DIR = Path(__file__).resolve().parents[4] / "vllm_omni" / "deploy"
|
||||
_DEPLOY_LAYOUTS = {
|
||||
"minicpmo_4_5.yaml": ["0", "0", "0"],
|
||||
"minicpmo_4_5_batching.yaml": ["0", "1", "1"],
|
||||
"minicpmo_4_5_2gpu.yaml": ["0", "1", "1"],
|
||||
"minicpmo_4_5_3gpu.yaml": ["0", "1", "2"],
|
||||
"minicpmo_4_5_8x4090.yaml": ["0,1,2,3", "4", "5"],
|
||||
}
|
||||
|
||||
|
||||
class TestRegistryDeclaration:
|
||||
def test_declared_in_omni_pipelines(self) -> None:
|
||||
assert _PIPELINE_KEY in OMNI_PIPELINES
|
||||
|
||||
def test_visible_in_central_registry(self) -> None:
|
||||
assert _PIPELINE_KEY in OMNI_PIPELINES
|
||||
assert "minicpmo_4_5_fused" not in OMNI_PIPELINES
|
||||
|
||||
def test_lazy_load_returns_pipeline_config(self) -> None:
|
||||
pipeline = OMNI_PIPELINES[_PIPELINE_KEY]
|
||||
@@ -64,9 +74,9 @@ class TestPipelineTopology:
|
||||
def pipeline(self) -> PipelineConfig:
|
||||
return OMNI_PIPELINES[_PIPELINE_KEY]
|
||||
|
||||
def test_two_stages(self, pipeline: PipelineConfig) -> None:
|
||||
assert len(pipeline.stages) == 2
|
||||
assert [s.stage_id for s in pipeline.stages] == [0, 1]
|
||||
def test_three_stages(self, pipeline: PipelineConfig) -> None:
|
||||
assert len(pipeline.stages) == 3
|
||||
assert [s.stage_id for s in pipeline.stages] == [0, 1, 2]
|
||||
|
||||
def test_topology_validates(self, pipeline: PipelineConfig) -> None:
|
||||
# ``validate`` returns a list of structural errors; empty == valid.
|
||||
@@ -90,11 +100,15 @@ class TestPipelineTopology:
|
||||
assert talker.execution_type == StageExecutionType.LLM_AR
|
||||
# talker consumes thinker output
|
||||
assert talker.input_sources == (0,)
|
||||
assert talker.final_output is True
|
||||
assert talker.final_output_type == "audio"
|
||||
assert talker.engine_output_type == "audio"
|
||||
assert talker.final_output is False
|
||||
assert talker.final_output_type is None
|
||||
assert talker.engine_output_type == "latent"
|
||||
# scope KV cache / mrope sizing to talker sub-config
|
||||
assert talker.hf_config_name == "tts_config"
|
||||
assert talker.custom_process_next_stage_input_func is None
|
||||
assert talker.async_chunk_process_next_stage_input_func == (
|
||||
"vllm_omni.model_executor.stage_input_processors.minicpmo_4_5_omni.tts2code2wav_async_chunk"
|
||||
)
|
||||
|
||||
def test_talker_routes_through_llm2tts(self, pipeline: PipelineConfig) -> None:
|
||||
talker = pipeline.get_stage(1)
|
||||
@@ -106,6 +120,73 @@ class TestPipelineTopology:
|
||||
"vllm_omni.model_executor.stage_input_processors.minicpmo_4_5_omni.llm2tts"
|
||||
)
|
||||
|
||||
def test_code2wav_stage(self, pipeline: PipelineConfig) -> None:
|
||||
code2wav = pipeline.get_stage(2)
|
||||
assert code2wav is not None
|
||||
assert code2wav.model_stage == "code2wav"
|
||||
assert code2wav.execution_type == StageExecutionType.LLM_GENERATION
|
||||
assert code2wav.input_sources == (1,)
|
||||
assert code2wav.final_output is True
|
||||
assert code2wav.final_output_type == "audio"
|
||||
assert code2wav.engine_output_type == "audio"
|
||||
assert code2wav.model_arch == "MiniCPMO45Code2Wav"
|
||||
assert code2wav.sync_process_input_func is None
|
||||
|
||||
|
||||
class TestDeployTopology:
|
||||
@pytest.mark.parametrize(("filename", "devices"), _DEPLOY_LAYOUTS.items())
|
||||
def test_deploy_resolves_three_stage_pipeline(self, filename: str, devices: list[str]) -> None:
|
||||
deploy = load_deploy_config(_DEPLOY_DIR / filename)
|
||||
pipeline = OMNI_PIPELINES[deploy.pipeline]
|
||||
stages = merge_pipeline_deploy(pipeline, deploy)
|
||||
|
||||
assert deploy.pipeline == _PIPELINE_KEY
|
||||
assert deploy.async_chunk is True
|
||||
assert [stage.stage_id for stage in stages] == [0, 1, 2]
|
||||
assert [stage.yaml_runtime["devices"] for stage in stages] == devices
|
||||
assert "additional_config" not in stages[1].yaml_engine_args
|
||||
assert "skip_mm_profiling" not in stages[0].yaml_engine_args
|
||||
assert stages[1].yaml_engine_args["skip_mm_profiling"] is True
|
||||
assert stages[2].yaml_engine_args["skip_mm_profiling"] is True
|
||||
assert stages[1].yaml_extras["output_connectors"]["to_stage_2"] == "connector_of_shared_memory"
|
||||
assert stages[2].yaml_extras["input_connectors"]["from_stage_1"] == "connector_of_shared_memory"
|
||||
connector = deploy.connectors["connector_of_shared_memory"]
|
||||
assert connector["name"] == "SharedMemoryConnector"
|
||||
assert connector["extra"]["codec_chunk_frames"] == 25
|
||||
assert connector["extra"]["codec_left_context_frames"] == 3
|
||||
assert connector["extra"]["connector_get_max_wait_first_chunk"] == 3000
|
||||
assert connector["extra"]["connector_get_max_wait"] == 300
|
||||
if filename == "minicpmo_4_5.yaml":
|
||||
assert [stage.yaml_engine_args["max_num_seqs"] for stage in stages] == [4, 4, 4]
|
||||
assert [stage.yaml_engine_args["gpu_memory_utilization"] for stage in stages] == [
|
||||
0.65,
|
||||
0.15,
|
||||
0.15,
|
||||
]
|
||||
elif filename in {"minicpmo_4_5_batching.yaml", "minicpmo_4_5_2gpu.yaml"}:
|
||||
assert [stage.yaml_engine_args["gpu_memory_utilization"] for stage in stages] == [
|
||||
0.9,
|
||||
0.55,
|
||||
0.35,
|
||||
]
|
||||
|
||||
def test_pipeline_exposes_no_full_payload_or_token_placeholder_hooks(self) -> None:
|
||||
pipeline = OMNI_PIPELINES[_PIPELINE_KEY]
|
||||
talker = pipeline.get_stage(1)
|
||||
code2wav = pipeline.get_stage(2)
|
||||
assert talker is not None
|
||||
assert code2wav is not None
|
||||
assert talker.custom_process_next_stage_input_func is None
|
||||
assert code2wav.sync_process_input_func is None
|
||||
|
||||
|
||||
def test_code2wav_model_is_lazily_registered() -> None:
|
||||
assert _OMNI_MODELS["MiniCPMO45Code2Wav"] == (
|
||||
"minicpmo_4_5",
|
||||
"minicpmo_4_5_code2wav",
|
||||
"MiniCPMO45Code2Wav",
|
||||
)
|
||||
|
||||
|
||||
class TestArchAliases:
|
||||
"""``hf_architectures`` must cover both the shared and explicit names."""
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Request-alignment tests for MiniCPM-o 4.5's native Talker."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni import (
|
||||
MiniCPMO45OmniForConditionalGeneration,
|
||||
)
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
MiniCPMO45OmniTTSForConditionalGeneration,
|
||||
_max_audio_tokens,
|
||||
)
|
||||
from vllm_omni.utils.mm_outputs import to_payload_element
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
class _FakeNativeTalker(nn.Module):
|
||||
has_preprocess = True
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.forward_kwargs = None
|
||||
|
||||
def forward(self, **kwargs):
|
||||
self.forward_kwargs = kwargs
|
||||
return torch.ones(2, 4)
|
||||
|
||||
|
||||
def test_wrapper_always_delegates_talker_to_native_ar_path() -> None:
|
||||
model = MiniCPMO45OmniForConditionalGeneration.__new__(MiniCPMO45OmniForConditionalGeneration)
|
||||
nn.Module.__init__(model)
|
||||
model.model_stage = "tts"
|
||||
model.talker = _FakeNativeTalker()
|
||||
|
||||
output = model(
|
||||
input_ids=torch.tensor([1, 2]),
|
||||
positions=torch.arange(2),
|
||||
model_intermediate_buffer=[{"request_id": "req"}],
|
||||
)
|
||||
|
||||
assert output.shape == (2, 4)
|
||||
assert model.talker.forward_kwargs["model_intermediate_buffer"][0]["request_id"] == "req"
|
||||
|
||||
|
||||
def _make_talker() -> MiniCPMO45OmniTTSForConditionalGeneration:
|
||||
talker = MiniCPMO45OmniTTSForConditionalGeneration.__new__(MiniCPMO45OmniTTSForConditionalGeneration)
|
||||
nn.Module.__init__(talker)
|
||||
talker._num_audio_tokens = 8
|
||||
talker._batch_stop_logits = None
|
||||
talker._request_generators = {}
|
||||
talker._request_audio_states = {}
|
||||
talker._deferred_cleanup_ids = set()
|
||||
return talker
|
||||
|
||||
|
||||
def _routed(output, index: int):
|
||||
return to_payload_element(
|
||||
output.multimodal_outputs,
|
||||
index,
|
||||
index,
|
||||
index + 1,
|
||||
seq_len=2,
|
||||
scheduled_seq_len=2,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("condition_tokens", "expected"),
|
||||
[(3, 64), (100, 1000), (1000, 2048)],
|
||||
)
|
||||
def test_audio_token_limit_scales_with_condition_length(
|
||||
condition_tokens: int,
|
||||
expected: int,
|
||||
) -> None:
|
||||
assert _max_audio_tokens(condition_tokens) == expected
|
||||
|
||||
|
||||
def test_talker_emits_request_aligned_codec_deltas_after_compaction(mocker) -> None:
|
||||
talker = _make_talker()
|
||||
seen: list[tuple[str, list[float], list[int]]] = []
|
||||
|
||||
def sample(hidden, history, request_id, step):
|
||||
assert step == 0
|
||||
seen.append((request_id, hidden.reshape(-1).tolist(), history.tolist()))
|
||||
return torch.tensor(2 if request_id == "req-a" else 3)
|
||||
|
||||
mocker.patch.object(talker, "_sample_audio_code", side_effect=sample)
|
||||
infos = [
|
||||
{"request_id": "req-a", "audio_codes": {"accumulated": torch.tensor([1])}},
|
||||
{"request_id": "req-b", "audio_codes": {"accumulated": torch.empty(0, dtype=torch.long)}},
|
||||
]
|
||||
|
||||
output = talker.make_omni_output(
|
||||
torch.tensor([[1.0, 0.0], [2.0, 0.0], [3.0, 0.0]]),
|
||||
model_intermediate_buffer=infos,
|
||||
request_token_spans=[(0, 2), (2, 3)],
|
||||
)
|
||||
|
||||
assert seen == [
|
||||
("req-a", [2.0, 0.0], [1]),
|
||||
("req-b", [3.0, 0.0], []),
|
||||
]
|
||||
assert infos[0]["audio_codes"]["accumulated"].tolist() == [1, 2]
|
||||
assert infos[1]["audio_codes"]["accumulated"].tolist() == [3]
|
||||
assert set(output.multimodal_outputs) == {"codes", "meta"}
|
||||
assert "model_outputs" not in output.multimodal_outputs
|
||||
assert "sr" not in output.multimodal_outputs
|
||||
assert _routed(output, 0)["codes"]["audio"].tolist() == [[2]]
|
||||
assert _routed(output, 1)["codes"]["audio"].tolist() == [[3]]
|
||||
assert _routed(output, 0)["meta"]["finished"].item() is False
|
||||
assert talker.compute_logits(output.text_hidden_states).argmax(dim=-1).tolist() == [0, 0]
|
||||
|
||||
|
||||
def test_incomplete_prefill_emits_no_code_and_does_not_advance_state(mocker) -> None:
|
||||
talker = _make_talker()
|
||||
sample = mocker.patch.object(talker, "_sample_audio_code", return_value=torch.tensor(2))
|
||||
infos = [
|
||||
{
|
||||
"request_id": "req-prefill",
|
||||
"audio_state": {"step": 0},
|
||||
"audio_codes": {"accumulated": torch.empty(0, dtype=torch.long)},
|
||||
},
|
||||
{
|
||||
"request_id": "req-decode",
|
||||
"audio_state": {"step": 4},
|
||||
"audio_codes": {"accumulated": torch.tensor([1])},
|
||||
},
|
||||
]
|
||||
|
||||
output = talker.make_omni_output(
|
||||
torch.tensor([[1.0, 0.0], [2.0, 0.0], [3.0, 0.0]]),
|
||||
model_intermediate_buffer=infos,
|
||||
request_token_spans=[(0, 2), (2, 3)],
|
||||
request_sample_eligible=[False, True],
|
||||
)
|
||||
|
||||
sample.assert_called_once()
|
||||
assert sample.call_args.args[2] == "req-decode"
|
||||
assert infos[0]["audio_state"]["step"] == 0
|
||||
assert infos[0]["audio_codes"]["accumulated"].numel() == 0
|
||||
assert infos[1]["audio_state"]["step"] == 5
|
||||
assert _routed(output, 0)["codes"]["audio"].shape == (0, 1)
|
||||
assert _routed(output, 1)["codes"]["audio"].tolist() == [[2]]
|
||||
|
||||
|
||||
def test_eos_is_terminal_once_and_never_enters_codec_history(mocker) -> None:
|
||||
talker = _make_talker()
|
||||
sample = mocker.patch.object(talker, "_sample_audio_code", return_value=torch.tensor(7))
|
||||
info = {
|
||||
"request_id": "req-stop",
|
||||
"audio_state": {"step": 3},
|
||||
"audio_codes": {"accumulated": torch.tensor([4, 5])},
|
||||
}
|
||||
|
||||
first = talker.make_omni_output(
|
||||
torch.ones(1, 2),
|
||||
model_intermediate_buffer=[info],
|
||||
request_token_spans=[(0, 1)],
|
||||
)
|
||||
first_logits = talker.compute_logits(first.text_hidden_states)
|
||||
second = talker.make_omni_output(
|
||||
torch.ones(1, 2),
|
||||
model_intermediate_buffer=[info],
|
||||
request_token_spans=[(0, 1)],
|
||||
)
|
||||
|
||||
sample.assert_called_once()
|
||||
assert info["audio_codes"]["accumulated"].tolist() == [4, 5]
|
||||
assert first.multimodal_outputs["codes"]["audio"][0].shape == (0, 1)
|
||||
assert first.multimodal_outputs["meta"]["finished"][0].item() is True
|
||||
assert second.multimodal_outputs["meta"]["finished"][0].item() is False
|
||||
assert first_logits.argmax(dim=-1).tolist() == [1]
|
||||
assert talker.compute_logits(second.text_hidden_states).argmax(dim=-1).tolist() == [1]
|
||||
|
||||
|
||||
def test_max_token_terminal_includes_only_new_codec_delta(mocker) -> None:
|
||||
talker = _make_talker()
|
||||
mocker.patch.object(talker, "_sample_audio_code", return_value=torch.tensor(3))
|
||||
info = {
|
||||
"request_id": "req-limit",
|
||||
"audio_state": {"step": 1, "max_tokens": 2},
|
||||
"audio_codes": {"accumulated": torch.tensor([4, 5])},
|
||||
}
|
||||
|
||||
output = talker.make_omni_output(
|
||||
torch.ones(1, 2),
|
||||
model_intermediate_buffer=[info],
|
||||
request_token_spans=[(0, 1)],
|
||||
)
|
||||
|
||||
assert info["audio_codes"]["accumulated"].tolist() == [4, 5, 3]
|
||||
assert output.multimodal_outputs["codes"]["audio"][0].tolist() == [[3]]
|
||||
assert output.multimodal_outputs["meta"]["finished"][0].item() is True
|
||||
assert talker.compute_logits(output.text_hidden_states).argmax(dim=-1).tolist() == [1]
|
||||
|
||||
|
||||
def test_request_local_state_survives_missing_runner_buffer_update(mocker) -> None:
|
||||
talker = _make_talker()
|
||||
mocker.patch.object(talker, "_sample_audio_code", return_value=torch.tensor(3))
|
||||
first_info = {
|
||||
"request_id": "req-local-state",
|
||||
"audio_state": {"step": 1, "max_tokens": 3},
|
||||
"audio_codes": {"accumulated": torch.tensor([4])},
|
||||
}
|
||||
|
||||
talker.make_omni_output(
|
||||
torch.ones(1, 2),
|
||||
model_intermediate_buffer=[first_info],
|
||||
request_token_spans=[(0, 1)],
|
||||
)
|
||||
second = talker.make_omni_output(
|
||||
torch.ones(1, 2),
|
||||
model_intermediate_buffer=[{"request_id": "req-local-state"}],
|
||||
request_token_spans=[(0, 1)],
|
||||
)
|
||||
|
||||
assert second.multimodal_outputs["meta"]["finished"][0].item() is True
|
||||
assert talker._request_audio_states["req-local-state"]["step"] == 3
|
||||
|
||||
|
||||
def test_missing_conditioning_fails_clearly() -> None:
|
||||
talker = _make_talker()
|
||||
|
||||
with pytest.raises(ValueError, match="tts_token_ids and tts_hidden_states"):
|
||||
talker.preprocess(
|
||||
torch.tensor([0]),
|
||||
None,
|
||||
_omni_is_prefill=True,
|
||||
request_id="req-invalid",
|
||||
)
|
||||
|
||||
|
||||
def test_request_cleanup_evicts_ar_rng_and_decode_state() -> None:
|
||||
talker = _make_talker()
|
||||
talker._request_generators["req-done"] = torch.Generator()
|
||||
talker._request_audio_states["req-done"] = {"step": 1}
|
||||
|
||||
talker.on_requests_finished(["req-done"])
|
||||
talker._flush_deferred_cleanup()
|
||||
|
||||
assert "req-done" not in talker._request_generators
|
||||
assert "req-done" not in talker._request_audio_states
|
||||
@@ -0,0 +1,182 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from collections import defaultdict
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from vllm.v1.request import RequestStatus
|
||||
|
||||
from vllm_omni.model_executor.stage_input_processors.minicpmo_4_5_omni import (
|
||||
tts2code2wav_async_chunk,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def _manager():
|
||||
return SimpleNamespace(
|
||||
connector=SimpleNamespace(config={"extra": {"codec_chunk_frames": 25, "codec_left_context_frames": 3}}),
|
||||
code_prompt_token_ids=defaultdict(list),
|
||||
request_payload={},
|
||||
put_req_chunk=defaultdict(int),
|
||||
)
|
||||
|
||||
|
||||
def _request(external_id: str, internal_id: str | None = None):
|
||||
request = SimpleNamespace(
|
||||
external_req_id=external_id,
|
||||
request_id=internal_id or external_id,
|
||||
status=RequestStatus.RUNNING,
|
||||
)
|
||||
request.is_finished = lambda: RequestStatus.is_finished(request.status)
|
||||
return request
|
||||
|
||||
|
||||
def _delta(*codes: int):
|
||||
return {
|
||||
"codes": {"audio": torch.tensor(codes, dtype=torch.long).reshape(-1, 1)},
|
||||
"meta": {"finished": torch.tensor(False)},
|
||||
}
|
||||
|
||||
|
||||
def _codes(payload) -> list[int]:
|
||||
assert payload.codes is not None
|
||||
assert isinstance(payload.codes.audio, torch.Tensor)
|
||||
assert payload.codes.audio.dtype == torch.long
|
||||
assert payload.codes.audio.ndim == 1
|
||||
return payload.codes.audio.tolist()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("count", "emitted"), [(24, False), (25, True), (26, True)])
|
||||
def test_first_chunk_threshold_is_25_generated_codes(count: int, emitted: bool) -> None:
|
||||
manager = _manager()
|
||||
payload = tts2code2wav_async_chunk(
|
||||
transfer_manager=manager,
|
||||
multimodal_output=_delta(*range(count)),
|
||||
request=_request("req"),
|
||||
is_finished=False,
|
||||
)
|
||||
|
||||
assert (payload is not None) is emitted
|
||||
if payload is not None:
|
||||
assert _codes(payload) == [4218, 4218, 4218, *range(25)]
|
||||
assert payload.meta.chunk_seq == 0
|
||||
assert payload.meta.code_flat_numel == 28
|
||||
|
||||
|
||||
def test_steady_chunk_has_three_code_overlap_and_25_new_codes() -> None:
|
||||
manager = _manager()
|
||||
request = _request("req")
|
||||
|
||||
first = tts2code2wav_async_chunk(manager, _delta(*range(25)), request, False)
|
||||
manager.put_req_chunk["req"] += 1
|
||||
steady = tts2code2wav_async_chunk(manager, _delta(*range(25, 50)), request, False)
|
||||
|
||||
assert first is not None
|
||||
assert steady is not None
|
||||
assert _codes(steady) == [22, 23, 24, *range(25, 50)]
|
||||
assert steady.meta.chunk_seq == 1
|
||||
|
||||
|
||||
def test_exact_boundary_final_flushes_held_lookahead() -> None:
|
||||
manager = _manager()
|
||||
request = _request("req")
|
||||
|
||||
assert tts2code2wav_async_chunk(manager, _delta(*range(25)), request, False) is not None
|
||||
manager.put_req_chunk["req"] += 1
|
||||
final = tts2code2wav_async_chunk(manager, None, request, True)
|
||||
|
||||
assert final is not None
|
||||
assert _codes(final) == [22, 23, 24]
|
||||
assert final.meta.chunk_seq == 1
|
||||
assert final.meta.code_flat_numel == 3
|
||||
assert final.meta.last_chunk is True
|
||||
assert final.meta.finished.item() is True
|
||||
|
||||
|
||||
def test_short_final_flushes_silence_prefix_and_tail() -> None:
|
||||
manager = _manager()
|
||||
final = tts2code2wav_async_chunk(manager, _delta(*range(7)), _request("req"), True)
|
||||
|
||||
assert final is not None
|
||||
assert _codes(final) == [4218, 4218, 4218, *range(7)]
|
||||
assert final.meta.last_chunk is True
|
||||
assert final.meta.finished.item() is True
|
||||
|
||||
|
||||
def test_first_chunk_forwards_reference_voice_and_duplex_identity() -> None:
|
||||
manager = _manager()
|
||||
request = _request("req")
|
||||
request.additional_information = {
|
||||
"codes": {"ref": [0.1, -0.1]},
|
||||
"meta": {
|
||||
"ref_audio_sr": 16000,
|
||||
"native_duplex_segment_text": "hello",
|
||||
"segment_end": True,
|
||||
"turn_end": True,
|
||||
},
|
||||
"duplex": {"epoch": 3, "model_turn_id": 7},
|
||||
}
|
||||
|
||||
payload = tts2code2wav_async_chunk(manager, _delta(*range(7)), request, True)
|
||||
|
||||
assert payload is not None
|
||||
assert payload.codes.ref.tolist() == pytest.approx([0.1, -0.1])
|
||||
assert payload.meta.ref_audio_sr == 16000
|
||||
assert payload.meta.native_duplex_segment_text == "hello"
|
||||
assert payload.meta.duplex_epoch == 3
|
||||
assert payload.meta.duplex_turn_id == 7
|
||||
assert payload.meta.segment_end is True
|
||||
assert payload.meta.turn_end is True
|
||||
|
||||
|
||||
def test_empty_final_releases_wait_gate_once() -> None:
|
||||
manager = _manager()
|
||||
request = _request("req")
|
||||
|
||||
final = tts2code2wav_async_chunk(manager, None, request, True)
|
||||
duplicate = tts2code2wav_async_chunk(manager, None, request, True)
|
||||
|
||||
assert final is not None
|
||||
assert _codes(final) == []
|
||||
assert final.meta.chunk_seq == 0
|
||||
assert final.meta.request_id == "req"
|
||||
assert final.meta.cache_epoch == 0
|
||||
assert final.meta.last_chunk is True
|
||||
assert duplicate is None
|
||||
|
||||
|
||||
def test_staggered_requests_keep_accumulators_isolated() -> None:
|
||||
manager = _manager()
|
||||
req_a = _request("a")
|
||||
req_b = _request("b")
|
||||
|
||||
assert tts2code2wav_async_chunk(manager, _delta(*range(24)), req_a, False) is None
|
||||
out_b = tts2code2wav_async_chunk(manager, _delta(*range(100, 125)), req_b, False)
|
||||
out_a = tts2code2wav_async_chunk(manager, _delta(24), req_a, False)
|
||||
|
||||
assert out_b is not None
|
||||
assert out_a is not None
|
||||
assert _codes(out_b) == [4218, 4218, 4218, *range(100, 125)]
|
||||
assert _codes(out_a) == [4218, 4218, 4218, *range(25)]
|
||||
assert out_a.meta.request_id == "a"
|
||||
assert out_b.meta.request_id == "b"
|
||||
|
||||
|
||||
def test_cancel_drops_epoch_state_and_stale_request_cannot_publish() -> None:
|
||||
manager = _manager()
|
||||
stale = _request("req", "internal-0")
|
||||
|
||||
assert tts2code2wav_async_chunk(manager, _delta(*range(10)), stale, False) is None
|
||||
stale.status = RequestStatus.FINISHED_ABORTED
|
||||
assert tts2code2wav_async_chunk(manager, None, stale, True) is None
|
||||
assert tts2code2wav_async_chunk(manager, _delta(*range(25)), stale, False) is None
|
||||
|
||||
replacement = _request("req", "internal-1")
|
||||
payload = tts2code2wav_async_chunk(manager, _delta(*range(25)), replacement, False)
|
||||
|
||||
assert payload is not None
|
||||
assert payload.meta.cache_epoch == 1
|
||||
assert _codes(payload) == [4218, 4218, 4218, *range(25)]
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1129,23 +1129,22 @@ class TestDeployConfigLoading:
|
||||
stages = merge_pipeline_deploy(pipeline, deploy)
|
||||
|
||||
assert deploy.session_mode == "duplex"
|
||||
assert deploy.async_chunk is False
|
||||
assert deploy.async_chunk is True
|
||||
assert deploy.active_stream_window == 1
|
||||
assert [stage.session_mode for stage in stages] == ["duplex", "duplex"]
|
||||
assert [stage.to_omegaconf().session_mode for stage in stages] == ["duplex", "duplex"]
|
||||
assert [stage.yaml_engine_args["async_scheduling"] for stage in stages] == [False, False]
|
||||
assert [stage.session_mode for stage in stages] == ["duplex", "duplex", "duplex"]
|
||||
assert [stage.to_omegaconf().session_mode for stage in stages] == ["duplex", "duplex", "duplex"]
|
||||
assert [stage.yaml_engine_args["async_scheduling"] for stage in stages] == [False, False, False]
|
||||
assert all("Async" not in (stage.scheduler_cls or "") for stage in stages)
|
||||
assert deploy.stages[1].enforce_eager is False
|
||||
assert deploy.stages[1].compilation_config == {"cudagraph_mode": "PIECEWISE"}
|
||||
assert stages[1].yaml_extras["default_sampling_params"]["max_tokens"] == 4096
|
||||
assert stages[1].yaml_extras["default_sampling_params"]["stop_token_ids"] == [151645]
|
||||
assert stages[1].yaml_extras["default_sampling_params"]["max_tokens"] == 2048
|
||||
assert stages[1].yaml_extras["default_sampling_params"]["stop_token_ids"] == [1]
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("filename", "stage0_devices", "stage1_devices", "stage1_replicas"),
|
||||
("filename", "stage0_devices", "stage1_devices", "stage2_devices", "stage1_replicas"),
|
||||
[
|
||||
("minicpmo_4_5_3gpu_stage1_replicas.yaml", "0", "1,2", 2),
|
||||
("minicpmo_4_5_4gpu_stage1_replicas.yaml", "0", "1,2,3", 3),
|
||||
("minicpmo_4_5_8x4090_stage1_replicas.yaml", "0,1,2,3", "4,5,6,7", 4),
|
||||
("minicpmo_4_5_3gpu_stage1_replicas.yaml", "0", "1,2", "0", 2),
|
||||
("minicpmo_4_5_4gpu_stage1_replicas.yaml", "0", "1,2,3", "0", 3),
|
||||
("minicpmo_4_5_8x4090_stage1_replicas.yaml", "0,1,2,3", "4,5,6,7", "5", 4),
|
||||
],
|
||||
)
|
||||
def test_load_minicpmo_replica_deploy_configs(
|
||||
@@ -1153,6 +1152,7 @@ class TestDeployConfigLoading:
|
||||
filename: str,
|
||||
stage0_devices: str,
|
||||
stage1_devices: str,
|
||||
stage2_devices: str,
|
||||
stage1_replicas: int,
|
||||
):
|
||||
deploy_path = Path(__file__).parent.parent / "vllm_omni" / "deploy" / filename
|
||||
@@ -1164,11 +1164,15 @@ class TestDeployConfigLoading:
|
||||
stages = merge_pipeline_deploy(pipeline, deploy)
|
||||
|
||||
assert deploy.session_mode == "duplex"
|
||||
assert [stage.yaml_runtime["devices"] for stage in stages] == [stage0_devices, stage1_devices]
|
||||
assert [stage.yaml_runtime["devices"] for stage in stages] == [
|
||||
stage0_devices,
|
||||
stage1_devices,
|
||||
stage2_devices,
|
||||
]
|
||||
assert stages[0].yaml_runtime["num_replicas"] == 1
|
||||
assert stages[1].yaml_runtime["num_replicas"] == stage1_replicas
|
||||
assert all(stage.yaml_engine_args["async_scheduling"] is False for stage in stages)
|
||||
assert all("Async" not in (stage.scheduler_cls or "") for stage in stages)
|
||||
assert all(stage.yaml_engine_args["async_scheduling"] is False for stage in stages[:2])
|
||||
assert all("Async" not in (stage.scheduler_cls or "") for stage in stages[:2])
|
||||
|
||||
def test_custom_voice_dir_is_pipeline_wide_engine_arg(self, tmp_path):
|
||||
deploy_path = tmp_path / "qwen3_tts_custom_voice.yaml"
|
||||
|
||||
@@ -663,6 +663,7 @@ def test_sample_tokens_tail_only_prefix_cache_uses_staged_cpu_hidden_states(monk
|
||||
# inter_stage_outputs mirrors multimodal_outputs (PR #4792).
|
||||
assert output.inter_stage_outputs is not None
|
||||
assert output.multimodal_outputs is not None
|
||||
assert output.inter_stage_outputs is output.multimodal_outputs
|
||||
assert torch.equal(output.inter_stage_outputs[0]["hidden"], output.multimodal_outputs[0]["hidden"])
|
||||
assert torch.equal(output.inter_stage_outputs[1]["hidden"], output.multimodal_outputs[1]["hidden"])
|
||||
assert torch.equal(output.multimodal_outputs[0]["hidden"], torch.tensor([[1.0, 10.0]]))
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
import os
|
||||
import threading
|
||||
from types import SimpleNamespace
|
||||
|
||||
import numpy as np
|
||||
@@ -544,220 +542,6 @@ def test_minicpmo_stage0_rejects_invalid_resolved_ref_audio():
|
||||
)
|
||||
|
||||
|
||||
def test_minicpmo_tts_native_duplex_exports_segment_text_not_accumulated_condition_text():
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni import (
|
||||
MiniCPMO45OmniForConditionalGeneration,
|
||||
)
|
||||
|
||||
class _Talker:
|
||||
_ar_last_chunk_flags = [False]
|
||||
_ar_last_emitted_text = "你好,你有什莫想聊的吗?"
|
||||
|
||||
def __call__(self, **kwargs):
|
||||
del kwargs
|
||||
return None, torch.zeros(8, dtype=torch.float32)
|
||||
|
||||
model = MiniCPMO45OmniForConditionalGeneration.__new__(MiniCPMO45OmniForConditionalGeneration)
|
||||
model.model_stage = "tts"
|
||||
model.config = SimpleNamespace(hidden_size=4)
|
||||
model.talker = _Talker()
|
||||
|
||||
output = model.forward(
|
||||
input_ids=torch.zeros(1, dtype=torch.long),
|
||||
positions=torch.zeros(1, dtype=torch.long),
|
||||
runtime_additional_information=[
|
||||
{
|
||||
"native_duplex": True,
|
||||
"llm_output_text": ["你好,你有什莫想聊的吗?你好,你有什莫想聊的吗?"],
|
||||
"meta": {
|
||||
"native_duplex_segment_text": "你好,你有什莫想聊的吗?",
|
||||
},
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
text_bytes = output.multimodal_outputs["meta.llm_output_text_utf8"].detach().cpu().tolist()
|
||||
assert bytes(text_bytes).decode("utf-8") == "你好,你有什莫想聊的吗?"
|
||||
assert int(output.multimodal_outputs["meta.audio_text_total_chars"].item()) == len("你好,你有什莫想聊的吗?")
|
||||
|
||||
|
||||
def test_minicpmo_tts_native_duplex_exports_model_turn_end_metadata():
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni import (
|
||||
MiniCPMO45OmniForConditionalGeneration,
|
||||
)
|
||||
|
||||
class _Talker:
|
||||
_ar_last_chunk_flags = [True]
|
||||
_ar_turn_end_flags = [True]
|
||||
|
||||
def __call__(self, **kwargs):
|
||||
del kwargs
|
||||
return None, torch.zeros(0, dtype=torch.float32)
|
||||
|
||||
model = MiniCPMO45OmniForConditionalGeneration.__new__(MiniCPMO45OmniForConditionalGeneration)
|
||||
model.model_stage = "tts"
|
||||
model.config = SimpleNamespace(hidden_size=4)
|
||||
model.talker = _Talker()
|
||||
|
||||
output = model.forward(
|
||||
input_ids=torch.zeros(1, dtype=torch.long),
|
||||
positions=torch.zeros(1, dtype=torch.long),
|
||||
runtime_additional_information=[
|
||||
{
|
||||
"native_duplex": True,
|
||||
"meta": {"native_duplex_segment_text": ""},
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
assert int(output.multimodal_outputs["meta.turn_end"].item()) == 1
|
||||
|
||||
|
||||
def test_minicpmo_tts_routes_batched_requests_and_terminal_flags_independently():
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni import (
|
||||
MiniCPMO45OmniForConditionalGeneration,
|
||||
)
|
||||
|
||||
class _Talker:
|
||||
def __init__(self):
|
||||
self.calls = []
|
||||
self._ar_last_chunk_flags = [True]
|
||||
self._ar_turn_end_flags = [False]
|
||||
self._ar_last_emitted_text = ""
|
||||
|
||||
def __call__(self, **kwargs):
|
||||
info = kwargs["additional_information"]
|
||||
request_id = info["global_request_id"][0]
|
||||
self.calls.append(request_id)
|
||||
is_last = request_id == "req-b"
|
||||
self._ar_last_chunk_flags = [is_last]
|
||||
self._ar_turn_end_flags = [is_last]
|
||||
self._ar_last_emitted_text = request_id
|
||||
value = 1.0 if request_id == "req-a" else 2.0
|
||||
return None, torch.full((2,), value, dtype=torch.float32)
|
||||
|
||||
model = MiniCPMO45OmniForConditionalGeneration.__new__(MiniCPMO45OmniForConditionalGeneration)
|
||||
model.model_stage = "tts"
|
||||
model.config = SimpleNamespace(hidden_size=4)
|
||||
model.talker = _Talker()
|
||||
|
||||
output = model.forward(
|
||||
input_ids=torch.zeros(3, dtype=torch.long),
|
||||
positions=torch.zeros(3, dtype=torch.long),
|
||||
runtime_additional_information=[
|
||||
{
|
||||
"global_request_id": ["req-a"],
|
||||
"native_duplex": True,
|
||||
"duplex": {"epoch": 3, "turn_id": 7},
|
||||
"meta": {"native_duplex_segment_text": "first"},
|
||||
},
|
||||
{
|
||||
"global_request_id": ["req-idle"],
|
||||
"native_duplex": True,
|
||||
"duplex": {"epoch": 3, "turn_id": 9},
|
||||
"meta": {"native_duplex_segment_text": "idle"},
|
||||
},
|
||||
{
|
||||
"global_request_id": ["req-b"],
|
||||
"native_duplex": True,
|
||||
"duplex": {"epoch": 4, "turn_id": 8},
|
||||
"meta": {"native_duplex_segment_text": "second"},
|
||||
},
|
||||
],
|
||||
request_token_spans=[(0, 2), (2, 2), (2, 3)],
|
||||
)
|
||||
|
||||
assert model.talker.calls == ["req-a", "req-b"]
|
||||
assert model.talker._ar_last_chunk_flags == [False, False, True]
|
||||
assert model.talker._ar_turn_end_flags == [False, False, True]
|
||||
assert output.multimodal_outputs["meta.req_id"] == ["req-a", "req-b"]
|
||||
assert output.multimodal_outputs["meta.sparse_audio"] == ["1"]
|
||||
assert [waveform.tolist() for waveform in output.multimodal_outputs["model_outputs"]] == [
|
||||
[1.0, 1.0],
|
||||
[2.0, 2.0],
|
||||
]
|
||||
assert [int(value.item()) for value in output.multimodal_outputs["meta.tts_is_last_chunk"]] == [0, 1]
|
||||
assert [int(value.item()) for value in output.multimodal_outputs["meta.turn_end"]] == [0, 1]
|
||||
assert [int(value.item()) for value in output.multimodal_outputs["meta.duplex_epoch"]] == [3, 4]
|
||||
assert [int(value.item()) for value in output.multimodal_outputs["meta.duplex_turn_id"]] == [7, 8]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("runtime_info", "request_token_spans", "expected_rows", "expected_ids"),
|
||||
[
|
||||
(
|
||||
[
|
||||
{
|
||||
"global_request_id": ["req-a"],
|
||||
"native_duplex": True,
|
||||
"duplex": {"epoch": 3, "turn_id": 7},
|
||||
"meta": {"native_duplex_segment_text": "first"},
|
||||
}
|
||||
],
|
||||
[(0, 3)],
|
||||
[3],
|
||||
["req-a"],
|
||||
),
|
||||
(
|
||||
[
|
||||
{
|
||||
"global_request_id": ["req-a"],
|
||||
"native_duplex": True,
|
||||
"duplex": {"epoch": 3, "turn_id": 7},
|
||||
"meta": {"native_duplex_segment_text": "first"},
|
||||
},
|
||||
{
|
||||
"global_request_id": ["req-b"],
|
||||
"native_duplex": True,
|
||||
"duplex": {"epoch": 4, "turn_id": 8},
|
||||
"meta": {"native_duplex_segment_text": "second"},
|
||||
},
|
||||
],
|
||||
[(0, 2), (2, 3)],
|
||||
[2, 1],
|
||||
["req-a", "req-b"],
|
||||
),
|
||||
],
|
||||
ids=["single-request", "batched-requests"],
|
||||
)
|
||||
def test_minicpmo_tts_ignores_cuda_graph_padding_after_request_spans(
|
||||
runtime_info,
|
||||
request_token_spans,
|
||||
expected_rows,
|
||||
expected_ids,
|
||||
):
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni import (
|
||||
MiniCPMO45OmniForConditionalGeneration,
|
||||
)
|
||||
|
||||
class _Talker:
|
||||
def __init__(self):
|
||||
self.input_rows = []
|
||||
self._ar_last_chunk_flags = [True]
|
||||
self._ar_turn_end_flags = [False]
|
||||
self._ar_last_emitted_text = ""
|
||||
|
||||
def __call__(self, **kwargs):
|
||||
self.input_rows.append(int(kwargs["input_ids"].shape[0]))
|
||||
return None, torch.ones(2, dtype=torch.float32)
|
||||
|
||||
model = MiniCPMO45OmniForConditionalGeneration.__new__(MiniCPMO45OmniForConditionalGeneration)
|
||||
model.model_stage = "tts"
|
||||
model.config = SimpleNamespace(hidden_size=4)
|
||||
model.talker = _Talker()
|
||||
|
||||
output = model.forward(
|
||||
input_ids=torch.zeros(4, dtype=torch.long),
|
||||
positions=torch.zeros(4, dtype=torch.long),
|
||||
runtime_additional_information=runtime_info,
|
||||
request_token_spans=request_token_spans,
|
||||
)
|
||||
|
||||
assert model.talker.input_rows == expected_rows
|
||||
assert output.text_hidden_states.shape == (4, 4)
|
||||
assert output.multimodal_outputs["meta.req_id"] == expected_ids
|
||||
|
||||
|
||||
def test_minicpmo_stage0_special_token_ids_are_tokenizer_derived():
|
||||
from vllm_omni.experimental.fullduplex.minicpmo45.stage0 import (
|
||||
MiniCPMO45Stage0DuplexRuntime,
|
||||
@@ -2427,150 +2211,3 @@ def test_minicpmo_stage0_session_context_includes_resolved_ref_audio():
|
||||
|
||||
assert state.context_token_ids == [1, 2, 3, 151683, 151683, 4, 5]
|
||||
assert len(state.context_embeds) == 6
|
||||
|
||||
|
||||
def test_minicpmo_tts_ref_audio_lru_evicts_matching_vocoder_base_cache(tmp_path):
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
MiniCPMO45OmniTTSForConditionalGeneration,
|
||||
MiniCPMO45TTSRuntimeConfig,
|
||||
)
|
||||
|
||||
model = MiniCPMO45OmniTTSForConditionalGeneration.__new__(MiniCPMO45OmniTTSForConditionalGeneration)
|
||||
model._runtime_config = MiniCPMO45TTSRuntimeConfig(ref_audio_file_cache_size=1)
|
||||
model._t2w_base_caches = {}
|
||||
model._token2wav_state_lock = threading.RLock()
|
||||
first_path = model._write_ref_audio_prompt_wav(np.array([0.1, -0.1], dtype=np.float32), 16_000)
|
||||
assert first_path is not None
|
||||
model._t2w_base_caches[first_path] = (torch.tensor([1]), {"cache": torch.tensor([2])})
|
||||
|
||||
second_path = model._write_ref_audio_prompt_wav(np.array([0.2, -0.2], dtype=np.float32), 16_000)
|
||||
|
||||
assert second_path is not None
|
||||
assert second_path != first_path
|
||||
assert first_path not in model._t2w_base_caches
|
||||
assert not os.path.exists(first_path)
|
||||
|
||||
|
||||
def test_minicpmo_tts_prompt_wav_path_does_not_default_to_model_asset(tmp_path):
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
MiniCPMO45OmniTTSForConditionalGeneration,
|
||||
)
|
||||
|
||||
model_dir = tmp_path / "MiniCPM-o-4_5"
|
||||
assets_dir = model_dir / "assets"
|
||||
assets_dir.mkdir(parents=True)
|
||||
(assets_dir / "HT_ref_audio.wav").write_bytes(b"placeholder")
|
||||
|
||||
model = MiniCPMO45OmniTTSForConditionalGeneration.__new__(MiniCPMO45OmniTTSForConditionalGeneration)
|
||||
model.vllm_config = SimpleNamespace(model_config=SimpleNamespace(model=str(model_dir)))
|
||||
model._write_ref_audio_prompt_wav = lambda ref_audio, ref_audio_sr: None
|
||||
|
||||
assert model._resolve_prompt_wav_path(None, None) == (None, None)
|
||||
|
||||
|
||||
def test_minicpmo_tts_stream_turn_id_prefers_duplex_identity():
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
MiniCPMO45OmniTTSForConditionalGeneration,
|
||||
)
|
||||
|
||||
model = MiniCPMO45OmniTTSForConditionalGeneration.__new__(MiniCPMO45OmniTTSForConditionalGeneration)
|
||||
|
||||
assert (
|
||||
model._stream_turn_id(
|
||||
{
|
||||
"duplex": {"turn_id": 0, "model_turn_id": 4},
|
||||
"meta": {"turn_id": 3},
|
||||
}
|
||||
)
|
||||
== 4
|
||||
)
|
||||
assert (
|
||||
model._stream_turn_id(
|
||||
{
|
||||
"duplex": {"turn_id": 0},
|
||||
"meta": {"turn_id": 3},
|
||||
}
|
||||
)
|
||||
== 0
|
||||
)
|
||||
assert model._stream_turn_id({"meta": {"turn_id": 3}, "turn_id": 2}) == 3
|
||||
assert model._stream_turn_id({"turn_id": 2}) == 2
|
||||
|
||||
|
||||
def test_minicpmo_tts_no_ref_audio_initializes_empty_vocoder_cache():
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
MiniCPMO45OmniTTSForConditionalGeneration,
|
||||
_TalkerTurnState,
|
||||
)
|
||||
|
||||
class AudioTokenizer:
|
||||
def set_stream_cache(self, prompt_wav_path):
|
||||
raise AssertionError(f"unexpected reference-audio cache load: {prompt_wav_path!r}")
|
||||
|
||||
model = MiniCPMO45OmniTTSForConditionalGeneration.__new__(MiniCPMO45OmniTTSForConditionalGeneration)
|
||||
model._t2w_base_caches = {}
|
||||
model._token2wav_state_lock = threading.RLock()
|
||||
model.audio_tokenizer = AudioTokenizer()
|
||||
state = _TalkerTurnState(None, None)
|
||||
|
||||
model._begin_turn_vocoder_cache(None, state=state)
|
||||
|
||||
assert state.stream_cache is None
|
||||
assert state.hift_cache_dict == {}
|
||||
assert state.vocoder_initialized is True
|
||||
assert model._t2w_base_caches[""] == (None, {})
|
||||
|
||||
|
||||
def test_minicpmo_tts_native_duplex_merges_and_left_pads_nonfinal_unit_audio():
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
_native_duplex_unit_waveform,
|
||||
)
|
||||
|
||||
waveform = _native_duplex_unit_waveform(
|
||||
[torch.tensor([1.0, 2.0]), torch.tensor([3.0])],
|
||||
turn_end=False,
|
||||
target_samples=6,
|
||||
)
|
||||
|
||||
assert waveform is not None
|
||||
assert waveform.tolist() == [0.0, 0.0, 0.0, 1.0, 2.0, 3.0]
|
||||
|
||||
|
||||
def test_minicpmo_tts_native_duplex_does_not_pad_final_unit_audio():
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
_native_duplex_unit_waveform,
|
||||
)
|
||||
|
||||
waveform = _native_duplex_unit_waveform(
|
||||
[torch.tensor([1.0, 2.0]), torch.tensor([3.0])],
|
||||
turn_end=True,
|
||||
target_samples=6,
|
||||
)
|
||||
|
||||
assert waveform is not None
|
||||
assert waveform.tolist() == [1.0, 2.0, 3.0]
|
||||
|
||||
|
||||
def test_minicpmo_tts_turn_cleanup_removes_deleted_ref_audio_vocoder_cache(tmp_path):
|
||||
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_omni_tts import (
|
||||
MiniCPMO45OmniTTSForConditionalGeneration,
|
||||
_TalkerTurnState,
|
||||
)
|
||||
|
||||
prompt_path = tmp_path / "session-ref.wav"
|
||||
prompt_path.write_bytes(b"wav")
|
||||
model = MiniCPMO45OmniTTSForConditionalGeneration.__new__(MiniCPMO45OmniTTSForConditionalGeneration)
|
||||
model._talker_turn_states = {
|
||||
"request": _TalkerTurnState(str(prompt_path), str(prompt_path)),
|
||||
}
|
||||
model._talker_consumed_tokens = {"request": 1}
|
||||
model._talker_request_keys = {}
|
||||
model._t2w_base_caches = {
|
||||
str(prompt_path): (torch.tensor([1]), {"cache": torch.tensor([2])}),
|
||||
}
|
||||
model._token2wav_state_lock = threading.RLock()
|
||||
model.audio_tokenizer = None
|
||||
|
||||
assert model._close_turn_state("request") is True
|
||||
assert str(prompt_path) not in model._t2w_base_caches
|
||||
assert not prompt_path.exists()
|
||||
@@ -440,6 +440,33 @@ def test_update_intermediate_buffer_accumulates():
|
||||
assert torch.allclose(buf["b"], torch.tensor([2.0]))
|
||||
|
||||
|
||||
def test_update_additional_information_deserializes_new_request_payload():
|
||||
from vllm_omni.engine.serialization import serialize_additional_information
|
||||
|
||||
runner = _make_runner(req_ids=("r1",), hidden_size=4)
|
||||
conditioning = {
|
||||
"tts_token_ids": torch.tensor([1, 2]),
|
||||
"tts_hidden_states": torch.ones(2, 4),
|
||||
}
|
||||
scheduler_output = SimpleNamespace(
|
||||
scheduled_new_reqs=[
|
||||
SimpleNamespace(
|
||||
req_id="r1",
|
||||
additional_information=serialize_additional_information(conditioning),
|
||||
)
|
||||
],
|
||||
scheduled_cached_reqs=SimpleNamespace(),
|
||||
)
|
||||
|
||||
OmniGPUModelRunner._update_additional_information(runner, scheduler_output)
|
||||
|
||||
assert torch.equal(runner.model_intermediate_buffer["r1"]["tts_token_ids"], conditioning["tts_token_ids"])
|
||||
assert torch.equal(
|
||||
runner.model_intermediate_buffer["r1"]["tts_hidden_states"],
|
||||
conditioning["tts_hidden_states"],
|
||||
)
|
||||
|
||||
|
||||
def test_update_intermediate_buffer_skips_empty_update():
|
||||
"""Validate that an empty update dict is a no-op."""
|
||||
runner = _make_runner(req_ids=("r1",), hidden_size=4)
|
||||
|
||||
Reference in new issue
Block a user