Ptn RNN
Ptn RNN is the old-school sequence workhorse
- PTMODEL
PtnRNN drops a PyTorch nn.RNN - the classic recurrent layer - into the graph as a model node. It's the "vanilla" RNN: the one with the tanh/relu activation, no gates, no fancy machinery. In a world where everyone reaches for LSTM or GRU, this is the node you pick when you want the simplest possible sequence model that still has a tunable hidden state.
Why you'd reach for it
This pack is about training real models in ComfyUI, and its example workflows cover the whole recurrence family: RNN, GRU, LSTM, and a Transformer path. PtnRNN is the baseline member. The rnn_classification.json example runs text classification with it - GloVe-embedded sequences in, class scores out. Start here when you want to feel how a sequence model fits into the training pipeline before you graduate to the gated architectures, or when your data genuinely doesn't need the extra capacity. RNNs train fast and are brutally honest about whether a sequence-based approach is even worth it for your problem.
How it works
The node constructs an nn.RNN with the settings you give it and wraps it as a PTMODEL. Two details in the source are worth knowing. First, batch_first defaults to True - the input is assumed to be [Batch, Seq, Token] - which is the opposite of PyTorch's default. The author deliberately flipped it, so this pack's convention is consistent across the data loaders. Keep it True unless you have a specific reason not to. Second, weights get initialized properly: Xavier for tanh, Kaiming for relu, which beats PyTorch's default initialization and is a quiet reason models built here train cleanly. The RNN's forward returns the full output sequence plus the final hidden state; that raw form is what you'd hand to a head node.
The inputs that matter
- input_size - features per timestep. For text with GloVe embeddings that's the embedding dimension; for time series, the number of series you're feeding.
- hidden_size - width of the hidden state. This is your capacity knob.
- num_layers - stack depth. More layers = more capacity, slower training.
- nonlinearity -
tanh(default flavor, smoother gradients) orrelu. - dropout - applied between layers only; never on the final layer's output. If
num_layersis 1, dropout does nothing. That's PyTorch behavior, not a bug. - bidirectional - runs the sequence backwards too and concatenates; effectively doubles the hidden size.
The single PTMODEL output wires into a Pt Chained Model, a trainer like Pt Train Classification Model, or - most commonly - into Ptn RNN Linear, which slaps a classification head on top.
Where people get burned
The classic RNN complaint is the vanishing gradient, and this node won't rescue you from it - that's why the pack also ships LSTM and GRU nodes. If you push num_layers to 3–4 with tanh and training goes nowhere, that's the gradient dying, not a setup error. Drop batch_first to False without also flipping your data's layout and you'll get a silent shape disaster - tensors are [Batch, Seq, Token] everywhere in this pack's loaders, so leave it on. And keep dropout at 0 for a single-layer RNN; it's dead weight there.
Installing it
Ships in ComfyUI-Pt-Wrapper (HowToSD's no-code PyTorch pack, a spin-off of ComfyUI-Data-Analysis). Install via ComfyUI Manager (search "ComfyUI-Pt-Wrapper") or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI; the first start is slow while requirements.txt installs pandas, scikit-learn, transformers, sentencepiece, peft and friends. No model files needed - the RNN example workflow downloads its own dataset.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| input_size | INT | 11–1000000 | — |
| hidden_size | INT | 11–1000000 | — |
| num_layers | INT | 11–1000 | — |
| nonlinearity | COMBO | 2 options: tanh, relu | |
| bias | BOOLEAN | true | — |
| batch_first | BOOLEAN | true | — |
| dropout | FLOAT | 0.0000–1 | — |
| bidirectional | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTMODEL | PTMODEL | — |