跳到内容

llmcompressor.transformers

用于将 LLM Compressor 与 transformers 训练流程集成的工具。

模块

函数

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