Nodes/ComfyUI-SizeFromPresets/Random Size From Presets (SDXL)
ComfyUI Node

Random Size From Presets (SDXL)

A random SDXL size every queue, minus the latent plumbing

By nkchocoai·Created 3 years ago·Updated about a year ago· 13
Random Size From Presets (SDXL)
    • w
    • h
    seed0

    Sometimes you don't want the latent - you just want two numbers. That's this node. Feed it a seed and it picks one of the nine SDXL presets from presets/sdxl.csv at random, then outputs that preset's w and h as INTs. What you do with them is your business: wire them into a normal Empty Latent Image, feed them to a resize or conditioning node, or just let them drive some other part of the graph.

    It's part of nkchocoai's ComfyUI-SizeFromPresets pack, which exists to keep you on the aspect ratios a model was actually trained on. For SDXL that means the classic nine: 1024x1024, 1152x896, 896x1152, 1216x832, 832x1216, 1344x768, 768x1344, 1536x640, 640x1536. Every one is right around the 1-megapixel budget SDXL was trained at, and every one is divisible by 8, so the latent you build from these numbers matches the declared size exactly. Off-ratio generation is how you get stretched bodies and duplicated limbs; this list is the guardrail.

    How it works

    The whole node is:

    random_gen = np.random.default_rng(seed)
    preset = random_gen.choice(self.SIZE_PRESETS_INPUT)
    

    NumPy's default_rng is deterministic, so a given seed always maps to the same preset. That's the feature - lock the seed and you lock the size. There's no state, no RNG shared with the rest of ComfyUI, nothing to leak between runs.

    The one input

    • seed - that's all. batch_size doesn't exist here because there's no latent to batch. Default 0, max 0xffffffffffffffff.

    Outputs are w and h, INTs in that order.

    Where people get burned

    The same trap as every node in this family: the seed has to actually change for the size to change. A fixed seed widget (default 0) returns the same size on every queue. If you want a fresh roll each run, randomize the seed via the widget's control-after-generate menu or wire in a changing seed.

    Second, remember the pool is the whole CSV. Portrait sizes like 832x1216 and 640x1536 are in the mix, so a "random" workflow will happily hand you a portrait frame you didn't plan for. If your downstream nodes assume landscape, you'll find out the hard way. And because this node only outputs numbers, it's the easier one to misread - check what w/h landed on before you blame your sampler for a weird composition.

    Install and troubleshooting

    Via ComfyUI Manager, search "ComfyUI-SizeFromPresets". Or clone:

    cd <ComfyUI>/custom_nodes
    git clone https://github.com/nkchocoai/ComfyUI-SizeFromPresets.git
    

    Restart after installing. No requirements.txt, no model downloads - the pack uses only numpy, torch, and the csv standard library, all already present in any ComfyUI install.

    If you want a different roll of the dice, edit presets/sdxl.csv and restart ComfyUI - the list is read once at import, so edits don't apply until then. And keep the clone's folder name as ComfyUI-SizeFromPresets; the code looks up that exact path to find the CSV, so renaming the folder breaks every node in the pack.

    CategorySizeFromPresets

    Inputs (1)

    NameTypeDefaultDescription
    seedINT00–18446744073709550000

    Outputs (2)

    NameTypeDescription
    wINT
    hINT