跳到内容

llmcompressor.transformers.utils

用于将稀疏化算法应用于 Hugging Face transformers 流的实用工具

模块

  • helpers

    用于将 LLM Compressor 与之集成的辅助变量和函数

  • preprocessing_functions

    文本生成任务的数据集预处理函数。

函数

is_model_ct_quantized_from_path

is_model_ct_quantized_from_path(path: str) -> bool

根据配置确定模型是否已量化

参数

  • 路径

    (str) –

    模型或 HF 存根的路径

返回

  • bool

    如果配置包含来自给定路径的 quantization_config,则为 True

源代码位于 llmcompressor/transformers/utils/helpers.py
def is_model_ct_quantized_from_path(path: str) -> bool:
    """
    Determine if model from path is quantized based
    on the config

    :param path: path to the model or HF stub
    :return: True if config contains quantization_config from the given path

    """
    config = AutoConfig.from_pretrained(path)
    if config is not None:
        if (
            hasattr(config, "quantization_config")
            and config.quantization_config["quant_method"] == "compressed-tensors"
        ):
            return True
    return False