ComfyUI Node

MBW Gradient

Block-by-block merge ratios, the old MBW way

By 54rt1n·Created 3 years ago·Updated about a year ago· 98
MBW Gradient
  • model
  • LAYER_GRADIENT
time1.00
label1.00
input_blocks.00.00
input_blocks.10.00
input_blocks.20.00
input_blocks.30.00
input_blocks.40.00
input_blocks.50.00
input_blocks.60.00
input_blocks.70.00
input_blocks.80.00
input_blocks.90.00
input_blocks.100.00
input_blocks.110.00
middle_block.00.00
middle_block.10.00
middle_block.20.00
output_blocks.00.00
output_blocks.10.00
output_blocks.20.00
output_blocks.30.00
output_blocks.40.00
output_blocks.50.00
output_blocks.60.00
output_blocks.70.00
output_blocks.80.00
output_blocks.90.00
output_blocks.100.00
output_blocks.110.00
out0.00

MBW - "merge by weight" - is the old-school way of doing block merges, inherited from the A1111/SuperMerger era: instead of one ratio for the whole model, you set a separate ratio for each block of the UNet. DM_MBWGradient brings that familiar per-block dial interface into ComfyUI-DareMerge's newer LAYER_GRADIENT system, so you can feed it into the Advanced/DARE merger instead of hand-typing an MBW string.

How it works

The node takes a MODEL in and emits a single LAYER_GRADIENT out. On the surface it looks intimidating - there's a float input for input_blocks.0 through .11, middle_block.0 through .2, output_blocks.0 through .11, plus time, label, and out. That's the SD1.5 UNet layout spelled out, one slider per block. Each slider is the merge ratio for that block, and DareMerge's convention applies throughout the pack: 1 means keep the first model, 0 means keep the second.

Internally it walks the model's state dict and assigns each tensor the ratio of the block it belongs to, producing a gradient dict that the Advanced DARE merger consumes. You don't need to know any of that to use it - think of the output as "a saved ratio recipe for every layer," which is exactly what a layer gradient is.

The trap in the defaults

Here's where people get burned, and it's right there in the node's own defaults: time and label start at 1.0, but every block starts at 0.0. Per the convention above, that means the default gradient is "keep model B for all the blocks, keep model A for the time and label embeddings." Wire this in without touching anything and you'll get a result that's mostly the second model - probably not what you meant.

So the actual workflow is: decide which blocks do the work in your source models (input blocks near the start and output blocks near the end tend to carry style and composition), set those to something like 0.6–1.0 to lean on the first model, and leave the rest low. The time and label sliders control the embedding tensors - keep those high unless you want B's conditioning behavior to win.

When to reach for it

If you already think in MBW block numbers from the A1111 days, this is the most comfortable entry point into DareMerge. It's also the most manual gradient node in the pack - the Shell Gradient gives you the same control in three sliders, and the Block Gradient collapses it to six. MBW is what you use when you specifically want block 7 and block 3 handled differently and you're happy to say so out loud.

The one thing to keep in mind: this node (and DareMerge's whole gradient system) is built around the SD1.5 UNet's 12-block layout, and the pack's own README frames SD1.5 and SDXL as the targets. On SDXL the block counts differ, and gradient math that assumes 12 input blocks won't line up the same way.

Installing it

It's one node in the 54rt1n/ComfyUI-DareMerge pack, so install the pack once via ComfyUI Manager (search "ComfyUI-DareMerge") or:

cd ComfyUI/custom_nodes
git clone https://github.com/54rt1n/ComfyUI-DareMerge

then restart. Dependencies are just matplotlib, numpy, torch, pillow - nothing you won't already have in a working ComfyUI besides possibly matplotlib. No model downloads.

The short version: if you want granular block control over a merge and you're tired of squinting at MBW text strings, this is the node that turns those strings into sliders. Just don't trust the defaults.

CategoryDareMerge/gradient

Inputs (31)

NameTypeDefaultDescription
modelMODEL
timeFLOAT1.000–1
labelFLOAT1.000–1
input_blocks.0FLOAT0.000–1
input_blocks.1FLOAT0.000–1
input_blocks.2FLOAT0.000–1
input_blocks.3FLOAT0.000–1
input_blocks.4FLOAT0.000–1
input_blocks.5FLOAT0.000–1
input_blocks.6FLOAT0.000–1
input_blocks.7FLOAT0.000–1
input_blocks.8FLOAT0.000–1
input_blocks.9FLOAT0.000–1
input_blocks.10FLOAT0.000–1
input_blocks.11FLOAT0.000–1
middle_block.0FLOAT0.000–1
middle_block.1FLOAT0.000–1
middle_block.2FLOAT0.000–1
output_blocks.0FLOAT0.000–1
output_blocks.1FLOAT0.000–1
output_blocks.2FLOAT0.000–1
output_blocks.3FLOAT0.000–1
output_blocks.4FLOAT0.000–1
output_blocks.5FLOAT0.000–1
output_blocks.6FLOAT0.000–1
output_blocks.7FLOAT0.000–1
output_blocks.8FLOAT0.000–1
output_blocks.9FLOAT0.000–1
output_blocks.10FLOAT0.000–1
output_blocks.11FLOAT0.000–1
outFLOAT0.000–1

Outputs (1)

NameTypeDescription
LAYER_GRADIENTLAYER_GRADIENT