Nodes/ComfyUI-FLATTEN/Unsampler (Flatten)
ComfyUI Node

Unsampler (Flatten)

Run your video backwards — the unsampler that feeds FLATTEN

By logtd·Created 3 years ago·Updated 2 years ago· 114
Unsampler (Flatten)
  • model
  • positive
  • latent_image
  • trajectories
  • LATENT
  • INJECTIONS
steps20
save_steps8
sampler_name
scheduler
normalize
old_qk0

The front half of video editing

Video editing with FLATTEN works in two acts. Act one is this node: Unsampler (Flatten) takes your input video's latent and runs the diffusion process backwards, turning footage into noise. Act two is the KSampler (Flatten), which runs it forward again under a new prompt. The trick is that this node doesn't just dump you at the noisy end - it also records the intermediate features it passed through and hands them to the sampler as INJECTIONS, which is exactly what keeps the re-generated video anchored to your original footage.

If you've used ComfyUI's img2img, the shape of this is familiar: you're finding "the latent your video would have come from." The FLATTEN difference is that the backward pass runs through the 3D UNet with the flow trajectories active, and the features it saves along the way become the edit's memory.

How it works

It's a reverse Euler-style inversion through the FLATTEN model. The node hardcodes cfg = 1 and adds no noise (the noise_seed of 777 in the source is a dead giveaway it isn't adding any), so the inversion is deterministic and driven purely by the input frames. At save_steps intervals along the backward pass it captures the UNet's intermediate features into an injection dict, keyed by context window. That's the INJECTIONS output. The normalize toggle cleans up the trajectory/noise tensors as they go, and old_qk selects the same attention variant as the sampler.

The inputs

  • model - from Load Checkpoint with FLATTEN model. Not a regular loader's model.
  • latent_image - your input frames, VAEncoded.
  • trajectories - from Sample Trajectories, same resolution as the latent.
  • steps (default 20) and save_steps (default 8) - total inversion steps and how often features are captured.
  • sampler_name, scheduler, normalize, positive, old_qk - with one hard rule, below.

Outputs: LATENT (the unsampled noisy latent) and INJECTIONS - wire both into the KSampler (Flatten), which is where the actual edit is made.

The hard rule

Only use Euler or ddpm2m here. The README is blunt: "this process creates noise from the input images," and the inversion math is built around those samplers. Feed it a dpmpp_2m and you're asking the backward pass to do something it wasn't designed for. The recommended full-recipe pairing is Euler on the unsampler, dpmpp_2m on the KSampler, old_qk = 0 on both. For the experimental scene-editing path, keep LCM off this node and on the KSampler only.

Installing

Search ComfyUI-FLATTEN in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/logtd/ComfyUI-FLATTEN

Restart ComfyUI. No extra pip packages - requirements.txt is empty and everything runs on ComfyUI's bundled torch/torchvision. You need an SD 1.5 checkpoint, plus Kosinkadik's ComfyUI-AnimateDiff-Evolved if you want context-windowed batching (which the pack's example workflow uses).

Categorysampling

Inputs (10)

NameTypeDefaultDescription
modelMODEL
stepsINT201–10000
save_stepsINT80–10000
sampler_nameCOMBO27 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +21
schedulerCOMBO6 options: normal, karras, exponential, sgm_uniform, simple, ddim_uniform
normalizeCOMBO2 options: disable, enable
positiveCONDITIONING
latent_imageLATENT
trajectoriesTRAJECTORY
old_qkINT00–1

Outputs (2)

NameTypeDescription
LATENTLATENT
INJECTIONSINJECTIONS