Skip to content

Instantly share code, notes, and snippets.

@SebastianBitsch
Last active March 20, 2025 11:45
Show Gist options
  • Save SebastianBitsch/7ee22162dc8b1c0460aaca5caeaebaf2 to your computer and use it in GitHub Desktop.
Save SebastianBitsch/7ee22162dc8b1c0460aaca5caeaebaf2 to your computer and use it in GitHub Desktop.
Count pytorch model parameter
import torch
def count_parameters(model):
"""
Nice to have helper function stolen from:
https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325/9
"""
return sum(p.numel() for p in model.parameters() if p.requires_grad)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment