Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7fd4b38
perf(minicpmo): stage1 sampling fusion kernel + measurement infra
y-null Oct 19, 2026
b5ec4b6
test(minicpmo): defer NPU device construction in fused-prelude tests
y-null Oct 19, 2026
3672648
Merge branch 'main' into perf/minicpmo-opt-20261019
amy-why-3459 Oct 19, 2026
7bd410c
perf(minicpmo): batch the per-request cache split
y-null Oct 19, 2026
087e0e9
perf(minicpmo): clone the conformer splits and document the cache lif…
y-null Oct 19, 2026
876b5d2
fix(ci): classify the minicpmo token2wav env vars in the inventory
y-null Oct 19, 2026
e176287
refactor(minicpmo): prefix the new env switches with the model name
y-null Oct 19, 2026
b1047e7
docs(minicpmo): state the chunk-pinning bound as an assumption
y-null Oct 19, 2026
fc9cf24
refactor(minicpmo): drop the redundant device-spk env switch
y-null Oct 19, 2026
58bec20
refactor(minicpmo): replace the fused-prelude env switch with runtime…
y-null Oct 19, 2026
c5f27a3
style(minicpmo): keep the fused-prelude fallback warning on one line
y-null Oct 19, 2026
64fd37c
feat(minicpmo): expose the codec prelude as a stage config switch
y-null Oct 19, 2026
202ca50
fix(minicpmo): wire the fused-prelude switch to the stage connector e…
y-null Oct 19, 2026
e71d005
test(minicpmo): cover the connector-extra read path for the prelude s…
y-null Oct 19, 2026
0a7dc50
Merge branch 'main' into perf/minicpmo-opt-20261019
y-null Oct 19, 2026
4a7486c
[Bugfix] Parse token2wav_device_spk strictly so a quoted "false" works
y-null Oct 20, 2026
15a42f2
Merge branch 'main' into perf/minicpmo-opt-20261019
y-null Oct 20, 2026
63f193c
[Bugfix] Parse every code2wav stage boolean through one strict helper
y-null Oct 20, 2026
505d911
[Bugfix] Make MiniCPM-o code2wav stage-extra booleans uniformly strict
y-null Oct 20, 2026
21171a7
[Bugfix] Treat a null TF32 override as unset and reject unknown values
y-null Oct 20, 2026
cfe0dd1
[CI] Use a non-dictionary token in the TF32 rejection test
y-null Oct 20, 2026
e41618d
[Bugfix] Resolve the TF32 mode once at startup on every platform
y-null Oct 20, 2026
56a0e5b
Merge branch 'main' into perf/minicpmo-opt-20261019
y-null Oct 20, 2026
dfeb990
[CI] Fix the two MiniCPM-o tests that the L1/L4 gates caught
y-null Oct 20, 2026
1978708
Merge branch 'main' into perf/minicpmo-opt-20261019
amy-why-3459 Oct 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,24 @@ def test_tf32_mode_reads_shipped_yaml_key(monkeypatch):
assert _tf32_mode({}) == "tf32"


def test_tf32_mode_null_means_unset_and_typos_raise(monkeypatch):
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_code2wav import _tf32_mode

monkeypatch.delenv("MINICPMO_CODE2WAV_TF32", raising=False)
# An explicit null means "unset": fall through to the alias, then the default.
assert _tf32_mode({"token2wav_allow_tf32": None}) == "tf32"
assert _tf32_mode({"token2wav_allow_tf32": None, "code2wav_allow_tf32": False}) == "off"
assert _tf32_mode({"token2wav_allow_tf32": "off"}) == "off"
assert _tf32_mode({"token2wav_allow_tf32": " TF32 "}) == "tf32"
with pytest.raises(ValueError, match="allow_tf32"):
_tf32_mode({"token2wav_allow_tf32": "maybe"})
with pytest.raises(ValueError, match="allow_tf32"):
_tf32_mode({"token2wav_allow_tf32": 2})
monkeypatch.setenv("MINICPMO_CODE2WAV_TF32", "maybe")
with pytest.raises(ValueError, match="allow_tf32"):
_tf32_mode({})


def _encoder_dispatch_backend(eager, precaptured, dynamic):
return SimpleNamespace(
flow=SimpleNamespace(training=False),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""Regression tests for the ``token2wav_device_spk`` backend switch.

The switch selects between the on-device CAM++ speaker embedding and the CPU
onnxruntime fallback used for accuracy triage. ``bool("false")`` is ``True``,
so a quoted YAML/JSON stage override would silently keep the device path on and
make the fallback unusable. These tests drive the real backend-selection branch
in ``_build_backend`` (only the model assets are faked) and assert which
embedding path gets enabled.
"""

from __future__ import annotations

from types import SimpleNamespace

import pytest

from vllm_omni.model_executor.models.minicpmo_4_5 import (
minicpmo_4_5_code2wav as code2wav_module,
)
from vllm_omni.model_executor.models.minicpmo_4_5 import (
minicpmo_4_5_token2wav as token2wav_module,
)
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_code2wav import (
MiniCPMO45Code2Wav,
)
from vllm_omni.platforms import current_omni_platform

pytestmark = [pytest.mark.core_model, pytest.mark.cpu]


class _FakeToken2Wav:
def __init__(self, path, **kwargs):
self.path = path
self.kwargs = kwargs
self.device_spk_calls = 0
self.trt_spk_calls = 0

def enable_device_spk_embedding(self):
self.device_spk_calls += 1

def enable_trt_spk_embedding(self):
self.trt_spk_calls += 1


class _FakeBackend:
def __init__(self, token2wav, **kwargs):
self.token2wav = token2wav
self.kwargs = kwargs


@pytest.fixture
def npu_platform(monkeypatch):
"""Route ``_build_backend`` down the NPU branch on a CPU-only machine."""
monkeypatch.setattr(current_omni_platform, "is_npu", lambda: True)
monkeypatch.setattr(current_omni_platform, "is_cuda", lambda: False)


def _build_backend(tmp_path, monkeypatch, extra):
"""Run ``_build_backend`` with fake assets, returning (model, token2wav)."""
assets = tmp_path / "assets"
(assets / "token2wav").mkdir(parents=True)
(assets / "HT_ref_audio.wav").write_bytes(b"")
created = {}

def _fake_token2wav(path, **kwargs):
created["token2wav"] = _FakeToken2Wav(path, **kwargs)
return created["token2wav"]

monkeypatch.setattr(token2wav_module, "MiniCPMO45Token2wav", _fake_token2wav)
monkeypatch.setattr(code2wav_module, "BatchedToken2Wav", _FakeBackend)
config = SimpleNamespace(
model_config=SimpleNamespace(
model=str(tmp_path),
stage_connector_config={"extra": extra},
)
)
model = MiniCPMO45Code2Wav(vllm_config=config)
model._build_backend()
# Reaching the end proves the switch branch ran, not just the parser.
assert isinstance(model.backend, _FakeBackend)
return model, created["token2wav"]


@pytest.mark.parametrize("value", [False, "false", " FALSE ", 0, "0"])
def test_explicit_false_keeps_the_cpu_onnxruntime_fallback(tmp_path, monkeypatch, npu_platform, value):
_, token2wav = _build_backend(tmp_path, monkeypatch, {"token2wav_device_spk": value})
assert token2wav.device_spk_calls == 0
assert token2wav.trt_spk_calls == 0


@pytest.mark.parametrize("value", [None, True, "true", 1, "1"])
def test_unset_or_true_enables_the_device_embedding(tmp_path, monkeypatch, npu_platform, value):
extra = {} if value is None else {"token2wav_device_spk": value}
_, token2wav = _build_backend(tmp_path, monkeypatch, extra)
assert token2wav.device_spk_calls == 1


@pytest.mark.parametrize("value", ["maybe", "yes", 2, 1.5, []])
def test_invalid_value_is_rejected(tmp_path, monkeypatch, npu_platform, value):
with pytest.raises(ValueError, match="token2wav_device_spk"):
_build_backend(tmp_path, monkeypatch, {"token2wav_device_spk": value})


def test_invalid_value_is_rejected_off_npu_too(tmp_path, monkeypatch):
"""The flag is parsed before the platform branch, so a typo fails anywhere."""
monkeypatch.setattr(current_omni_platform, "is_npu", lambda: False)
monkeypatch.setattr(current_omni_platform, "is_cuda", lambda: False)

with pytest.raises(ValueError, match="token2wav_device_spk"):
_build_backend(tmp_path, monkeypatch, {"token2wav_device_spk": "maybe"})


_OTHER_DEFAULTS = {
"token2wav_float16",
"token2wav_trt",
"code2wav_bfloat16_attention_cache",
"cfm_graph_precapture",
"token2wav_ref_prefetch",
"token2wav_ref_prefetch_setup",
"enable_hift_graph",
"enable_cfm_graph",
"cfm_onset_merge",
"enable_code2wav_encoder_graph",
"code2wav_encoder_capture_after_precapture",
"cfm_fused_body",
"cfm_slot_pool",
"enable_whole_euler",
"cfm_row_offset_merge",
"cfm_encoder_cuda_graph",
"cfm_cross_turn_buckets",
"cfm_precapture_empty_cache",
"cfm_drop_upstream_att_buffer",
}


@pytest.mark.parametrize("key", sorted(_OTHER_DEFAULTS))
def test_other_stage_extra_flags_are_strict(tmp_path, monkeypatch, npu_platform, key):
with pytest.raises(ValueError, match=key):
_build_backend(tmp_path, monkeypatch, {key: "maybe"})


def test_quoted_false_disables_other_stage_flags(tmp_path, monkeypatch, npu_platform):
model, _ = _build_backend(
tmp_path,
monkeypatch,
{
"cfm_graph_precapture": "false",
"enable_hift_graph": "false",
"token2wav_ref_prefetch": "false",
},
)
assert model._precapture_pending is False
assert model._hift_graph_config["enabled"] is False
assert model._ref_prefetch_enabled is False


def test_quoted_false_disables_default_on_flags(tmp_path, monkeypatch, npu_platform):
"""`cfm_fused_body` and `enable_whole_euler` default on: a quoted "false" must still turn them off."""
model, _ = _build_backend(
tmp_path,
monkeypatch,
{"cfm_fused_body": "false", "enable_whole_euler": "false"},
)
assert model._cfm_graph_config["fused_body"] is False
assert model._cfm_graph_config["enable_whole_euler"] is False


def test_quoted_true_enables_flags_previously_compared_with_is_true(tmp_path, monkeypatch, npu_platform):
model, _ = _build_backend(
tmp_path,
monkeypatch,
{
"cfm_row_offset_merge": "true",
"cfm_slot_pool": "true",
"cfm_encoder_cuda_graph": "true",
"enable_code2wav_encoder_graph": "true",
"cfm_cross_turn_buckets": "true",
"cfm_precapture_empty_cache": "true",
},
)
assert model._cfm_graph_config["row_offset_merge"] is True
assert model._cfm_graph_config["slot_pool"] is True
assert model._encoder_graph_config["enabled"] is True
assert model._chunk_encoder_graph_config["enabled"] is True
assert model._cross_turn_buckets is True
assert model._precapture_empty_cache is True


def test_explicit_null_falls_back_to_the_default(tmp_path, monkeypatch, npu_platform):
"""`key: ~` in a YAML override means "unset", not "false"."""
model, token2wav = _build_backend(
tmp_path,
monkeypatch,
{
"token2wav_device_spk": None,
"cfm_fused_body": None,
"cfm_graph_precapture": None,
"enable_whole_euler": None,
},
)
assert token2wav.device_spk_calls == 1
assert model._cfm_graph_config["fused_body"] is True
assert model._cfm_graph_config["enable_whole_euler"] is True
assert model._precapture_pending is True


@pytest.mark.parametrize("key", ["token2wav_allow_tf32", "code2wav_allow_tf32"])
def test_invalid_tf32_value_fails_at_startup_even_off_cuda(tmp_path, monkeypatch, npu_platform, key):
"""The TF32 mode is resolved in `__init__`, so a typo cannot wait for the first forward."""
with pytest.raises(ValueError, match="allow_tf32"):
_build_backend(tmp_path, monkeypatch, {key: "maybe"})


def test_invalid_tf32_env_fails_at_startup_even_off_cuda(tmp_path, monkeypatch, npu_platform):
monkeypatch.setenv("MINICPMO_CODE2WAV_TF32", "maybe")
with pytest.raises(ValueError, match="allow_tf32"):
_build_backend(tmp_path, monkeypatch, {})


def test_tf32_mode_is_resolved_once_and_reused(tmp_path, monkeypatch, npu_platform):
model, _ = _build_backend(tmp_path, monkeypatch, {"token2wav_allow_tf32": "off"})
assert model._tf32_mode == "off"
# Mutating the stage config afterwards must not re-read it per forward.
model.vllm_config.model_config.stage_connector_config["extra"]["token2wav_allow_tf32"] = True
assert model._tf32_mode == "off"
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from vllm_omni.core.sched.output import OmniRequestPrewarm
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
from vllm_omni.platforms import current_omni_platform

pytestmark = [pytest.mark.core_model, pytest.mark.cpu]

Expand All @@ -47,6 +48,7 @@ def _prefetch_model(
ref_prefetch: bool | None = None,
prefetch_setup: bool | None = None,
max_waiters: int = 1,
allow_tf32: bool | None = None,
) -> tuple[MiniCPMO45Code2Wav, _FakeToken2Wav]:
"""Code2Wav over the fake Token2wav; ``token2wav.cold_setups`` records the
prompt key of every setup built on a setup-cache miss."""
Expand All @@ -57,6 +59,8 @@ def _prefetch_model(
extra["token2wav_ref_prefetch"] = ref_prefetch
if prefetch_setup is not None:
extra["token2wav_ref_prefetch_setup"] = prefetch_setup
if allow_tf32 is not None:
extra["token2wav_allow_tf32"] = allow_tf32
token2wav = _FakeToken2Wav()
backend = BatchedToken2Wav(token2wav, setup_cache_size=setup_cache_size)
_enable_fake_ragged_kernel(backend)
Expand Down Expand Up @@ -739,8 +743,10 @@ def test_bad_prefetch_payload_is_skipped_without_raising(payload, warns, mocker)
def test_prefetch_phases_run_under_the_stage_matmul_policy(allow_tf32, monkeypatch):
# The prefetch runs chunk 0's preparation calls outside forward, so it must
# apply the same TF32 policy as forward and restore the caller's afterwards.
model, _ = _prefetch_model(prefetch_setup=True)
model.vllm_config.model_config.stage_connector_config["extra"]["token2wav_allow_tf32"] = allow_tf32
# The mode is resolved once at construction and every call site reuses it.
monkeypatch.setattr(current_omni_platform, "is_cuda", lambda: True)
model, _ = _prefetch_model(prefetch_setup=True, allow_tf32=allow_tf32)
assert model._tf32_mode == ("tf32" if allow_tf32 else "off")
seen: list[tuple[str, bool]] = []
for name in ("prepare_prompt", "setup_batch"):
original = getattr(model.backend, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2474,9 +2474,13 @@ def entry(*, graph_batch: int, fill, **_: object) -> tuple:


@pytest.mark.parametrize("fail", [False, True])
def test_vocoder_restores_tf32_policy(fail):
def test_vocoder_restores_tf32_policy(fail, monkeypatch):
from vllm_omni.model_executor.models.minicpmo_4_5.minicpmo_4_5_code2wav import MiniCPMO45Code2Wav
from vllm_omni.platforms import current_omni_platform

# The policy is a no-op off CUDA; pin it so the restore path stays covered
# on every CI platform.
monkeypatch.setattr(current_omni_platform, "is_cuda", lambda: True)
previous = torch.backends.cuda.matmul.allow_tf32

def forward(*args, **kwargs):
Expand All @@ -2485,7 +2489,9 @@ def forward(*args, **kwargs):
raise RuntimeError("injected")
return "ok"

model = SimpleNamespace(_extra_config=lambda: {"token2wav_allow_tf32": True}, _forward_impl=forward)
# `_tf32_mode` is resolved in `__init__` now, so the stub model carries the
# resolved value instead of a config the policy would re-read per forward.
model = SimpleNamespace(_tf32_mode="tf32", _forward_impl=forward)
if fail:
with pytest.raises(RuntimeError, match="injected"):
MiniCPMO45Code2Wav.forward(model)
Expand Down
Loading
Loading