def count_trainable_parameters(model) -> str:
    """Count and return the number of trainable parameters in a model."""
    trainable_params = 0
    all_param = 0
    for param in model.parameters():
        all_param += param.numel()
        if param.requires_grad:
            trainable_params += param.numel()
    return (
        f"trainable params: {trainable_params} || all params: {all_param} "
        f"|| trainable%: {100 * trainable_params / all_param:.2f}"
    )
Count and return the number of trainable parameters in a model.
olive/passes/pytorch/train_utils.py