PyTorch 2 · Autograd and models

Count a model's parameters

Count trainable parameters.

sum(p.numel() for p in model.parameters() if p.requires_grad)

Official PyTorch 2 documentation

More autograd and models commands

All autograd and models commands · PyTorch 2 cheatsheet

Was this page helpful?