Nodes/LanPaint/LanPaint KSampler
ComfyUI Node

LanPaint KSampler

Training-free inpainting for any model

By scraed·Created about a year ago·Updated about a month ago· 1,285
LanPaint KSampler
  • model
  • positive
  • negative
  • latent_image
  • LATENT
seed0
steps30
cfg5.0
sampler_name
schedulerkarras
denoise1.00
LanPaint_NumSteps5
LanPaint_PromptMode
LanPaint_InfoLanPaint KSampler.
Inpainting_mode🖼️ Image Inpainting

Here's the problem LanPaint solves. Dedicated inpainting checkpoints basically stopped shipping after FLUX.1 Fill dev in late 2024. So when you're on Z-Image, Flux 2, Qwen, Wan, or any shiny new base, there is no "-inpainting" version of it to download - and masking a region in plain img2img on a model that was never trained for it gives you seams and color shifts. LanPaint KSampler is the training-free way around that. It's a drop-in replacement for the standard KSampler that teaches any model to inpaint, with no fine-tune, no extra checkpoint, no download beyond the node itself. In the wider inpainting picture it's the universal fallback: not always the best if a real Fill model exists for your stack, but the thing that works when nothing else does. As one user put it, it's the goto for high-quality inpaint - the only real downside is speed.

How the "think mode" works

Normal denoising takes one step toward a clean image per step. LanPaint inserts a little loop before each of those steps where the model "thinks": it runs a few iterations of Langevin dynamics that nudge the masked region toward something statistically consistent with the unmasked pixels you're keeping. It's the ComfyUI implementation of a real paper (TMLR 2025, Training-Free Diffusion Inpainting with Asymptotically Exact and Fast Conditional Sampling), and the practical upshot is that the extra compute buys you cleaner, more coherent fills - the masked area actually respects its surroundings instead of hallucinating a seam. The cost is right there in the mechanism: five thinking iterations means roughly five times the sampling time. You're literally trading minutes for quality.

The inputs that matter

Wire it exactly like a KSampler - model, positive, negative, latent_image, plus seed, steps, cfg, sampler_name, scheduler, and denoise. The mask isn't a separate socket on this node; it rides in on latent_image, so your graph is the standard Set Latent Noise Mask inpainting setup feeding this node in place of the vanilla sampler. The single LATENT output goes straight to your VAE Decode.

The three knobs that are actually LanPaint's:

  • LanPaint_NumSteps (default 5) - thinking depth. This is the master dial. 2–5 for easy fixes, push to 10 for hard ones. It's also exactly what multiplies your render time, so it's the first thing to drop if you're impatient.
  • LanPaint_PromptMode - Image First fills from the surrounding image context and may half-ignore your prompt; Prompt First leans harder on the text, which is what you want for tricks like consistent characters or new views. Heads up: Prompt First works by pushing CFG negative internally, so it does nothing on Flux and other models that don't use CFG guidance.
  • Inpainting_mode - leave it on Image Inpainting unless you're doing Wan 2.2 video, then flip it to Video.

Keep steps in the 20–50 range and match sampler_name/scheduler to your base model. One trap worth calling out: the node ships with scheduler defaulted to karras, which is fine for SD 1.5 and SDXL but a bad fit for flow-matching bases like Flux and Z-Image, where karras tends to fall apart - switch to beta or simple on those. If you want the deeper controls (lambda, step size, friction, early stop), those live on the separate LanPaint KSampler (Advanced) node; this one hides them behind sensible defaults on purpose.

Installing it

The easy way: open ComfyUI Manager, search LanPaint, install, restart. Or from a terminal, cd ComfyUI/custom_nodes && git clone https://github.com/scraed/LanPaint and restart ComfyUI. You need ComfyUI newer than 0.3.11. There's nothing else to fetch - no models, no heavy dependencies - because LanPaint reuses whatever checkpoint you already have. After the restart the nodes show up under the sampling category.

Where people get burned

  • It's slow, and that's not a bug. NumSteps directly multiplies sampling time. If a render crawls, lower NumSteps or cut total steps before you go looking for a problem.
  • Distillation models misbehave. Flux.dev and friends have degraded inpainting here for the same reason they're hard to LoRA-train. The fix from the author is to run low flux guidance, around 1.0–2.0.
  • Glowing or broken mask edges? That was a real bug squashed in v1.5.0 (it especially hit z-image-base and could blur results). If you see it, update the pack first.
  • Give it a real prompt. LanPaint leans heavily on your text to decide what fills the mask - describe the content explicitly, and fight artifacts with targeted negatives. It also wants a clean binary mask; set your mask editor's opacity and hardness to max.
  • Composite afterward for pixel-perfect edges. Standard inpainting hygiene applies, and the pack ships a LanPaint Mask Blend node if you want the unmasked region to match the original exactly.
Categorysampling

Inputs (14)

NameTypeDefaultDescription
modelMODELThe model used for denoising the input latent.
seedINT00–18446744073709550000The random seed used for creating the noise.
stepsINT301–10000The number of steps used in the denoising process.
cfgFLOAT5.00–100The Classifier-Free Guidance scale balances creativity and adherence to the prompt. Higher values result in images more closely matching the prompt however too high values will negatively impact quality.
sampler_nameCOMBORecommended: euler.
schedulerCOMBOkarrasThe scheduler controls how noise is gradually removed to form the image.
positiveCONDITIONINGThe conditioning describing the attributes you want to include in the image.
negativeCONDITIONINGThe conditioning describing the attributes you want to exclude from the image.
latent_imageLATENTThe latent image to denoise.
denoiseFLOAT1.000–1The amount of denoising applied, lower values will maintain the structure of the initial image allowing for image to image sampling.
LanPaint_NumStepsINT50–100The number of steps for the Langevin dynamics, representing the turns of thinking per step.
LanPaint_PromptModeCOMBOImage First: emphasis image quality, Prompt First: emphasis prompt following
LanPaint_InfoSTRINGLanPaint KSampler.For more info, visit https://github.com/scraed/LanPaint. If you find it useful, please give a star ⭐️!
Inpainting_modeCOMBO🖼️ Image InpaintingChoose Image mode for photos or Video mode for video frames with temporal consistency

Outputs (1)

NameTypeDescription
LATENTLATENTThe denoised latent.