import torch


def count_parameters(model: torch.nn.Module) -> int:
    """Return the number of trainable parameters of a model.

    Taken from: https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325/7.

    Parameters
    ----------
    model : torch.nn.Module
        The model to count the parameters from.

    Returns
    -------
    int
        The number of trainable parameters of the given model.
    """
    return sum(p.numel() for p in model.parameters() if p.requires_grad)