Skip to content

Commit 6207f86

Browse files
Fix VAEEncodeForInpaint to support WAN VAE tuple downscale_ratio (Comfy-Org#11572)
Use vae.spacial_compression_encode() instead of directly accessing downscale_ratio to handle both standard VAEs (int) and WAN VAEs (tuple). Addresses reviewer feedback on PR Comfy-Org#11259. Co-authored-by: ChrisFab16 <christopher@fabritius.dk>
1 parent 1dc3da6 commit 6207f86

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

nodes.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,15 @@ def INPUT_TYPES(s):
378378
CATEGORY = "latent/inpaint"
379379

380380
def encode(self, vae, pixels, mask, grow_mask_by=6):
381-
x = (pixels.shape[1] // vae.downscale_ratio) * vae.downscale_ratio
382-
y = (pixels.shape[2] // vae.downscale_ratio) * vae.downscale_ratio
381+
downscale_ratio = vae.spacial_compression_encode()
382+
x = (pixels.shape[1] // downscale_ratio) * downscale_ratio
383+
y = (pixels.shape[2] // downscale_ratio) * downscale_ratio
383384
mask = torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(pixels.shape[1], pixels.shape[2]), mode="bilinear")
384385

385386
pixels = pixels.clone()
386387
if pixels.shape[1] != x or pixels.shape[2] != y:
387-
x_offset = (pixels.shape[1] % vae.downscale_ratio) // 2
388-
y_offset = (pixels.shape[2] % vae.downscale_ratio) // 2
388+
x_offset = (pixels.shape[1] % downscale_ratio) // 2
389+
y_offset = (pixels.shape[2] % downscale_ratio) // 2
389390
pixels = pixels[:,x_offset:x + x_offset, y_offset:y + y_offset,:]
390391
mask = mask[:,:,x_offset:x + x_offset, y_offset:y + y_offset]
391392

0 commit comments

Comments
 (0)