AddLinearLayerNode
The workhorse that stacks fully-connected layers in your ComfyUI model
- model
- TORCH_MODEL
If you're building a neural network in ComfyUI with the EternalKernel PyTorch Nodes pack, AddLinearLayerNode is the node you'll use more than any other. It's a thin wrapper around torch.nn.Linear - the classic fully-connected layer - and it appends one to the end of the nn.Sequential model you're assembling. Every tutorial-grade network (the kind that learns XOR, classifies MNIST, or fits some toy regression) is mostly these stacked in a row with activations between them.
Think of it as the "add a layer" button. You start from SequentialModelProvider (which gives you an empty nn.Sequential()), chain a few of these with Activation nodes between, end with a Softmax or leave the last layer raw for a loss like cross-entropy, and hand the result to TrainModel.
How it works
The node constructs nn.Linear(in_features, out_features, bias=...) with the dtype you pick, marks it trainable, and calls model.insert(len(model), layer) to push it onto the end of your Sequential. Your input model is mutated in place and returned. Nothing exotic - which is the whole point of this pack. It's stock PyTorch wearing a ComfyUI costume.
Inputs that matter
- model (
TORCH_MODEL) - the Sequential being extended. Output ofSequentialModelProvideror another ETK layer node. - in_features / out_features - the input and output dimensions. The
in_featuresof each layer must match theout_featuresof the one before it (or the flattened size of the tensor feeding it). This is where 90% of beginner breakage happens - count your dimensions. - bias - leave
Trueunless you know why you're dropping it. - initialization -
default(PyTorch's built-in init) is right for 95% of cases.xavier_uniformandxavier_normalare there if you're replicating a paper; they only initialize this one layer, and only its weight. - dtype - stick with
float32. The dropdown also offers int types, but aLinearbuilt with an integer dtype will blow up the moment you try to train it or run float input through it. That's a trap, not a feature.
Output is a single TORCH_MODEL - chain it onward or into TrainModel.
Install
Via ComfyUI Manager, search "EternalKernel PyTorch Nodes". Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/TashaSkyUp/EternalKernelPytorchNodes
cd EternalKernelPytorchNodes
pip install -r requirements.txt
Restart ComfyUI; the node lives under ETK/pytorch. Everything this pack needs (torch, torchvision, numpy) ships with ComfyUI; requirements.txt additionally pulls scipy, scikit-learn, transformers, and einops.
Common issues
- Shape mismatches are on you.
nn.Linearonly cares that the last dimension matchesin_features; a batch of(64, 784)images feeding a 784-input layer is fine, but feeding it(1, 28, 28)is not. Flatten first (there's aFlattenTensorand anAddReshapeLayerin the pack). - "not an nn.Sequential model" error. This node - like every layer builder in the pack - only appends to a Sequential. Start from
SequentialModelProvider. - It mutates the model in place. Since the output model is the same object, don't reuse the pre-wire version expecting a copy.
Pack-wide heads-up: this pack patches ComfyUI's execution.validate_inputs at load to ignore return_type_mismatch errors, so a mismatched wire might not raise the error you expect. It's a small pack with no community tutorials - when something's weird, the source is a single readable pytorch_nodes.py, and the fix usually is too.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| model | TORCH_MODEL | — | |
| in_features | INT | 1–16777216 | — |
| out_features | INT | 1–1000000000 | — |
| bias | COMBO | 2 options: true, false | |
| initialization | COMBO | 3 options: default, xavier_uniform, xavier_normal | |
| dtype | COMBO | 8 options: float32, float64, float16, int32, int64, int16, +2 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_MODEL | TORCH_MODEL | — |