ComfyUI Node

sum_latent

Sum_latent and the black art of blank canvases

By cardenluo·Created 2 years ago·Updated a day ago· 324
sum_latent
  • context
  • latent
  • pixels
  • mask
  • context
  • latent
  • mask
diff_difusiontrue
smoothness0
ratio_selectedNone
batch_size1
width512
height512

Before the sampler can do anything, it needs a latent - and "empty latent" is rarely what you actually want. Sometimes you want a latent at a specific aspect ratio. Sometimes you want an image you already have VAE-encoded into latent space. Sometimes you want a masked edit, where the latent carries a noise mask so the sampler only touches part of the frame. sum_latent is the Apt_Preset node that handles all three jobs and then stuffs the result back into the context.

It's the pack's "what is my canvas" node, and it sits in the chx_tool category - meaning it's a utility you drop in where needed, not the start or end of the pipeline.

What it actually does

Reads the context, then picks a path depending on what you feed it:

  • No latent, no pixels → builds a fresh empty latent from the aspect-ratio preset or width/height you set.
  • pixels → VAE-encodes the image into latent space. If you also give it a mask, it goes through InpaintModelConditioning instead, so the conditioning and latent come out pre-wired for a masked regeneration.
  • latent → passes it through, just honoring batch_size (repeats the latent to batch size).
  • diff_difusion (default on) → applies Differential Diffusion, which is ComfyUI's way of letting the noise level vary per-pixel inside the masked region instead of slamming one denoise level across the whole edit. Leave it on for masked work.

One subtlety the code handles for you: the latent channel count. Flux 2-family models want a 128-channel latent; SD-class models want 4 channels. sum_latent builds the right shape based on the context's clip_type, and it's also where the pack's update note about "sum_load and sum_edit compatible with Flux2_Klein latent size" shows up - this node's whole reason for checking the model family.

The inputs that matter

  • ratio_selected - the pack's aspect-ratio library: 1:1, 2:3, 9:16, 竖屏标清 (720x1280 portrait), and ~30 more, plus customer_WxH for your own numbers. Picking one overrides width/height.
  • pixels / mask - image + mask for encode-and-inpaint.
  • smoothness - 0–150, Gaussian blur applied to the mask before inpainting. Higher = softer edges on the painted region, which is usually what you want for hair and background transitions.
  • diff_difusion - Differential Diffusion toggle.
  • batch_size - repeat the latent N times for batch sampling.
  • width / height - used when ratio_selected is customer_WxH.

The outputs that matter

context (with latent and possibly updated model), latent (feed to the sampler), and mask - the mask comes back out for downstream nodes that need it, like the pack's editor or a refinement stage.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
cd ComfyUI-Apt_Preset
pip install -r requirements.txt   # Windows: double-click install.bat

Or ComfyUI Manager → ComfyUI-Apt_Preset.

Common issues

The one hard error this node can throw is deliberate: feeding both latent and pixels at once raises ValueError - it's a guard so you don't silently pick the wrong source. If you're coming from stock ComfyUI where "just encode the image" is a separate step, remember that sum_latent also replaces the context latent, so an upstream latent you were hoping to keep will be overwritten unless you let it pass through untouched. And with diff_difusion on, don't be surprised that masked results behave differently than a plain inpaint - that's the feature, a more organic feathering at the cost of slightly less predictable control.

CategoryApt_Preset/chx_tool

Inputs (10)

NameTypeDefaultDescription
contextRUN_CONTEXT
latentoptLATENT
pixelsoptIMAGE
maskoptMASK
diff_difusionoptBOOLEANtrue
smoothnessoptINT00–150
ratio_selectedoptCOMBONone32 options: None, customer_WxH, [384x512]AD, [512x384]AD, [512x512]1:1, [512x768]2:3, +26
batch_sizeoptINT11–300
widthoptINT5128–16384
heightoptINT5128–16384

Outputs (3)

NameTypeDescription
contextRUN_CONTEXT
latentLATENT
maskMASK