CFG Where: Region Mask
Guidance is a global dial. This node makes it regional.
- model
- mask
- MODEL
Here's what makes CFG annoying: it's one number for the whole frame. You bump the scale because a face is mushy, and the sky and every highlight get pushed just as hard - which is how you end up with the deep-fried look the troubleshooting docs warn about. CFG Where: Region Mask, from the CFG Megapack (AbstractPhil's pack that takes classifier-free guidance apart into seven stages), scales the guidance push per region instead, so you can lean on the subject and leave the rest of the frame closer to the plain conditional prediction.
Don't confuse it with regional prompting (Latent Couple, Regional Prompter, Forge Couple), which gives different prompts to different areas to stop two characters' hair colors bleeding together. This doesn't touch prompts: one prompt, one global CFG value, and it decides where the extrapolation applies.
How the region mask works
At every step the sampler hands the pack a conditional prediction c and an unconditional one u, and plain CFG is u + w(c - u). The pack thinks in terms of the guidance term, G = x0_hat - c - how far past the conditional prediction the guided estimate was pushed, which for plain CFG is (w - 1)(c - u). Stage 4 rebuilds the result as c + G, and this node multiplies G by a per-pixel map.
That map comes straight from your mask: bilinearly resized to the latent resolution, optionally blurred by feather latent pixels, clamped to 0–1, optionally inverted, then interpolated between the two multipliers - outside_multiplier where the mask is black, inside_multiplier where it's white. A multiplier of 1 leaves guidance alone; 0 gives the conditional prediction alone, i.e. guidance off, but still a fully sampled and prompted image - not the background you had before. The range goes to -5, so you can push against guidance inside a region; nobody sane starts there.
The five things you actually set
- model - the MODEL from your checkpoint loader. Wire the output into the KSampler's
modelinput, or the next Megapack node in the chain. It patches the model; it never touches your conditioning. - mask - a MASK. Load Image's MASK output works, as does anything else in your graph that produces one. White is inside.
- inside_multiplier / outside_multiplier - the two numbers that matter, and where the surprise lives.
- feather - blur of the mask edge, in latent pixels (default 1). At 1024×1024 the latent is 128×128, so one latent pixel is eight image pixels: 4–8 is a visibly soft edge, and a large value bleeds guidance into the area you meant to leave alone.
- invert - swaps inside and outside.
Where people get burned
The defaults are a hard split, and they aren't neutral. inside_multiplier defaults to 1 and outside_multiplier to 0, so the moment you plug a mask in, everything outside it stops being guided. If you assumed "outside the mask = untouched", surprise: the outside isn't preserved, it's rendered with guidance off - a flatter, washed image. The shape most people actually want is outside_multiplier at 1 (background as normal) with inside_multiplier above 1 (subject pushed harder).
Masks routinely arrive inverted. The subject is white in the file you drew, black after the wrong node. If the node acts exactly backwards, flip invert.
There's no step window here. Masking runs for the whole sampling run, against the one piece of regional advice that has survived every architecture change: stop masking once composition has formed and let the conditioning blend the rest, or regions look collaged. With no window, soften instead - a wide feather and modest multipliers go a long way.
Nothing happens at all. The Megapack shares ComfyUI's single CFG-function slot with other packs' RescaleCFG, Mahiro and RenormCFG; the one chained last wins. Within the pack, a later node of the same stage replaces an earlier one instead of stacking, so chain CFG Plan Readout and confirm the region rule is the one on the plan.
Install
No dependencies, no models to download: the pack uses torch and the Python standard library only (there's deliberately no requirements.txt), but it needs a recent ComfyUI (>= 0.38.0) since it's built on the comfy_api.latest node API.
# ComfyUI Manager: search "CFG Megapack" and install, then restart
# or, with comfy-cli:
comfy node install comfy-cfg-megapack
# or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/AbstractEyes/comfy-cfg-megapack
Restart ComfyUI and it shows up under CFG Megapack > 4 where, with bundled examples under Workflow > Browse Templates > Custom Nodes > comfy-cfg-megapack - each renders one seed twice, plain CFG and the variant, which is the only fair way to judge whether the mask did anything. One expectation to set: this pack is new and undocumented outside its own HOWTO, so there's no reddit thread to check your settings against.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| mask | MASK | — | |
| inside_multiplier | FLOAT | 1.00-5–10 | — |
| outside_multiplier | FLOAT | 0.00-5–10 | — |
| feather | FLOAT | 1.00–32 | Blur of the mask edge in latent pixels (0 = hard edge). |
| invert | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |