[feat][Qwen3TTS] Simple dynamic TTFA based on Code2Wav load (#1714)
Signed-off-by: pablo <pablo@agigo.ai> Co-authored-by: pablo <pablo@agigo.ai>
This commit is contained in:
1 parent
2fdc647ed7
commit
1d0a97f0d1
14 files changed
+221
-121
No files matched your search
@@ -29,7 +29,7 @@ class CUDAGraphDecoderWrapper:
|
||||
output = wrapper.decode(codes) # Automatically uses CUDA graph if possible
|
||||
"""
|
||||
|
||||
DEFAULT_CAPTURE_SIZES = [25, 50, 100, 150, 200, 250, 300]
|
||||
DEFAULT_CAPTURE_SIZES = [2, 4, 8, 16, 25, 32, 50, 100, 150, 200, 250, 300]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -96,10 +96,6 @@ runtime:
|
||||
# Align with Omni: small chunks with sufficient context overlap.
|
||||
codec_chunk_frames: 25
|
||||
codec_left_context_frames: 25
|
||||
# First chunk size for reduced TTFA (0 = disabled).
|
||||
# When > 0, emits small chunks every N frames during the initial phase,
|
||||
# then switches to codec_chunk_frames cadence.
|
||||
initial_codec_chunk_frames: 0
|
||||
|
||||
edges:
|
||||
- from: 0
|
||||
|
||||
@@ -98,10 +98,6 @@ runtime:
|
||||
# Align with Omni: small chunks with sufficient context overlap.
|
||||
codec_chunk_frames: 25
|
||||
codec_left_context_frames: 25
|
||||
# First chunk size for reduced TTFA (0 = disabled).
|
||||
# When > 0, emits small chunks every N frames during the initial phase,
|
||||
# then switches to codec_chunk_frames cadence.
|
||||
initial_codec_chunk_frames: 0
|
||||
|
||||
edges:
|
||||
- from: 0
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
|
||||
def max_ic_for_chunk_size(chunk_size: int) -> int:
|
||||
"""Largest power of 2 strictly less than chunk_size."""
|
||||
if chunk_size <= 2:
|
||||
return 1
|
||||
return 1 << ((chunk_size - 1).bit_length() - 1)
|
||||
|
||||
|
||||
def compute_dynamic_initial_chunk_size(
|
||||
active_requests: int,
|
||||
max_batch_size: int,
|
||||
max_ic: int,
|
||||
) -> int:
|
||||
"""Select IC from power-of-2 steps [2, 4, ..., max_ic] based on load factor.
|
||||
|
||||
- Low load: small IC (faster TTFA).
|
||||
- High load: large IC (amortise decode cost).
|
||||
"""
|
||||
steps: list[int] = []
|
||||
v = 2
|
||||
while v <= max_ic:
|
||||
steps.append(v)
|
||||
v <<= 1
|
||||
if not steps:
|
||||
return max(1, max_ic)
|
||||
if max_batch_size <= 0:
|
||||
return steps[0]
|
||||
load_factor = min(active_requests / max_batch_size, 1.0)
|
||||
idx = int(round(load_factor * (len(steps) - 1)))
|
||||
return steps[idx]
|
||||
@@ -5,6 +5,11 @@ from typing import Any
|
||||
import torch
|
||||
from vllm.logger import init_logger
|
||||
|
||||
from vllm_omni.model_executor.stage_input_processors.chunk_size_utils import (
|
||||
compute_dynamic_initial_chunk_size,
|
||||
max_ic_for_chunk_size,
|
||||
)
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
@@ -14,7 +19,7 @@ def talker2code2wav(
|
||||
prompt: Any = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
) -> list[Any]:
|
||||
"""Non-async processor: wait for talker to finish, then pass all codes to code2wav at once."""
|
||||
"""Non-async: collect all talker codes, then pass to code2wav at once."""
|
||||
from vllm_omni.inputs.data import OmniTokensPrompt
|
||||
from vllm_omni.model_executor.stage_input_processors.qwen3_omni import _validate_stage_inputs
|
||||
|
||||
@@ -94,9 +99,12 @@ def talker2code2wav_async_chunk(
|
||||
cfg = raw_cfg.get("extra", raw_cfg) if isinstance(raw_cfg, dict) else {}
|
||||
chunk_size = int(cfg.get("codec_chunk_frames", 25))
|
||||
left_context_size_config = int(cfg.get("codec_left_context_frames", 25))
|
||||
initial_chunk_size = int(cfg.get("initial_codec_chunk_frames", 0))
|
||||
# Per-request override (takes priority over stage config)
|
||||
|
||||
# Per-request override takes priority over dynamic IC.
|
||||
per_request_override = False
|
||||
initial_chunk_size = 0
|
||||
additional_information = getattr(request, "additional_information", None)
|
||||
|
||||
if (
|
||||
additional_information is not None
|
||||
and hasattr(additional_information, "entries")
|
||||
@@ -105,12 +113,32 @@ def talker2code2wav_async_chunk(
|
||||
entry = additional_information.entries["initial_codec_chunk_frames"]
|
||||
if entry.list_data is not None and len(entry.list_data) == 1:
|
||||
initial_chunk_size = int(entry.list_data[0])
|
||||
per_request_override = True
|
||||
|
||||
# Dynamic IC: always derived from chunk_size, recomputed every call to adapt to load.
|
||||
if not per_request_override:
|
||||
max_ic = max_ic_for_chunk_size(chunk_size)
|
||||
active = sum(1 for v in transfer_manager.code_prompt_token_ids.values() if len(v) > 0)
|
||||
capacity = getattr(transfer_manager, "scheduler_max_num_seqs", 1)
|
||||
initial_chunk_size = compute_dynamic_initial_chunk_size(active, capacity, max_ic)
|
||||
logger.debug(
|
||||
"Dynamic IC: active=%d, capacity=%d, max_ic=%d, ic=%d, cs=%d, req=%s, keys=%d",
|
||||
active,
|
||||
capacity,
|
||||
max_ic,
|
||||
initial_chunk_size,
|
||||
chunk_size,
|
||||
request_id,
|
||||
len(transfer_manager.code_prompt_token_ids),
|
||||
)
|
||||
|
||||
if chunk_size <= 0 or left_context_size_config < 0 or initial_chunk_size < 0:
|
||||
raise ValueError(
|
||||
f"Invalid codec chunk config: codec_chunk_frames={chunk_size}, "
|
||||
f"codec_left_context_frames={left_context_size_config}, "
|
||||
f"initial_codec_chunk_frames={initial_chunk_size}"
|
||||
)
|
||||
|
||||
if initial_chunk_size > chunk_size:
|
||||
logger.warning(
|
||||
"initial_codec_chunk_frames=%d > codec_chunk_frames=%d, clamping to codec_chunk_frames.",
|
||||
@@ -120,8 +148,6 @@ def talker2code2wav_async_chunk(
|
||||
initial_chunk_size = chunk_size
|
||||
length = len(transfer_manager.code_prompt_token_ids[request_id])
|
||||
|
||||
# Avoid emitting empty chunks during normal streaming. If the request is
|
||||
# finished and nothing was produced, emit an EOF marker.
|
||||
if length <= 0:
|
||||
if finished:
|
||||
return {
|
||||
@@ -130,34 +156,32 @@ def talker2code2wav_async_chunk(
|
||||
}
|
||||
return None
|
||||
|
||||
in_initial_phase = initial_chunk_size > 0 and length <= chunk_size
|
||||
in_initial_phase = initial_chunk_size > 0 and initial_chunk_size < chunk_size and length < chunk_size
|
||||
|
||||
if in_initial_phase:
|
||||
# Initial-chunk phase: emit every initial_chunk_size frames with full accumulated context.
|
||||
already_sent = transfer_manager.put_req_chunk[request_id] * initial_chunk_size
|
||||
pending = length - already_sent
|
||||
if pending <= 0:
|
||||
# IC phase: emit every initial_chunk_size frames with growing left context.
|
||||
if not finished and length % initial_chunk_size != 0:
|
||||
return None
|
||||
if pending < initial_chunk_size and not finished:
|
||||
return None
|
||||
context_length = min(pending, initial_chunk_size)
|
||||
end_index = length
|
||||
left_context_size = max(0, length - context_length)
|
||||
window_frames = transfer_manager.code_prompt_token_ids[request_id][:length]
|
||||
context_length = (
|
||||
length % initial_chunk_size if (finished and length % initial_chunk_size != 0) else initial_chunk_size
|
||||
)
|
||||
else:
|
||||
# Normal phase: standard chunk_size cadence with left_context sliding window.
|
||||
# Offset by initial_coverage so normal starts from where the initial-chunk phase left off.
|
||||
initial_coverage = (chunk_size // initial_chunk_size) * initial_chunk_size if initial_chunk_size > 0 else 0
|
||||
# Normal phase: offset so the first normal emit picks up after IC phase.
|
||||
# IC is stateless (may change with load); any mismatch is absorbed by left_context.
|
||||
initial_coverage = (
|
||||
((chunk_size - 1) // initial_chunk_size) * initial_chunk_size if 0 < initial_chunk_size < chunk_size else 0
|
||||
)
|
||||
adjusted = length - initial_coverage
|
||||
chunk_length = adjusted % chunk_size
|
||||
if chunk_length != 0 and not finished:
|
||||
if not finished and adjusted % chunk_size != 0:
|
||||
return None
|
||||
chunk_length = adjusted % chunk_size
|
||||
context_length = chunk_length if chunk_length != 0 else chunk_size
|
||||
end_index = min(length, left_context_size_config + context_length)
|
||||
left_context_size = max(0, int(end_index - context_length))
|
||||
window_frames = transfer_manager.code_prompt_token_ids[request_id][-end_index:]
|
||||
|
||||
# Match offline Base ICL decoding by prepending ref_code only once to the first decoder window.
|
||||
end_index = min(length, left_context_size_config + context_length)
|
||||
left_context_size = max(0, end_index - context_length)
|
||||
window_frames = transfer_manager.code_prompt_token_ids[request_id][-end_index:]
|
||||
|
||||
# Prepend ref_code to the first decoder window only.
|
||||
if transfer_manager.put_req_chunk[request_id] == 0:
|
||||
ref_code = request_payload.pop(request_id, None)
|
||||
if isinstance(ref_code, torch.Tensor) and ref_code.numel() > 0:
|
||||
@@ -165,7 +189,6 @@ def talker2code2wav_async_chunk(
|
||||
window_frames = ref_frames + window_frames
|
||||
left_context_size += len(ref_frames)
|
||||
|
||||
# Pack context + chunk into codebook-major flat codes for adapter.
|
||||
code_predictor_codes = torch.tensor(window_frames).transpose(0, 1).reshape(-1).tolist()
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user