ComfyUI Node

RefLatent

The 20-line node that feeds reference images to Qwen-Edit and Klein

By sweetndata·Created about a year ago·Updated about a year ago· 0
RefLatent
  • conditioning
  • latent
  • CONDITIONING

Edit models are picky about how they get their reference images. Qwen-Image-Edit, FLUX 2 Klein, Kontext - none of them take a raw image at the sampler. They expect a VAE-encoded latent stashed on your conditioning under a key called reference_latents. RefLatent is the generic, model-agnostic way to set that key yourself.

It's a tiny node - one input for conditioning, one optional latent, one output. No weights, no config, no model downloads. If the text encoder in your workflow already attaches a reference for you (ComfyUI's TextEncodeQwenImageEdit does this internally when you plug an image in), you don't strictly need it. Where it earns its keep is when you want to supply the reference yourself, feed more than one, or patch a workflow whose text-encode node doesn't carry a reference at all. There's a well-known Qwen-Edit-2509 workflow trick where people hand in their own reference latents to fix the "unzooming"/misalignment problem at odd resolutions - this node is exactly the tool for that kind of surgery.

How it works

The mechanism is dead simple, and it's worth understanding because it demystifies half the edit-model packs on the market. Conditioning in ComfyUI is a list of [tensor, metadata_dict] pairs. RefLatent takes your latent's samples and appends them to the metadata's reference_latents list:

conditioning = conditioning_set_values(conditioning,
    {"reference_latents": [latent["samples"]]}, append=True)

That's the whole node. Because it appends rather than replaces, chaining two RefLatent nodes gives you two reference latents in order - which is what the author's description means by "if the model supports it you can chain multiple to set multiple reference images." And if you leave latent unconnected, it's a clean pass-through; the conditioning comes out untouched.

Downstream, the model's extra_conds reads that key and routes the latents through its own VAE latent processing. Who actually consumes it: FLUX 2 Klein uses the full list as additive reference conditioning (natively up to ten images), Qwen-Image-Edit takes a reference latent for appearance control alongside the vision-language tokens, and Wan, HiDream, SCAIL-2 and friends read the same key. Plain SDXL or SD 1.5 models have no slot for it and silently ignore it.

Worth knowing: recent ComfyUI ships an essentially identical node called Set Reference Latent (same description, same append semantics). This pack is that utility, standalone, and it predates the core version. If you're on a fresh ComfyUI you may already have the equivalent built in.

The inputs that matter

  • conditioning (required) - your positive (or negative) conditioning, from the edit model's text encoder. This is where the reference gets attached.
  • latent (optional) - a VAE-encoded reference. Not an image. Wire VAEEncode's output in, or a latent from an earlier generation you liked.

Output is a single CONDITIONING, wired straight into your sampler's positive input. There's nothing else - no strength, no mask, no mode. The tradeoff for that simplicity: you get zero control over how hard the model leans on the reference. For per-reference weighting on Klein, you want a dedicated pack like ComfyUI-Flux2Klein-Enhancer instead.

Installing it

ComfyUI Manager: search ComfyUI-Reflatent, install, restart. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/sweetndata/ComfyUI-Reflatent

No requirements.txt, no extra Python packages, no model files. It's one file of Python.

Where people get burned

The model has to actually support the key. Krea 2 has no slot for a reference latent and throws it away; SDXL ignores it. If your result looks like the reference never mattered, check you're on an edit model that reads reference_latents before you blame the node.

Wrong VAE = reference that does nothing. The latent must come from the model's own VAE. Encoding your reference with an SDXL VAE and feeding it to Klein produces a latent the model reads as noise or ignores entirely - a silent failure, since the graph still runs.

Your output resolution is the empty latent, not the reference. A 1024×1024 reference doesn't imply a 1024×1024 result. Set your canvas size where you always do.

It's a utility, not a feature. Half the battle with edit models is getting the reference in the right shape - and when that's your problem, this is the node you reach for.

Categoryadvanced/conditioning/edit_models

Inputs (2)

NameTypeDefaultDescription
conditioningCONDITIONING
latentoptLATENT

Outputs (1)

NameTypeDescription
CONDITIONINGCONDITIONING