Skip to content

Why does calculate_dimensions in qwen-image-edit require image height/width to be multiples of 32? #12997

Open

Description

@lucky-liuzhihong

Hi, thanks for the great work!
I have a question regarding the logic in calculate_dimensions.
Currently, the image height and width are constrained to be multiples of 32.
From my understanding:
The VAE has a downsampling factor of 8, so the latent spatial size should require the input dimensions to be multiples of 8.
Before entering the DiT, the latent is passed through a Patch Embedding layer with patch_size = 2.
That would further imply a total factor of 8 × 2 = 16.
Based on this, it seems that constraining the image dimensions to be multiples of 16 should already be sufficient.

Could you clarify why a multiple of 32 is required here?
Is there an additional downsampling stage, architectural constraint, or implementation detail that I might be missing?
Thanks in advance for the clarification!

Activity

  1. chinmayirm commented on Sep 22, 2026

    @chinmayirm

    Hi @lucky-liuzhihong, the factor of 16 you derived is the architectural minimum. The 32 in calculate_dimensions is the size this pipeline actually resizes to.

    Root cause

    vae_scale_factor is 8, and the transformer packs latents in 2×2 patches, so vae_scale_factor * 2 is 16. __call__ checks that multiple, and VaeImageProcessor is built with it. A side of 16 is enough for the VAE and the patch embedding.

    calculate_dimensions then does round(x / 32) * 32 anyway. There is no third downsample. The Qwen-Image-Edit release resizes condition images on that 32 grid (area 1024 * 1024 for the VAE image, 384 * 384 for the vision-language image). The helper matches that preprocessing, so a local run hits the same height and width as the published pipeline.

    Proposed approach

    Keep the rounding at 32. Changing it to 16 would load and decode sizes the release pipeline never uses. A one-line comment on calculate_dimensions is enough: 16 is the model constraint, 32 is the release grid.

    I would be glad to open a PR for that comment if it would help.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions