-
Notifications
You must be signed in to change notification settings - Fork 149
Gp/output #825
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
Gp/output #825
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 |
|---|---|---|
|
|
@@ -399,12 +399,14 @@ def run_pipeline(self, input_info): | |
|
|
||
| if not input_info.return_result_tensor: | ||
| image = images[0] | ||
| image.save(f"{input_info.save_result_path}") | ||
| image.save(input_info.save_result_path) | ||
| logger.info(f"Image saved: {input_info.save_result_path}") | ||
|
|
||
| del latents, generator | ||
| torch_device_module.empty_cache() | ||
| gc.collect() | ||
|
|
||
| # Return (images, audio) - audio is None for default runner | ||
| return images, None | ||
| if input_info.return_result_tensor: | ||
| return {"images": images} | ||
| elif input_info.save_result_path is not None: | ||
| return {"images": None} | ||
|
Comment on lines
+409
to
+412
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. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -344,12 +344,14 @@ def run_pipeline(self, input_info): | |
|
|
||
| if not input_info.return_result_tensor: | ||
| image = images[0] | ||
| image.save(f"{input_info.save_result_path}") | ||
| image.save(input_info.save_result_path) | ||
| logger.info(f"Image saved: {input_info.save_result_path}") | ||
|
|
||
| del latents, generator | ||
| torch_device_module.empty_cache() | ||
| gc.collect() | ||
|
|
||
| # Return (images, audio) - audio is None for default runner | ||
| return images, None | ||
| if input_info.return_result_tensor: | ||
| return {"images": images} | ||
| elif input_info.save_result_path is not None: | ||
| return {"images": None} | ||
|
Comment on lines
+354
to
+357
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. Similar to other image runners, the return type of the |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -106,68 +106,42 @@ def cache_video( | |||||||||||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def vae_to_comfyui_image(vae_output: torch.Tensor) -> torch.Tensor: | ||||||||||||||||||||||||||||||||||||||||||||
| def wan_vae_to_comfy(vae_output: torch.Tensor) -> torch.Tensor: | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| Convert VAE decoder output to ComfyUI Image format | ||||||||||||||||||||||||||||||||||||||||||||
| Convert VAE decoder output to ComfyUI Image format (inplace operation) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output: VAE decoder output tensor, typically in range [-1, 1] | ||||||||||||||||||||||||||||||||||||||||||||
| Shape: [B, C, T, H, W] or [B, C, H, W] | ||||||||||||||||||||||||||||||||||||||||||||
| WARNING: This tensor will be modified in-place! | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||
| ComfyUI Image tensor in range [0, 1] | ||||||||||||||||||||||||||||||||||||||||||||
| Shape: [B, H, W, C] for single frame or [B*T, H, W, C] for video | ||||||||||||||||||||||||||||||||||||||||||||
| Note: The returned tensor is the same object as input (modified in-place) | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+111
to
+121
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. The docstring for
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| # Handle video tensor (5D) vs image tensor (4D) | ||||||||||||||||||||||||||||||||||||||||||||
| if vae_output.dim() == 5: | ||||||||||||||||||||||||||||||||||||||||||||
| # Video tensor: [B, C, T, H, W] | ||||||||||||||||||||||||||||||||||||||||||||
| B, C, T, H, W = vae_output.shape | ||||||||||||||||||||||||||||||||||||||||||||
| # Reshape to [B*T, C, H, W] for processing | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output = vae_output.permute(0, 2, 1, 3, 4).reshape(B * T, C, H, W) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Normalize from [-1, 1] to [0, 1] | ||||||||||||||||||||||||||||||||||||||||||||
| images = (vae_output + 1) / 2 | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Clamp values to [0, 1] | ||||||||||||||||||||||||||||||||||||||||||||
| images = torch.clamp(images, 0, 1) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Convert from [B, C, H, W] to [B, H, W, C] | ||||||||||||||||||||||||||||||||||||||||||||
| images = images.permute(0, 2, 3, 1).cpu() | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output.add_(1.0).mul_(0.5).clamp_(0.0, 1.0) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return images | ||||||||||||||||||||||||||||||||||||||||||||
| if vae_output.ndim == 5: | ||||||||||||||||||||||||||||||||||||||||||||
| # Video: [B, C, T, H, W] -> [B, T, H, W, C] | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output = vae_output.permute(0, 2, 3, 4, 1) | ||||||||||||||||||||||||||||||||||||||||||||
| # -> [B*T, H, W, C] | ||||||||||||||||||||||||||||||||||||||||||||
| return vae_output.cpu().flatten(0, 1) | ||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||
| # Image: [B, C, H, W] -> [B, H, W, C] | ||||||||||||||||||||||||||||||||||||||||||||
| return vae_output.permute(0, 2, 3, 1).cpu() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def vae_to_comfyui_image_inplace(vae_output: torch.Tensor) -> torch.Tensor: | ||||||||||||||||||||||||||||||||||||||||||||
| def diffusers_vae_to_comfy(vae_output: torch.Tensor) -> torch.Tensor: | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| Convert VAE decoder output to ComfyUI Image format (inplace operation) | ||||||||||||||||||||||||||||||||||||||||||||
| Convert Diffusers VAE decoder output to ComfyUI Image format | ||||||||||||||||||||||||||||||||||||||||||||
| Image processor for VAE, return tensor in range [0, 1] when do_denormalize is True. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output: VAE decoder output tensor, typically in range [-1, 1] | ||||||||||||||||||||||||||||||||||||||||||||
| Shape: [B, C, T, H, W] or [B, C, H, W] | ||||||||||||||||||||||||||||||||||||||||||||
| WARNING: This tensor will be modified in-place! | ||||||||||||||||||||||||||||||||||||||||||||
| ref: https://github.com/huggingface/diffusers/blob/main/src/diffusers/image_processor.py#L744 | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||
| ComfyUI Image tensor in range [0, 1] | ||||||||||||||||||||||||||||||||||||||||||||
| Shape: [B, H, W, C] for single frame or [B*T, H, W, C] for video | ||||||||||||||||||||||||||||||||||||||||||||
| Note: The returned tensor is the same object as input (modified in-place) | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
| # Handle video tensor (5D) vs image tensor (4D) | ||||||||||||||||||||||||||||||||||||||||||||
| if vae_output.dim() == 5: | ||||||||||||||||||||||||||||||||||||||||||||
| # Video tensor: [B, C, T, H, W] | ||||||||||||||||||||||||||||||||||||||||||||
| B, C, T, H, W = vae_output.shape | ||||||||||||||||||||||||||||||||||||||||||||
| # Reshape to [B*T, C, H, W] for processing (inplace view) | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output = vae_output.permute(0, 2, 1, 3, 4).contiguous().view(B * T, C, H, W) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Normalize from [-1, 1] to [0, 1] (inplace) | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output.add_(1).div_(2) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Clamp values to [0, 1] (inplace) | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output.clamp_(0, 1) | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Convert from [B, C, H, W] to [B, H, W, C] and move to CPU | ||||||||||||||||||||||||||||||||||||||||||||
| vae_output = vae_output.permute(0, 2, 3, 1).cpu() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return vae_output | ||||||||||||||||||||||||||||||||||||||||||||
| return vae_output.permute(0, 2, 3, 1).cpu() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def save_to_video( | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
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.
The change from
vae_to_comfyui_image(which was not in-place) towan_vae_to_comfy(which performs in-place normalization) represents a behavioral change forself.gen_video_final. While the assignment immediately overwrites the reference, it's important to be aware thatself.gen_video_finalis now modified in-place before being reassigned. This is generally acceptable for efficiency, but it's a subtle change from the previous non-in-place function.