[4/N] Unify worker-side MP4 encoding and wire Wan into it (#7048)
Signed-off-by: specture724 <specture724@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
12 files changed
+1177
-232
No files matched your search
@@ -40,12 +40,20 @@ from vllm_omni.diffusion.models.dmd2 import DMD2PipelineMixin
|
||||
from vllm_omni.diffusion.models.interface import SupportsComponentDiscovery
|
||||
from vllm_omni.diffusion.models.progress_bar import ProgressBarMixin, _is_rank_zero
|
||||
from vllm_omni.diffusion.models.schedulers import FlowUniPCMultistepScheduler
|
||||
from vllm_omni.diffusion.models.wan2_2.chunked_mp4 import (
|
||||
resolve_wan_output_fps,
|
||||
resolve_wan_preencode_batch_frames,
|
||||
resolve_wan_preencode_mp4,
|
||||
resolve_wan_video_codec_options,
|
||||
wan_preencoded_mp4_payload,
|
||||
)
|
||||
from vllm_omni.diffusion.models.wan2_2.scheduling_wan_euler import WanEulerScheduler
|
||||
from vllm_omni.diffusion.models.wan2_2.wan2_2_transformer import WanSelfAttention, WanTransformer3DModel
|
||||
from vllm_omni.diffusion.offloader import OffloadPlan
|
||||
from vllm_omni.diffusion.postprocess import interpolate_video_tensor
|
||||
from vllm_omni.diffusion.profiler.diffusion_pipeline_profiler import DiffusionPipelineProfilerMixin
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
from vllm_omni.diffusion.utils.chunked_video import decode_to_mp4
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch, split_diffusion_output_by_request
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams, OmniTextPrompt
|
||||
from vllm_omni.platforms import current_omni_platform
|
||||
@@ -269,6 +277,9 @@ def get_wan22_post_process_func(
|
||||
output_type = sampling_params.output_type
|
||||
if output_type == "latent":
|
||||
return video
|
||||
encoded = wan_preencoded_mp4_payload(video)
|
||||
if encoded is not None:
|
||||
return encoded
|
||||
video_metadata = {}
|
||||
if sampling_params is not None and getattr(sampling_params, "enable_frame_interpolation", False):
|
||||
video, multiplier = interpolate_video_tensor(
|
||||
@@ -711,6 +722,8 @@ class Wan22Pipeline(
|
||||
num_steps = 40 if common.num_inference_steps is None else common.num_inference_steps
|
||||
|
||||
output_type = common.output_type or "np"
|
||||
preencode_mp4 = resolve_wan_preencode_mp4(common, output_type=output_type)
|
||||
preencode_batch_frames = resolve_wan_preencode_batch_frames(common) if preencode_mp4 else 17
|
||||
num_outputs_per_prompt = common.num_outputs_per_prompt or 1
|
||||
attention_kwargs: dict | None = None
|
||||
|
||||
@@ -965,27 +978,36 @@ class Wan22Pipeline(
|
||||
latents.device, latents.dtype
|
||||
)
|
||||
latents = latents / latents_std + latents_mean
|
||||
decoded = self.vae.decode(latents, return_dict=False)[0]
|
||||
# Distributed VAE decode uses broadcast_result=False, so only the
|
||||
# output-owning rank receives the full [B, C, T, H, W] video; other
|
||||
# ranks get an empty placeholder. Emit typed media only from the
|
||||
# owning rank and keep the placeholder on the legacy output field, so
|
||||
# the media batch-dimension check in split_diffusion_output_by_request
|
||||
# does not trip on every non-owner rank.
|
||||
if decoded.dim() == 5:
|
||||
output = None
|
||||
media = DiffusionMediaOutput(
|
||||
video=VideoMediaOutput(
|
||||
tensor=decoded,
|
||||
spec=VideoTensorSpec(
|
||||
layout=VideoTensorLayout.BCTHW,
|
||||
encoding=VideoTensorEncoding.NORMALIZED_FLOAT,
|
||||
value_range=VideoValueRange.NEGATIVE_ONE_TO_ONE,
|
||||
),
|
||||
)
|
||||
if preencode_mp4:
|
||||
output = decode_to_mp4(
|
||||
self.vae,
|
||||
latents,
|
||||
fps=resolve_wan_output_fps(common),
|
||||
batch_frames=preencode_batch_frames,
|
||||
video_codec_options=resolve_wan_video_codec_options(common),
|
||||
)
|
||||
else:
|
||||
output = decoded
|
||||
decoded = self.vae.decode(latents, return_dict=False)[0]
|
||||
# Distributed VAE decode uses broadcast_result=False, so only the
|
||||
# output-owning rank receives the full [B, C, T, H, W] video; other
|
||||
# ranks get an empty placeholder. Emit typed media only from the
|
||||
# owning rank and keep the placeholder on the legacy output field, so
|
||||
# the media batch-dimension check in split_diffusion_output_by_request
|
||||
# does not trip on every non-owner rank.
|
||||
if decoded.dim() == 5:
|
||||
output = None
|
||||
media = DiffusionMediaOutput(
|
||||
video=VideoMediaOutput(
|
||||
tensor=decoded,
|
||||
spec=VideoTensorSpec(
|
||||
layout=VideoTensorLayout.BCTHW,
|
||||
encoding=VideoTensorEncoding.NORMALIZED_FLOAT,
|
||||
value_range=VideoValueRange.NEGATIVE_ONE_TO_ONE,
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
output = decoded
|
||||
|
||||
if DEBUG_PERF:
|
||||
current_omni_platform.synchronize()
|
||||
|
||||
Reference in new issue
Block a user