def _set_optimizer_param(optimizer, param_group, param_name, value):
    """Set a parameter on an all or a specific parameter group of an
    optimizer instance. To select all param groups, use ``param_group='all'``.
    """
    if param_group == 'all':
        groups = optimizer.param_groups
    else:
        groups = [optimizer.param_groups[int(param_group)]]
    for group in groups:
        group[param_name] = value
