Extensions/Mecha Merge Node Pack
ComfyUI Extension

Mecha Merge Node Pack

model merging nodes powered by sd-mecha, a memory efficient state dict recipe merger.

By ljleb·Created 3 years ago·Updated about a month ago· 101
ljleb/comfy-mecha
Nodes83
On cloudLocal install
Categorymecha
Stars101
Updatedabout a month ago

Nodes (83)

Add Cosine A

Add only what's actually similar

mecha
Add Cosine B

The more forgiving similarity merge — Add Cosine A, plus magnitude

mecha
Add Difference

The merge formula most CivitAI checkpoints are made of

mecha
Add Opposite Mask

Get the mask itself — 'where do these models disagree?' as a param recipe

mecha
Add Opposite

Add a delta only where the parents actually disagree

mecha
Add Strict Opposite Mask

Only add where the models are *truly* opposite — the strict mask

mecha
Already Loaded Model

Merge with the model already in your workflow — no reload, no refile

mecha
Any Model

Load *any* safetensors as a merge ingredient — checkpoints, LoRAs, even diffusers-style files

mecha
Balance Attention

Permute attention layers so two models actually line up before you merge

mecha
Blocks

Per-block merge weights — the SuperMerger MBW dial for ComfyUI

mecha
Bool

A true/false switch as a recipe — the pack's on/off dials are params too

mecha
Cast

Force a merge to run in fp64 or on CPU — the precision/VRAM escape hatch

mecha
Clamped Add Opposite

Add a difference but refuse to leave the [A, B] band — the 'safe transplant' merge

mecha
Clamp

Squash any merge into the box you define — bounds as a recipe list, stiffness as a dial

mecha
Crossover

Mixing models by frequency — keep the texture of one, the structure of the other

mecha
Dropout

DARE-style pruning for deltas — the n-supermario merge that beats plain averaging

mecha
Exchange Ema

Swap in the EMA weights before you merge — they're usually the better half

mecha
Extract Kohya Lokr

Extract a LoKr (the LoRA that kept its rank) from a merge delta

mecha
Extract Kohya Lora

Turn a merge delta into an actual LoRA file

mecha
Extract Lycoris Lokr

Extract a LyCORIS-format LoKr, for when the layout matters

mecha
Extract Lycoris Lora

Extract a LoRA the LyCORIS way — same SVD, different key names

mecha
Fallback

Use A, and only fall back to default where A is missing

mecha
Float

A plain number, wrapped

mecha
FLUX-FLUX Components Params

Weight FLUX's four sub-models separately — diffuser, CLIP-L, T5, and VAE as one param recipe

mecha
Geometric Median

The merge that doesn't get dragged by outliers — a median instead of a mean

mecha
Geometric Sum

Interpolate in log space — the geometric mean between two models

mecha
Get Device

Ask a recipe where it lives — and hand that answer back to the merge

mecha
Get Dtype

Read a recipe's precision as a param — wire it into cast-style merges or just debug

mecha
Get Rank From Ratio

Size a low-rank truncation automatically — rank = ratio × min(tensor dims)

mecha
Int

Integer params as recipes — how you feed rank, maxiter, and seed into a merge

mecha
Lora

Merge a LoRA into a checkpoint with ComfyUI, no extra RAM

mecha
Converter

Translate a merge recipe between key layouts — kohya, diffusers, supermerger, and back

mecha
Deserializer

Paste a .mecha recipe string back into the graph — the load half of recipe bookkeeping

mecha
Cache Unit

Stop re-SVDing the same merge — a persistent cache for the expensive methods

mecha
Merger

The terminal node — turn a recipe graph into a usable MODEL, CLIP, and VAE

mecha
Recipe List

Bundle any number of recipes into one wire — the input every multi-model merge needs

mecha
Regex Weights

Per-key merge weights by pattern — block weights, but with regex instead of architecture

mecha
Serializer

Freeze your merge in plain text (and share it without the gigabytes)

mecha
Subtract Recipe List

Turn a pile of models into deltas in one step

mecha
Model

Turn any checkpoint into a merge ingredient

mecha
Model Stock

The mergekit stock recipe, now streaming on your GPU (or your CPU)

mecha
Multiply Quotient

The weird interpolation node nobody tells you about (and why it exists)

mecha
N Average

The honest average for merging more than two models

mecha
Omit Component

Merge everything except the VAE (or whatever you don't want touched)

mecha
Omit Non Finite

Quietly delete the NaN weights so your merge doesn't fall apart

mecha
Perpendicular Component

Remove the part of B that points along A, and merge what's actually new

mecha
Pick Component

Keep only the VAE, the CLIP, or the UNet — merge pieces on purpose

mecha
Randperm

Shuffle your model's neurons on purpose (research-grade merging)

mecha
Rebasin

Align models by permuting their weights

mecha
Rotate

Align two models by rotation, not by averaging

mecha
Scale

Turn strength into a merge parameter

mecha
SD1-LDM Components Params

Weigh each part of an SD1 model separately — CLIP, VAE, UNet, EMA, scheduler

mecha
SD1-KOHYA Components Params

Per-part weights for SD1 in kohya's key layout — the LoRA merger's param node

mecha
SD1-KOHYA_KOHYA_LORA Components Params

Component weights for kohya-format LoRAs on SD1

mecha
SD1-KOHYA_LYCORIS_LORA Components Params

Per-component weights for LyCORIS networks on SD1

mecha
SD1-LDM Blocks

SuperMerger-style block weights for SD1 — now in ComfyUI

mecha
SD1-SUPERMERGER_BLOCKS Components Params

One slider for all of SD1's blocks — the uniform block-weight shortcut

mecha
SD3-COMFYUI Components Params

Weigh the five parts of an SD3 merge — two CLIPs, T5, UNet, and VAE

mecha
SDXL-SGM Components Params

Merge the UNet at full strength and the text encoders at half

mecha
SDXL-DIFFUSERS_UNET_ONLY Components Params

The one-slider param node for SDXL UNets that live in a diffusers folder

mecha
SDXL-KOHYA_BUT_DIFFUSERS Components Params

The kohya node for SDXL, except the UNet keys are diffusers-style

mecha
SDXL-KOHYA_BUT_DIFFUSERS_KOHYA_LORA Components Params

The node for the messiest common setup

mecha
SDXL-KOHYA_BUT_DIFFUSERS_LYCORIS_LORA Components Params

Kohya checkpoint, diffusers UNet, LyCORIS LoRA

mecha
SDXL-KOHYA Components Params

Per-component merge weights for kohya-style SDXL checkpoints

mecha
SDXL-KOHYA_KOHYA_LORA Components Params

Per-component weights for kohya checkpoints with kohya-trained LoRAs

mecha
SDXL-KOHYA_LYCORIS_LORA Components Params

Per-component weights for kohya checkpoints with LyCORIS LoRAs

mecha
SDXL-SGM Blocks

26 sliders for the UNet

mecha
SDXL-SUPERMERGER_BLOCKS Components Params

The SuperMerger blocks param node that keeps the old muscle memory

mecha
SINGLETON-MECHA Components Params

Merge anything, keys be damned

mecha
Slerp

The merge that goes around, not through

mecha
Stack

The plumbing node you'll probably never wire by hand

mecha
String

When a merge recipe needs to be a text value

mecha
Subtract

How you build a delta, the move every good merge starts with

mecha
Tensor Sum

Swap a slice of one model's weights with another's

mecha
Ties Sum Extended

The full version with geometric median, model stock, and every knob

mecha
Ties Sum

Merge a pile of LoRAs without them fighting to a standstill

mecha
Ties Sum With Dropout

The LoRA-packing node for big style stacks

mecha
Top K Tensor Sum

Keep the important weights, graft in the other model's values

mecha
Train Difference Mask

The training trick that says 'change here, not there' — as a merge mask

mecha
Train Difference

The mask that keeps only what a fine-tune actually learned

mecha
Truncate Kronecker

The LoKr path

mecha
Truncate Rank

SVD your deltas

mecha
Weighted Sum

The weighted sum merge, without the 20 GB RAM spike

mecha
Readme

Discord Server

sd-mecha for Comfyui

comfy-mecha is a complete model merging nodepack for ComfyUI with a focus on low memory footprint.

  • compose complex recipes without needing to save dozens of intermediate merges to disk
  • merge loras to models
  • support for block weights
  • and a bunch of other stuff. For more info, see the nodes listing below. See also the readme of the underlying library sd-mecha

Workflows

Basic weighted sum

resources/weighted_sum.png

Clipped add difference

resources/clipped_add_difference.png

Ties merging

resources/ties_merging.png

Recipe workflows can get much, much more complex than this.
If you are familiar with writing python code, you might be interested in using the sd-mecha library directly for experiments as an alternative to ComfyUI: https://github.com/ljleb/sd-mecha

Install

Install with ComfyUI-Manager

Assuming you have ComfyUI-Manager installed:

  1. Open a browser tab on ComfyUI
  2. Click on the "Manager" button
  3. Click on "Install Custom Nodes"
  4. Search for "mecha"
  5. Install "Mecha Merge Node Pack"

Install manually

You can also install the node pack manually:

cd custom_nodes
git clone https://github.com/ljleb/comfy-mecha.git
pip install -r comfy-mecha/requirements.txt

Nodes listing

Merge nodes

Nodes used for merging. They all have Recipe in their name except for Mecha Merger.

  • nodes ending in ... Mecha Recipe return a merge recipe
  • Mecha Merger takes a MECHA_RECIPE as input, and returns a unet and a text encoder
  • Serializer takes a MECHA_RECIPE as input, and returns the recipe instructions using the mecha format
  • Deserializer takes a mecha recipe string as input, and returns the deserialized MECHA_RECIPE (this is the inverse operation of Serializer)
  • Mecha Model Recipe loads a model as a recipe to be used as input to other recipe nodes.
  • Mecha Lora Recipe loads a lora model as a recipe to be used as input to other recipe nodes.
  • Mecha Recipe List takes an arbitrary number of recipes and returns a MECHA_RECIPE_LIST. It is intended to be used as input to recipe nodes that accept an arbitrary number of recipes as input, i.e. the bounds input of Clip Mecha Recipe
  • Mecha Subtract Recipe List is the same as Mecha Recipe List but takes an additional base_recipe input that is subtracted from all other recipe inputs. This can simplify workflows that work with multiple deltas all obtained from the same base model.

Param Nodes

Nodes used to specify parameters to merge methods. For example, Weighted Sum Mecha Recipe has a param input alpha with a default value of 0.5.

  • Blocks Mecha Params can specify a different parameter for each block of the models to be merged (A.K.A. "merge block weighted")
  • Float Mecha Params specifies the same float for all keys of the models to be merged

Extensions

To add custom merge nodes, you can add python scripts that make use of the mecha extension API under the mecha_extensions directory. The nodepack will run all scripts placed there and turn them into Comfy nodes.

Currently, the documentation for the mecha extension API is under construction. For now, to get more information, you can either take a look at the custom merge method example, open a discussion post to ask questions, or join the discord server.