Nodes/comfyui-auto-size/πŸ“ Auto Size Latent
ComfyUI Node

πŸ“ Auto Size Latent

An empty latent that already knows your model's native size

By jluo-githubΒ·Created 7 months agoΒ·Updated 5 months agoΒ· 0
πŸ“ Auto Size Latent
    • latent
    • width
    • height
    • size
    β—„modelqwen-imageβ–Ί
    β—„sizeFull Custom (Use Inputs Below)β–Ί
    β—„custom_longer_size0β–Ί
    β—„custom_ratio1:1β–Ί
    β—„batch_size1β–Ί

    For text-to-image, you usually don't have a source image to resize - you have a blank canvas and a resolution box. If you've ever stood in front of ComfyUI's default EmptyLatentImage wondering whether to type 1024 or 1328, this is the node for you. πŸ“ Auto Size Latent is the sibling of πŸ“ Auto Size: same resolution logic, but instead of resizing an existing image it generates an empty latent directly at the size your model actually wants.

    What it does

    You pick a model - qwen-image, illustrious, z-image, or flux - and a size from the dropdown, and the node hands you a ready-to-sample empty latent at that model's native resolution. No remembering that Qwen-Image runs on 28px multiples (hence odd-looking numbers like 1328x1328) while Illustrious, Z-Image and Flux run on 32px. The preset table in utils/presets.py does the remembering for you.

    It shares the whole resolution mechanism with Auto Size. Preset mode uses the fixed entries like Qwen - 9:16 (928x1664) verbatim; Full Custom mode takes custom_longer_size (longer side in pixels) plus custom_ratio, computes the other side, and snaps both to the model's multiple. batch_size sets how many latents you get in one go - 1 by default, which is what you'll want almost always.

    The mechanism, and the one thing to check

    Under the hood it's exactly what ComfyUI's own EmptyLatentImage does, with the resolution math swapped in:

    • latent_width = target_width // 8, latent_height = target_height // 8
    • a torch.zeros([batch_size, 4, latent_height, latent_width]) tensor

    Four channels, 8x downsampled. That's perfect for SDXL-family models - Illustrious being the one in this pack's list where it's exactly right. But here's the trap: Flux does not use a 4-channel latent. Its VAE produces 16-channel latents, and its samplers expect that shape. If you feed this node's output into a Flux KSampler you'll get a shape mismatch, not a nice image. Same story applies to any model whose VAE isn't the bog-standard SDXL layout - Qwen-Image's VAE is another one that isn't a plain 4-channel encoder.

    So treat AutoSize Latent as: flawless for Illustrious, and a solid resolution calculator for Flux and Qwen. If your model needs a different latent shape, use its own empty-latent node for the actual tensor and steal the width and height outputs from this node to keep everything aligned.

    Inputs and outputs

    Inputs: model, size, custom_longer_size, custom_ratio, batch_size. Outputs: latent, width, height, size. The width/height integers are genuinely useful - they're the model-aligned dimensions, so you can wire them straight into anything that wants a resolution (upscale targets, conditioning, a second KSampler's size). The node is an output node, so the resolved size also appears as text in the UI.

    Installing it

    Same pack, one install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jluo-github/comfyui-auto-size.git
    

    Then restart ComfyUI. ComfyUI Manager also finds it under "Auto Size". No model downloads, no Python deps beyond torch (already present). It's a small pack with two nodes that share this install - you get Auto Size for image editing workflows at the same time.

    When you'd actually reach for it

    If you batch-generate across model families and keep forgetting which resolution each one wants, this node removes a whole class of "why is this soft/blurry/wrong-shaped" debugging. If you only ever run one model at one size, it's a convenience you may not need - but the width/height outputs plus the model-aware snapping make it more than a pretty dropdown.

    Categorylatent/AutoSize

    Inputs (5)

    NameTypeDefaultDescription
    modelCOMBOqwen-image4 options: qwen-image, illustrious, z-image, flux
    sizeCOMBOFull Custom (Use Inputs Below)51 options: Full Custom (Use Inputs Below), Qwen - 1:1 (1328x1328), Qwen - 9:16 (928x1664), Qwen - 16:9 (1664x928), Qwen - 3:4 (1104x1472), Qwen - 4:3 (1472x1104), +45
    custom_longer_sizeINT00–8192β€”
    custom_ratioCOMBO1:115 options: 1:1, 1:2, 2:1, 2:3, 3:2, 3:4, +9
    batch_sizeINT11–4096β€”

    Outputs (4)

    NameTypeDescription
    latentLATENTβ€”
    widthINTβ€”
    heightINTβ€”
    sizeSTRINGβ€”