Nodes/ComfyUI Impact Pack/TwoSamplersForMask
ComfyUI Node Runs on cloud

TwoSamplersForMask

Two different samplers, split by a mask

By ltdrdata·Created 3 years ago·Updated 4 months ago· 3,242
TwoSamplersForMask
  • latent_image
  • base_sampler
  • mask_sampler
  • mask
  • LATENT

Most masked workflows use one sampler and let the mask control where it applies - denoise strength, inpaint conditioning, that kind of thing. TwoSamplersForMask does something different: it runs two entirely separate samplers on the same latent, one for the area outside the mask and a different one for the area inside it. Per the README: "The base_sampler is applied to the area where the mask is 0, while the mask_sampler is applied to the area where the mask is 1." Different steps, different CFG, even a different model or LoRA stack per region - split cleanly at the mask boundary.

The use case this actually earns its keep on: you want distinctly different sampling behavior inside a masked region versus outside it - a harder-fought edit inside the mask, a lighter touch (or none at all) outside it - and adjusting a single sampler's settings, or denoise alone, can't get you there.

How it works

base_sampler runs on the region where the mask is 0; mask_sampler runs where the mask is 1. Both are KSAMPLER objects - you build them with KSamplerProvider (a plain KSampler wrapped for this purpose) or TiledKSamplerProvider if either region is large enough to need tiling. TwoSamplersForMask runs the base sampler across the full area first, then applies the mask sampler on top for the masked region - sequential, not simultaneous. Its sibling, TwoAdvancedSamplersForMask, does both at every step interleaved instead, if you need the two regions to influence each other more tightly during sampling.

One hard limitation stated directly in the README: the latent encoded through VAEEncodeForInpaint cannot be used as this node's input. Encode your latent a different way if you're feeding this node.

The inputs and outputs that matter

  • latent_image (LATENT, required) - the latent to run both samplers against.
  • base_sampler (KSAMPLER, required) - runs where the mask is 0. Build with KSamplerProvider or TiledKSamplerProvider.
  • mask_sampler (KSAMPLER, required) - runs where the mask is 1. Same sampler-building options.
  • mask (MASK, required) - defines the split. 0 is base sampler's territory, 1 is mask sampler's.

Output is a single LATENT - decode it normally once both samplers have run.

How to install it

Via ComfyUI Manager: search ComfyUI Impact Pack, install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
cd comfyui-impact-pack
python -m pip install -r requirements.txt   # ComfyUI's python; python_embeded on portable

then restart. No models bundled with this node itself. If you want a tiled sampler on either side, KSamplerProvider/TiledKSamplerProvider are the pieces you build separately - TiledKSamplerProvider additionally needs BlenderNeko/ComfyUI_TiledKSampler installed.

Common issues & troubleshooting

Errors on a latent you know is valid elsewhere. Check whether it came from VAEEncodeForInpaint - the README states this specific node can't accept that. Encode with a plain VAEEncode instead, and handle masking through the mask input here rather than through the encode step.

Nothing to plug into base_sampler/mask_sampler. These are strictly KSAMPLER-typed - you need a KSamplerProvider (or TiledKSamplerProvider) feeding each, not a plain sampler_name dropdown.

The two regions look tonally inconsistent where they meet. Somewhat expected with a hard sequential split at the mask boundary - there's no built-in blending between base and mask regions here. If seams bother you, consider TwoAdvancedSamplersForMask (interleaved per-step instead of sequential) or feather the mask edge before feeding it in.

Not sure you need two samplers at all. If your goal is just "sample this region differently by degree" - more or less denoise, mostly - a single sampler with mask-driven denoise or an inpaint-conditioned latent gets you there more simply. Reach for TwoSamplersForMask specifically when the two regions genuinely need different sampler settings, not just different strengths of the same one.

CategoryImpactPack/Sampler

Inputs (4)

NameTypeDefaultDescription
latent_imageLATENTinput latent image
base_samplerKSAMPLERSampler to apply to the region outside the mask.
mask_samplerKSAMPLERSampler to apply to the masked region.
maskMASKregion mask

Outputs (1)

NameTypeDescription
LATENTLATENTresult latent