Nodes/comfyui-timesaver/TS Langevin Inpaint
ComfyUI Node

TS Langevin Inpaint

An inpaint sampler that makes the repair agree with its surroundings

By AlexYez·Created 2 years ago·Updated about 22 hours ago· 12
TS Langevin Inpaint
  • model
  • positive
  • negative
  • latent_image
  • LATENT
seed0
steps20
cfg1.0
sampler_name
scheduler
denoise1.00
think_steps5
guidance16.0
step_size0.20
beta1.0
friction15.0

Ordinary masked inpainting has a failure mode you've seen a hundred times: the patch is fine - right colors, plausible texture - but it sits in the image like a sticker. It doesn't agree with what's around it, so your eye lands on the seam instantly. TS Langevin Inpaint is a sampler built to fix exactly that: it spends extra inner "thinking" steps at every noise level so the repainted region is pulled into agreement with the known pixels, instead of merely filling the hole.

This is the same family of idea as LanPaint's "let the model think while inpainting" - an inference-time technique that adds corrective steps during denoising, works with any model, and needs no training, no Fill checkpoint, no ControlNet. The value proposition is precisely that universality: on a heavily fine-tuned model or an unusual family, a purpose-trained inpaint model often doesn't exist, and this gives you an inpainter that runs on whatever you already have.

How it works

You swap it in where a plain KSampler would go. Feed it a latent that carries a noise mask (white = repaint), and it returns the finished latent.

Ordinary sampling lets the masked region see its surroundings only through the model's attention, which isn't enough. Langevin dynamics adds a short corrective loop at each noise level - think_steps of them - where the patch is pulled towards the known pixels with guidance, damped by step_size, beta and friction. Think of it as the sampler double-checking its own work at every step. The defaults are tuned for photographic content: raise think_steps when a seam is still visible, lower it when the patch turns mushy.

The inputs that matter

Most of these are the KSampler inputs you already know - model, positive, negative, latent_image, seed, steps, cfg, sampler_name, scheduler, denoise. The interesting four are the Langevin knobs:

  • think_steps (default 5) - inner Langevin steps per noise level. 0 disables the refinement entirely and leaves you with an ordinary masked sample, which is a handy A/B switch.
  • guidance (default 16) - how hard the masked region is pulled toward agreement with the known pixels. Higher binds tighter; too high can oscillate.
  • step_size (default 0.2) - Langevin step size. Larger converges faster, less stably.
  • beta (default 1) - time-step ratio of the masked branch; lower it to compensate a high guidance value.
  • friction (default 15) - damping of the inertial dynamics; lower converges faster and less stably.

Output: LATENT - the finished latent, ready for a VAE decode.

Installation

Part of the comfyui-timesaver pack. Install via ComfyUI Manager (search "Timesaver") or:

cd ComfyUI/custom_nodes
git clone https://github.com/AlexYez/comfyui-timesaver
cd comfyui-timesaver
python -m pip install -r requirements.txt

Restart ComfyUI. It lives under TS/Image/Retouch.

When it's worth the extra steps

This node costs more than a plain sampler - every noise level runs extra inner steps - so it's not your everyday inpaint. Reach for it when a repaint has to blend into genuinely complicated surroundings: skin, fabric, foliage, hair, textures where a visible patch ruins the shot. If you're repainting a flat wall, a normal sampler does fine and this is wasted compute.

The knobs are forgiving but the failure modes are directional: visible seam → raise think_steps. Mushy, over-smoothed patch → lower think_steps (or check that guidance isn't so high it's over-correcting into mush). If you see oscillation, drop guidance or raise beta.

If you'd rather not replace your sampler node and already run SamplerCustomAdvanced, the pack's TS Universal Inpaint Sampler is the same idea packaged as a SAMPLER you plug into the sampling chain instead of around it - same think_steps mental model.

CategoryTS/Image/Retouch

Inputs (15)

NameTypeDefaultDescription
modelMODEL
positiveCONDITIONING
negativeCONDITIONING
latent_imageLATENTLatent with a noise mask (white = repaint).
seedINT00–18446744073709550000
stepsINT201–200
cfgFLOAT1.00–100
sampler_nameCOMBO45 options: euler, euler_cfg_pp, euler_ancestral, euler_ancestral_cfg_pp, heun, heunpp2, +39
schedulerCOMBO11 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +5
denoiseFLOAT1.000–1
think_stepsINT50–20Inner Langevin steps per noise level. 0 disables the refinement and leaves an ordinary masked sample.
guidanceFLOAT16.00.1–50How hard the masked region is pulled towards agreement with the known pixels. Higher binds tighter, too high can oscillate.
step_sizeFLOAT0.200.001–1Langevin step size. Larger converges faster, less stably.
betaFLOAT1.00.01–5Time-step ratio of the masked branch. Lower it to compensate a high guidance value.
frictionFLOAT15.00–50Damping of the inertial dynamics. Lower converges faster and is less stable.

Outputs (1)

NameTypeDescription
LATENTLATENT