Nodes/ComfyUI-Pt-Wrapper/Ptn Chained Model
ComfyUI Node

Ptn Chained Model

The glue node that lets you build your own network

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptn Chained Model
  • model_a
  • model_b
  • closure
  • PTMODEL

Ptn Chained Model is the node that makes the whole HowToSD/ComfyUI-Pt-Wrapper pack work. It takes two PTMODEL layers - a Ptn Linear, Ptn Conv2d, Ptn GRU, whatever - and runs them in sequence: input goes through model_a, then model_b, and optionally through a closure function. That's it. But that small trick is how you go from "pre-built models only" to "I built my own network" without writing a line of Python.

Why you'd reach for it

The pack's pre-built models (Ptn Conv Model, Ptn ResNet Model, Ptn EmbeddingTransformerLinear) are convenient, but they're someone else's architecture. The moment you want a conv layer followed by a linear head, or a GRU feeding a classifier, or just to experiment with what layer order does, you're assembling it from parts - and Ptn Chained Model is the assembly line. The author's "build a model from scratch" guide walks you through exactly this: chain Conv2d → BatchNorm2d → ReLU → ... → Linear and suddenly you've got a custom CNN. Chain enough pieces and you can build a Transformer encoder from primitives, which is one of the pack's headline examples. It's the node that turns this from a "use preset models" toy into an actual no-code model designer.

How it works

Under the hood it's a tiny nn.Module whose forward pass is literally x = model_a(x); x = model_b(x); x = closure(x). The shapes have to line up - model_a's output must be exactly what model_b expects as input, so keep channel/feature dims consistent between the two. The optional closure accepts a PTCALLABLE - an activation like Ptf ReLU or Ptf Sigmoid - applied to the chain's output. The result is a PTMODEL you can chain again (chains of chains are fine and encouraged) or hand straight to a training node.

The inputs

  • model_a - first model in the chain.
  • model_b - second model in the chain.
  • closure (optional) - a PTCALLABLE applied after model_b.

Output: PTMODEL.

Installing the pack

Ptn Chained Model is in the pack's "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; no model downloads at install.

Common issues

  • Shape mismatch between the two models - the #1 failure. If model_a outputs 64 features and model_b expects 128, the forward pass errors on the first training step. Check the layer definitions before chaining.
  • Forgetting the closure - if you chain Linear → Linear with no activation between them, you've built a linear function wearing a trench coat; the network gains nothing. Activations between layers are what make stacking meaningful.
  • Memory - long chains of big layers add up. If VRAM or RAM balloons, simplify the chain; model nodes also rebuild every run, which costs a bit of time on each graph execution.
  • Solo-project caveat - this pack is a single-author educational tool with almost no presence on r/comfyui or r/StableDiffusion. The "Building a Model from Scratch" docs on the repo are genuinely good - use them.
CategoryTraining

Inputs (3)

NameTypeDefaultDescription
model_aPTMODEL
model_bPTMODEL
closureoptPTCALLABLE

Outputs (1)

NameTypeDescription
PTMODELPTMODEL