Nodes/comfyui-lopi999-nodes/Random SDXL Latent Size
ComfyUI Node

Random SDXL Latent Size

Random SDXL sizes, done right

By LaVie024·Created about a year ago·Updated 8 months ago· 8
Random SDXL Latent Size
    • LATENT
    • WIDTH
    • HEIGHT
    • RESOLUTION_TEXT
    seed0
    landscapetrue
    portraittrue
    resolution_multiplier1.00
    landscape_min_res1024x1024 (1.00)
    landscape_max_res1728x576 (3.00)
    portrait_min_res576x1728 (0.33)
    portrait_max_res1024x1024 (1.00)
    batch_size1

    The author says this is the node that started the whole collection, and it's easy to see why. Every time you manually change the resolution in ComfyUI, you're fighting two forces at once: SDXL wants dimensions that are multiples of 8 (its latent space compresses pixels 8x8), and it was trained on a specific bucket of aspect ratios. RandomSDXLLatentSize picks from those trained ratios for you - landscape, portrait, or both - within bounds you set, and hands you a ready-to-use empty latent plus the width, height, and a text string describing what it chose.

    Why you'd reach for it

    Resolution variety is the cheapest way to make a batch of generations stop looking samey. Set the landscape and portrait ranges, enable both orientations, and every queue run gets a random aspect ratio the model actually knows how to draw - instead of the distorted or cropped results you get from throwing arbitrary dimensions at SDXL. It's heavily based on the Empty Latent Picker from cubiq's ComfyUI_essentials, so if you know that node, this is the same idea with the two random flags and the min/max bounds added. The README is upfront about the debt, which is a good sign.

    How it works

    The node keeps a curated list of aspect ratios in each orientation - landscape runs from 1024x1024 up to 1728x576 (3:1), portrait from 576x1728 down to 1024x1024 - and seeds a random pick from whatever falls inside your landscape_min_res to landscape_max_res (and same for portrait) bounds. The chosen ratio is multiplied by resolution_multiplier if you want to scale everything up or down, then the node allocates a zeros latent of shape [batch, 4, h/8, w/8]. That divide-by-8 is exactly why it keeps ratios multiple-of-8-friendly: the latent stays valid for the model.

    The outputs are the star feature. You get the LATENT itself plus WIDTH, HEIGHT, and RESOLUTION_TEXT - so you can feed the size into other nodes or metadata without parsing it out of anything.

    The inputs that matter

    • seed (INT) - reproducibility for the random pick.
    • landscape / portrait (BOOLEAN, both default true) - which orientations are in the pool. Turn one off to force the other.
    • landscape_min_res / landscape_max_res / portrait_min_res / portrait_max_res (enums) - the bounds of the random range. The defaults give you the full spread, which is honestly the best starting point.
    • resolution_multiplier (FLOAT, default 1) - scales the chosen size. 0.5 halves it, 2 doubles it.
    • batch_size (INT, default 1) - how many latents to allocate.
    • Outputs: LATENT, WIDTH, HEIGHT, RESOLUTION_TEXT.

    Installing it

    cd ComfyUI/custom_nodes
    git clone https://github.com/LaVie024/comfyui-lopi999-nodes
    

    Restart ComfyUI, or find "comfyui-lopi999-nodes" in ComfyUI Manager. No model downloads. This one's pure torch and needs nothing extra.

    Common issues

    If you set landscape and portrait both to off, the node falls back to 1024x1024 rather than erroring - a sensible default, but worth knowing. And a real trap: the resolution_multiplier scales the pixel dimensions, and if you push it too far the latent can exceed what your GPU handles. Also remember that SDXL-adjacent fine-tunes (Illustrious, NoobAI, Pony) were trained on very similar buckets, so this node's ratio list transfers to them well - but if you're running a flow-matching model like Flux, its native resolution expectations differ and you're better off with that model's own size handling.

    Categorylopi999/random

    Inputs (9)

    NameTypeDefaultDescription
    seedINT00–18446744073709550000
    landscapeBOOLEANtrue
    portraitBOOLEANtrue
    resolution_multiplierFLOAT1.000.01–100
    landscape_min_resCOMBO1024x1024 (1.00)16 options: 1024x1024 (1.00), 1024x960 (1.07), 1088x960 (1.13), 1088x896 (1.21), 1152x896 (1.29), 1152x832 (1.38), +10
    landscape_max_resCOMBO1728x576 (3.00)16 options: 1024x1024 (1.00), 1024x960 (1.07), 1088x960 (1.13), 1088x896 (1.21), 1152x896 (1.29), 1152x832 (1.38), +10
    portrait_min_resCOMBO576x1728 (0.33)16 options: 576x1728 (0.33), 576x1664 (0.35), 640x1600 (0.40), 640x1536 (0.42), 704x1472 (0.48), 704x1408 (0.50), +10
    portrait_max_resCOMBO1024x1024 (1.00)16 options: 576x1728 (0.33), 576x1664 (0.35), 640x1600 (0.40), 640x1536 (0.42), 704x1472 (0.48), 704x1408 (0.50), +10
    batch_sizeINT11–4096

    Outputs (4)

    NameTypeDescription
    LATENTLATENT
    WIDTHINT
    HEIGHTINT
    RESOLUTION_TEXTSTRING