Mask Operations
Union, intersect, difference, xor — but for model masks
- mask_a
- mask_b
- MODEL_MASK
Mask Operations takes two MODEL_MASKs and performs set logic on them. Union, intersection, difference, xor - the same operations you'd use on image masks in Photoshop, but applied to tensors of booleans where every boolean says "merge this parameter" or "leave it alone." It's a combinator, and it's how you build compound protection schemes out of simple masks.
A mask in this pack is a per-parameter whitelist for a merge. Build a Magnitude Masker for one pair of models, another for a different concern, and you've got two opinions about what a merge should be allowed to touch. This node reconciles them:
- union - selected by either mask. The loosest combination: a parameter merges if either protection scheme says it's fine.
- intersect - selected by both. The strictest: a parameter only merges if both schemes agree it should. Use this when you want both of two conditions to hold.
- difference - mask_a minus mask_b: everything in A that isn't also in B. "Protect these, except where the other mask says don't bother."
- xor - the symmetric difference: in one mask or the other, but not both.
The pack's README is charmingly honest about how speculative all this is - it muses about "potentially binning the parameters of a model up with some fancy set thresholding, and then merging a different model in to each slice." Nobody has published a recipe for that, but it's the kind of thing these nodes make possible: split a model into four non-overlapping random slices with Quad Masker, then run a different merge into each slice using the same base model. Mask Operations is the glue.
The inputs
- mask_a, mask_b - two
MODEL_MASKs. They needn't cover identical layer sets; the operations handle missing keys sensibly (difference and union keep one-sided keys, intersect requires both). - operation -
union(default),intersect,difference,xor.
The output
A single MODEL_MASK, ready to feed any merger's model_mask input, or onward into Mask Edit for further surgery.
Install and gotchas
ComfyUI Manager (search "DareMerge") or:
cd ComfyUI/custom_nodes
git clone https://github.com/54rt1n/ComfyUI-DareMerge
Restart ComfyUI. Dependencies: matplotlib, numpy, torch, pillow; no downloads.
Two practical notes. First, masks are memory-heavy - boolean tensors at full model scale - and each operation builds new tensors, so a chain of several mask ops can add up; the pack chunks the heavy math to cope, and you'll see peak VRAM printed to the console. Second, the mental model that keeps you out of trouble: the mask is a whitelist for change, so union is the permissive direction and intersect is the restrictive one. If a masked merge comes out looking like pure model A, your mask likely shrank the mergeable set to nearly nothing - that's the mask doing its job, not a broken node.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask_a | MODEL_MASK | — | |
| mask_b | MODEL_MASK | — | |
| operation | COMBO | union | 4 options: union, intersect, difference, xor |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL_MASK | MODEL_MASK | — |