ComfyUI Node

NNT Define RNN Layer

Sequence modeling without writing a loop

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Define RNN Layer
  • LAYER_STACK
  • LAYER_STACK
input_size10
hidden_size20
num_layers1
nonlinearitytanh
biasTrue
batch_firstTrue
dropout0.0
bidirectionalFalse

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 - tanh or relu for the hidden update; tanh is the classic stable default.
  • bidirectional - True makes 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.

CategoryNNT Neural Network Toolkit/Layers

Inputs (9)

NameTypeDefaultDescription
input_sizeINT101–2048
hidden_sizeINT201–2048
num_layersINT11–10
nonlinearityCOMBOtanh2 options: tanh, relu
biasCOMBOTrue2 options: True, False
batch_firstCOMBOTrue2 options: True, False
dropoutFLOAT0.00–1
bidirectionalCOMBOFalse2 options: True, False
LAYER_STACKoptLIST

Outputs (1)

NameTypeDescription
LAYER_STACKLIST