Skip to content

llmcompressor.modifiers.smoothquant.utils

get_layer_mappings_from_architecture(architecture)

Parameters:

Name Type Description Default
architecture str

str: The architecture of the model

required

Returns:

Type Description
List[LayerMap]

list: The layer mappings for the given architecture

Source code in src/llmcompressor/modifiers/smoothquant/utils.py
def get_layer_mappings_from_architecture(architecture: str) -> List[LayerMap]:
    """
    :param architecture: str: The architecture of the model
    :return: list: The layer mappings for the given architecture
    """

    if architecture not in MAPPINGS_REGISTRY:
        logger.info(
            f"Architecture {architecture} not found in mappings. "
            f"Using default mappings: {DEFAULT_SMOOTHQUANT_MAPPINGS}"
        )

    return MAPPINGS_REGISTRY.get(architecture, DEFAULT_SMOOTHQUANT_MAPPINGS)

handle_mapping_resolution_errors(func)

Decorator to catch any errors that occur when resolving mappings and provide a helpful error message to the user pointing them to the README

Source code in src/llmcompressor/modifiers/smoothquant/utils.py
def handle_mapping_resolution_errors(func):
    """
    Decorator to catch any errors that occur when resolving mappings and provide a
    helpful error message to the user pointing them to the README
    """

    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as original_exception:
            readme_location = (
                "https://github.com/vllm-project/llm-compressor/tree/main/"
                "src/llmcompressor/modifiers/smoothquant"
            )
            raise RuntimeError(
                f"Error resolving mappings for given architecture."
                f"Please refer to the README at {readme_location} for more information."
            ) from original_exception

    return wrapper