Gradient Edit
Reach into a merge gradient and change one layer
- gradient
- LAYER_GRADIENT
Gradient Edit is the scalpel for LAYER_GRADIENTs. Block Gradient and Attention Gradient hand you whole categories of ratios; this node lets you take any gradient and change specific layers afterward - set a layer to keep model A, zero it out so model B takes over, or nudge it with arithmetic. It's the difference between "blend the whole encoder at 0.7" and "blend the encoder at 0.7, except block 4's attention which stays fully on model A."
The layer targeting uses the same language as Mask Edit: a multiline layers field with comma or newline separated patterns, * as a wildcard, and {0,1} brace expansions for fanning out across blocks. diffusion_model.input_blocks.4.1.transformer_blocks.0.attn2.to_q.weight is one exact layer; diffusion_model.output_blocks.*.1.transformer_blocks.0.attn1.* hits a specific attention weight across every output block. If you need the exact key names, the Gradient Reporting node's details report lists them all.
The inputs that matter
- gradient - the
LAYER_GRADIENTyou're editing. The node edits in place (it returns the same dict object, mutated). - operation -
set,add,subtract,multiply, ordivide. - value - the operand. With
set, the targeted layers get exactly this ratio. Withadd/subtract, they're nudged; withmultiply/divide, scaled. - layers - the pattern list. Leave it empty or mistype a name and you get a "No layers specified" error, so this is where you'll spend your time.
How it works
It takes each pattern, expands it against the actual layer keys in the gradient (patterns that match nothing get skipped with a console note - no error, just silence), and applies the operation to every matching entry. Note the value range: the value slider is clamped 0–1, which is fine for set but means multiply by 0 is how you zero a layer out, and divide by a small number will blow a ratio way past 1 - the merger will happily use it (a ratio above 1 on the Advanced merger just means "more than all of model A," which is rarely what you want). Multiplication is the operation you'll actually use: it's how you take a coarse block gradient and carve a specific layer out of it.
The output
A LAYER_GRADIENT - the same gradient, edited - ready for Model Merger (Advanced) or Model Merger (Advanced/DARE). Chain multiple edits before the merger to build up a custom weighting.
Install and gotchas
ComfyUI Manager (search "DareMerge") or:
cd ComfyUI/custom_nodes
git clone https://github.com/54rt1n/ComfyUI-DareMerge
Restart ComfyUI. Dependencies are matplotlib, numpy, torch, pillow; no downloads.
Two gotchas worth internalizing. First, remember the gradient is a filter: editing a layer out (multiplying by 0) doesn't mean "blend at 0," it means that layer keeps model A entirely - same result, but the mechanism is "no merge here," which is why the pack's report nodes exist. Second, if you're debugging a merge and the fix isn't landing, verify your pattern actually matched something: unmatched patterns fail silently, and a gradient that's missing a layer key is a gradient that silently leaves that layer on model A.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| gradient | LAYER_GRADIENT | — | |
| operation | COMBO | set | 5 options: set, add, subtract, multiply, divide |
| value | FLOAT | 0.000–1 | — |
| layers | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LAYER_GRADIENT | LAYER_GRADIENT | — |