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 2 years ago·Updated 13 days ago· 101
ljleb/comfy-mecha
Nodes83
On cloudLocal install
Categorymecha
Stars101
Updated13 days ago

Nodes (83)

Add Cosine A
mecha
Add Cosine B
mecha
Add Difference
mecha
Add Opposite Mask
mecha
Add Opposite
mecha
Add Strict Opposite Mask
mecha
Already Loaded Model
mecha
Any Model
mecha
Balance Attention
mecha
Blocks
mecha
Bool
mecha
Cast
mecha
Clamped Add Opposite
mecha
Clamp
mecha
Crossover
mecha
Dropout
mecha
Exchange Ema
mecha
Extract Kohya Lokr
mecha
Extract Kohya Lora
mecha
Extract Lycoris Lokr
mecha
Extract Lycoris Lora
mecha
Fallback
mecha
Float
mecha
FLUX-FLUX Components Params
mecha
Geometric Median
mecha
Geometric Sum
mecha
Get Device
mecha
Get Dtype
mecha
Get Rank From Ratio
mecha
Int
mecha
Lora
mecha
Converter
mecha
Deserializer
mecha
Cache Unit
mecha
Merger
mecha
Recipe List
mecha
Regex Weights
mecha
Serializer
mecha
Subtract Recipe List
mecha
Model
mecha
Model Stock
mecha
Multiply Quotient
mecha
N Average
mecha
Omit Component
mecha
Omit Non Finite
mecha
Perpendicular Component
mecha
Pick Component
mecha
Randperm
mecha
Rebasin
mecha
Rotate
mecha
Scale
mecha
SD1-LDM Components Params
mecha
SD1-KOHYA Components Params
mecha
SD1-KOHYA_KOHYA_LORA Components Params
mecha
SD1-KOHYA_LYCORIS_LORA Components Params
mecha
SD1-LDM Blocks
mecha
SD1-SUPERMERGER_BLOCKS Components Params
mecha
SD3-COMFYUI Components Params
mecha
SDXL-SGM Components Params
mecha
SDXL-DIFFUSERS_UNET_ONLY Components Params
mecha
SDXL-KOHYA_BUT_DIFFUSERS Components Params
mecha
SDXL-KOHYA_BUT_DIFFUSERS_KOHYA_LORA Components Params
mecha
SDXL-KOHYA_BUT_DIFFUSERS_LYCORIS_LORA Components Params
mecha
SDXL-KOHYA Components Params
mecha
SDXL-KOHYA_KOHYA_LORA Components Params
mecha
SDXL-KOHYA_LYCORIS_LORA Components Params
mecha
SDXL-SGM Blocks
mecha
SDXL-SUPERMERGER_BLOCKS Components Params
mecha
SINGLETON-MECHA Components Params
mecha
Slerp
mecha
Stack
mecha
String
mecha
Subtract
mecha
Tensor Sum
mecha
Ties Sum Extended
mecha
Ties Sum
mecha
Ties Sum With Dropout
mecha
Top K Tensor Sum
mecha
Train Difference Mask
mecha
Train Difference
mecha
Truncate Kronecker
mecha
Truncate Rank
mecha
Weighted Sum
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.