From 3d46721b5c6d433425125faa6d1a27820cb437fc Mon Sep 17 00:00:00 2001 From: Jayce-Ping <315229706@qq.com> Date: Wed, 28 Jan 2026 07:24:18 +0800 Subject: [PATCH 1/4] Fix Wan/WanI2V patchification --- src/diffusers/pipelines/wan/pipeline_wan.py | 10 ++++++++++ src/diffusers/pipelines/wan/pipeline_wan_i2v.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/diffusers/pipelines/wan/pipeline_wan.py b/src/diffusers/pipelines/wan/pipeline_wan.py index dc2bb471101d..cc473606439e 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan.py +++ b/src/diffusers/pipelines/wan/pipeline_wan.py @@ -495,6 +495,16 @@ def __call__( ) num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) + + multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification + calc_height = height // multiple_of * multiple_of + calc_width = width // multiple_of * multiple_of + if height != calc_height or width != calc_width: + logger.warning( + f"`height` and `width` must be multiples of {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 b7fd0b05980f..cbacb7b39d55 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py +++ b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py @@ -637,6 +637,16 @@ def __call__( num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) + multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification + calc_height = height // multiple_of * multiple_of + calc_width = width // multiple_of * multiple_of + if height != calc_height or width != calc_width: + logger.warning( + f"`height` and `width` must be multiples of {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 From 543559cacdb9d7c739cd26531d8f94878557dc11 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 28 Jan 2026 06:20:43 +0000 Subject: [PATCH 2/4] Apply style fixes --- src/diffusers/pipelines/wan/pipeline_wan.py | 4 ++-- src/diffusers/pipelines/wan/pipeline_wan_i2v.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/diffusers/pipelines/wan/pipeline_wan.py b/src/diffusers/pipelines/wan/pipeline_wan.py index cc473606439e..c8e697c70c8d 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan.py +++ b/src/diffusers/pipelines/wan/pipeline_wan.py @@ -495,8 +495,8 @@ def __call__( ) num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) - - multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification + + multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification calc_height = height // multiple_of * multiple_of calc_width = width // multiple_of * multiple_of if height != calc_height or width != calc_width: diff --git a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py index cbacb7b39d55..119f880c90f8 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py +++ b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py @@ -637,7 +637,7 @@ def __call__( num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) - multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification + multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification calc_height = height // multiple_of * multiple_of calc_width = width // multiple_of * multiple_of if height != calc_height or width != calc_width: @@ -646,7 +646,7 @@ def __call__( 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 From 7c8154bab7306e9e8fecc59ae22c9a3e79819206 Mon Sep 17 00:00:00 2001 From: Jayce <93087577+Jayce-Ping@users.noreply.github.com> Date: Wed, 28 Jan 2026 16:18:17 +0800 Subject: [PATCH 3/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I agree with you for the idea of using `patch_size` instead. Thanks!😊 Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com> --- src/diffusers/pipelines/wan/pipeline_wan.py | 7 ++++--- src/diffusers/pipelines/wan/pipeline_wan_i2v.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/diffusers/pipelines/wan/pipeline_wan.py b/src/diffusers/pipelines/wan/pipeline_wan.py index c8e697c70c8d..a1cf5c307c83 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan.py +++ b/src/diffusers/pipelines/wan/pipeline_wan.py @@ -496,9 +496,10 @@ def __call__( num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) - multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification - calc_height = height // multiple_of * multiple_of - calc_width = width // multiple_of * multiple_of + 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 {multiple_of} for proper patchification. " diff --git a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py index 119f880c90f8..7fbdb5a99fb5 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py +++ b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py @@ -637,9 +637,10 @@ def __call__( num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1 num_frames = max(num_frames, 1) - multiple_of = self.vae_scale_factor_spatial * 2 # 2 for patchification - calc_height = height // multiple_of * multiple_of - calc_width = width // multiple_of * multiple_of + 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 {multiple_of} for proper patchification. " From eb7b08328784ec088ab14b3904f11c158bcbf19b Mon Sep 17 00:00:00 2001 From: Jayce-Ping <315229706@qq.com> Date: Wed, 28 Jan 2026 19:29:51 +0800 Subject: [PATCH 4/4] Fix logger warning --- src/diffusers/pipelines/wan/pipeline_wan.py | 2 +- src/diffusers/pipelines/wan/pipeline_wan_i2v.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffusers/pipelines/wan/pipeline_wan.py b/src/diffusers/pipelines/wan/pipeline_wan.py index a1cf5c307c83..362440c8c9c8 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan.py +++ b/src/diffusers/pipelines/wan/pipeline_wan.py @@ -502,7 +502,7 @@ def __call__( 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 {multiple_of} for proper patchification. " + 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 diff --git a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py index 7fbdb5a99fb5..e22d8393bd1a 100644 --- a/src/diffusers/pipelines/wan/pipeline_wan_i2v.py +++ b/src/diffusers/pipelines/wan/pipeline_wan_i2v.py @@ -643,7 +643,7 @@ def __call__( 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 {multiple_of} for proper patchification. " + 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