AddDropoutLayer
The cheap regularizer your ComfyUI-built model is probably missing
- model
- TORCH_MODEL
Your ComfyUI-built model trains great on the training set and falls apart on anything new? Welcome to overfitting, and AddDropoutLayer is the two-minute fix. It appends torch.nn.Dropout to your nn.Sequential, and dropout is the cheapest regularization there is: during training, random neurons get zeroed out so the network can't rely on any single one; at inference, everything runs at full strength.
It's a small node with a tiny job - but it's the difference between a toy network that memorizes its 60,000 MNIST digits and one that generalizes. In the EternalKernel PyTorch Nodes pack, you typically drop this in after your linear layers, right before an activation, and let TrainModel do the rest.
How it works
The node wraps nn.Dropout(p=p, inplace=inplace) and inserts it at the end of your Sequential (mutating your model in place and returning it). One PyTorch detail worth internalizing: dropout only fires in training mode. nn.Dropout is a no-op when the model is in eval mode, and TrainModel in this pack puts models through a real training loop, so dropout behaves exactly as PyTorch intends. If you run inference on a model that was never trained (or you're not sure the training loop actually ran), dropout won't be the thing making your outputs look weird - that's normal.
Inputs
- model (
TORCH_MODEL) - your Sequential. Start fromSequentialModelProvider. - p - the dropout probability: the chance each neuron gets zeroed per training pass. Default
0.5, which is the classic value for hidden layers. For the input layer people often use a gentler0.2–0.3. Above ~0.5 you're usually just starving the network. - inplace -
Falseby default, and leave it there. In-place dropout is a micro-optimization that can cause subtle issues when you share tensors; the "default to False" advice from PyTorch applies.
Output: one TORCH_MODEL.
Install
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 is under ETK/pytorch. No model downloads. Most of the requirements (torch, numpy, torchvision) are already in your ComfyUI environment; the pack additionally wants scipy, scikit-learn, transformers, and einops.
Common issues
- "Not an nn.Sequential model." Same rule as every layer node here: it only extends a Sequential.
- "I added dropout and nothing changed." Check whether your model is actually being trained. If you wired your data wrong and
TrainModelnever really ran, dropout's in-training behavior never kicked in. Also remember dropout is inactive at inference by design - that's not a bug. - Over-regularizing.
p=0.5stacked in every layer of a small network can make training painfully slow to converge. If your loss crawls, lowerp, don't remove the node.
This is a quiet little pack - no tutorials, no community threads to lean on. The source is one readable file though, and the nodes are thin wrappers around stock torch, so anything confusing here is really a PyTorch question and answers are everywhere. And one pack-wide quirk to remember: it patches ComfyUI's input validator to ignore return_type_mismatch, so a wrong wire may not produce the error you're hunting for.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| model | TORCH_MODEL | — | |
| p | FLOAT | 0.500–1 | — |
| inplaceopt | COMBO | False | 2 options: True, False |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TORCH_MODEL | TORCH_MODEL | — |