SD 3.5 Perfect Resolution
Stop hand-calculating megapixel-safe dimensions
- LATENT
- width
- height
Every diffusion architecture has a pixel budget it was trained at, and going meaningfully off it is how you get stretched anatomy and repeated limbs. The annoying part is that the "right" width and height for a given aspect ratio isn't obvious - you're doing mental math with divisibility constraints and megapixel targets every time you want something other than a square. This node is that calculator, wired directly into your graph: pick a ratio, pick a target size, get a correctly-sized empty latent out the other end.
How it works
It was built for SD 3.5 specifically - the author says so directly, and the node's own description backs that up - but the README also notes it works fine for other models like Flux, which shares SD3's rough "any resolution, must be divisible by a fixed step" flexibility rather than SDXL's fixed set of trained buckets. You choose a target size band (1MP or 2MP) and an aspect ratio from a long preset list, and the node works out the width and height that land in that pixel budget while respecting the ratio and staying compatible with what SD3-family models expect. It then hands you a ready-to-use empty LATENT at that resolution, plus the raw width and height as separate integers so you don't have to read them off a tooltip or eyeball the node.
If none of the 23 preset ratios fit - you want something oddball like 21:9 - flip on custom_ratio and type your own into custom_aspect_ratio.
The inputs and outputs that matter
mode-1MPor2MP, the total pixel budget you're targeting. 1MP is roughly SD3.5's native training scale; 2MP pushes higher resolution at the cost of more VRAM and slower generation.aspect_ratio- a dropdown of 23 named presets, from1:1 (Perfect Square)through portrait and landscape ratios like4:5 (Artistic Frame)(the default) up to extreme ones like9:32 (Skyline). The names are the author's own flavor text, not standardized terms.custom_ratio- a boolean. Leave it off to use the dropdown; turn it on to override with your own ratio.custom_aspect_ratio(optional, default"1:1") - only read whencustom_ratiois true. Type a ratio like21:9.
Three outputs: LATENT (wire straight into your KSampler), and width / height as separate INT outputs - genuinely useful for feeding into anything downstream that wants explicit dimensions, like an upscale node or a resize step, without you retyping numbers by hand.
How to install it
Search KGnodes in ComfyUI Manager, or:
cd ComfyUI/custom_nodes
git clone https://github.com/shahkoorosh/ComfyUI-KGnodes.git
pip install -r requirements.txt
Restart, then find it under Add Node → 🎨KG as "SD 3.5 Perfect Resolution." No models or downloads - it's pure arithmetic, producing an empty latent the same way ComfyUI's stock Empty Latent Image does, just with the resolution math done for you.
Common issues & troubleshooting
Using this on SDXL and wondering why results look off. SDXL doesn't work off a continuous megapixel formula the way SD3/Flux-family models do - it was trained on a fixed list of specific resolutions (1024×1024, 1152×896, 1216×832, and a handful of others). This node's math is built for SD3.5's rules, so on SDXL you're generally better off sticking to the model's actual trained buckets rather than a computed 1MP/2MP resolution that happens to be close but not one of them.
2MP mode is slow or runs out of VRAM. That's expected - you're roughly doubling the pixel count and therefore the compute and memory cost versus 1MP. If you're VRAM-constrained, generate at 1MP and upscale afterward rather than fighting 2MP directly.
Custom ratio doesn't seem to apply. Double check custom_ratio is actually toggled on - the custom_aspect_ratio string is ignored entirely while it's off, which is an easy toggle to forget after you've typed your ratio in.
Width/height outputs don't match what you expected for a given ratio. The node is solving for "closest valid resolution to this ratio within this pixel budget," not "exact ratio at any cost" - expect some rounding, especially at 1MP where there's less room to hit an exact fraction cleanly.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| mode | COMBO | 1MP | 2 options: 1MP, 2MP |
| aspect_ratio | COMBO | 4:5 (Artistic Frame) | 23 options: 1:1 (Perfect Square), 2:3 (Classic Portrait), 3:4 (Golden Ratio), 3:5 (Elegant Vertical), 4:5 (Artistic Frame), 5:7 (Balanced Portrait), +17 |
| custom_ratio | BOOLEAN | false | — |
| custom_aspect_ratioopt | STRING | 1:1 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |
| width | INT | — |
| height | INT | — |