def validate_min_max_layers(min_layer, max_layer, num_layers):
    """Verify min_layer and max_layer are valid and return the valid range."""
    min_layer = min_layer or 0
    if min_layer < 0:
        # if user specified min_layer < 0, set min_layer to 0
        logger.warning("min_layer (%d) is less than 0. Setting to 0.", min_layer)
        min_layer = 0
    max_layer = max_layer or num_layers
    if max_layer > num_layers:
        # if user specified max_layer > number of layers, set max_layer to number of layers
        logger.warning(
            "max_layer (%d) is greater than number of layers (%(num_layers)d). Setting to %(num_layers)d.",
            max_layer,
            num_layers=num_layers,
        )
        max_layer = num_layers
        # don't need to worry about min_layer since if min_layer >= max_layer, the range will be empty
    return min_layer, max_layer
Verify min_layer and max_layer are valid and return the valid range.
olive/passes/pytorch/sparsegpt_utils.py