Skip to content

Commit a58d0b9

Browse files
Jayce-Pinggithub-actions[bot]dg845
authored
Fix Wan/WanI2V patchification (#13038)
* 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] <github-actions[bot]@users.noreply.github.com> Co-authored-by: dg845 <58458699+dg845@users.noreply.github.com>
1 parent 0ab2124 commit a58d0b9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/diffusers/pipelines/wan/pipeline_wan.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,17 @@ def __call__(
496496
num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1
497497
num_frames = max(num_frames, 1)
498498

499+
h_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[1]
500+
w_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[2]
501+
calc_height = height // h_multiple_of * h_multiple_of
502+
calc_width = width // w_multiple_of * w_multiple_of
503+
if height != calc_height or width != calc_width:
504+
logger.warning(
505+
f"`height` and `width` must be multiples of ({h_multiple_of}, {w_multiple_of}) for proper patchification. "
506+
f"Adjusting ({height}, {width}) -> ({calc_height}, {calc_width})."
507+
)
508+
height, width = calc_height, calc_width
509+
499510
if self.config.boundary_ratio is not None and guidance_scale_2 is None:
500511
guidance_scale_2 = guidance_scale
501512

src/diffusers/pipelines/wan/pipeline_wan_i2v.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,17 @@ def __call__(
637637
num_frames = num_frames // self.vae_scale_factor_temporal * self.vae_scale_factor_temporal + 1
638638
num_frames = max(num_frames, 1)
639639

640+
h_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[1]
641+
w_multiple_of = self.vae_scale_factor_spatial * self.transformer.config.patch_size[2]
642+
calc_height = height // h_multiple_of * h_multiple_of
643+
calc_width = width // w_multiple_of * w_multiple_of
644+
if height != calc_height or width != calc_width:
645+
logger.warning(
646+
f"`height` and `width` must be multiples of ({h_multiple_of}, {w_multiple_of}) for proper patchification. "
647+
f"Adjusting ({height}, {width}) -> ({calc_height}, {calc_width})."
648+
)
649+
height, width = calc_height, calc_width
650+
640651
if self.config.boundary_ratio is not None and guidance_scale_2 is None:
641652
guidance_scale_2 = guidance_scale
642653

0 commit comments

Comments
 (0)