LanPaint KSampler (Advanced)
Masked inpainting on any model, with all the dials
- model
- positive
- negative
- latent_image
- LATENT
Here's the problem LanPaint exists to solve. Your favorite model never got a dedicated inpainting checkpoint. Flux, Qwen, Z-Image, half the SDXL finetunes on Civitai - most of them can only inpaint by masking a region and hoping, which gives you seams and color drift. The only base trained properly for the job is FLUX.1 Fill dev, and that's 2024 weights now. So what do you do when you want to inpaint into a 2026 model?
You reach for LanPaint. It's a training-free inpainting sampler, not a checkpoint - swap it in for your KSampler and any diffusion or rectified-flow model suddenly does masked inpainting, no fine-tune required. It's the community's universal fallback for exactly this situation. The Advanced node is the full-control version: same idea as the one-knob basic LanPaint KSampler, but with every dial exposed for when the defaults don't land.
How it works
The name of the trick is "think mode." Before each denoising step, LanPaint runs a handful of extra Langevin-dynamics iterations that reconcile the masked region with the fixed, unmasked context - it "thinks" about how the fill should connect to what's already there, then denoises. More thinking iterations, better coherence. The cost is linear: if you tell it to think 5 times per step, your generation takes roughly 5x longer. That's the whole trade, and LanPaint's own users say so - it's the go-to for quality inpainting, and the one downside everyone names is speed.
The inputs and outputs that matter
It looks like ComfyUI's KSampler (Advanced) with a stack of LanPaint_ widgets bolted on. Wire in your model, positive/negative conditioning, and a latent_image (your image encoded with the mask set as its noise mask), the same as any inpaint graph. The knobs a beginner actually touches:
LanPaint_NumSteps- thinking depth. Default 5, which the author recommends for most tasks; push to 10 for hard ones. This is your main quality/speed lever.steps- total sampling steps, default 30. The tuning guide calls raising this the single most important quality move.LanPaint_PromptMode- Image First fills based on surrounding image context (may ignore the prompt); Prompt First leans on the prompt, useful for character-consistency tricks. Note it's disabled on Flux, which uses no CFG.
Then the stability trio for when results go weird: LanPaint_Lambda (alignment strength, ships at 16 - the docs suggest trying 4–10 if it's over-constrained), LanPaint_StepSize (default 0.2), and LanPaint_Friction (default 15; lower is faster but less stable). You've also got the standard Advanced-KSampler plumbing - add_noise, start_at_step, end_at_step, return_with_leftover_noise - which let you do partial inpaints that reference the original rather than generating from scratch, plus an Inpainting_mode switch for Wan 2.2 video.
The single output is a LATENT. Send it to your VAE Decode like any sampler.
How to install it
Via ComfyUI Manager: search "LanPaint" and install, or use "Install via Git URL" with https://github.com/scraed/LanPaint.git. Manually: cd ComfyUI/custom_nodes && git clone https://github.com/scraed/LanPaint, then restart. You need ComfyUI newer than 0.3.11. There are no model files or heavy dependencies to download for the node itself - it's a sampler - but you do need whatever base model you're inpainting with already installed. The nodes show up under the "sampling" category.
Common issues & troubleshooting
- It's slow, and that's expected.
NumStepsmultiplies your runtime. If you're just iterating, drop it to 2–3, or raiseLanPaint_StepSizeand lowerLanPaint_Frictionto converge faster. - Your mask has soft edges. LanPaint wants binary masks - set opacity and hardness to max in the mask editor. Gradients get force-converted anyway, so paint hard.
- The fill ignores what you wanted. LanPaint leans hard on the prompt. Describe the masked content explicitly and use targeted negatives to kill artifacts.
- Flux or another distilled model looks mushy. Distillation models degrade with LanPaint; the fix is low Flux guidance (1.0–2.0).
- Glowing or broken mask boundaries? That was a real bug fixed in v1.5.0 (especially on z-image-base). Update the pack. And z-image-base can diverge outright - start with a small
StepSizeand fewer thinking steps. - Unmasked area shifted slightly. LanPaint generates 100% new content and round-trips the VAE, so untouched pixels aren't bit-identical. If you need them exact, composite with the pack's LanPaint Mask Blend node afterward.
Inputs (24)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| add_noise | COMBO | 2 options: enable, disable | |
| noise_seed | INT | 00–18446744073709550000 | — |
| steps | INT | 301–10000 | — |
| cfg | FLOAT | 5.00–100 | — |
| sampler_name | COMBO | 22 options: euler, euler_ancestral, heun, heunpp2, dpm_2, dpm_2_ancestral, +16 | |
| scheduler | COMBO | 9 options: simple, sgm_uniform, karras, exponential, ddim_uniform, beta, +3 | |
| positive | CONDITIONING | — | |
| negative | CONDITIONING | — | |
| latent_image | LATENT | — | |
| start_at_step | INT | 00–10000 | — |
| end_at_step | INT | 100000–10000 | — |
| return_with_leftover_noise | COMBO | 2 options: disable, enable | |
| LanPaint_NumSteps | INT | 50–100 | The number of steps for the Langevin dynamics, representing the turns of thinking per step. |
| LanPaint_Lambda | FLOAT | 16.00.1–50 | The bidirectional guidance scale. Higher values align with known regions more closely, but may result in instability. |
| LanPaint_StepSize | FLOAT | 0.200.0001–1 | The step size for the Langevin dynamics. Higher values result in faster convergence but may be unstable. |
| LanPaint_Beta | FLOAT | 1.00.0001–5 | The step size ratio between masked / unmasked regions. Lower value can compensate high values of LanPaint_Lambda. |
| LanPaint_Friction | FLOAT | 15.00–50 | The friction parameter for fast langevin, lower values result in faster convergence but may be unstable. |
| LanPaint_PromptMode | COMBO | Image First: emphasis image quality, Prompt First: emphasis prompt following | |
| LanPaint_EarlyStop | INT | 10–10000 | The number of steps to stop the LanPaint early, useful for preventing the image from irregular patterns. |
| LanPaint_Info | STRING | LanPaint KSampler Adv. | For more info, visit https://github.com/scraed/LanPaint. If you find it useful, please give a star ⭐️! |
| Inpainting_mode | COMBO | 🖼️ Image Inpainting | Choose Image mode for photos or Video mode for video frames with temporal consistency |
| LanPaint_InnerThreshold | FLOAT | 0.00000–1 | Early stop threshold for Langevin iterations based on semantic distance. 0.0 to disable. (Contributed by godnight10061) |
| LanPaint_InnerPatience | INT | 11–100 | Number of consecutive steps below threshold required to stop. (Contributed by godnight10061) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |