Pto SGD
Pto SGD does the classic update, momentum and all
- model
- PTOPTIMIZER
PtoSGD is the pack's wrapper around PyTorch's stochastic gradient descent - the optimizer with zero adaptive magic. Where Adam and AdamW adjust each parameter's step size based on gradient history, SGD takes one plain step in the downhill direction per batch, optionally smoothed by momentum. It's the node to reach for when you want to understand what your training is actually doing, or when a well-tuned SGD genuinely beats Adam (which happens more than the Adam-default crowd admits, especially on small clean datasets).
Why you'd reach for it
Three reasons. First, teaching: with SGD you can actually see what an optimizer does - Pto Simple is even more stripped down, but SGD is the realistic baseline. Second, generalization: SGD with momentum and a good learning-rate schedule often lands in flatter, more general minima than Adam. Third, control: every knob maps directly to the classic torch.optim.SGD signature, so anything you've read about SGD tuning applies verbatim.
How it works
Under the hood it's torch.optim.SGD(model.parameters(), lr, momentum, dampening, weight_decay, nesterov). Inputs:
- model (PTMODEL) - the parameters to optimize.
- learning_rate - the step size. SGD has no per-parameter adaptation, so this matters far more than with Adam; you'll be tuning it constantly.
- momentum - carries a fraction of the previous update forward, smoothing zig-zags. Default
0. A common starting point is0.9. - dampening - reduces the momentum contribution of the current gradient (it's subtracted before momentum kicks in). Leave
0unless you know why you're changing it. - weight_decay - classic L2 regularization on the weights. Default
0. - nesterov - the Nesterov accelerated variant, which "looks ahead" before stepping. Only meaningful when
momentum > 0; PyTorch ignores it otherwise. It's the speed upgrade for momentum training.
Output is a single PTOPTIMIZER, wired into a training node and optionally an LR scheduler.
Where people get burned
With Adam you can be sloppy about learning_rate; with SGD you can't. A rate that works on day one of training is often wrong by day five - that's why you pair SGD with a scheduler (the pack's Pto Lr Scheduler Step or Reduce On Plateau) almost by default. Also: nesterov does nothing unless momentum is set, which is easy to forget mid-experiment. And remember that SGD optimizes whatever model you connected when the node runs - swap the model later and the optimizer is still bound to the old parameters. The pack's training nodes handle this, but it explains weirdness in hand-built 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; first boot is slow while pandas, scikit-learn, transformers, sentencepiece, peft and friends install. No model files to download for this node.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| model | PTMODEL | — | |
| learning_rate | FLOAT | 01e-10–1 | — |
| momentum | FLOAT | 00–1 | — |
| dampening | FLOAT | 00–1 | — |
| weight_decay | FLOAT | 00–1 | — |
| nesterov | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTOPTIMIZER | PTOPTIMIZER | — |