Nodes/comfyui-koala/Koala Aspect Ratio Empty Latent
ComfyUI Node

Koala Aspect Ratio Empty Latent

Stop guessing resolutions — snap your empty latent to a trained aspect ratio

By cloudkoala·Created about a year ago·Updated about a year ago· 0
Koala Aspect Ratio Empty Latent
  • image
  • latent
  • width
  • height
  • aspect_ratio
  • info
batch_size1
width1024
height1024

The stock Empty Latent node will happily give you a 1137×931 latent and let the sampler cook up double heads and stretched anatomy at it. The Koala Aspect Ratio Empty Latent node won't. It takes whatever resolution you feed it, snaps it to the nearest ratio in a fixed table of 40 "training-optimized" buckets, and hands you an empty latent that actually lands on a ratio your model was trained on. If you've ever stared at a weird aspect-ratio output and wondered why the model lost it, this is the fix in node form.

Here's why it matters: diffusion models are trained on a discrete set of aspect ratios, not every resolution under the sun. Generate way off one and you get the classic failure modes - duplicated anatomy, stretched limbs, composition chaos. The standard advice is to generate at a trained ratio and then upscale or crop. This node automates the "which trained ratio?" part of that.

How it works

You give it either an image or a width/height, and it computes the aspect ratio as height ÷ width. It then picks the closest entry from a table of 40 buckets spanning 0.25 (512×2048) to 4.0 (2048×512), all multiples of 64, centered on 1024×1024 - including your 1:1, 16:9, 9:16, 4:3 and friends. The matched dimensions are then divided by 8 to build the latent, since the VAE downscales 8× per side: a 1024×1024 target becomes a 128×128 latent.

A neat consequence: a 16:9 image comes out as 1344×768 - that's 7:4, the closest trained ratio - which is exactly what the resolution advice in every workflow thread tells you to do by hand.

The inputs and outputs that matter

  • batch_size (1–64): how many empty latents to make. Leave at 1.
  • image (optional): if you connect one, its dimensions win and width/height are ignored. Great for img2img where you want to match a reference's ratio.
  • width / height (optional, defaults 1024, step 8): the manual fallback when no image is attached.

You get five outputs: the latent itself (wire it into your sampler), the matched width and height as plain ints, the matched aspect_ratio as a float, and an info string that shows exactly what went in and what it snapped to - genuinely handy for debugging why your output is 1344×768 when you asked for 1920×1080.

The catch: it's SD/SDXL-shaped

The latent is hardcoded to 4 channels and 8× downscale. That's correct for SD 1.5 and SDXL, and wrong for Flux (16 latent channels) and the 2026 pixel-space models that have no VAE at all. Point this at a Flux sampler and you'll get garbage or a hard error - use Flux's own empty latent there. For SD/SDXL it's exactly right.

Install

No model downloads, no heavy deps - it's pure Python over torch/numpy/Pillow, all of which ComfyUI already has. The README says ComfyUI Manager support is "coming soon," so the reliable path is still the manual clone:

cd ComfyUI/custom_nodes
git clone https://github.com/cloudkoala/comfyui-koala.git

Restart ComfyUI and look for "Koala Aspect Ratio Empty Latent" under the Koala category. It's part of the same pack as Koala's two save-anywhere nodes, so you get all three at once.

CategoryKoala

Inputs (4)

NameTypeDefaultDescription
batch_sizeINT11–64
imageoptIMAGE
widthoptINT102464–8192
heightoptINT102464–8192

Outputs (5)

NameTypeDescription
latentLATENT
widthINT
heightINT
aspect_ratioFLOAT
infoSTRING