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

TwoAdvancedSamplersForMask

Run two samplers on one latent, step by step together

By ltdrdata·Created 3 years ago·Updated 4 months ago· 3,242
TwoAdvancedSamplersForMask
  • samples
  • base_sampler
  • mask_sampler
  • mask
  • LATENT
seed0
steps20
denoise1.00
overlap_factor10

Sometimes you want two completely different samplers acting on one image at once - a base sampler handling the untouched area, a different sampler (different steps, different denoise character, maybe a different model entirely via the sampler wrapper) handling a masked region. Impact Pack has two nodes for this, and TwoAdvancedSamplersForMask is the more tightly-interleaved one.

Its sibling, TwoSamplersForMask, runs the base area to completion first and only then samples the masked area. TwoAdvancedSamplersForMask does it differently: per the README, it "performs sampling in both the base area and the mask area sequentially at each step" - meaning at every single sampling step, both regions advance together, rather than one finishing before the other starts. That interleaving is the entire reason to reach for the "Advanced" variant instead of the plain one: it matters when the two regions need to stay in sync as noise resolves, rather than one being fully denoised context before the other even begins.

How it works

You feed it a samples latent and a mask. base_sampler handles the unmasked area, mask_sampler handles the masked area - both wired in as KSAMPLER_ADVANCED type, which means you build them with the pack's own KSamplerAdvancedProvider wrapper node beforehand rather than plugging in a plain KSampler directly. At each step, the node samples a bit of both regions and blends them at the mask boundary, governed by overlap_factor. steps, denoise, and seed apply to the overall pass; the individual sampler providers carry their own settings (and, per the README, a sigma_factor on KSamplerAdvancedProvider that lets you scale the denoise schedule independently for each side).

One thing worth knowing before you build around this: the README notes the latent produced by VAEEncodeForInpaint cannot be used with TwoSamplersForMask-family nodes. Feed it a plain encoded latent plus a separate mask input instead.

The inputs and outputs that matter

  • samples (LATENT, required) - the latent both samplers work on together.
  • base_sampler / mask_sampler (both KSAMPLER_ADVANCED, required) - build these with KSamplerAdvancedProvider first. base_sampler covers everything outside the mask; mask_sampler covers inside it.
  • mask (MASK, required) - defines which pixels belong to which sampler.
  • seed, steps, denoise - the overall pass controls. Defaults are 0 / 20 steps / full denoise (1.0).
  • overlap_factor (default 10, range 0–10000) - how much blending happens at the mask boundary between the two sampled regions. Higher values smooth the seam more; too low and you risk a visible line where base meets mask.

Output is a single LATENT - the combined result, ready for a VAE decode like any other sampled latent.

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 extra models for the node itself - you supply whatever checkpoints your two KSamplerAdvancedProvider setups reference.

Common issues & troubleshooting

Type mismatch on base_sampler / mask_sampler. These want KSAMPLER_ADVANCED, not a plain KSampler node's output. Build each side with KSamplerAdvancedProvider first - that's the wrapper the README specifically calls out for use with this node.

Errored on a latent from an inpaint-encode node. Confirmed limitation: VAEEncodeForInpaint output isn't compatible here. Use a normal latent (plain VAEEncode or an empty latent) alongside a separate mask input instead.

Visible seam at the mask boundary. Raise overlap_factor for smoother blending between the two sampled regions. If it's still visible, check that mask_sampler and base_sampler aren't producing wildly different tonal results - a big style mismatch between the two won't be hidden by blending alone.

Not sure whether you want this or the plain TwoSamplersForMask. If the two regions genuinely need to evolve together step by step (they interact, or you want consistent global noise resolution), use the Advanced version here. If the mask area is fully independent and can just be finished after the base area, the plain TwoSamplersForMask is simpler and does less work per step.

CategoryImpactPack/Sampler

Inputs (8)

NameTypeDefaultDescription
seedINT00–18446744073709550000Random seed to use for generating CPU noise for sampling.
stepsINT201–10000total sampling steps
denoiseFLOAT1.000–1The amount of noise to remove. This amount is the noise added at the start, and the higher it is, the more the input latent will be modified before being returned.
samplesLATENTinput latent image
base_samplerKSAMPLER_ADVANCEDSampler to apply to the region outside the mask.
mask_samplerKSAMPLER_ADVANCEDSampler to apply to the masked region.
maskMASKregion mask
overlap_factorINT100–10000To smooth the seams of the region boundaries, expand the mask by the overlap_factor amount to overlap with other regions.

Outputs (1)

NameTypeDescription
LATENTLATENTresult latent