Nodes/WAS Node Suite v3/Scale Latent to Max Dimension
ComfyUI Node Runs on cloud

Scale Latent to Max Dimension

Cap a latent at a longest side, in latent space

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Scale Latent to Max Dimension
  • samples
  • vae
  • samples
  • width
  • height
upscale_methodbislerp
largest_size2048
scale_modealways
spatial_compression8

Sometimes you don't care about exact dimensions - you care that the longest side of a picture is a particular size, aspect ratio kept. "Make this fit a 2048 ceiling" is a shape-of-image question, not an exact-pixels question, and WAS Scale Latent to Max Dimension answers it in latent space: it resizes the latent so the picture it decodes to has its longest side at your chosen number of pixels.

Why latent space matters is the whole pitch. If you decode to pixels, resize, and re-encode, you've added a full VAE round-trip - detail lost, time spent, and (with video) possible inconsistency. This node resizes the latent tensor directly, so nothing is decoded and re-encoded on the way. The size is worked out in latent units, then reported back to you in pixels of the decoded picture.

The key input is largest_size (default 2048, range up to 16384): how long the longest side should be, in pixels of the decoded image, not latent units. The tooltip's arithmetic is the honest one - 2048 on a 3:2 latent gives 2048×1360 - and the target is rounded down to whole latent units, so the result never comes out larger than you asked. scale_mode decides which way it's allowed to go: always hits the target from either side, downscale_only treats largest_size as a ceiling and leaves smaller latents alone (the right call for capping mixed input sizes before they meet a batch), and upscale_only does the reverse for bringing small latents up.

The subtle trap is spatial_compression, default 8: how many pixels one latent unit becomes on the VAE that will decode this. It's 8 for SD, SDXL, Flux and Wan 2.1; 16 for Wan 2.2 TI2V; 32 for Hunyuan Image. Get it wrong and the result scales by the ratio of the two numbers - you asked for 2048 and got 4096, or 1024, with no error message to explain why. The escape hatch is the optional vae input: connect the VAE this latent will be decoded with and the compression ratio is read straight off it, removing the need to know the number at all. If you're ever unsure which model family a latent came from, wiring in the VAE is the safer habit.

upscale_method matters more than people expect on latents. The default bislerp interpolates along the shape of the latent rather than straight through it, and is the safest choice for a latent - that's why it's the default. bilinear and bicubic are the ordinary smooth options, area averages the source region and suits shrinking, and nearest-exact copies the closest value and stays blocky. For latents, reach for bislerp and don't feel clever about it.

Outputs are the resized samples (passed through untouched when scale_mode rules the resize out, or when it's already the right size), plus width and height - the pixel dimensions the latent now decodes to. Those two INTs are the quietly useful part: feed them to anything that must be built at the same size, like an empty image or a second resize, and you never have to compute the aspect-preserved dimension by hand.

Install

Part of WAS Node Suite v3. ComfyUI Manager, search "WAS Node Suite", or:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui

Restart after. Needs ComfyUI 0.14.0+ and Python 3.10+. No pip packages or model downloads. (The v2 pack's install weight is gone in v3 - this suite installs clean.)

Common issues

  • Result is twice or half the size you asked. spatial_compression doesn't match the model's VAE. Connect the actual vae and it's read automatically.
  • Small latents got upscaled when you wanted them untouched. That's scale_mode - use downscale_only for a ceiling.
  • Size comes out slightly under your target. Expected - the target is rounded down to whole latent units so it never exceeds the ask.
CategoryWAS Suite/Latent/Transform

Inputs (6)

NameTypeDefaultDescription
samplesLATENTThe latent to resize. A video latent with a time axis is resized on its height and width only, and keeps every frame.
upscale_methodCOMBObislerpHow values in between the existing ones are worked out. `bislerp` interpolates along the shape of the latent rather than straight through it and is the safest choice for a latent; `bilinear` and `bicubic` are the ordinary smooth options; `area` averages the source region and suits shrinking; `nearest-exact` copies the closest value and stays blocky.
largest_sizeINT20488–16384How long the longest side should be, in pixels of the decoded picture rather than in latent units. 2048 on a 3:2 latent gives 2048x1360. The target is rounded down to whole latent units, so the result never comes out larger than asked for.
scale_modeCOMBOalwaysWhich direction the resize is allowed to go. `always` hits the target from either side. `downscale_only` treats largest_size as a ceiling and leaves anything already smaller alone, which is what suits capping mixed input sizes. `upscale_only` is the reverse: it brings small latents up and leaves large ones untouched.
spatial_compressionINT81–64How many pixels one latent unit becomes on the VAE that will decode this: 8 for SD, SDXL, Flux and Wan 2.1, 16 for Wan 2.2 TI2V, 32 for Hunyuan Image. Getting it wrong scales the result by the ratio of the two numbers. Ignored when a vae is connected.
vaeoptVAEThe VAE this latent will be decoded with. Connect it and the compression ratio is read straight off it, which removes the need to know the right spatial_compression for the model in use.

Outputs (3)

NameTypeDescription
samplesLATENTThe resized latent. It is passed through untouched when scale_mode rules the resize out, or when it is already the right size.
widthINTWidth the latent now decodes to, in pixels. Feed it to anything that has to be built at the same size, such as an empty image or a second resize.
heightINTHeight the latent now decodes to, in pixels.