Nodes/comfyui-lrw-nodes/Latent Vector from Diff (LRW)
ComfyUI Node

Latent Vector from Diff (LRW)

Turn two latents into a direction

By lajjadred·Created 3 months ago·Updated 3 months ago· 12
Latent Vector from Diff (LRW)
  • latent_from
  • latent_to
  • vector
scale1.00

This is the smallest node in the pack and probably the least glamorous, but it's where the style-transfer story starts. Latent Vector from Diff subtracts two latents and calls the result a vector. That's it. vector = (latent_to - latent_from) * scale. Three inputs, one output, zero mystery.

Why a subtraction matters

Diffusion people have been doing arithmetic on embeddings for years - "cat minus dog plus cat ears" and all that. This is the same trick applied to latent tensors instead of text embeddings. You VAEEncode two images that differ in a meaningful way - say, the same person with and without a hat - and the difference between their latents is a direction that encodes "hat-ness." Multiply by scale to control how much hat-ness you're capturing, and you've got a reusable direction vector.

That's a vector, not a final image. The real use is to hand it to LRW_ParallelTransport, which can carry that direction to a different location in latent space while preserving what it means. The pack's README literally frames it that way: create a style direction, transport it, apply it. This node is step one of that pipeline.

The inputs:

  • latent_from - the "before" latent.
  • latent_to - the "after" latent.
  • scale (default 1, range −5 to 5) - scales the vector. Use it to tune how strong the direction is before you transport it. Can be negative if you want the opposite direction.

Output is a single vector of type LATENT. It's not a real latent - it won't decode to anything sensible on its own - but it rides the LATENT type because that's what the transport and apply nodes accept. Don't try to VAEDecode it.

The honest limits

A pure difference vector is a Euclidean notion, and the entire premise of this pack is that latent space is curved. So the diff vector is the naive starting point, and the transport node is what corrects it for curvature. On small image models the difference between "raw diff" and "transported diff" can be subtle; on bigger or more curved spaces it matters more. Also: the two latents need to be the same shape or this throws a shape error at you, and if the two images are wildly different in composition, the diff is mostly noise. It works best on images that are close except for the one thing you want to isolate.

Install

Part of comfyui-lrw-nodes by lajjadred - the ComfyUI front-end for his latent-riemannian-world package. Search the pack name in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/lajjadred/comfyui-lrw-nodes
cd comfyui-lrw-nodes
pip install -r requirements.txt

Restart ComfyUI. Real deps: latent-riemannian-world >= 0.3.0, torch >= 2.4, Python 3.12+. Early builds had a node-registration bug (nodes showing as broken/UNKNOWN) fixed by git pull + full restart; keep only one copy of the pack in custom_nodes. License is BSL-1.1.

Categorylrw/core

Inputs (3)

NameTypeDefaultDescription
latent_fromLATENT
latent_toLATENT
scaleFLOAT1.00-5–5

Outputs (1)

NameTypeDescription
vectorLATENT