Ptn Batch Norm 2d
The layer that keeps your conv net training sane
- PTMODEL
Ptn Batch Norm 2d is a batch-normalization layer for convolutional networks, wrapped as a node in the HowToSD/ComfyUI-Pt-Wrapper pack. It re-centers and re-scales each channel of a (batch, channels, height, width) tensor so that activations don't drift to crazy magnitudes as training progresses. If you've ever had a conv net refuse to converge, batch norm is often the difference between "loss stuck at a plateau" and "loss actually going down." It's one of those layers that quietly makes everything else work.
Why you'd reach for it
Training stability is the whole pitch. Deep conv stacks (like the Ptn Conv Model) have a tendency to blow up or die out: earlier layers shift the distribution of activations, and every layer downstream has to chase it. Batch norm normalizes each channel over the current batch, which lets you use higher learning rates and get away with worse weight initialization. In this pack's image-classification workflows you'll typically slip one in after a convolution - chain Conv2d → BatchNorm2d → activation inside a Ptn Chained Model, or let it ride inside the conv model's per-layer structure.
How it works
It's nn.BatchNorm2d. During training it normalizes using the current batch's mean and variance per channel, then applies a learnable scale and shift (the affine parameters). If track_running_stats is on (default), it also keeps an exponential moving average of batch statistics; at evaluation time those running stats are what get used, so a model that trains fine but predicts garbage in eval mode is often a running-stats problem. The node outputs a PTMODEL - a layer to assemble, not a result - and rebuilds on every run like the rest of the model nodes.
The inputs that matter
- num_features - the channel count. For a tensor of shape
[8, 4, 256, 256], that's 4. Get this wrong (mismatch with the previous layer's output channels) and the graph errors immediately. - affine (default on) - whether to learn the scale/bias. Leave it on unless you know why you'd turn it off.
- track_running_stats (default on) - keep the EMA for eval-time normalization. Off means eval uses batch stats too, which is rarely what you want.
- momentum (default 0.1) - how much weight the running average gives to the current batch. Higher = more responsive to recent batches.
Output: PTMODEL.
Installing the pack
Part of 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. The pack drags in transformers, datasets, peft, scikit-learn, gensim and more on install; no model downloads are needed for the model-building nodes.
Common issues
- num_features mismatch - the #1 failure. Must equal the channel count coming in from the previous layer.
- Small batches wobble - batch norm on a batch of 1 or 2 is noisy and can hurt training. Use a reasonable batch size, or skip norm on tiny batches.
- Train vs eval confusion - if your trained model's validation score tanks, check that
track_running_statsstayed on and that the eval path actually switches the model to eval mode. - Community support is thin - Pt-Wrapper is a single-author educational pack, essentially absent from r/comfyui and r/StableDiffusion discussions. The repo's training guides and node reference are your documentation; there's no crowd to ask.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| num_features | INT | 11–1000000 | — |
| affine | BOOLEAN | true | — |
| track_running_stats | BOOLEAN | true | — |
| momentum | FLOAT | 0.10000–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTMODEL | PTMODEL | — |