[FEAT] support multi-stage deployment (#2396)
Signed-off-by: ZhengWG <zwg0606@gmail.com> Signed-off-by: Zheng Wengang <zwg0606@gmail.com> Signed-off-by: Peiqi Yin <60515999+yinpeiqi@users.noreply.github.com> Signed-off-by: yinpe <11810305@mail.sustech.edu.cn> Signed-off-by: yinpeiqi <yinpeiqi809@gmail.com> Co-authored-by: Peiqi Yin <60515999+yinpeiqi@users.noreply.github.com> Co-authored-by: yinpe <11810305@mail.sustech.edu.cn> Co-authored-by: yinpeiqi <yinpeiqi809@gmail.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com> Co-authored-by: Gao Han <hgaoaf@connect.ust.hk> Co-authored-by: Chenguang Zheng <645327136@qq.com>
This commit is contained in:
55 files changed
+4684
-3407
No files matched your search
@@ -63,15 +63,11 @@ def _decode_additional_information(raw_info: Any) -> dict[str, Any]:
|
||||
|
||||
|
||||
def text2flow(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
source_outputs: list[Any],
|
||||
prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
requires_multimodal_data: bool = True,
|
||||
_requires_multimodal_data: bool = True,
|
||||
):
|
||||
"""Build stage-1 inputs by prefixing stage-0 prompt ids to its outputs."""
|
||||
source_stage_id = engine_input_source[0]
|
||||
source_outputs = stage_list[source_stage_id].engine_outputs
|
||||
|
||||
engine_inputs: list[OmniTokensPrompt] = []
|
||||
for source_output in source_outputs:
|
||||
output = source_output.outputs[0]
|
||||
|
||||
@@ -87,22 +87,10 @@ def _decode_runtime_bridge_info(value: Any) -> dict[str, Any]:
|
||||
|
||||
|
||||
def _bridge_tokens(
|
||||
stage_list,
|
||||
engine_input_source,
|
||||
source_outputs,
|
||||
prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
):
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
|
||||
source_stage_id = engine_input_source[0]
|
||||
if source_stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid stage_id: {source_stage_id}")
|
||||
|
||||
if stage_list[source_stage_id].engine_outputs is None:
|
||||
raise RuntimeError(f"Stage {source_stage_id} has no outputs yet")
|
||||
|
||||
source_outputs = stage_list[source_stage_id].engine_outputs
|
||||
next_inputs = []
|
||||
if not isinstance(prompt, list):
|
||||
prompt = [prompt]
|
||||
@@ -119,9 +107,7 @@ def _bridge_tokens(
|
||||
if not token_ids:
|
||||
token_ids = list(output.cumulative_token_ids or [])
|
||||
if not token_ids:
|
||||
raise RuntimeError(
|
||||
f"Stage {source_stage_id} output for request {source_output.request_id} has no token_ids"
|
||||
)
|
||||
raise RuntimeError(f"Stage output for request {source_output.request_id} has no token_ids")
|
||||
|
||||
detok_id = _to_int(mm_out.get("detok_id"), default=0)
|
||||
src_prompt = prompt_meta_by_reqid.get(source_output.request_id, {})
|
||||
@@ -147,18 +133,16 @@ def _bridge_tokens(
|
||||
|
||||
|
||||
def token2text_to_token2image(
|
||||
stage_list,
|
||||
engine_input_source,
|
||||
source_outputs,
|
||||
prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
):
|
||||
return _bridge_tokens(stage_list, engine_input_source, prompt, requires_multimodal_data)
|
||||
return _bridge_tokens(source_outputs, prompt, requires_multimodal_data)
|
||||
|
||||
|
||||
def token2image_to_token2audio(
|
||||
stage_list,
|
||||
engine_input_source,
|
||||
source_outputs,
|
||||
prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
):
|
||||
return _bridge_tokens(stage_list, engine_input_source, prompt, requires_multimodal_data)
|
||||
return _bridge_tokens(source_outputs, prompt, requires_multimodal_data)
|
||||
@@ -24,16 +24,14 @@ def _extract_last_frame(pooling_output: dict[str, Any]) -> torch.Tensor | None:
|
||||
|
||||
|
||||
def slow_ar_to_dac_decoder(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
prompt: Any = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
source_outputs: list[Any],
|
||||
_prompt: Any = None,
|
||||
_requires_multimodal_data: bool = False,
|
||||
) -> list[Any]:
|
||||
"""Non-async processor: wait for Slow AR to finish, then pass all codes to DAC decoder."""
|
||||
from vllm_omni.inputs.data import OmniTokensPrompt
|
||||
from vllm_omni.model_executor.stage_input_processors.qwen3_omni import _validate_stage_inputs
|
||||
|
||||
slow_ar_outputs = _validate_stage_inputs(stage_list, engine_input_source)
|
||||
slow_ar_outputs = source_outputs
|
||||
dac_inputs: list[OmniTokensPrompt] = []
|
||||
|
||||
for output in slow_ar_outputs:
|
||||
|
||||
@@ -212,25 +212,20 @@ def _parse_generated_tokens(
|
||||
|
||||
|
||||
def ar2diffusion(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
source_outputs: list[Any],
|
||||
prompt: OmniTokensPrompt | TextPrompt | list | None = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
streaming_context: Any | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Process AR stage outputs to create Diffusion stage inputs."""
|
||||
"""Process AR stage outputs to create Diffusion stage inputs.
|
||||
|
||||
This processor accepts the stage-pool transition interface:
|
||||
``ar2diffusion(source_outputs, prompt, requires_multimodal_data)``.
|
||||
"""
|
||||
del streaming_context
|
||||
|
||||
_t_total = time.perf_counter()
|
||||
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
|
||||
source_stage_id = engine_input_source[0]
|
||||
if source_stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid stage_id: {source_stage_id}")
|
||||
|
||||
if stage_list[source_stage_id].engine_outputs is None:
|
||||
raise RuntimeError(f"Stage {source_stage_id} has no outputs yet")
|
||||
|
||||
ar_outputs = stage_list[source_stage_id].engine_outputs
|
||||
ar_outputs = source_outputs
|
||||
diffusion_inputs = []
|
||||
|
||||
# Normalize prompt to list
|
||||
|
||||
@@ -22,33 +22,20 @@ logger = init_logger(__name__)
|
||||
|
||||
|
||||
def ar2diffusion(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
source_outputs: list[Any],
|
||||
prompt: OmniTokensPrompt | TextPrompt | list | None = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Process AR stage outputs to create Diffusion stage inputs.
|
||||
|
||||
Args:
|
||||
stage_list: List of stage clients (set by orchestrator).
|
||||
engine_input_source: List of source stage IDs (from YAML).
|
||||
prompt: Original user prompt (may contain multimodal data).
|
||||
requires_multimodal_data: Whether to forward multimodal data.
|
||||
|
||||
Returns:
|
||||
List of dicts, each consumable by the HunyuanImage3 diffusion pipeline.
|
||||
"""
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
|
||||
source_stage_id = engine_input_source[0]
|
||||
if source_stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid source stage_id: {source_stage_id}")
|
||||
|
||||
if stage_list[source_stage_id].engine_outputs is None:
|
||||
raise RuntimeError(f"Stage {source_stage_id} has no outputs yet")
|
||||
|
||||
ar_outputs = stage_list[source_stage_id].engine_outputs
|
||||
ar_outputs = source_outputs
|
||||
diffusion_inputs = []
|
||||
|
||||
# Normalize prompt to list
|
||||
|
||||
@@ -9,15 +9,12 @@ from vllm_omni.inputs.data import OmniTokensPrompt
|
||||
|
||||
|
||||
def ar2dit(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
source_outputs: list[Any],
|
||||
prompts: OmniTokensPrompt | TextPrompt | None = None,
|
||||
requires_multimodal_data: bool = False, # noqa: ARG001 — interface param, unused for ar2dit
|
||||
_requires_multimodal_data: bool = False,
|
||||
) -> list[OmniTokensPrompt]:
|
||||
"""Convert AR stage outputs to DiT stage inputs."""
|
||||
|
||||
source_stage_id = engine_input_source[0]
|
||||
ar_outputs = stage_list[source_stage_id].engine_outputs
|
||||
ar_outputs = source_outputs
|
||||
|
||||
dit_inputs: list[OmniTokensPrompt] = []
|
||||
for ar_output, prompt in zip(ar_outputs, prompts):
|
||||
|
||||
@@ -182,8 +182,7 @@ def llm2code2wav_async_chunk(
|
||||
|
||||
|
||||
def llm2code2wav(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
source_outputs: list[Any],
|
||||
prompt: OmniTokensPrompt | TextPrompt | None = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
) -> list[OmniTokensPrompt]:
|
||||
@@ -196,25 +195,13 @@ def llm2code2wav(
|
||||
3. Package for code2wav stage
|
||||
|
||||
Args:
|
||||
stage_list: List of stage objects
|
||||
engine_input_source: Source stage IDs (typically [1] for talker)
|
||||
prompt: Original prompt data
|
||||
requires_multimodal_data: Whether multimodal data is required
|
||||
|
||||
Returns:
|
||||
List of OmniTokensPrompt for code2wav stage
|
||||
"""
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
|
||||
source_stage_id = engine_input_source[0]
|
||||
if source_stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid stage_id: {source_stage_id}")
|
||||
|
||||
if stage_list[source_stage_id].engine_outputs is None:
|
||||
raise RuntimeError(f"Stage {source_stage_id} has no outputs yet")
|
||||
|
||||
talker_outputs = stage_list[source_stage_id].engine_outputs
|
||||
talker_outputs = source_outputs
|
||||
code2wav_inputs = []
|
||||
|
||||
# Process each talker output
|
||||
|
||||
@@ -10,22 +10,15 @@ from vllm_omni.inputs.data import OmniTokensPrompt
|
||||
|
||||
|
||||
def tokens2audio(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
requires_multimodal_data: bool = True,
|
||||
source_outputs: list[Any],
|
||||
_prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
_requires_multimodal_data: bool = True,
|
||||
):
|
||||
"""Build stage-1 (decoder) inputs from stage-0 (generator) outputs.
|
||||
|
||||
Takes the 8-codebook audio tokens from the generator and packages
|
||||
them for the HiggsAudioV2 decoder.
|
||||
"""
|
||||
source_stage_id = engine_input_source[0]
|
||||
source_outputs = stage_list[source_stage_id].engine_outputs
|
||||
|
||||
if not isinstance(prompt, list):
|
||||
prompt = [prompt]
|
||||
|
||||
source_output = source_outputs[0]
|
||||
output = source_output.outputs[0]
|
||||
|
||||
|
||||
@@ -10,19 +10,11 @@ TALKER_CODEC_END_TOKEN_ID = 8294
|
||||
|
||||
|
||||
def thinker2talker(
|
||||
stage_list,
|
||||
engine_input_source,
|
||||
source_outputs,
|
||||
prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
):
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
source_stage_id = engine_input_source[0]
|
||||
if source_stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid stage_id: {source_stage_id}")
|
||||
if stage_list[source_stage_id].engine_outputs is None:
|
||||
raise RuntimeError(f"Stage {source_stage_id} has no outputs yet")
|
||||
thinker_outputs = stage_list[source_stage_id].engine_outputs
|
||||
thinker_outputs = source_outputs
|
||||
talker_inputs = []
|
||||
if not isinstance(prompt, list):
|
||||
prompt = [prompt]
|
||||
|
||||
@@ -90,36 +90,23 @@ def _ensure_list(x):
|
||||
return list(x)
|
||||
|
||||
|
||||
def _validate_stage_inputs(stage_list, engine_input_source):
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
|
||||
stage_id = engine_input_source[0]
|
||||
if stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid stage_id: {stage_id}")
|
||||
|
||||
stage = stage_list[stage_id]
|
||||
if stage.engine_outputs is None:
|
||||
raise RuntimeError(f"Stage {stage_id} has no outputs yet")
|
||||
|
||||
return stage.engine_outputs
|
||||
|
||||
|
||||
# =========================
|
||||
# PD disaggregation helpers
|
||||
# =========================
|
||||
|
||||
|
||||
def _get_prefill_stage(stage_list: list[Any], source_stage_id: int) -> Any | None:
|
||||
if source_stage_id <= 0:
|
||||
def _get_prefill_multimodal_output(
|
||||
request_id: str,
|
||||
streaming_context: Any | None,
|
||||
) -> dict[str, Any] | None:
|
||||
bridge_states = getattr(streaming_context, "bridge_states", None)
|
||||
if not isinstance(bridge_states, dict):
|
||||
return None
|
||||
source_stage = stage_list[source_stage_id]
|
||||
if not getattr(source_stage, "is_decode_only", False):
|
||||
by_req = bridge_states.get("pd_prefill_multimodal_output_by_req")
|
||||
if not isinstance(by_req, dict):
|
||||
return None
|
||||
prev_stage = stage_list[source_stage_id - 1]
|
||||
if getattr(prev_stage, "is_prefill_only", False) and prev_stage.engine_outputs is not None:
|
||||
return prev_stage
|
||||
return None
|
||||
prefill_mm = by_req.get(request_id)
|
||||
return prefill_mm if isinstance(prefill_mm, dict) else None
|
||||
|
||||
|
||||
def _merge_pd_embeddings(
|
||||
@@ -167,16 +154,6 @@ def _merge_pd_embeddings(
|
||||
return merged_emb, merged_hid
|
||||
|
||||
|
||||
def _get_prefill_multimodal_output(prefill_stage: Any, output_index: int) -> dict[str, Any] | None:
|
||||
"""Return multimodal_output dict from the PD prefill stage for a given batch index."""
|
||||
try:
|
||||
prefill_eos = prefill_stage.engine_outputs
|
||||
prefill_eo = prefill_eos[min(output_index, len(prefill_eos) - 1)]
|
||||
return prefill_eo.outputs[0].multimodal_output
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _resolve_tts_token_embedding(
|
||||
key: str,
|
||||
*,
|
||||
@@ -407,8 +384,7 @@ def thinker2talker_async_chunk(
|
||||
|
||||
|
||||
def thinker2talker(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
source_outputs: list[Any],
|
||||
prompt: OmniTokensPrompt | TextPrompt | None = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
streaming_context: Any | None = None,
|
||||
@@ -425,23 +401,17 @@ def thinker2talker(
|
||||
decode-stage generated embeddings before handing off to the talker.
|
||||
|
||||
Args:
|
||||
stage_list: List of stage objects
|
||||
engine_input_source: Source stage IDs (typically [0] for thinker)
|
||||
prompt: Original prompt data
|
||||
requires_multimodal_data: Whether multimodal data is required
|
||||
|
||||
Returns:
|
||||
List of OmniTokensPrompt for talker stage
|
||||
"""
|
||||
thinker_outputs = _validate_stage_inputs(stage_list, engine_input_source)
|
||||
thinker_outputs = source_outputs
|
||||
talker_inputs: list[OmniTokensPrompt] = []
|
||||
|
||||
device = torch.device(current_platform.device_type)
|
||||
|
||||
# PD disaggregation: look up the preceding prefill stage (if any)
|
||||
source_stage_id = engine_input_source[0]
|
||||
prefill_stage = _get_prefill_stage(stage_list, source_stage_id)
|
||||
|
||||
# Process each thinker output
|
||||
for i, thinker_output in enumerate(thinker_outputs):
|
||||
output = thinker_output.outputs[0]
|
||||
@@ -478,8 +448,7 @@ def thinker2talker(
|
||||
thinker_hid = hid_layer.detach().to(device=device, dtype=torch.float)[-new_seq_length:]
|
||||
|
||||
prefill_mm: dict[str, Any] | None = None
|
||||
if prefill_stage is not None:
|
||||
prefill_mm = _get_prefill_multimodal_output(prefill_stage, i)
|
||||
prefill_mm = _get_prefill_multimodal_output(req_id, streaming_context)
|
||||
|
||||
if prefill_mm is not None:
|
||||
expected_total = len(prompt_token_ids) + len(output_ids)
|
||||
@@ -610,10 +579,9 @@ def talker2code2wav_async_chunk(
|
||||
|
||||
|
||||
def talker2code2wav(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
prompt: OmniTokensPrompt | TextPrompt | None = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
source_outputs: list[Any],
|
||||
_prompt: OmniTokensPrompt | TextPrompt | None = None,
|
||||
_requires_multimodal_data: bool = False,
|
||||
streaming_context: Any | None = None,
|
||||
) -> list[OmniTokensPrompt]:
|
||||
"""
|
||||
@@ -625,15 +593,10 @@ def talker2code2wav(
|
||||
3. Package for code2wav stage
|
||||
|
||||
Args:
|
||||
stage_list: List of stage objects
|
||||
engine_input_source: Source stage IDs (typically [1] for talker)
|
||||
prompt: Original prompt data
|
||||
requires_multimodal_data: Whether multimodal data is required
|
||||
|
||||
Returns:
|
||||
List of OmniTokensPrompt for code2wav stage
|
||||
"""
|
||||
talker_outputs = _validate_stage_inputs(stage_list, engine_input_source)
|
||||
talker_outputs = source_outputs
|
||||
code2wav_inputs: list[OmniTokensPrompt] = []
|
||||
# Process each talker output
|
||||
for i, talker_output in enumerate(talker_outputs):
|
||||
|
||||
@@ -20,16 +20,14 @@ logger = init_logger(__name__)
|
||||
|
||||
|
||||
def talker2code2wav(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
source_outputs: list[Any],
|
||||
prompt: Any = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
_requires_multimodal_data: bool = False,
|
||||
) -> list[Any]:
|
||||
"""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
|
||||
|
||||
talker_outputs = _validate_stage_inputs(stage_list, engine_input_source)
|
||||
talker_outputs = source_outputs
|
||||
code2wav_inputs: list[OmniTokensPrompt] = []
|
||||
for i, talker_output in enumerate(talker_outputs):
|
||||
if not talker_output.finished:
|
||||
|
||||
@@ -42,24 +42,10 @@ def _coerce_finished_flag(value: Any) -> bool:
|
||||
|
||||
|
||||
def latent2vae(
|
||||
stage_list: list[Any],
|
||||
engine_input_source: list[int],
|
||||
prompt: OmniTokensPrompt | TextPrompt | None = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
source_outputs: list[Any],
|
||||
_prompt: OmniTokensPrompt | TextPrompt | None = None,
|
||||
_requires_multimodal_data: bool = False,
|
||||
) -> list[OmniTokensPrompt]:
|
||||
del prompt, requires_multimodal_data
|
||||
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
|
||||
source_stage_id = engine_input_source[0]
|
||||
if source_stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid stage_id: {source_stage_id}")
|
||||
|
||||
source_outputs = stage_list[source_stage_id].engine_outputs
|
||||
if source_outputs is None:
|
||||
raise RuntimeError(f"Stage {source_stage_id} has no outputs yet")
|
||||
|
||||
vae_inputs: list[OmniTokensPrompt] = []
|
||||
for source_output in source_outputs:
|
||||
output = source_output.outputs[0]
|
||||
|
||||
@@ -10,22 +10,12 @@ logger = init_logger(__name__)
|
||||
|
||||
|
||||
def generator2tokenizer(
|
||||
stage_list,
|
||||
engine_input_source,
|
||||
prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
requires_multimodal_data: bool = False,
|
||||
source_outputs: list[Any],
|
||||
_prompt: OmniTokensPrompt | TextPrompt = None,
|
||||
_requires_multimodal_data: bool = False,
|
||||
):
|
||||
if not engine_input_source:
|
||||
raise ValueError("engine_input_source cannot be empty")
|
||||
source_stage_id = engine_input_source[0]
|
||||
if source_stage_id >= len(stage_list):
|
||||
raise IndexError(f"Invalid stage_id: {source_stage_id}")
|
||||
if stage_list[source_stage_id].engine_outputs is None:
|
||||
raise RuntimeError(f"Stage {source_stage_id} has no outputs yet")
|
||||
|
||||
generator_outputs = stage_list[source_stage_id].engine_outputs
|
||||
tokenizer_inputs = []
|
||||
for generator_output in generator_outputs:
|
||||
for generator_output in source_outputs:
|
||||
output = generator_output.outputs[0]
|
||||
audio_tokens = torch.cat(output.multimodal_output["audio"], dim=-1).flatten().detach().cpu().tolist()
|
||||
tokenizer_inputs.append(
|
||||
|
||||
Reference in new issue
Block a user