From 4e14032c02d580e8f54f1e336199e2dee4340ef9 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Fri, 13 Dec 2024 07:21:52 -0500 Subject: [PATCH] Make pad_to_patch_size function work on multi dim. --- comfy/ldm/common_dit.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/comfy/ldm/common_dit.py b/comfy/ldm/common_dit.py index a9139696..e0f3057f 100644 --- a/comfy/ldm/common_dit.py +++ b/comfy/ldm/common_dit.py @@ -4,9 +4,12 @@ import comfy.ops def pad_to_patch_size(img, patch_size=(2, 2), padding_mode="circular"): if padding_mode == "circular" and (torch.jit.is_tracing() or torch.jit.is_scripting()): padding_mode = "reflect" - pad_h = (patch_size[0] - img.shape[-2] % patch_size[0]) % patch_size[0] - pad_w = (patch_size[1] - img.shape[-1] % patch_size[1]) % patch_size[1] - return torch.nn.functional.pad(img, (0, pad_w, 0, pad_h), mode=padding_mode) + + pad = () + for i in range(img.ndim - 2): + pad = (0, (patch_size[i] - img.shape[i + 2] % patch_size[i]) % patch_size[i]) + pad + + return torch.nn.functional.pad(img, pad, mode=padding_mode) try: rms_norm_torch = torch.nn.functional.rms_norm