Nodes/ComfyUI Neural Network Toolkit NNT /NNT Merge and Extend Model
ComfyUI Node

NNT Merge and Extend Model

Combine two models, or grow a new tail

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Merge and Extend Model
  • MODEL_A
  • MODEL_B
  • LAYER_STACK
  • MODEL
  • STRING
operationMerge models
merge_methodweighted_average
weight_a0.5

Merging weights is one of those ML operations that sounds exotic until you realize it's just arithmetic - a weighted average of two models' parameters, or a layer-by-layer pick. NNT Merge and Extend Model brings that to the NNT graph in two flavors: blend two trained models into one, or bolt extra layers onto an existing model as a new tail. If you've ever merged checkpoints in the image-model world, this is the same family of trick, applied to the small models you train here.

What it actually does

Pick operation:

  • Merge models - takes MODEL_A and optional MODEL_B and blends them with one of three strategies. weighted_average (default) interpolates every parameter as weight_a * A + (1 - weight_a) * B; layer_fusion takes the element-wise max of each parameter; alternating takes whole parameters from A, then B, then A... walking through the model. Before merging, the node checks the two models are architecturally identical - same module structure and parameter keys - and returns an error if they're not.
  • Add layers - takes MODEL_A and a LAYER_STACK and appends the new layers to the end, figuring out the input feature size from the last layer of the existing model. This is how you take a trained feature extractor and grow a new classifier head on top.

Outputs are the resulting MODEL and a STRING status message.

Inputs that matter

  • operation - Merge models or Add layers. Decides whether you supply MODEL_B or LAYER_STACK.
  • MODEL_A - always required; the base model.
  • merge_method - weighted_average, layer_fusion, or alternating.
  • weight_a - how much weight A gets in the average (0–1). 0.5 is a 50/50 blend.
  • MODEL_B (optional) - the second model for merging; required if you pick Merge models.
  • LAYER_STACK (optional) - needed for Add layers; build it with the define nodes as usual.

The honest gotchas

Three things to know. First, merging requires identical architectures - same layer count, same parameter keys. Merge two models trained with different layer counts and you'll get a clean "incompatible architectures" error, not a weird silent result. Second, the merge is done without gradient tracking, so it's fast, but the blended model is generally not a trained model anymore - it's a starting point that usually needs fine-tuning. That's true of model merging in general, not a bug here. Third, the whole pack is a self-described work in progress; Add layers supports the classic Linear/Conv2d block types, so don't expect the transformer layer stack to bolt on smoothly yet. Use the status STRING output to confirm what happened - it's the node's own report card.

Installing NNT

Part of inventorado/ComfyUI_NNT. ComfyUI Manager (search "ComfyUI Neural Network Toolkit") or:

cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt

Restart ComfyUI after. The requirements are a heavy scientific stack - torch, scikit-learn, pandas, transformers, shap - so expect a chunky first install. The pack's example workflows also want ComfyUI-Jjk-Nodes for text output; Manager's "Install Missing Custom Nodes" covers it.

CategoryNNT Neural Network Toolkit/Models

Inputs (6)

NameTypeDefaultDescription
operationCOMBOMerge models2 options: Merge models, Add layers
MODEL_AMODEL
merge_methodCOMBOweighted_average3 options: weighted_average, layer_fusion, alternating
weight_aFLOAT0.50–1
MODEL_BoptMODEL
LAYER_STACKoptLIST

Outputs (2)

NameTypeDescription
MODELMODEL
STRINGSTRING