MD: Empty Latent Ratio Select
Aspect-ratio-aware empty latents that won't blow up your model
- latent
- width
- height
If you've ever hand-typed "1216x832" into an Empty Latent Image and crossed your fingers, this node is for you. MD_EmptyLatentRatioSelector does what its name says: it generates a latent at a chosen aspect ratio and megapixel target, with the width and height computed to land on multiples of 8 so nothing gets snapped weirdly downstream.
It's a small utility, and it earns its place because getting resolution right is one of the cheapest wins in ComfyUI. Models are trained at a specific pixel count - SDXL around 1.0 MP, SD1.5 around 0.26 MP, FLUX happier a bit higher - and wandering far from that is the classic cause of doubled-up subjects, composition weirdness, and tiling artifacts. This node keeps the total area on target while letting the shape float.
How it works
You pick a ratio, an orientation, and a total megapixel budget. The node computes width = sqrt(area × ratio) and height = area / width, then rounds both down to a multiple of 8 (the CONST_DIVISIBLE_BY = 8 in the source) before building the latent via ComfyUI's empty latent constructor. Portrait just swaps the axes. The math keeps total pixels near your target, so a 21:9 output isn't secretly a 16:9 crop with extra pixels.
The inputs you actually set
- ratio_preset - 1:1, 16:9, 21:9, 32:9 and the in-between ratios. The tooltip's warning about extreme ultrawides is real: if your model wasn't trained on them, you'll see duplicate subjects.
- orientation - landscape or portrait. Match it to the prompt's intent (portrait for characters, landscape for environments).
- base_mp_preset - the resolution class: SD1.5, SDXL, 1080p, 4K, or Custom. Match this to the model you're loading. Pushing SDXL to 8.3 MP without an upscale stage is how you get artifacts, not detail.
- manual_mp_size - only used when the preset is
Custom; a slider from 0.1 to 16 MP. - dimension_scale - a linear multiplier for the final dimensions.
0.5gives you a half-res test render without touching the MP logic. Handy for rapid iteration. - batch_size - how many latents in one batch; VRAM scales with it.
Outputs: the latent (into your KSampler), plus width and height as INTs so you can feed resolution into a filename builder or a text node if you want.
Installing
It ships with the MD Nodes pack. Either way you do it - ComfyUI Manager (search MD Nodes) or a manual clone - the steps are the same:
cd path/to/ComfyUI/custom_nodes
git clone https://github.com/MDMAchine/ComfyUI_MD_Nodes.git
cd ComfyUI_MD_Nodes
pip install -r requirements.txt
Then restart ComfyUI. This particular node is pure Python with no extra dependencies, so if you only care about this one, you can even skip the requirements install and it'll still load - but the pack's audio nodes will complain until you install their deps.
Common gotchas
The biggest one is expecting more than it delivers: this is a resolution calculator, not an upscaler. A 4K preset at native SDXL resolution doesn't magically give you 4K detail - it gives you an SDXL-sized image stretched to a big latent, which often looks worse than generating at native size and upscaling. Keep dimension_scale at 1.0 for finals and use the low presets for testing.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| ratio_preset | COMBO | 16:9 (Standard) | ASPECT RATIO • Purpose: Defines the width-to-height relationship. • Options: 1:1, 16:9, 21:9, 32:9, etc. • Trade-offs: Extreme ultrawide ratios may cause duplicate subjects if model isn't trained for it. ⭐ Recommended: 16:9 for standard outputs, 1:1 for social media. |
| orientation | COMBO | Landscape (Horizontal) | ORIENTATION • Purpose: Rotates the selected aspect ratio. • Options: Landscape (Width > Height) or Portrait (Height > Width). • Trade-offs: Ensure orientation matches prompt intent (e.g., Portrait for character art). ⭐ Recommended: Landscape for environments, Portrait for characters. |
| base_mp_preset | COMBO | SDXL (1024x1024) - 1.0 MP | MEGAPIXEL TARGET • Purpose: Sets the total resolution/quality class of the generation. • Options: SD1.5 (0.26 MP), SDXL (1.0 MP), 1080p (2.0 MP), 4K (8.3 MP), or Custom. • Trade-offs: Higher MP targets exponentially increase VRAM usage and generation time. ⭐ Recommended: Match this exactly to your underlying model's training resolution (e.g., SDXL = 1.0 MP). |
| manual_mp_size | FLOAT | 1.00.1–16 | CUSTOM MEGAPIXELS • Purpose: Sets a specific resolution target when 'base_mp_preset' is set to 'Custom'. • Range: 0.1 to 16.0 MP. • Trade-offs: Pushing models beyond their trained MP limit can cause compositional artifacting. ⭐ Recommended: 1.0 (Standard SDXL) or 2.0 (FLUX). |
| dimension_scale | FLOAT | 1.000.1–4 | DIMENSION SCALE • Purpose: Linear multiplier for the final calculated dimensions. • Options: 0.5 (Half resolution), 1.0 (Default), 2.0 (Double resolution). • Trade-offs: Quickly scales up/down testing renders without changing the MP target logic. ⭐ Recommended: 1.0 for final outputs, 0.5 for rapid testing. |
| batch_size | INT | 11–64 | BATCH SIZE • Purpose: Number of latent samples to generate in a single batch. • Range: 1 to 64. • Trade-offs: VRAM usage scales linearly with batch size. ⭐ Recommended: 1 to 4 depending on GPU VRAM. |
| debug_mode | COMBO | 0 - Silent | LOGGING VERBOSITY • Purpose: Controls console output and enables analytical reporting. • Options: 0 (Production), 1 (Shows calculated WxH and timing). ⭐ Recommended: 0 - Silent. |
| enable_profiling | BOOLEAN | false | ENABLE PROFILING • Purpose: Measure timing of mathematical operations and tensor allocations. • Note: Automatically enabled if debug_mode is 1 - Info. ⭐ Recommended: False. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | — |
| width | INT | — |
| height | INT | — |