Skip to content

vllm.model_executor.layers.quantization

Modules:

Classes:

Functions:

QuantizationConfig

Bases: ABC

Base class for quantization configs.

Methods:

_ignore_unexpected_suffixes = ('.q_scale', '.k_scale', '.v_scale', '.q_zero_point', '.k_zero_point', '.v_zero_point') class-attribute instance-attribute

Suffixes of quantization parameters that may be present in the checkpoint but not in the model, and should be ignored if unexpected during loading. These are used after remapping, so should be in vLLM format (e.g. .q_scale, not .q.scale).

apply_vllm_mapper(hf_to_vllm_mapper)

Interface for models to update module names referenced in quantization configs in order to reflect the vllm model structure

Parameters:

  • hf_to_vllm_mapper

    (WeightsMapper) –

    maps from hf model structure (the assumed structure of the qconfig) to vllm model structure

from_config(config) abstractmethod classmethod

Create a config class from the model's quantization config.

get_cache_scale_mapper() staticmethod

Mapping from checkpoint KV-cache scale names to vLLM scale names.

Returning a mapper here causes AutoWeightsLoader to apply it to the weight stream automatically; individual model load_weights methods do not need to know about KV-cache scales.

get_checkpoint_weight_mapper() staticmethod

Discard activation-order metadata unused by supported kernels.

get_config_filenames() abstractmethod staticmethod

List of filenames to search for in the model directory.

get_from_keys(config, keys) staticmethod

Get a value from the model's quantization config.

get_from_keys_or(config, keys, default) staticmethod

Get an optional value from the model's quantization config.

get_kv_cache_dtype(prefix)

Return a checkpoint-selected KV-cache dtype for one layer.

get_min_capability() abstractmethod classmethod

Minimum GPU capability to support the quantization method.

E.g., 70 for Volta, 75 for Turing, 80 for Ampere. This requirement is due to the custom CUDA kernels used by the quantization method.

get_name() abstractmethod

Name of the quantization method.

get_quant_method(layer, prefix) abstractmethod

Get the quantize method to use for the quantized layer, from the pre-quantized checkpoint quant_method.

Parameters:

  • layer

    (Module) –

    The layer for the quant method.

  • prefix

    (str) –

    The full name of the layer in the state dict

Returns: The quantize method. None if the given layer doesn't support quant method.

get_supported_act_dtypes() abstractmethod

List of supported activation dtypes.

maybe_update_config(model_name, hf_config=None, revision=None)

Interface to update values after config initialization.

Parameters:

  • model_name

    (str) –

    The name of the model

  • hf_config

    (PreTrainedConfig | None, default: None ) –

    The Hugging Face config of the model

  • revision

    (str | None, default: None ) –

    The revision of the model

Returns:

override_quantization_method(hf_quant_cfg, user_quant, hf_config=None) classmethod

Detects if this quantization method can support a given checkpoint format by overriding the user specified quantization method -- this method should only be overwritten by subclasses in exceptional circumstances.

Parameters:

  • hf_quant_cfg

    (dict[str, Any]) –

    The checkpoint's quantization config dict.

  • user_quant

    (str | None) –

    The user-specified quantization method string.

  • hf_config

    (Any, default: None ) –

    The HuggingFace model config object (e.g. for model_type checks). May be None if not available.

register_quantization_config(quantization)

Register a customized vllm quantization config.

When a quantization method is not supported by vllm, you can register a customized quantization config to support it.

Parameters:

  • quantization

    (str) –

    The quantization method name.

Examples:

>>> from vllm.model_executor.layers.quantization import (
...     register_quantization_config,
... )
>>> from vllm.model_executor.layers.quantization import get_quantization_config
>>> from vllm.model_executor.layers.quantization.base_config import (
...     QuantizationConfig,
... )
>>>
>>> @register_quantization_config("my_quant")
... class MyQuantConfig(QuantizationConfig):
...     pass
>>>
>>> get_quantization_config("my_quant")
<class 'MyQuantConfig'>

resolve_quant_method(quant_config, layer, prefix)

Return the checkpoint method with configured online quantization.