Ptn GRU Linear
The ready-made GRU text classifier
- PTMODEL
Ptn GRU Linear is the pack's pre-wired sequence classifier: a GRU followed by mean-pooling over the valid tokens and a linear classification head, all in one node. You set the GRU's shape (input size, hidden size, layers) plus the classifier's output size, and you get a PTMODEL that takes token-embedded sequences and returns one score per class. Compared to the bare Ptn GRU, this one saves you the assembly - it already knows how to turn a sequence of outputs into a single classification vector.
Why you'd reach for it
Recurrent layers output one vector per time step, but classification needs one answer per sequence. The fiddly part is deciding how to compress the sequence - take the last hidden state? average everything? - and doing it without messing up padded tokens. This node handles that decision for you: it mean-pools over the valid (non-padded) tokens only, so padding doesn't drag the average down, then pushes the pooled vector through a linear head. If your job is "classify a sequence and I don't want to build the pooling by hand," this is the node. It's the slightly higher-level sibling of Ptn GRU, and the natural pick over Ptn Embedding RNN Linear if you're embedding the tokens upstream yourself.
How it works
The GRU runs over your (batch, seq, features) input (batch-first, as with all pack RNN nodes). Its full output sequence gets passed through a helper that finds the valid, unpadded tokens and averages them, then an nn.Linear (with xavier-initialized weights) maps that mean vector to linear_output_size class scores. With bidirectional on, the GRU reads the sequence both ways, the hidden state doubles, and the linear layer is sized accordingly - the node wires that up for you. Output is a PTMODEL ready for a training node.
The inputs
- input_size / hidden_size / num_layers - GRU geometry; the capacity dials.
- bias, batch_first (on), dropout, bidirectional - GRU settings.
batch_firstdefaults toTrue, matching the pack's convention. - linear_output_size / linear_bias - the classifier head: number of classes, and whether the head has a bias.
Output: PTMODEL.
Installing the pack
In the "Training" category. Install via ComfyUI Manager (search "ComfyUI-Pt-Wrapper") or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI. Install pulls in transformers, datasets, peft, scikit-learn, gensim and more; example datasets download on demand.
Common issues
- Embedding upstream mismatch - whatever feeds this node must produce
(batch, seq, input_size)tensors. If you're embedding with a Ptn Embedding node, itsembedding_dimshould equalinput_size. - Padding correctness - the pooling skips padded tokens, but only if your upstream actually marks them; if your sequences are padded inconsistently, results get muddy. Pad to a consistent length.
- batch_first - input is
(batch, seq, features)here, not PyTorch's(seq, batch, features)default. Feed the right layout. - Dropout no-op - with
num_layers = 1, dropout between layers does nothing; that's by design. - Thin community - single-author educational pack, essentially absent from r/comfyui. The repo's
training_rnn_for_classificationdoc is the authoritative guide.
Inputs (9)
| 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 | — |
| linear_output_size | INT | 11–1000000 | — |
| linear_bias | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTMODEL | PTMODEL | — |