NNT Define RNN Layer
Sequence modeling without writing a loop
- LAYER_STACK
- LAYER_STACK
Convolutional layers handle images; recurrent layers handle sequences - time series, audio, token streams. NNT Define RNN Layer drops a vanilla PyTorch RNN into your layer stack, which is the toolkit's door into sequence modeling. This is the node behind the pack's Fashion-MNIST RNN autoencoder example, where image rows are treated as a sequence and reconstructed one step at a time - a genuinely neat way to see recurrence in action.
What it actually does
Like every define node in the pack, it appends a layer description to the LAYER_STACK list that NntCompileModel turns into a compiled model. The layer carries the standard torch.nn.RNN parameters: an input_size, a hidden_size (the width of the recurrent state - this is your main "how much capacity does the memory have" knob), and num_layers to stack recurrent layers. Because it's a recurrent cell, the same weights are applied at every timestep; that's the whole trick, and it's why RNNs handle varying-length sequences.
Inputs that matter
input_size- the feature dimension per timestep. For the Fashion-MNIST example, each image row is a timestep with 28 pixel values, so input size is 28.hidden_size- the state dimension. Bigger = more memory capacity and more parameters; 20–128 is a sensible toy range.num_layers- stack several RNNs vertically. Each extra layer roughly multiplies the depth; 1–2 is plenty for learning purposes.nonlinearity-tanhorrelufor the hidden update;tanhis the classic stable default.bidirectional-Truemakes the layer read the sequence forward and backward and concatenate the states. Great for classification over a whole sequence, wrong for anything causal.
Then the quieter ones: bias (leave on), batch_first (keep True so your tensors are [batch, seq, features] rather than the awkward [seq, batch, features] PyTorch default), and dropout (applied between stacked layers, not on the last one - and ignored entirely when num_layers is 1).
The honest gotcha
Same caveat that runs through this whole pack: NNT is explicitly a work in progress, and the recurrent layers are where that bites. The RNN (and LSTM/GRU) nodes produce clean, inspectable layer-stack entries - great for teaching what recurrence is - but the current compile path in NntCompileModel builds the classic conv/dense/pool/norm blocks directly, and not every exotic layer type is guaranteed to materialize in the compiled Sequential yet. Before you commit to a big RNN architecture, run the compile node's "Only create script" mode and check what actually gets built. The Fashion-MNIST workflow in workflows/ is the best reference for what works today.
Installing NNT
Part of inventorado/ComfyUI_NNT. Easiest via ComfyUI Manager (search "ComfyUI Neural Network Toolkit"); manually:
cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt
Restart ComfyUI after. That requirements file is a heavy stack (torch, numpy, scikit-learn, pandas, transformers, shap…) so the first install is chunky. The example workflows also want ComfyUI-Jjk-Nodes for their text output - Manager's "Install Missing Custom Nodes" sorts it.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| input_size | INT | 101–2048 | — |
| hidden_size | INT | 201–2048 | — |
| num_layers | INT | 11–10 | — |
| nonlinearity | COMBO | tanh | 2 options: tanh, relu |
| bias | COMBO | True | 2 options: True, False |
| batch_first | COMBO | True | 2 options: True, False |
| dropout | FLOAT | 0.00–1 | — |
| bidirectional | COMBO | False | 2 options: True, False |
| LAYER_STACKopt | LIST | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LAYER_STACK | LIST | — |