import torch


def num_parameters(model: torch.nn.Module, count_all: bool = True) -> int:
    """Count parameters in a model.

    Args:
        model: We iterate over model.parameters() and count .numel()
        count_all: Also count parameters with p.requires_grad False

    Returns:
        The number of parameters.

    """

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