ONNX tracing fixes.

This commit is contained in:
comfyanonymous
2024-08-04 15:45:43 -04:00
parent 0a6b008117
commit 3b71f84b50
5 changed files with 16 additions and 13 deletions

8
comfy/ldm/common_dit.py Normal file
View File

@@ -0,0 +1,8 @@
import torch
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)