Merge branch 'main' into codex-vae-spatial-decode-auto
This commit is contained in:
186 files changed
+10814
-1165
No files matched your search
@@ -743,6 +743,48 @@ class TestTTSMethods:
|
||||
assert speech_server._is_tts is False
|
||||
assert speech_server._tts_stage is None
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("model_type", "expected_speed"),
|
||||
[("indextts2_5", 1.0), ("qwen3_tts", 2.0)],
|
||||
)
|
||||
def test_audio_encode_speed_respects_adapter_native_control(
|
||||
self,
|
||||
speech_server,
|
||||
model_type,
|
||||
expected_speed,
|
||||
):
|
||||
speech_server._tts_model_type = model_type
|
||||
request = OpenAICreateSpeechRequest(input="Hello", speed=2.0)
|
||||
|
||||
assert speech_server._audio_encode_speed(request) == expected_speed
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_non_streaming_native_speed_skips_generic_audio_adjustment(
|
||||
self,
|
||||
speech_server,
|
||||
mocker: MockerFixture,
|
||||
):
|
||||
async def mock_generate():
|
||||
yield create_mock_audio_output_for_test()
|
||||
|
||||
speech_server._tts_model_type = "indextts2_5"
|
||||
mocker.patch.object(
|
||||
speech_server,
|
||||
"_prepare_speech_generation",
|
||||
new=mocker.AsyncMock(return_value=("speech-native-speed", mock_generate(), {})),
|
||||
)
|
||||
create_audio = mocker.patch.object(
|
||||
speech_server,
|
||||
"create_audio",
|
||||
return_value=SimpleNamespace(audio_data=b"dummy", media_type="audio/wav"),
|
||||
)
|
||||
|
||||
await speech_server._generate_audio_bytes(OpenAICreateSpeechRequest(input="Hello", speed=2.0))
|
||||
|
||||
audio_obj = create_audio.call_args.args[0]
|
||||
assert isinstance(audio_obj, CreateAudio)
|
||||
assert audio_obj.speed == 1.0
|
||||
|
||||
def test_is_tts_detection_with_tts_stage(self, mocker: MockerFixture):
|
||||
"""Test TTS model detection when TTS stage exists."""
|
||||
mock_engine_client = mocker.MagicMock()
|
||||
@@ -2178,17 +2220,17 @@ class TestStreamingProtocolValidation:
|
||||
assert req.is_streaming() is False
|
||||
|
||||
def test_stream_validation_errors(self):
|
||||
"""stream=True requires response_format in ('pcm', 'wav') and speed=1.0."""
|
||||
"""The request schema validates formats; model-aware speed checks happen in serving."""
|
||||
with pytest.raises(ValidationError, match="requires response_format='pcm' or 'wav'"):
|
||||
OpenAICreateSpeechRequest(input="Hello", stream=True, response_format="mp3")
|
||||
with pytest.raises(ValidationError, match="Speed adjustment is not supported"):
|
||||
OpenAICreateSpeechRequest(input="Hello", stream=True, response_format="pcm", speed=2.0)
|
||||
request = OpenAICreateSpeechRequest(input="Hello", stream=True, response_format="pcm", speed=2.0)
|
||||
assert request.speed == 2.0
|
||||
|
||||
def test_stream_format_audio_validation_errors(self):
|
||||
with pytest.raises(ValidationError, match="requires response_format='pcm' or 'wav'"):
|
||||
OpenAICreateSpeechRequest(input="Hello", stream_format="audio", response_format="mp3")
|
||||
with pytest.raises(ValidationError, match="Speed adjustment is not supported"):
|
||||
OpenAICreateSpeechRequest(input="Hello", stream_format="audio", response_format="pcm", speed=2.0)
|
||||
request = OpenAICreateSpeechRequest(input="Hello", stream_format="audio", response_format="pcm", speed=2.0)
|
||||
assert request.speed == 2.0
|
||||
|
||||
def test_stream_valid(self):
|
||||
"""stream=True + response_format in ('pcm', 'wav') + speed=1.0 is accepted as SSE."""
|
||||
@@ -2271,6 +2313,18 @@ class TestStreamingResponse:
|
||||
models=mock_models,
|
||||
request_logger=mocker.MagicMock(),
|
||||
)
|
||||
speech_server._tts_model_type = None
|
||||
speech_server._adapter = None
|
||||
speech_server._diffusion_mode = False
|
||||
mocker.patch.object(speech_server, "_uses_native_speed_control", return_value=False)
|
||||
mocker.patch.object(
|
||||
speech_server,
|
||||
"create_error_response",
|
||||
side_effect=lambda message, **_: JSONResponse(
|
||||
status_code=400,
|
||||
content={"error": {"message": message}},
|
||||
),
|
||||
)
|
||||
|
||||
original_create_speech = speech_server.create_speech
|
||||
sig = signature(original_create_speech)
|
||||
@@ -2285,6 +2339,7 @@ class TestStreamingResponse:
|
||||
|
||||
app = FastAPI()
|
||||
app.add_api_route("/v1/audio/speech", speech_server.create_speech, methods=["POST"], response_model=None)
|
||||
app.state.speech_server = speech_server
|
||||
return app
|
||||
|
||||
@staticmethod
|
||||
@@ -2393,6 +2448,39 @@ class TestStreamingResponse:
|
||||
assert response.status_code in (400, 422)
|
||||
assert "audio/" not in response.headers.get("content-type", "")
|
||||
|
||||
@pytest.mark.parametrize("stream_format", ["sse", "audio"])
|
||||
def test_native_speed_control_accepts_streaming_speed(
|
||||
self,
|
||||
streaming_app,
|
||||
mocker: MockerFixture,
|
||||
stream_format: str,
|
||||
):
|
||||
speech_server = streaming_app.state.speech_server
|
||||
speech_server._tts_model_type = "indextts2_5"
|
||||
speech_server._uses_native_speed_control.return_value = True
|
||||
|
||||
async def prepare(request, request_id=None, **kwargs):
|
||||
del kwargs
|
||||
generator = speech_server.engine_client.generate(prompt={}, request_id=request_id)
|
||||
return request_id, generator, {"duration_factor": [1.0 / request.speed]}
|
||||
|
||||
mocker.patch.object(speech_server, "_prepare_speech_generation", side_effect=prepare)
|
||||
|
||||
client = TestClient(streaming_app)
|
||||
response = client.post(
|
||||
"/v1/audio/speech",
|
||||
json={
|
||||
"input": "Hello",
|
||||
"stream_format": stream_format,
|
||||
"response_format": "pcm",
|
||||
"speed": 2.0,
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
expected_media_type = "text/event-stream" if stream_format == "sse" else "audio/pcm"
|
||||
assert expected_media_type in response.headers["content-type"]
|
||||
|
||||
@pytest.fixture
|
||||
def erroring_streaming_app(self, mocker: MockerFixture):
|
||||
"""Test app whose mock engine raises mid-stream, to exercise the SSE error event."""
|
||||
@@ -2616,6 +2704,18 @@ def test_streaming_speech_session_config_accepts_non_streaming_mode():
|
||||
assert config.non_streaming_mode is True
|
||||
|
||||
|
||||
def test_streaming_speech_session_config_scopes_native_speed_to_http():
|
||||
with pytest.raises(
|
||||
ValidationError,
|
||||
match="native speed control is only available through HTTP streaming",
|
||||
):
|
||||
StreamingSpeechSessionConfig(
|
||||
stream_audio=True,
|
||||
response_format="pcm",
|
||||
speed=1.5,
|
||||
)
|
||||
|
||||
|
||||
class TestAsyncOmniSupportedTasks:
|
||||
"""Test that AsyncOmni reports correct supported tasks based on output modalities."""
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
Pure-Python registry/resolution logic; no model or GPU resources are loaded.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm_omni.entrypoints.openai.tts_adapters import (
|
||||
@@ -11,9 +14,19 @@ from vllm_omni.entrypoints.openai.tts_adapters import (
|
||||
ARTTSAdapter,
|
||||
DiffusionTTSAdapter,
|
||||
all_tts_model_types,
|
||||
detect_tts_model_type,
|
||||
resolve_adapter,
|
||||
)
|
||||
from vllm_omni.entrypoints.openai.tts_adapters.indextts2 import (
|
||||
IndexTTS2Adapter,
|
||||
IndexTTS25Adapter,
|
||||
indextts2_conditioning_cache_salt,
|
||||
)
|
||||
from vllm_omni.entrypoints.openai.tts_adapters.qwen3_tts import Qwen3TTSAdapter
|
||||
from vllm_omni.model_executor.models.indextts2 import prompt_utils
|
||||
from vllm_omni.model_executor.models.indextts2.tokenizer_v2_5 import (
|
||||
INDEXTTS25_TOKENIZER_FILE,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
@@ -35,6 +48,8 @@ EXPECTED_MODEL_TYPES = {
|
||||
"higgs_audio_v3",
|
||||
"glm_tts",
|
||||
"step_audio2",
|
||||
"indextts2",
|
||||
"indextts2_5",
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +99,113 @@ def test_qwen3_tts_metadata():
|
||||
assert issubclass(Qwen3TTSAdapter, ARTTSAdapter)
|
||||
|
||||
|
||||
def test_indextts_adapters_are_versioned():
|
||||
assert resolve_adapter("indextts2") is IndexTTS2Adapter
|
||||
assert resolve_adapter("indextts2_5") is IndexTTS25Adapter
|
||||
assert IndexTTS25Adapter.stage_keys == frozenset({"indextts2_5_talker"})
|
||||
assert detect_tts_model_type("indextts2_5_talker", None) == "indextts2_5"
|
||||
|
||||
|
||||
def test_indextts25_validates_explicit_language():
|
||||
adapter = IndexTTS25Adapter(type("Context", (), {"server": object()})())
|
||||
|
||||
assert adapter._validate_extra_params({"lang": "ja"}) is None
|
||||
assert "Unsupported IndexTTS 2.5 language" in adapter._validate_extra_params({"lang": "xx-invalid"})
|
||||
|
||||
|
||||
def _indextts25_adapter_and_request(*, speed: float):
|
||||
server = SimpleNamespace(
|
||||
uploaded_speakers={},
|
||||
_validate_ref_audio_format=lambda ref_audio: None,
|
||||
)
|
||||
adapter = IndexTTS25Adapter(SimpleNamespace(server=server))
|
||||
request = SimpleNamespace(
|
||||
input="hello",
|
||||
voice="alloy",
|
||||
ref_audio=object(),
|
||||
max_new_tokens=None,
|
||||
extra_params=None,
|
||||
speed=speed,
|
||||
)
|
||||
return adapter, request
|
||||
|
||||
|
||||
def test_indextts25_uses_native_speed_control_duration_factor():
|
||||
adapter, fast_request = _indextts25_adapter_and_request(speed=2.0)
|
||||
_, slow_request = _indextts25_adapter_and_request(speed=0.5)
|
||||
|
||||
assert adapter.native_speed_control is True
|
||||
assert adapter.validate(fast_request) is None
|
||||
assert adapter.validate(slow_request) is None
|
||||
assert asyncio.run(adapter._build_params(fast_request))["duration_factor"] == [0.5]
|
||||
assert asyncio.run(adapter._build_params(slow_request))["duration_factor"] == [2.0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("speed", [0.49, 2.01])
|
||||
def test_indextts25_rejects_out_of_range_native_speed(speed):
|
||||
adapter, request = _indextts25_adapter_and_request(speed=speed)
|
||||
|
||||
assert adapter.validate(request) == "IndexTTS 2.5 speed must be between 0.5 and 2.0"
|
||||
|
||||
|
||||
def test_indextts25_speed_does_not_change_conditioning_cache_salt():
|
||||
adapter, fast_request = _indextts25_adapter_and_request(speed=2.0)
|
||||
_, slow_request = _indextts25_adapter_and_request(speed=0.5)
|
||||
slow_request.ref_audio = fast_request.ref_audio
|
||||
|
||||
fast_params = asyncio.run(adapter._build_params(fast_request))
|
||||
slow_params = asyncio.run(adapter._build_params(slow_request))
|
||||
|
||||
assert indextts2_conditioning_cache_salt(
|
||||
fast_request,
|
||||
fast_params,
|
||||
) == indextts2_conditioning_cache_salt(slow_request, slow_params)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("hf_config", "expected_tokenizer_file"),
|
||||
[
|
||||
(SimpleNamespace(tokenizer_file="custom-tokenizer.tiktoken"), "custom-tokenizer.tiktoken"),
|
||||
(SimpleNamespace(), INDEXTTS25_TOKENIZER_FILE),
|
||||
],
|
||||
)
|
||||
def test_indextts25_build_uses_configured_tokenizer_file(
|
||||
monkeypatch,
|
||||
hf_config,
|
||||
expected_tokenizer_file,
|
||||
):
|
||||
captured = {}
|
||||
|
||||
def fake_estimate(*args, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return 4
|
||||
|
||||
async def fake_build_params(request):
|
||||
return {"lang": ["en"], "text_normalization": [True]}
|
||||
|
||||
monkeypatch.setattr(
|
||||
prompt_utils,
|
||||
"estimate_indextts2_prefill_prompt_len",
|
||||
fake_estimate,
|
||||
)
|
||||
server = SimpleNamespace(
|
||||
engine_client=SimpleNamespace(
|
||||
model_config=SimpleNamespace(
|
||||
model="/model",
|
||||
hf_config=hf_config,
|
||||
)
|
||||
)
|
||||
)
|
||||
adapter = IndexTTS25Adapter(SimpleNamespace(server=server))
|
||||
monkeypatch.setattr(adapter, "_build_params", fake_build_params)
|
||||
request = SimpleNamespace(input="hello", ref_audio=None)
|
||||
|
||||
prepared = asyncio.run(adapter.build(request, [], False))
|
||||
|
||||
assert prepared.prompt["prompt_token_ids"] == [1] * 4
|
||||
assert captured["tokenizer_file"] == expected_tokenizer_file
|
||||
|
||||
|
||||
def test_diffusion_adapter_extra_body_params_fallback():
|
||||
class _DiffAdapter(DiffusionTTSAdapter):
|
||||
name = "diff_probe"
|
||||
|
||||
@@ -149,6 +149,7 @@ _PIPELINE_STAGES = [
|
||||
"glm_tts_dit",
|
||||
"higgs_audio_v2",
|
||||
"higgs_audio_v3",
|
||||
"indextts2_5_talker",
|
||||
"indextts2_s2mel_decoder",
|
||||
"indextts2_talker",
|
||||
"latent_generator",
|
||||
@@ -213,18 +214,23 @@ _CLAIMED_ARCH_CASES = [
|
||||
("fused_thinker_talker", "Qwen3TTSForConditionalGeneration"),
|
||||
]
|
||||
|
||||
_REACHABLE = list(itertools.product(_STAGES, _UNCLAIMED_ARCHS)) + _CLAIMED_ARCH_CASES
|
||||
# The frozen ladder can only be compared over stages it knew about. New
|
||||
# adapter-owned stages are covered by their adapter tests and by the registry
|
||||
# completeness checks below.
|
||||
_NEW_ADAPTER_STAGE_KEYS = all_tts_stage_keys() - _LEGACY_TTS_MODEL_STAGES
|
||||
_LEGACY_REACHABLE_STAGES = [stage for stage in _STAGES if stage not in _NEW_ADAPTER_STAGE_KEYS]
|
||||
_REACHABLE = list(itertools.product(_LEGACY_REACHABLE_STAGES, _UNCLAIMED_ARCHS)) + _CLAIMED_ARCH_CASES
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("model_stage", "model_arch"), _REACHABLE)
|
||||
def test_detection_matches_legacy_ladder(model_stage, model_arch):
|
||||
"""Registry detection is identical to the ladder it replaced.
|
||||
|
||||
Covers every ``model_stage`` any in-tree pipeline emits (``_PIPELINE_STAGES``,
|
||||
plus negatives) against every architecture no adapter claims, and each
|
||||
claimed architecture against the stage keys it really ships with. Pairing a
|
||||
claimed architecture with an unrelated model's stage key is excluded because
|
||||
no pipeline can produce it, and is covered separately by
|
||||
Covers every stage the frozen ladder knew about, plus non-TTS pipeline
|
||||
stages and negatives, against every architecture no adapter claims. New
|
||||
adapter-owned stages are tested by their adapter suites. Pairing a claimed
|
||||
architecture with an unrelated model's stage key is excluded because no
|
||||
pipeline can produce it, and is covered separately by
|
||||
``test_arch_matching_is_a_fallback_not_an_override``.
|
||||
"""
|
||||
assert detect_tts_model_type(model_stage, model_arch) == _legacy_detect(model_stage, model_arch)
|
||||
@@ -251,7 +257,7 @@ def test_arch_matching_is_a_fallback_not_an_override():
|
||||
|
||||
def test_stage_keys_cover_legacy_stage_set():
|
||||
"""No stage key was dropped when the module constants were deleted."""
|
||||
assert all_tts_stage_keys() == frozenset(_LEGACY_TTS_MODEL_STAGES)
|
||||
assert _LEGACY_TTS_MODEL_STAGES <= all_tts_stage_keys()
|
||||
|
||||
|
||||
def test_pipeline_stage_list_is_complete():
|
||||
|
||||
@@ -284,6 +284,37 @@ def test_serve_cli_accepts_diffusion_pipeline_profiler_flag():
|
||||
assert stage_cfg["engine_args"]["enable_diffusion_pipeline_profiler"] is True
|
||||
|
||||
|
||||
def test_serve_cli_forwards_distilled_lora_to_diffusion_stage():
|
||||
"""Ensure startup distilled LoRA options reach the online diffusion stage."""
|
||||
parser = TrackingArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
OmniServeCommand().subparser_init(subparsers)
|
||||
|
||||
args = parser.parse_args(
|
||||
[
|
||||
"serve",
|
||||
"Wan-AI/Wan2.2-T2V-A14B-Diffusers",
|
||||
"--omni",
|
||||
"--lora-backend",
|
||||
"distill",
|
||||
"--lora-path",
|
||||
"/models/high.safetensors",
|
||||
"/models/low.safetensors",
|
||||
]
|
||||
)
|
||||
|
||||
explicit_kwargs = args.get_explicit_kwargs_dict()
|
||||
stage_cfg = AsyncOmniEngine._create_default_diffusion_stage_cfg(explicit_kwargs)[0]
|
||||
engine_args = stage_cfg["engine_args"]
|
||||
|
||||
assert explicit_kwargs["lora_backend"] == "distill"
|
||||
assert engine_args["lora_backend"] == "distill"
|
||||
assert engine_args["lora_path"] == [
|
||||
"/models/high.safetensors",
|
||||
"/models/low.safetensors",
|
||||
]
|
||||
|
||||
|
||||
def test_serve_cli_forwards_distributed_offload_residency():
|
||||
"""Ensure the two-GPU DLO placement controls reach the diffusion stage."""
|
||||
parser = TrackingArgumentParser()
|
||||
|
||||
Reference in new issue
Block a user