From c05b1a2fd0ba27be6fe36c120b26a6f20d780107 Mon Sep 17 00:00:00 2001 From: ziyannchen <1041276865@qq.com> Date: Sun, 20 Jul 2025 11:13:20 +0000 Subject: [PATCH] fix a bug in sliding window inference --- diffsynth/pipelines/wan_video_new.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/diffsynth/pipelines/wan_video_new.py b/diffsynth/pipelines/wan_video_new.py index 59b4690..f1a4dfe 100644 --- a/diffsynth/pipelines/wan_video_new.py +++ b/diffsynth/pipelines/wan_video_new.py @@ -1012,12 +1012,16 @@ class TemporalTiler_BCTHW: def __init__(self): pass - def build_1d_mask(self, length, left_bound, right_bound, border_width): + def build_1d_mask(length, left_bound, right_bound, border_width): x = torch.ones((length,)) + if border_width == 0: + return x + + shift = 0.5 if not left_bound: - x[:border_width] = (torch.arange(border_width) + 1) / border_width + x[:border_width] = (torch.arange(border_width) + shift) / border_width if not right_bound: - x[-border_width:] = torch.flip((torch.arange(border_width) + 1) / border_width, dims=(0,)) + x[-border_width:] = torch.flip((torch.arange(border_width) + shift) / border_width, dims=(0,)) return x def build_mask(self, data, is_bound, border_width): @@ -1047,7 +1051,7 @@ class TemporalTiler_BCTHW: mask = self.build_mask( model_output, is_bound=(t == 0, t_ == T), - border_width=(sliding_window_size - sliding_window_stride + 1,) + border_width=(sliding_window_size - sliding_window_stride,) ).to(device=data_device, dtype=data_dtype) value[:, :, t: t_, :, :] += model_output * mask weight[:, :, t: t_, :, :] += mask