ComfyUI Node

Pto Adam

Pto Adam wraps Adam for the node graph

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pto Adam
  • model
  • PTOPTIMIZER
learning_rate0
beta11
beta21

PtoAdam is the pack's wrapper around PyTorch's Adam optimizer. If you're training any model in ComfyUI-Pt-Wrapper, this is the node you'll probably reach for first - it's the default optimizer for most of the pack's example workflows (the RNN text classifier uses it, the Transformer example uses its sibling AdamW). It takes a model and produces the PTOPTIMIZER that the training loop consumes. Zero surprises, which is exactly what you want from the piece that decides how your weights move.

Why it matters

Adam is the "it just works" optimizer of deep learning. Instead of a single learning rate pushing every weight, it keeps a running estimate of each gradient's mean and variance and adapts the step size per-parameter. That per-parameter adaptation is why you can often leave the learning rate near the default and still get a model that trains - it's enormously forgiving compared to plain SGD. If you're new to training in ComfyUI, this is the node to start on: build a model, feed it to Pto Adam, and you're 90% of the way to a working training loop.

How it works

The node calls torch.optim.Adam(model.parameters(), lr, betas=(beta1, beta2)) under the hood. Three inputs:

  • model (PTMODEL) - the model whose parameters get optimized. Wire any model node's output here. This is what makes the optimizer "know" what to update.
  • learning_rate - the base step size. The default 0.001 is Adam's classic sweet spot; you'll tune from there, usually down.
  • beta1 / beta2 - the exponential decay rates for the gradient mean (momentum-ish, default 0.9) and the squared-gradient mean (variance-ish, default 0.999). Leave them at defaults unless you have a specific reason to move them - the vast majority of training never touches these.

Output is a single PTOPTIMIZER, which feeds into a training node (Pt Train Classification Model, etc.) and optionally into one of the LR scheduler nodes to wrap it with a learning-rate schedule.

What actually trips people up

The learning rate is the knob you'll live and die by. If your loss is stuck or exploding, the first thing to check isn't the optimizer type - it's whether learning_rate is reasonable for your problem. And there's a subtle one: the optimizer is bound to the model's parameters at the time you run it. In this pack's graph that's handled for you by the training node, but it's worth knowing the optimizer isn't a free-floating object - it's locked to a specific model instance. If you swap the model after creating the optimizer, you're optimizing the old one. The pack's single-click training loop keeps you safe from this, but it explains a lot of weird behavior if you're hand-assembling graphs.

Installing it

Part of ComfyUI-Pt-Wrapper (HowToSD's no-code PyTorch pack, a spin-off of ComfyUI-Data-Analysis). ComfyUI Manager → search "ComfyUI-Pt-Wrapper", or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Restart after; the first boot is slow while pandas, scikit-learn, transformers, sentencepiece, peft and friends install. No model downloads needed for the node itself.

CategoryTraining

Inputs (4)

NameTypeDefaultDescription
modelPTMODEL
learning_rateFLOAT01e-10–1
beta1FLOAT11e-10–1
beta2FLOAT11e-10–1

Outputs (1)

NameTypeDescription
PTOPTIMIZERPTOPTIMIZER