AddModelAsLayer
Glue two Sequential models together end-to-end in ComfyUI
- model_main
- model_addition
- TORCH_MODEL
Building a network piece by piece in ComfyUI is nice, but sometimes you want to build two halves separately - a feature extractor here, a classifier head there - and snap them together. AddModelAsLayer is the node for that: it takes one model (model_main) and appends every layer of a second model (model_addition) onto the end of it, returning the merged nn.Sequential. Think of it as nn.Sequential(model_main, model_addition) expressed in the graph, except it mutates model_main in place rather than building a fresh container.
You'll reach for it when a workflow benefits from two independently-constructed sub-networks. The classic pattern: build and even freeze-train a feature extractor, then attach a fresh classifier head via this node, and train the whole thing. The pack's ExtractLayersAsModel produces exactly the kind of sub-model you'd want to graft back on this way.
How it works
Both inputs must be nn.Sequential models - it raises a TypeError otherwise. It then iterates model_addition.children() and adds each one to model_main via add_module, naming them added_layer_0, added_layer_1, and so on. Your original model_main object is returned, now longer. The layers themselves are shared references, not copies - that's usually what you want when you're composing, but know that training one model trains the same parameter objects.
Inputs and output
- model_main (
TORCH_MODEL) - the model being extended. The output ofSequentialModelProvideror anything this pack builds. - model_addition (
TORCH_MODEL) - the sub-model whose layers get appended.
Output: one TORCH_MODEL - your model_main, extended.
Install
ComfyUI Manager, search "EternalKernel PyTorch Nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI; node under ETK/pytorch. No model downloads - both inputs are built in-graph. Requirements are the standard stack plus scipy, scikit-learn, transformers, einops.
Common issues
- Both sides must be
nn.Sequential. A barenn.Module(say, a single layer someone passed through) raises immediately. Keep both inputs produced bySequentialModelProvideror pack builder nodes. - Shape continuity is on you. The node glues layers end-to-end and never checks that
model_main's last output dimension matchesmodel_addition's first input dimension. A mismatch fails later at inference/training with a shape error - count your features. - It mutates
model_mainin place. If you wiredmodel_mainelsewhere in the graph expecting the pre-merge version, it's now longer. Duplicate before merging if you need both. - Shared parameters. Because layers are shared references, training after a merge trains the originals too. For a "freeze the backbone" workflow you'd still want
freeze=Trueon the extractor side orSetModelTrainableafterward.
No community tutorials, no threads - this pack is a quiet corner. The upside: it's two torch primitives, so behavior is predictable from PyTorch docs. Pack-wide quirk to remember: it patches ComfyUI's validator to ignore return_type_mismatch, so a wrong wire might not produce the error you're hunting.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| model_main | TORCH_MODEL | — | |
| model_addition | TORCH_MODEL | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_MODEL | TORCH_MODEL | — |