Nodes/ComfyUI-SmartSize/Smart Image Size (Flux/SDXL)
ComfyUI Node

Smart Image Size (Flux/SDXL)

The size-snapper that kills the Flux/SDXL EinopsError

By Jnocode·Created 9 months ago·Updated 9 months ago· 0
Smart Image Size (Flux/SDXL)
  • image
  • width
  • height

The name understates it. "Smart Image Size (Flux/SDXL)" is really two things in one: a dumb image-size reader and a dimension snapper that floors width and height to the nearest multiple of 16. That second half is why people actually install it, because "not a multiple of 16" is the exact bug that greets you with einops.EinopsError and a collapsed generation.

Why this exists at all

Every modern diffusion model compresses its latent space with a VAE, and it does the downsampling in fixed chunks. SDXL's VAE drops the image 8× per side; Flux does the same, then feeds those latents through a patchify step that reshapes them into 2×2 patches. Do the math: 8 × 2 = 16. Any pixel dimension that isn't a multiple of 16 leaves an indivisible remainder at the reshape step, and einops throws Shape mismatch, can't divide axis of length 89 in chunks of 2-style errors (a real r/StableDiffusion thread about FluxGym hits exactly this on the pack_latents rearrange). It's an easy bug to hit - import a random photo, drag it into an img2img or Redux-ish workflow, and the latent shape silently stops dividing evenly.

The classic fix is boring manual math: type 1024×1024 or 992×1536 into Empty Latent and hope your reference image matches. This node does it for you - read the actual image, snap both sides down to the nearest multiple of 16, hand the numbers downstream.

How it works

GetImageSize_Custom is about fifty lines of pure PyTorch with zero dependencies. It takes your IMAGE tensor, which arrives as [Batch, Height, Width, Channels], pulls out h and w, and runs:

w = (w // 16) * 16
h = (h // 16) * 16

That's the whole mechanism - integer division, multiply back, done. 1000 → 992, 1024 → 1024 (already clean), 1001 → 992. No aspect-ratio logic, no rounding to nearest, no upscaling. It just emits the two numbers.

The inputs and outputs that matter

Only one input, and it's required:

  • image (IMAGE) - any image tensor; typically straight out of a Load Image node.

Two outputs:

  • width (INT)
  • height (INT)

These wire into the width/height widgets of Empty Latent, ModelSamplingFlux, or an ImageScale node. One gotcha the README calls out explicitly: those targets usually show their width/height as a plain widget, so you need to right-click the node → Convert Widget to Input before you can connect these numbers to it.

Installing it

The pack (ComfyUI-SmartSize) is one of the lightest installs you'll do - no requirements.txt, no model downloads, nothing but torch:

cd ComfyUI/custom_nodes
git clone https://github.com/xiujiang1987/ComfyUI-SmartSize

Restart ComfyUI and the node shows up under SmartSize as "Smart Image Size (Flux/SDXL)". ComfyUI Manager support is listed as "coming soon" in the README, so don't be surprised if a Manager search comes up empty yet - the repo is brand new (late 2025, essentially zero stars at the time of writing), so this is a clone-it-yourself situation for now.

Where people get burned

Two things to keep in mind. First, it floors, it doesn't round or rescale. A 1000×1000 source gives you 992×992 - you lost up to 15 pixels per side, and the node won't touch the actual image. If you're doing img2img you generally want to feed the same snapped numbers into an ImageScale node so the image and the latent actually agree, rather than passing 992 into a latent but keeping a 1000px image. Second, 16 is the floor, not the only convention. Flux workflows commonly recommend multiples of 64 as good practice - 16 is the structural minimum that stops the crash, but if a workflow template insists on 64-multiples, this node's output won't match that template's expectations. It's a small, honest utility: it solves one specific crash. For that one crash, it's genuinely the right tool.

CategorySmartSize

Inputs (1)

NameTypeDefaultDescription
imageIMAGE

Outputs (2)

NameTypeDescription
widthINT
heightINT