# How do I check the number of parameters of a model?

**URL:** <https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325>\
**Category:** Uncategorized\
**Created:** [June 26, 2017, 2:31pm UTC](https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325 "2017-06-26T14:31:33Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![baldassarre.fe](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/baldassarre.fe/32/1331_2.png) [@baldassarre.fe](https://discuss.pytorch.org/u/baldassarre.fe)\
**Post date:** [February 20, 2018, 12:57pm UTC](https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325/9 "2018-02-20T12:57:53Z")

</div>

I like this solution!

To add my 50 cents, I would use `numel()` instad of `np.prod()` and compress the expression in one line:

```auto
def count_parameters(model):
    return sum(p.numel() for p in model.parameters() if p.requires_grad)

```

---

_[View the full topic](https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325)._
