NNT Merge and Extend Model
Combine two models, or grow a new tail
- MODEL_A
- MODEL_B
- LAYER_STACK
- MODEL
- STRING
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_Aand optionalMODEL_Band blends them with one of three strategies.weighted_average(default) interpolates every parameter asweight_a * A + (1 - weight_a) * B;layer_fusiontakes the element-wise max of each parameter;alternatingtakes 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_Aand aLAYER_STACKand 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 supplyMODEL_BorLAYER_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.5is 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.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| operation | COMBO | Merge models | 2 options: Merge models, Add layers |
| MODEL_A | MODEL | — | |
| merge_method | COMBO | weighted_average | 3 options: weighted_average, layer_fusion, alternating |
| weight_a | FLOAT | 0.50–1 | — |
| MODEL_Bopt | MODEL | — | |
| LAYER_STACKopt | LIST | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |
| STRING | STRING | — |