Extensions/Advanced Latent Control
ComfyUI Extension

Advanced Latent Control

This custom node helps to transform latent in different ways.

By kuschanow·Created 2 years ago·Updated 10 days ago· 23
RomanKuschanow/ComfyUI-Advanced-Latent-Control
Nodes19
On cloudLocal install
Categorysampling/transforms, latent/advanced
Stars23
Updated10 days ago

Nodes (19)

Latent add transform

Inject a reference latent into sampling

sampling/transforms
Latent interpolate transform

Blend the sample toward a reference latent

sampling/transforms
Latent mirror

Flip a latent and blend it with the original

latent/advanced
Latent normalize

The rescue node for latents you've manhandled

latent/advanced
Latent shift

Slide a latent around without touching pixels

latent/advanced
Mirror transform

Flip and rotate the latent while it denoises

sampling/transforms
Multiply transform

The volume knob for latents, step by step

sampling/transforms
Combine offsets

Merge two step patterns into one rhythm

sampling/transforms
Latent add transform (one time)

Inject a reference latent at one step

sampling/transforms
Latent interpolate transform (one time)

One step toward the reference

sampling/transforms
Mirror transform (one time)

Snap the latent into symmetry at one step

sampling/transforms
Multiply transform (one time)

One punch, delivered on cue

sampling/transforms
Shift transform (one time)

One precise nudge at one precise step

sampling/transforms
Shift transform

Slide the latent sideways, mid-sampling

sampling/transforms
Transform Hijack

Use latent transforms with any sampler you already love

sampling/transforms
Transform offset

Fire a latent transform only on every Nth step

sampling/transforms
TSampler (Latent Control)

Edit the latent mid-sampling, not after it's done

model/sampling
TSampler Advanced (Latent Control)

Step-precise latent transforms for control freaks

model/sampling
Combine transforms

Stack two latent edits into one instruction

sampling/transforms
Readme

ComfyUI-Advanced-Latent-Control

This custom nodes helps to transform latent in different ways.

You can access new features earlier by switching from the master branch to dev, but you need to remember that there may be some issues on the dev branch and some nodes' behavior may change after release.

Latent mirror

This node can flip latent and merge original and flipped version.

Input:

  • latent

Fields:

  • direction – can be vertically, horizontally or both
  • multiplier – multiply latent by specified number

Output:

  • latent

Usage:
sample sample

Latent shift

This node can shift latent along x and y-axis.

Input:

  • latent

Fields:

  • x_shift – a number between -1 and 1 that indicates how much the latent should be shifted
  • y_shift – a number between -1 and 1 that indicates how much the latent should be shifted

Output:

  • latent

Usage:
sample

~~TSampler with transforms (Latent Control)~~

Removed from version 2.0.0

TSampler (Latent Control)

This node allows to combine a lot of transforms with different parameters.

Input:

  • base KSampler fields
  • transform_optional – field that can take output from one of those nodes: Mirror transform, Shift transform, Multiply transform or Combine transforms

Fields: exactly matches the base KSampler

Output: exactly matches the base KSampler

Usage:
sample
sample

Multiply, Mirror and Shift transform nodes parameters exactly match the corresponding KSampler with transforms (Latent Control) parameters.

There are two new transform nodes:

  • Latent add
  • Latent interpolate

They work exactly the same as LatentAdd and LatentBlend nodes from standard node pack, but also, can multiply result by specified number.

Offset

You can apply specific offset for transform nodes.

Fields:

  • process_every – a number that indicates which steps will be processed
  • offset – a number that indicates offset for previous parameter. For example: if process_every is 4 and offset is 0, sampler apply transformation with this pattern: 0 0 0 1. This pattern will repeat again and again. If offset is 2, pattern will be 0 1 0 0, if -1 – 1 0 0 0.
  • mode – can be process_every or skip_every. For example, with skip_every previous pattern (0 0 0 1) turn into this: 1 1 1 0

Output:

  • offset

Usage:
sample sample sample

You can combine different offsets to achieve interesting patterns. For example:
0 0 0 1 and 0 0 1 give this pattern: 0 0 1 1 0 1 0 1 1 0 0 1.

One time nodes

Each transform node has own one-time version. They allow to make one transform action at specified step.

Usage:
sample

Latent normalize

Fixes some issues when sampling modified latent space.

Input:
exactly matches the VAE Decode node

Output:

  • latent

When you multiply latent by negative or big positive (bigger than 2) number and paste this latent in sampler, you can see that the image will be generated very poorly. This is because stable diffusion cannot work with such set of numbers (meaning the numbers contained in latent).

sample

But you can prevent this behavior by sequential decode and encode latent using vae. Node Latent normalize make this process easier.

sample

This node also change some results even if output without this node looks good.

sample sample

And it very slightly changes results from latent, which have not been modified.

sample sample

Transform hijack

Allow you to use transforms with any samplers that you like.

Instead of patching the latent, this node patches the model: it attaches the transforms to a cloned model via a sampler post-cfg hook. Connect the returned model to any sampler (KSampler, KSamplerAdvanced, custom sampler nodes, etc.) and the transforms will be applied during sampling.

Inputs:

  • model
  • transforms

Outputs:

  • model

Usage: sample

Breaking change in 3.0.0: Transform hijack now takes and returns a MODEL instead of a LATENT. This replaces the old global common_ksampler monkey-patch, which conflicted with the stock KSampler and other custom nodes. Rewire this node to your model input/output after updating.