Ptn LSTM
Drop a real LSTM layer into ComfyUI without writing a single tensor
- PTMODEL
You want a recurrent layer in your model graph - for sequence data like text, time series, or per-frame features - and this node is the cleanest way to get one. PtnLSTM is a thin wrapper around PyTorch's nn.LSTM, exposed as a ComfyUI node. You configure it, it hands you a PTMODEL, and the pack's training nodes take care of the messy part: an LSTM's forward() returns a tuple of output sequence and hidden states, which no one wants to unpack by hand in a node graph.
How it works
Every parameter maps 1:1 to the constructor of nn.LSTM - this node is genuinely just a config surface for it. The LSTM processes your sequence one step at a time, maintaining a cell state that lets information flow across many time steps, which is exactly why you'd pick it over a plain feedforward net for sequential data. The internal mechanics are PyTorch's, battle-tested and unchanged.
The one twist to watch: batch_first defaults to True here, which is the opposite of PyTorch's LSTM default. This node expects input shaped (batch, seq, features) out of the box, and it's the saner convention - just remember it if you're porting a workflow from raw PyTorch.
The inputs that matter
- input_size - feature count per time step. If you're feeding GloVe embeddings, this is the embedding dimension (100 in the pack's RNN example).
- hidden_size - the hidden state dimension; also the output feature count per token.
- num_layers (default
1) - stack that many LSTM layers. - batch_first (default
True) -(batch, seq, features)versus(seq, batch, features). Leave it unless you have a reason not to. - dropout (default
0) - only applies between stacked layers, so it's a no-op withnum_layers=1. That's not a bug. - bidirectional (default
False) - doubles the effective output features per token. - proj_size (default
0) - if > 0, projects each hidden state down to that size (top layer only).
Output is a single PTMODEL. From there you chain it into a classifier head - or just use the packaged PtnLSTMLinear, which does the LSTM-plus-head job for you.
How you'd use it
The pack's lstm_classification.json shows the pattern: Ptv Hf Glove Dataset feeds word embeddings into the LSTM via Pt Data Loader, and Pt Train RNN Model trains it for text classification. That workflow lands around 87% validation accuracy on IMDB, which is a solid result for a single recurrent layer.
Installing
Same as every node in this pack. ComfyUI Manager → search "Pt-Wrapper", or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI. The requirements.txt pulls in the usual heavy set - transformers, datasets, scikit-learn, pandas - so the first startup is slow.
Where people get burned
batch_first is the trap, both because the default differs from PyTorch and because flipping it after wiring up silently changes every tensor shape in the chain. If your loss flatlines, check that the input you're feeding actually matches the layout this node expects. And don't set dropout expecting it to do anything on a single-layer LSTM - it won't, by design.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| input_size | INT | 11–1000000 | — |
| hidden_size | INT | 11–1000000 | — |
| num_layers | INT | 11–1000 | — |
| bias | BOOLEAN | true | — |
| batch_first | BOOLEAN | true | — |
| dropout | FLOAT | 0.0000–1 | — |
| bidirectional | BOOLEAN | false | — |
| proj_size | INT | 00–1000000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTMODEL | PTMODEL | — |