[REFACT]Refactor diffusion outputs to payload metadata (#4922)
Signed-off-by: bjf-frz <frz123db@gmail.com>
This commit is contained in:
1 parent
4b9d09cb87
commit
1a4a042a83
44 files changed
+1373
-478
No files matched your search
@@ -60,6 +60,15 @@ def get_audiox_post_process_func(od_config: OmniDiffusionConfig):
|
||||
"""Convert the pipeline's float audio tensor to a CPU numpy array for serving."""
|
||||
|
||||
def post_process_func(audio: torch.Tensor) -> Any:
|
||||
if isinstance(audio, dict) and isinstance(audio.get("payload"), dict):
|
||||
payload = dict(audio["payload"])
|
||||
audio_payload = payload.get("audio")
|
||||
if isinstance(audio_payload, torch.Tensor):
|
||||
payload["audio"] = audio_payload.detach().cpu().float().numpy()
|
||||
return {
|
||||
"payload": payload,
|
||||
"metadata": audio.get("metadata") or {},
|
||||
}
|
||||
if isinstance(audio, torch.Tensor):
|
||||
return audio.detach().cpu().float().numpy()
|
||||
return audio
|
||||
@@ -915,9 +924,10 @@ class AudioXPipeline(nn.Module, SupportAudioOutput, DiffusionPipelineProfilerMix
|
||||
audio = audio[..., :target_samples]
|
||||
|
||||
stage_durations = self.stage_durations if getattr(self, "enable_diffusion_pipeline_profiler", False) else None
|
||||
custom_output = {"audiox_task": task_norm}
|
||||
return DiffusionOutput(
|
||||
output=audio,
|
||||
custom_output=custom_output,
|
||||
output={
|
||||
"payload": {"audio": audio},
|
||||
"metadata": {"audio": {"audiox_task": task_norm}},
|
||||
},
|
||||
stage_durations=stage_durations,
|
||||
)
|
||||
@@ -739,8 +739,10 @@ class BagelPipeline(nn.Module, SupportsComponentDiscovery, DiffusionPipelineProf
|
||||
text_output = text_output.split("<|im_start|>")[-1]
|
||||
|
||||
return DiffusionOutput(
|
||||
output=text_output,
|
||||
custom_output={"text_output": text_output},
|
||||
output={
|
||||
"payload": {"text": text_output},
|
||||
"metadata": {"text": {"text_output": text_output}},
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
@@ -847,22 +849,28 @@ class BagelPipeline(nn.Module, SupportsComponentDiscovery, DiffusionPipelineProf
|
||||
if trajectory_log_probs:
|
||||
trajectory_log_probs_stacked = torch.stack(trajectory_log_probs)
|
||||
|
||||
custom = {}
|
||||
payload = {"image": img}
|
||||
metadata = {}
|
||||
if think_text is not None:
|
||||
custom["think_text"] = think_text
|
||||
# Mirror the PIL image into ``custom_output`` so callers reading via
|
||||
# the orchestrator IPC boundary (which strips the bare ``output``
|
||||
# field) can still recover the result. ``video_frames`` already
|
||||
# uses this pattern.
|
||||
custom["image"] = img
|
||||
metadata["text"] = {"think_text": think_text}
|
||||
trajectory_payload = {}
|
||||
if trajectory_latents_stacked is not None:
|
||||
trajectory_payload["latents"] = trajectory_latents_stacked
|
||||
if trajectory_timesteps_stacked is not None:
|
||||
trajectory_payload["timesteps"] = trajectory_timesteps_stacked
|
||||
if trajectory_log_probs_stacked is not None:
|
||||
trajectory_payload["log_probs"] = trajectory_log_probs_stacked
|
||||
if trajectory_decoded is not None:
|
||||
trajectory_payload["decoded"] = trajectory_decoded
|
||||
if trajectory_payload:
|
||||
payload["trajectory"] = trajectory_payload
|
||||
metadata["trajectory"] = {"type": "denoising"}
|
||||
|
||||
return DiffusionOutput(
|
||||
output=img,
|
||||
trajectory_latents=trajectory_latents_stacked,
|
||||
trajectory_timesteps=trajectory_timesteps_stacked,
|
||||
trajectory_log_probs=trajectory_log_probs_stacked,
|
||||
trajectory_decoded=trajectory_decoded,
|
||||
custom_output=custom,
|
||||
output={
|
||||
"payload": payload,
|
||||
"metadata": metadata,
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
from .pipeline_cosmos3 import (
|
||||
Cosmos3OmniDiffusersPipeline,
|
||||
get_cosmos3_action_post_process_func,
|
||||
get_cosmos3_post_process_func,
|
||||
get_cosmos3_pre_process_func,
|
||||
)
|
||||
@@ -11,7 +10,6 @@ from .transformer_cosmos3 import Cosmos3VFMTransformer
|
||||
|
||||
__all__ = [
|
||||
"Cosmos3OmniDiffusersPipeline",
|
||||
"get_cosmos3_action_post_process_func",
|
||||
"get_cosmos3_post_process_func",
|
||||
"get_cosmos3_pre_process_func",
|
||||
"Cosmos3VFMTransformer",
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
These helpers cover action modes that use action tokens as an auxiliary output
|
||||
stream: ``policy``, ``forward_dynamics``, and ``inverse_dynamics``. The pipeline
|
||||
returns predicted actions through ``custom_output`` rather than as a normal
|
||||
``modalities`` entry.
|
||||
returns predicted actions through the diffusion output payload/metadata
|
||||
envelope rather than as a video frame stream.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -20,7 +20,8 @@ Video generation is further specialized by inputs and extra args:
|
||||
transfer video generation.
|
||||
* ``action_mode``: action-capable video generation. RoboLab/OpenPI observation
|
||||
payloads in ``extra_args["robot_obs"]`` or ``extra_args["observation"]``
|
||||
bypass normal video output and return action-only custom output.
|
||||
bypass normal video output and return an action-only payload/metadata
|
||||
envelope.
|
||||
|
||||
Generated sound is video-only, cannot be combined with action or transfer, and
|
||||
is produced from sound latents rather than from ``multi_modal_data["audio"]``.
|
||||
@@ -133,6 +134,7 @@ from .utils import (
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
COSMOS3_DEFAULT_CONDITION_PIXEL_FRAMES = (
|
||||
max(COSMOS3_DEFAULT_CONDITION_FRAME_INDEXES_VISION) * COSMOS3_VAE_TEMPORAL_COMPRESSION + 1
|
||||
)
|
||||
@@ -530,6 +532,37 @@ def get_cosmos3_post_process_func(od_config: OmniDiffusionConfig):
|
||||
if output_type == "latent":
|
||||
return output
|
||||
|
||||
def _postprocess_action(action: Any, metadata: dict[str, Any]) -> Any:
|
||||
internal_metadata = metadata.get("internal")
|
||||
inputs = (
|
||||
internal_metadata.get("robolab_action_postprocess") if isinstance(internal_metadata, dict) else None
|
||||
)
|
||||
if isinstance(inputs, RoboLabActionPostprocessInputs):
|
||||
return postprocess_robolab_action(action, inputs)
|
||||
return action
|
||||
|
||||
pending_action = None
|
||||
pending_action_metadata: dict[str, Any] = {}
|
||||
envelope_public_metadata: dict[str, Any] = {}
|
||||
if isinstance(output, dict) and isinstance(output.get("payload"), dict):
|
||||
envelope_payload = dict(output.get("payload") or {})
|
||||
metadata = output.get("metadata") or {}
|
||||
envelope_metadata = metadata if isinstance(metadata, dict) else {}
|
||||
envelope_public_metadata = {key: value for key, value in envelope_metadata.items() if key != "internal"}
|
||||
action = envelope_payload.pop("actions", None)
|
||||
if action is not None:
|
||||
pending_action = _postprocess_action(action, envelope_metadata)
|
||||
pending_action_metadata = envelope_public_metadata
|
||||
if not envelope_payload:
|
||||
return {
|
||||
"payload": {
|
||||
"video": [],
|
||||
"actions": pending_action,
|
||||
},
|
||||
"metadata": pending_action_metadata,
|
||||
}
|
||||
output = envelope_payload
|
||||
|
||||
audio = None
|
||||
audio_sample_rate = None
|
||||
if isinstance(output, dict):
|
||||
@@ -568,11 +601,31 @@ def get_cosmos3_post_process_func(od_config: OmniDiffusionConfig):
|
||||
# check_video_safety expects a 5D tensor; re-add T axis.
|
||||
checked = check_video_safety(image.unsqueeze(2))
|
||||
image = checked.squeeze(2)
|
||||
return video_processor.postprocess(image, output_type="pil")
|
||||
if is_guardrails_enabled(od_config, sampling_params):
|
||||
processed_image = video_processor.postprocess(image, output_type="pil")
|
||||
if envelope_public_metadata:
|
||||
return {
|
||||
"payload": {"image": processed_image},
|
||||
"metadata": envelope_public_metadata,
|
||||
}
|
||||
return processed_image
|
||||
guardrails_enabled = is_guardrails_enabled(od_config, sampling_params)
|
||||
if guardrails_enabled:
|
||||
video = check_video_safety(video)
|
||||
processed_video = video_processor.postprocess_video(video, output_type=output_type)
|
||||
if audio is None:
|
||||
if pending_action is not None:
|
||||
return {
|
||||
"payload": {
|
||||
"video": processed_video,
|
||||
"actions": pending_action,
|
||||
},
|
||||
"metadata": pending_action_metadata,
|
||||
}
|
||||
if envelope_public_metadata:
|
||||
return {
|
||||
"payload": {"video": processed_video},
|
||||
"metadata": envelope_public_metadata,
|
||||
}
|
||||
return processed_video
|
||||
if isinstance(audio, torch.Tensor):
|
||||
audio = audio.detach().cpu()
|
||||
@@ -583,33 +636,38 @@ def get_cosmos3_post_process_func(od_config: OmniDiffusionConfig):
|
||||
}
|
||||
if audio_sample_rate is not None:
|
||||
result["audio_sample_rate"] = int(audio_sample_rate)
|
||||
if pending_action is not None:
|
||||
return {
|
||||
"payload": {
|
||||
"video": result["video"],
|
||||
"audio": result["audio"],
|
||||
"actions": pending_action,
|
||||
},
|
||||
"metadata": {
|
||||
**pending_action_metadata,
|
||||
"video": {"fps": result["fps"]},
|
||||
"audio": {"sample_rate": result.get("audio_sample_rate")},
|
||||
},
|
||||
}
|
||||
if envelope_public_metadata:
|
||||
return {
|
||||
"payload": {
|
||||
"video": result["video"],
|
||||
"audio": result["audio"],
|
||||
},
|
||||
"metadata": {
|
||||
**envelope_public_metadata,
|
||||
"video": {"fps": result["fps"], **envelope_public_metadata.get("video", {})}
|
||||
if isinstance(envelope_public_metadata.get("video"), dict)
|
||||
else {"fps": result["fps"]},
|
||||
"audio": {"sample_rate": result.get("audio_sample_rate")},
|
||||
},
|
||||
}
|
||||
return result
|
||||
|
||||
return post_process_func
|
||||
|
||||
|
||||
def get_cosmos3_action_post_process_func(od_config: OmniDiffusionConfig):
|
||||
"""Build the custom-output postprocessor for Cosmos3 action predictions.
|
||||
|
||||
Action modes return predicted action tensors in ``custom_output`` alongside
|
||||
normal video output. RoboLab/OpenPI policy serving marks action-only output
|
||||
and carries observation metadata used here to map model-space actions back
|
||||
to the requested robot action representation.
|
||||
"""
|
||||
del od_config
|
||||
|
||||
def action_post_process_func(action: Any, custom_output: dict[str, Any] | None = None, sampling_params=None):
|
||||
del sampling_params
|
||||
inputs = custom_output.get("robolab_action_postprocess") if isinstance(custom_output, dict) else None
|
||||
if isinstance(inputs, RoboLabActionPostprocessInputs):
|
||||
processed_action = postprocess_robolab_action(action, inputs)
|
||||
custom_output.pop("robolab_action_postprocess", None)
|
||||
return processed_action
|
||||
return action
|
||||
|
||||
return action_post_process_func
|
||||
|
||||
|
||||
def get_cosmos3_ir_op_priority_func(od_config: OmniDiffusionConfig):
|
||||
del od_config
|
||||
|
||||
@@ -669,9 +727,10 @@ class Cosmos3OmniDiffusersPipeline(
|
||||
T2I, transfer, and action+sound are rejected.
|
||||
* **Action generation** when ``action_mode`` is provided. ``policy`` and
|
||||
``forward_dynamics`` require an image or video input; ``inverse_dynamics``
|
||||
requires video input. Action predictions are returned in ``custom_output``.
|
||||
requires video input. Action predictions are returned in the diffusion
|
||||
output payload/metadata envelope.
|
||||
RoboLab/OpenPI observations in ``extra_args['robot_obs']`` or
|
||||
``extra_args['observation']`` return action-only custom output.
|
||||
``extra_args['observation']`` return an action-only envelope.
|
||||
* **T2V** otherwise (default video generation).
|
||||
"""
|
||||
|
||||
@@ -1409,15 +1468,25 @@ class Cosmos3OmniDiffusersPipeline(
|
||||
logger.info("Total pipeline time: %.2fs", time.time() - pipeline_start)
|
||||
|
||||
action = action_latents[:, :, :raw_action_dim].detach().cpu()
|
||||
custom_action_output: dict[str, Any] = {
|
||||
"action": action,
|
||||
"raw_action_dim": raw_action_dim,
|
||||
"action_mode": action_mode,
|
||||
"domain_id": domain_id,
|
||||
"action_only_output": True,
|
||||
"robolab_action_postprocess": make_robolab_action_postprocess_inputs(inputs),
|
||||
action_output: dict[str, Any] = {
|
||||
"payload": {
|
||||
"actions": action,
|
||||
},
|
||||
"metadata": {
|
||||
"actions": {
|
||||
"raw_action_dim": raw_action_dim,
|
||||
"action_mode": action_mode,
|
||||
"domain_id": domain_id,
|
||||
},
|
||||
"common": {
|
||||
"action_only_output": True,
|
||||
},
|
||||
"internal": {
|
||||
"robolab_action_postprocess": make_robolab_action_postprocess_inputs(inputs),
|
||||
},
|
||||
},
|
||||
}
|
||||
return DiffusionOutput(output={}, custom_output=custom_action_output)
|
||||
return DiffusionOutput(output=action_output)
|
||||
|
||||
@staticmethod
|
||||
def _truthy(value) -> bool:
|
||||
@@ -2881,11 +2950,15 @@ class Cosmos3OmniDiffusersPipeline(
|
||||
full_output = torch.cat([normalized_input.to(full_output), full_output], dim=-1)
|
||||
|
||||
return DiffusionOutput(
|
||||
output={"video": full_output},
|
||||
custom_output={
|
||||
"transfer_controls": full_controls,
|
||||
"transfer_hints": list(per_hint_frames),
|
||||
"fps": frame_rate,
|
||||
output={
|
||||
"payload": {"video": full_output},
|
||||
"metadata": {
|
||||
"transfer": {
|
||||
"controls": full_controls,
|
||||
"hints": list(per_hint_frames),
|
||||
},
|
||||
"video": {"fps": frame_rate},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -3287,12 +3360,18 @@ class Cosmos3OmniDiffusersPipeline(
|
||||
raise ValueError("Cosmos3 action generation finished without action latents.")
|
||||
action = action_latents[:, :, :raw_action_dim].detach().cpu()
|
||||
return DiffusionOutput(
|
||||
output={"video": video},
|
||||
custom_output={
|
||||
"action": action,
|
||||
"raw_action_dim": raw_action_dim,
|
||||
"action_mode": action_mode,
|
||||
"domain_id": domain_id,
|
||||
output={
|
||||
"payload": {
|
||||
"video": video,
|
||||
"actions": action,
|
||||
},
|
||||
"metadata": {
|
||||
"actions": {
|
||||
"raw_action_dim": raw_action_dim,
|
||||
"action_mode": action_mode,
|
||||
"domain_id": domain_id,
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -2209,7 +2209,6 @@ class HunyuanImage3Pipeline(
|
||||
if output_type == "latent":
|
||||
return DiffusionOutput(
|
||||
output=latents,
|
||||
custom_output={},
|
||||
stage_durations=getattr(self, "stage_durations", None),
|
||||
)
|
||||
|
||||
@@ -2232,12 +2231,14 @@ class HunyuanImage3Pipeline(
|
||||
)
|
||||
|
||||
cot_text_list = state.extra.get(_STEP_COT_TEXT_LIST) or []
|
||||
custom_output = {}
|
||||
metadata = {}
|
||||
if any(text is not None for text in cot_text_list):
|
||||
custom_output["ar_generated_text"] = cot_text_list[0]
|
||||
metadata["text"] = {"ar_generated_text": cot_text_list[0]}
|
||||
return DiffusionOutput(
|
||||
output=image[0],
|
||||
custom_output=custom_output,
|
||||
output={
|
||||
"payload": {"image": image[0]},
|
||||
"metadata": metadata,
|
||||
},
|
||||
stage_durations=getattr(self, "stage_durations", None),
|
||||
)
|
||||
|
||||
@@ -2302,12 +2303,14 @@ class HunyuanImage3Pipeline(
|
||||
|
||||
outputs = self._generate(**model_inputs, **kwargs)
|
||||
image = outputs[0]
|
||||
custom_output = {}
|
||||
metadata = {}
|
||||
if any(t is not None for t in cot_text_list):
|
||||
custom_output["ar_generated_text"] = cot_text_list[0] if len(cot_text_list) == 1 else cot_text_list
|
||||
metadata["text"] = {"ar_generated_text": cot_text_list[0] if len(cot_text_list) == 1 else cot_text_list}
|
||||
stage_durations = self.stage_durations if hasattr(self, "stage_durations") else None
|
||||
return DiffusionOutput(
|
||||
output=image,
|
||||
custom_output=custom_output,
|
||||
output={
|
||||
"payload": {"image": image},
|
||||
"metadata": metadata,
|
||||
},
|
||||
stage_durations=stage_durations,
|
||||
)
|
||||
@@ -247,11 +247,13 @@ class InternVLAA1Pipeline(nn.Module, DiffusionPipelineProfilerMixin):
|
||||
noise=extra_args.get("noise"),
|
||||
decode_image=bool(extra_args.get("decode_image", False)),
|
||||
)
|
||||
custom_output: dict[str, Any] = {}
|
||||
metadata: dict[str, Any] = {}
|
||||
if decoded is not None:
|
||||
custom_output["decoded"] = decoded
|
||||
metadata["actions"] = {"decoded": decoded}
|
||||
return DiffusionOutput(
|
||||
output=output,
|
||||
custom_output=custom_output,
|
||||
output={
|
||||
"payload": {"actions": output},
|
||||
"metadata": metadata,
|
||||
},
|
||||
post_process_func=get_internvla_a1_post_process_func(self.od_config),
|
||||
)
|
||||
@@ -836,8 +836,10 @@ class LancePipeline(BagelPipeline):
|
||||
frames = [Image.fromarray(f) for f in frames_np]
|
||||
logger.info("Lance t2v: decoded %d frames at %dx%d", len(frames), frames[0].width, frames[0].height)
|
||||
return DiffusionOutput(
|
||||
output=frames[0],
|
||||
custom_output={"video_frames": frames, "video_shape": video_shape},
|
||||
output={
|
||||
"payload": {"video": frames},
|
||||
"metadata": {"video": {"shape": video_shape}},
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
@@ -1069,13 +1071,11 @@ class LancePipeline(BagelPipeline):
|
||||
)
|
||||
|
||||
img = self._decode_image_from_latent(self.bagel, self.vae, latents[0], image_shape)
|
||||
# Put the PIL image into ``custom_output`` too — the orchestrator
|
||||
# serializes ``custom_output`` across the IPC boundary but strips
|
||||
# the bare ``output`` field, so consumers that only see
|
||||
# ``outputs[0].output`` (e.g. gradio_demo) get ``None`` otherwise.
|
||||
return DiffusionOutput(
|
||||
output=img,
|
||||
custom_output={"image": img, "image_shape": image_shape},
|
||||
output={
|
||||
"payload": {"image": img},
|
||||
"metadata": {"image": {"shape": image_shape}},
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
@@ -1361,8 +1361,10 @@ class LancePipeline(BagelPipeline):
|
||||
frames_np = self._decode_video_from_latent(self.bagel, self.vae, latents[0], out_shape)
|
||||
frames = [Image.fromarray(f) for f in frames_np]
|
||||
return DiffusionOutput(
|
||||
output=frames[0],
|
||||
custom_output={"video_frames": frames, "video_shape": out_shape},
|
||||
output={
|
||||
"payload": {"video": frames},
|
||||
"metadata": {"video": {"shape": out_shape}},
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
@@ -1622,8 +1624,10 @@ class LancePipeline(BagelPipeline):
|
||||
frames_np = self._decode_video_from_latent(self.bagel, self.vae, latents[0], video_shape)
|
||||
frames = [Image.fromarray(f) for f in frames_np]
|
||||
return DiffusionOutput(
|
||||
output=frames[0],
|
||||
custom_output={"video_frames": frames, "video_shape": video_shape},
|
||||
output={
|
||||
"payload": {"video": frames},
|
||||
"metadata": {"video": {"shape": video_shape}},
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
@@ -1705,8 +1709,10 @@ class LancePipeline(BagelPipeline):
|
||||
text_output = text_output.lstrip("\n")
|
||||
logger.info("Lance x2t_video: generated %d tokens", token_ids.shape[0])
|
||||
return DiffusionOutput(
|
||||
output=text_output,
|
||||
custom_output={"text_output": text_output},
|
||||
output={
|
||||
"payload": {"text": text_output},
|
||||
"metadata": {"text": {"text_output": text_output}},
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
@@ -1801,8 +1807,10 @@ class LancePipeline(BagelPipeline):
|
||||
text_output = text_output.lstrip("\n")
|
||||
logger.info("Lance x2t_image: generated %d tokens", token_ids.shape[0])
|
||||
return DiffusionOutput(
|
||||
output=text_output,
|
||||
custom_output={"text_output": text_output},
|
||||
output={
|
||||
"payload": {"text": text_output},
|
||||
"metadata": {"text": {"text_output": text_output}},
|
||||
},
|
||||
stage_durations=self.stage_durations if hasattr(self, "stage_durations") else None,
|
||||
)
|
||||
|
||||
|
||||
@@ -73,8 +73,19 @@ def get_qwen_image_post_process_func(
|
||||
image_processor = VaeImageProcessor(vae_scale_factor=vae_scale_factor * 2)
|
||||
|
||||
def post_process_func(
|
||||
images: torch.Tensor,
|
||||
images: torch.Tensor | dict[str, Any],
|
||||
):
|
||||
if isinstance(images, dict) and isinstance(images.get("payload"), dict):
|
||||
payload = dict(images["payload"])
|
||||
image_payload = payload.get("image")
|
||||
if image_payload is None:
|
||||
raise ValueError("Qwen-Image postprocess expected payload['image'] in output envelope.")
|
||||
payload["image"] = image_processor.postprocess(image_payload)
|
||||
metadata = images.get("metadata") or {}
|
||||
return {
|
||||
"payload": payload,
|
||||
"metadata": metadata if isinstance(metadata, dict) else {},
|
||||
}
|
||||
return image_processor.postprocess(images)
|
||||
|
||||
return post_process_func
|
||||
|
||||
@@ -938,8 +938,10 @@ class SenseNovaU1Pipeline(nn.Module, SupportsComponentDiscovery, DiffusionPipeli
|
||||
)
|
||||
logger.info("Text generation: %d chars", len(text_output))
|
||||
return DiffusionOutput(
|
||||
output=text_output,
|
||||
custom_output={"text_output": text_output},
|
||||
output={
|
||||
"payload": {"text": text_output},
|
||||
"metadata": {"text": {"text_output": text_output}},
|
||||
},
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
@@ -1457,10 +1459,15 @@ class SenseNovaU1Pipeline(nn.Module, SupportsComponentDiscovery, DiffusionPipeli
|
||||
|
||||
images = _to_pil(image_prediction)
|
||||
img = images[0] if images else None
|
||||
custom = {}
|
||||
metadata = {}
|
||||
if think_text:
|
||||
custom["think_text"] = think_text
|
||||
return DiffusionOutput(output=img, custom_output=custom)
|
||||
metadata["text"] = {"think_text": think_text}
|
||||
return DiffusionOutput(
|
||||
output={
|
||||
"payload": {"image": img},
|
||||
"metadata": metadata,
|
||||
}
|
||||
)
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# Weight loading
|
||||
|
||||
@@ -164,11 +164,11 @@ class SoulXPreprocessPipeline(nn.Module, SupportAudioInput, SupportsComponentDis
|
||||
sample_rate=self.target_sr,
|
||||
)
|
||||
|
||||
# Non-None placeholder so DiffusionEngine forwards custom_output to stage-1
|
||||
# (output=None triggers an early return that drops handoff).
|
||||
return DiffusionOutput(
|
||||
output=torch.zeros(0),
|
||||
custom_output={SOULX_PREPROCESSED_KEY: payload},
|
||||
output={
|
||||
"payload": {},
|
||||
"metadata": {SOULX_PREPROCESSED_KEY: payload},
|
||||
},
|
||||
to_cpu=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from collections.abc import Callable
|
||||
from contextlib import contextmanager
|
||||
from typing import Any, ClassVar
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from vllm.logger import init_logger
|
||||
@@ -30,6 +31,21 @@ _SOULX_PROFILER_TARGETS = [
|
||||
]
|
||||
|
||||
|
||||
def convert_soulx_audio_output_to_numpy(audio: torch.Tensor | dict[str, Any]) -> np.ndarray | dict[str, Any]:
|
||||
if isinstance(audio, dict) and isinstance(audio.get("payload"), dict):
|
||||
payload = dict(audio["payload"])
|
||||
audio_payload = payload.get("audio")
|
||||
if isinstance(audio_payload, torch.Tensor):
|
||||
payload["audio"] = audio_payload.detach().cpu().float().numpy()
|
||||
return {
|
||||
"payload": payload,
|
||||
"metadata": audio.get("metadata") or {},
|
||||
}
|
||||
if isinstance(audio, torch.Tensor):
|
||||
return audio.detach().cpu().float().numpy()
|
||||
return audio
|
||||
|
||||
|
||||
class FlowMatchingAudioPipeline(
|
||||
nn.Module,
|
||||
CFGParallelMixin,
|
||||
@@ -326,7 +342,7 @@ class FlowMatchingAudioPipeline(
|
||||
req: OmniDiffusionRequest,
|
||||
*,
|
||||
kind: str,
|
||||
custom_output_key: str,
|
||||
metadata_key: str,
|
||||
infer_batch_fn: Callable[..., tuple[torch.Tensor, int]],
|
||||
prepare_extra_args: Callable[[dict[str, Any], Any], dict[str, Any]] | None = None,
|
||||
) -> DiffusionOutput:
|
||||
@@ -353,7 +369,9 @@ class FlowMatchingAudioPipeline(
|
||||
)
|
||||
|
||||
return DiffusionOutput(
|
||||
output=audio,
|
||||
custom_output={custom_output_key: pitch_shift},
|
||||
output={
|
||||
"payload": {"audio": audio},
|
||||
"metadata": {"audio": {metadata_key: pitch_shift}},
|
||||
},
|
||||
stage_durations=self._profiler_stage_durations() or {},
|
||||
)
|
||||
@@ -19,6 +19,7 @@ from vllm_omni.diffusion.models.soulx_singer.modules import (
|
||||
)
|
||||
from vllm_omni.diffusion.models.soulx_singer.pipeline_soulx_singer_base import (
|
||||
FlowMatchingAudioPipeline,
|
||||
convert_soulx_audio_output_to_numpy,
|
||||
)
|
||||
from vllm_omni.diffusion.models.soulx_singer.preprocess.payload import (
|
||||
SOULX_PREPROCESSED_KEY,
|
||||
@@ -96,7 +97,7 @@ def get_soulxsinger_svc_pre_process_func(od_config: OmniDiffusionConfig):
|
||||
|
||||
def get_soulxsinger_post_process_func(od_config: OmniDiffusionConfig):
|
||||
def post_process_func(audio: torch.Tensor):
|
||||
return audio.detach().cpu().float().numpy()
|
||||
return convert_soulx_audio_output_to_numpy(audio)
|
||||
|
||||
return post_process_func
|
||||
|
||||
@@ -400,7 +401,7 @@ class PipelineSoulXSingerSVC(FlowMatchingAudioPipeline):
|
||||
return self._forward_batch_from_request(
|
||||
req,
|
||||
kind="svc",
|
||||
custom_output_key="pitch_shift",
|
||||
metadata_key="pitch_shift",
|
||||
infer_batch_fn=self.infer_svc_batch,
|
||||
)
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from vllm_omni.diffusion.models.soulx_singer.modules import (
|
||||
)
|
||||
from vllm_omni.diffusion.models.soulx_singer.pipeline_soulx_singer_base import (
|
||||
FlowMatchingAudioPipeline,
|
||||
convert_soulx_audio_output_to_numpy,
|
||||
)
|
||||
from vllm_omni.diffusion.models.soulx_singer.preprocess.payload import (
|
||||
SOULX_PREPROCESSED_KEY,
|
||||
@@ -97,7 +98,7 @@ def get_soulxsinger_post_process_func(od_config: OmniDiffusionConfig):
|
||||
"""Convert pipeline audio tensor output for offline consumers."""
|
||||
|
||||
def post_process_func(audio: torch.Tensor):
|
||||
return audio.detach().cpu().float().numpy()
|
||||
return convert_soulx_audio_output_to_numpy(audio)
|
||||
|
||||
return post_process_func
|
||||
|
||||
@@ -343,7 +344,7 @@ class PipelineSoulXSingerSVS(FlowMatchingAudioPipeline):
|
||||
return self._forward_batch_from_request(
|
||||
req,
|
||||
kind="svs",
|
||||
custom_output_key="f0_shift",
|
||||
metadata_key="f0_shift",
|
||||
infer_batch_fn=self.infer_svs_batch,
|
||||
prepare_extra_args=lambda extra_args, _sampling: normalize_svs_control_extra_args(extra_args),
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ SOULX_PRECOMPUTED_KEYS_BY_KIND: dict[str, tuple[str, ...]] = {
|
||||
|
||||
|
||||
# Key under which the SoulX preprocess payload is stored in
|
||||
# prompt["additional_information"] or DiffusionOutput.custom_output.
|
||||
# prompt["additional_information"] or diffusion output metadata.
|
||||
SOULX_PREPROCESSED_KEY = "soulx_preprocessed"
|
||||
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ def get_wan22_post_process_func(
|
||||
):
|
||||
if output_type == "latent":
|
||||
return video
|
||||
custom_output = {}
|
||||
video_metadata = {}
|
||||
if sampling_params is not None and getattr(sampling_params, "enable_frame_interpolation", False):
|
||||
video, multiplier = interpolate_video_tensor(
|
||||
video,
|
||||
@@ -195,10 +195,10 @@ def get_wan22_post_process_func(
|
||||
scale=sampling_params.frame_interpolation_scale,
|
||||
model_path=sampling_params.frame_interpolation_model_path,
|
||||
)
|
||||
custom_output["video_fps_multiplier"] = multiplier
|
||||
video_metadata["video_fps_multiplier"] = multiplier
|
||||
return {
|
||||
"video": video_processor.postprocess_video(video, output_type=output_type),
|
||||
"custom_output": custom_output,
|
||||
"payload": {"video": video_processor.postprocess_video(video, output_type=output_type)},
|
||||
"metadata": {"video": video_metadata} if video_metadata else {},
|
||||
}
|
||||
|
||||
return post_process_func
|
||||
|
||||
@@ -65,7 +65,7 @@ def get_wan22_i2v_post_process_func(
|
||||
):
|
||||
if output_type == "latent":
|
||||
return video
|
||||
custom_output = {}
|
||||
video_metadata = {}
|
||||
if sampling_params is not None and getattr(sampling_params, "enable_frame_interpolation", False):
|
||||
video, multiplier = interpolate_video_tensor(
|
||||
video,
|
||||
@@ -73,10 +73,10 @@ def get_wan22_i2v_post_process_func(
|
||||
scale=sampling_params.frame_interpolation_scale,
|
||||
model_path=sampling_params.frame_interpolation_model_path,
|
||||
)
|
||||
custom_output["video_fps_multiplier"] = multiplier
|
||||
video_metadata["video_fps_multiplier"] = multiplier
|
||||
return {
|
||||
"video": video_processor.postprocess_video(video, output_type=output_type),
|
||||
"custom_output": custom_output,
|
||||
"payload": {"video": video_processor.postprocess_video(video, output_type=output_type)},
|
||||
"metadata": {"video": video_metadata} if video_metadata else {},
|
||||
}
|
||||
|
||||
return post_process_func
|
||||
|
||||
Reference in new issue
Block a user