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

KSampler (Flatten)

The KSampler that actually runs FLATTEN — where your edit comes out

By logtd·Created 3 years ago·Updated 2 years ago· 114
KSampler (Flatten)
  • model
  • trajectories
  • positive
  • negative
  • latent_image
  • injections
  • LATENT
add_noise
noise_seed0
steps10
injection_steps8
old_qk0
cfg8.0
sampler_name
scheduler
start_at_step0
end_at_step10000
return_with_leftover_noise

The sampler the whole pack was built around

KSampler (Flatten) is where the edit actually happens. The rest of ComfyUI-FLATTEN feeds it: the Unsampler runs your input video backwards to noise and captures injection features, Sample Trajectories reads the optical flow, and this node runs the noisy latent forward again - with the injections and trajectories steering every denoise step - to produce the edited frames. It looks like a stock KSampler with extra knobs, and mostly it is, except those extra knobs are the entire point.

The core mechanism is feature injection: the Unsampler recorded intermediate features from your input frames, and this sampler replays them into the model's 3D UNet for the first injection_steps of the schedule. That's what pins the output to your original footage instead of letting it drift into a new, unrelated video. The old_qk toggle then chooses which FLATTEN attention variant runs - the README's two recipes are built entirely around it.

The knobs that matter

  • model - from Load Checkpoint with FLATTEN model. A regular loader's model won't work here.
  • injections - the INJECTIONS output of the Unsampler (Flatten). Required.
  • trajectories - from Sample Trajectories, sampled at the same resolution as the latent.
  • injection_steps - how many steps the injection features stay active (default 8, with steps defaulting to 10).
  • old_qk - 0 or 1. 0 is the video-editing recipe; 1 is the scene-editing one.
  • add_noise / noise_seed - leave add_noise off unless you're deliberately doing the experimental path.

Everything else - cfg (8), sampler_name, scheduler, positive/negative, start_at_step, end_at_step, return_with_leftover_noise, latent_image - works like a normal KSampler. Output is one LATENT, ready for VAEDecode.

Two recipes, straight from the README

Video editing (recommended). Unsampler on euler, this node on dpmpp_2m, old_qk = 0 on both, and add_noise off. Don't use other samplers - the author is explicit that other samplers or add_noise will wreck temporal consistency. If you add IP-Adapter for style, expect to fine-tune it; it struggles without extra noise.

Scene editing (experimental). Use LCM on the KSampler (not the Unsampler), old_qk = 1, and ancestral samplers work well here. You can experiment with add_noise when the sampler injects its own noise. IP-Adapter actually helps guide these toward a specific look. Expect some consistency loss and worse behavior on high-motion scenes - it's flagged experimental for a reason.

Gotchas

Batching a lot of frames degrades consistency - the author is candid that the current batching mechanism has this limit, and the fix is pending. Also remember the model contract: only the FLATTEN checkpoint loader's model belongs in this node.

Installing

Search ComfyUI-FLATTEN in ComfyUI Manager, or:

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

Restart ComfyUI. No extra Python packages - requirements.txt is empty, and everything rides on ComfyUI's own torch/torchvision. For batching you'll also want Kosinkadink's ComfyUI-AnimateDiff-Evolved, which the pack's example workflow uses for context windows.

Categorysampling

Inputs (17)

NameTypeDefaultDescription
modelMODEL
add_noiseCOMBO2 options: disable, enable
noise_seedINT00–18446744073709550000
stepsINT101–10000
injection_stepsINT80–10000
old_qkINT00–1
trajectoriesTRAJECTORY
cfgFLOAT8.00–100
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
positiveCONDITIONING
negativeCONDITIONING
latent_imageLATENT
injectionsINJECTIONS
start_at_stepINT00–10000
end_at_stepINT100000–10000
return_with_leftover_noiseCOMBO2 options: disable, enable

Outputs (1)

NameTypeDescription
LATENTLATENT