From a58d0b9bec320722aaf193f269bf5c2ffd51d0d4 Mon Sep 17 00:00:00 2001 From: Jayce <93087577+Jayce-Ping@users.noreply.github.com> Date: Thu, 29 Jan 2026 10:06:58 +0800 Subject: [PATCH] Fix Wan/WanI2V patchification (#13038) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix Wan/WanI2V patchification * Apply style fixes * Apply suggestions from code review I agree with you for the idea of using `patch_size` instead. Thanks!😊 Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com> * Fix logger warning --------- Co-authored-by: github-actions[bot] Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com> --- src/diffusers/pipelines/wan/pipeline_wan.py | 11 +++++++++++ src/diffusers/pipelines/wan/pipeline_wan_i2v.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/diffusers/pipelines/wan/pipeline_wan.py b/src/diffusers/pipelines/wan/pipeline_wan.py index dc2bb47110..362440c8c9 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan.py +++ b/src/diffusers/pipelines/wan/pipeline_wan.py @@ -496,6 +496,17 @@ class WanPipeline(DiffusionPipeline, WanLoraLoaderMixin): num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) + h_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[1] + w_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[2] + calc_height = height // h_multiple_of * h_multiple_of + calc_width = width // w_multiple_of * w_multiple_of + if height != calc_height or width != calc_width: + logger.warning( + f"`height` and `width` must be multiples of ({h_multiple_of}, {w_multiple_of}) for proper patchification. " + f"Adjusting ({height}, {width}) -> ({calc_height}, {calc_width})." + ) + height, width = calc_height, calc_width + if self.config.boundary_ratio is not None and guidance_scale_2 is None: guidance_scale_2 = guidance_scale diff --git a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py index b7fd0b0598..e22d8393bd 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py +++ b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py @@ -637,6 +637,17 @@ class WanImageToVideoPipeline(DiffusionPipeline, WanLoraLoaderMixin): num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) + h_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[1] + w_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[2] + calc_height = height // h_multiple_of * h_multiple_of + calc_width = width // w_multiple_of * w_multiple_of + if height != calc_height or width != calc_width: + logger.warning( + f"`height` and `width` must be multiples of ({h_multiple_of}, {w_multiple_of}) for proper patchification. " + f"Adjusting ({height}, {width}) -> ({calc_height}, {calc_width})." + ) + height, width = calc_height, calc_width + if self.config.boundary_ratio is not None and guidance_scale_2 is None: guidance_scale_2 = guidance_scale