Skip to content

Fix VAEEncodeForInpaint to support WAN VAE tuple downscale_ratio#11259

Open
ChrisFab16 wants to merge 1 commit intoComfy-Org:masterfrom
ChrisFab16:fix/wan-vae-downscale-ratio-inpaint
Open

Fix VAEEncodeForInpaint to support WAN VAE tuple downscale_ratio#11259
ChrisFab16 wants to merge 1 commit intoComfy-Org:masterfrom
ChrisFab16:fix/wan-vae-downscale-ratio-inpaint

Conversation

@ChrisFab16
Copy link
Contributor

  • Handle WAN VAE downscale_ratio which is a tuple (function, min, max) instead of integer
  • Fixes TypeError when using VAEEncodeForInpaint with Qwen Image/WAN VAEs
  • Backward compatible with standard VAEs that use integer downscale_ratio

nodes.py Outdated
def encode(self, vae, pixels, mask, grow_mask_by=6):
x = (pixels.shape[1] // vae.downscale_ratio) * vae.downscale_ratio
y = (pixels.shape[2] // vae.downscale_ratio) * vae.downscale_ratio
# Handle WAN VAE downscale_ratio which can be a tuple (function, min, max)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these actually min/max?

It looks like x and y. This code looks like it might be solving the same problem:

    def spacial_compression_decode(self):
        try:
            return self.upscale_ratio[-1]
        except:
            return self.upscale_ratio

    def spacial_compression_encode(self):
        try:
            return self.downscale_ratio[-1]
        except:
            return self.downscale_ratio

Can you just call vae.spacial_compression_encode():

        x = (pixels.shape[1] // vae.spacial_compression_encode()) * vae.spacial_compression_encode()
        y = (pixels.shape[2] // vae.spacial_compression_encode()) * vae.spacial_compression_encode()

@ChrisFab16
Copy link
Contributor Author

Thanks for the feedback, @rattus128!
I updated VAEEncodeForInpaint to use vae.spacial_compression_encode() for the downscale ratio and offsets, matching the existing VAE helper used elsewhere. This removes the manual tuple handling and works for both WAN-style tuples and standard ints. Tested locally with mock VAEs; both tuple and int downscale cases behave as expected.

@ChrisFab16 ChrisFab16 force-pushed the fix/wan-vae-downscale-ratio-inpaint branch from 58d8f0b to c01c1f8 Compare December 17, 2025 06:41
@rattus128
Copy link
Contributor

If you check the diff here, I think your IDE or git or something has done a full whitespace reformat of the file. You will need to reduce the diff back to just the content changes with whitespace consistency to surrounds.

image

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.
@ChrisFab16 ChrisFab16 force-pushed the fix/wan-vae-downscale-ratio-inpaint branch from fd6dd34 to 01b86f1 Compare December 19, 2025 09:40
rattus128 pushed a commit to rattus128/ComfyUI that referenced this pull request Dec 31, 2025
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.
comfyanonymous pushed a commit that referenced this pull request Jan 9, 2026
)

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 #11259.

Co-authored-by: ChrisFab16 <christopher@fabritius.dk>
@comfy-pr-bot
Copy link
Member

Test Evidence Check

⚠️ Warning: Test Explanation Missing

If this PR modifies behavior that requires testing, a test explanation is required. PRs lacking applicable test explanations may not be reviewed until added. Please add test explanations to ensure code quality and prevent regressions.

⚠️ Warning: Visual Documentation Missing

If this PR changes user-facing behavior, visual proof (screen recording or screenshot) is required. PRs without applicable visual documentation may not be reviewed until provided.

You can add it by:

  • GitHub: Drag & drop media directly into the PR description
  • YouTube: Include a link to a short demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants