-
Notifications
You must be signed in to change notification settings - Fork 233
update post process #1263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update post process #1263
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -522,7 +522,17 @@ def post_prompt_enhancer(self): | |||||||||||||||||||
| return enhanced_prompt | ||||||||||||||||||||
|
|
||||||||||||||||||||
| def process_images_after_vae_decoder(self): | ||||||||||||||||||||
| self.gen_video_final = wan_vae_to_comfy(self.gen_video_final) | ||||||||||||||||||||
| return_result_tensor = self.input_info.return_result_tensor | ||||||||||||||||||||
| save_result = self.input_info.save_result_path is not None | ||||||||||||||||||||
| main_process = not dist.is_initialized() or dist.get_rank() == 0 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| should_process = return_result_tensor or (save_result and main_process) | ||||||||||||||||||||
| if not should_process: | ||||||||||||||||||||
| self.gen_video_final = None | ||||||||||||||||||||
| return {"video": None} | ||||||||||||||||||||
|
Comment on lines
+530
to
+532
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| with ProfilingContext4DebugL2("wan_vae_to_comfy"): | ||||||||||||||||||||
| self.gen_video_final = wan_vae_to_comfy(self.gen_video_final) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if "video_frame_interpolation" in self.config: | ||||||||||||||||||||
| assert self.vfi_model is not None and self.config["video_frame_interpolation"].get("target_fps", None) is not None | ||||||||||||||||||||
|
|
@@ -534,36 +544,38 @@ def process_images_after_vae_decoder(self): | |||||||||||||||||||
| target_fps=target_fps, | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if self.input_info.return_result_tensor: | ||||||||||||||||||||
| if return_result_tensor: | ||||||||||||||||||||
| self.gen_video_final = self.gen_video_final.cpu() | ||||||||||||||||||||
| return {"video": self.gen_video_final} | ||||||||||||||||||||
|
Comment on lines
+547
to
549
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent the runner from holding onto the large video tensors after returning them to the caller, we should clear the internal references
Suggested change
|
||||||||||||||||||||
| elif self.input_info.save_result_path is not None: | ||||||||||||||||||||
| if "video_frame_interpolation" in self.config and self.config["video_frame_interpolation"].get("target_fps"): | ||||||||||||||||||||
| fps = self.config["video_frame_interpolation"]["target_fps"] | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| fps = self.config.get("fps", 16) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if not dist.is_initialized() or dist.get_rank() == 0: | ||||||||||||||||||||
| out_path = self.input_info.save_result_path | ||||||||||||||||||||
| img_in = (getattr(self.input_info, "image_path", None) or "").strip() | ||||||||||||||||||||
| vid_in = (getattr(self.input_info, "video_path", None) or "").strip() | ||||||||||||||||||||
| sr_from_image_only = self.config.get("task") == "sr" and bool(img_in) and not bool(vid_in) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if sr_from_image_only: | ||||||||||||||||||||
| logger.info("🖼 Start to save SR image (image_path input, no video_path) 🖼") | ||||||||||||||||||||
| save_to_image(self.gen_video_final, out_path) | ||||||||||||||||||||
| logger.info(f"✅ Image saved successfully to: {out_path} ✅") | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| logger.info(f"🎬 Start to save video 🎬") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| save_to_video(self.gen_video_final, out_path, fps=fps, method="ffmpeg") | ||||||||||||||||||||
| if self.config.get("task") in ("sr", "animate"): | ||||||||||||||||||||
| input_video_path = getattr(self.input_info, "video_path", "") | ||||||||||||||||||||
| if input_video_path: | ||||||||||||||||||||
| muxed_path = mux_audio_from_video(input_video_path, out_path) | ||||||||||||||||||||
| if muxed_path: | ||||||||||||||||||||
| logger.info(f"Audio muxed from input video: {input_video_path}") | ||||||||||||||||||||
| logger.info(f"✅ Video saved successfully to: {out_path} ✅") | ||||||||||||||||||||
| return {"video": None} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Reaching here means should_process was true because this is the main | ||||||||||||||||||||
| # process and a save path was provided. | ||||||||||||||||||||
| if "video_frame_interpolation" in self.config and self.config["video_frame_interpolation"].get("target_fps"): | ||||||||||||||||||||
| fps = self.config["video_frame_interpolation"]["target_fps"] | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| fps = self.config.get("fps", 16) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| out_path = self.input_info.save_result_path | ||||||||||||||||||||
| img_in = (getattr(self.input_info, "image_path", None) or "").strip() | ||||||||||||||||||||
| vid_in = (getattr(self.input_info, "video_path", None) or "").strip() | ||||||||||||||||||||
| sr_from_image_only = self.config.get("task") == "sr" and bool(img_in) and not bool(vid_in) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if sr_from_image_only: | ||||||||||||||||||||
| logger.info("🖼 Start to save SR image (image_path input, no video_path) 🖼") | ||||||||||||||||||||
| save_to_image(self.gen_video_final, out_path) | ||||||||||||||||||||
| logger.info(f"✅ Image saved successfully to: {out_path} ✅") | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| logger.info(f"🎬 Start to save video 🎬") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| save_to_video(self.gen_video_final, out_path, fps=fps, method="ffmpeg") | ||||||||||||||||||||
| if self.config.get("task") in ("sr", "animate"): | ||||||||||||||||||||
| input_video_path = getattr(self.input_info, "video_path", "") | ||||||||||||||||||||
| if input_video_path: | ||||||||||||||||||||
| muxed_path = mux_audio_from_video(input_video_path, out_path) | ||||||||||||||||||||
| if muxed_path: | ||||||||||||||||||||
| logger.info(f"Audio muxed from input video: {input_video_path}") | ||||||||||||||||||||
| logger.info(f"✅ Video saved successfully to: {out_path} ✅") | ||||||||||||||||||||
| return {"video": None} | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After successfully saving the video, the runner still holds references to
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @ProfilingContext4DebugL1("RUN pipeline", recorder_mode=GET_RECORDER_MODE(), metrics_func=monitor_cli.lightx2v_worker_request_duration, metrics_labels=["DefaultRunner"]) | ||||||||||||||||||||
| def run_pipeline(self, input_info): | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -827,23 +827,35 @@ def process_images_after_vae_decoder(self): | |||||||||||||||||||
| logger.info(f"Video saved to {self.input_info.save_result_path}") | ||||||||||||||||||||
| return {"video": None} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return_result_tensor = self.input_info.return_result_tensor | ||||||||||||||||||||
| save_result = self.input_info.save_result_path is not None | ||||||||||||||||||||
| main_process = is_main_process() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| should_process = return_result_tensor or (save_result and main_process) | ||||||||||||||||||||
| if not should_process: | ||||||||||||||||||||
| self.gen_video_final = None | ||||||||||||||||||||
| return {"video": None} | ||||||||||||||||||||
|
Comment on lines
+835
to
+837
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| self.gen_video_final = wan_vae_to_comfy(self.gen_video) | ||||||||||||||||||||
| if self.input_info.return_result_tensor: | ||||||||||||||||||||
| if return_result_tensor: | ||||||||||||||||||||
| self.gen_video_final = self.gen_video_final.cpu() | ||||||||||||||||||||
| return {"video": self.gen_video_final} | ||||||||||||||||||||
|
Comment on lines
+840
to
842
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent the runner from holding onto the large video tensors after returning them to the caller, we should clear the internal references
Suggested change
|
||||||||||||||||||||
| if self.input_info.save_result_path is not None and is_main_process(): | ||||||||||||||||||||
| out_path = self.input_info.save_result_path | ||||||||||||||||||||
| os.makedirs(os.path.dirname(out_path) or ".", exist_ok=True) | ||||||||||||||||||||
| save_to_video(self.gen_video_final, out_path, fps=self.target_fps, method="ffmpeg") | ||||||||||||||||||||
| # Prefer original input audio (full quality) over the 16kHz resampled wav | ||||||||||||||||||||
| original_audio = getattr(self.input_info, "audio_path", None) or self.config.get("audio_path", "") | ||||||||||||||||||||
| original_audio = original_audio.split(",")[0].strip() if original_audio else None | ||||||||||||||||||||
| mux_audio = original_audio if (original_audio and os.path.isfile(original_audio)) else self.video_audio_path | ||||||||||||||||||||
| if mux_audio and os.path.isfile(mux_audio): | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| self._mux_audio(out_path, mux_audio) | ||||||||||||||||||||
| finally: | ||||||||||||||||||||
| self._remove_video_audio_path() | ||||||||||||||||||||
| logger.info(f"Video saved to {out_path}") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Reaching here means should_process was true because this is the main | ||||||||||||||||||||
| # process and a save path was provided. | ||||||||||||||||||||
| out_path = self.input_info.save_result_path | ||||||||||||||||||||
| os.makedirs(os.path.dirname(out_path) or ".", exist_ok=True) | ||||||||||||||||||||
| save_to_video(self.gen_video_final, out_path, fps=self.target_fps, method="ffmpeg") | ||||||||||||||||||||
| # Prefer original input audio (full quality) over the 16kHz resampled wav | ||||||||||||||||||||
| original_audio = getattr(self.input_info, "audio_path", None) or self.config.get("audio_path", "") | ||||||||||||||||||||
| original_audio = original_audio.split(",")[0].strip() if original_audio else None | ||||||||||||||||||||
| mux_audio = original_audio if (original_audio and os.path.isfile(original_audio)) else self.video_audio_path | ||||||||||||||||||||
| if mux_audio and os.path.isfile(mux_audio): | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| self._mux_audio(out_path, mux_audio) | ||||||||||||||||||||
| finally: | ||||||||||||||||||||
| self._remove_video_audio_path() | ||||||||||||||||||||
| logger.info(f"Video saved to {out_path}") | ||||||||||||||||||||
| return {"video": None} | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After successfully saving the video, the runner still holds references to
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
dist.is_initialized()directly might fail if the distributed package is not available on the platform. It is safer and more robust to checkdist.is_available()first, consistent with the helper functionis_main_process().