Nodes/ComfyUI-Pt-Wrapper/Ptn GRU Linear
ComfyUI Node

Ptn GRU Linear

The ready-made GRU text classifier

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptn GRU Linear
    • PTMODEL
    input_size1
    hidden_size1
    num_layers1
    biastrue
    batch_firsttrue
    dropout0.000
    bidirectionalfalse
    linear_output_size1
    linear_biastrue

    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_first defaults to True, 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, its embedding_dim should equal input_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_classification doc is the authoritative guide.
    CategoryTraining

    Inputs (9)

    NameTypeDefaultDescription
    input_sizeINT11–1000000
    hidden_sizeINT11–1000000
    num_layersINT11–1000
    biasBOOLEANtrue
    batch_firstBOOLEANtrue
    dropoutFLOAT0.0000–1
    bidirectionalBOOLEANfalse
    linear_output_sizeINT11–1000000
    linear_biasBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    PTMODELPTMODEL