Skip to content

vllm.model_executor.layers.quantization.base_config

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.

QuantizeMethodBase

Bases: ABC

Base class for different quantized methods.

Methods:

Attributes:

requires_device_loading = True class-attribute instance-attribute

Whether post-load processing requires parameters on the target device.

supports_pre_processed_weights = False class-attribute instance-attribute

Whether process_weights_after_loading supports running under weights_already_processed. Methods must skip tensor transforms in that mode; the loader driver rejects methods that do not declare support.

uses_meta_device = False class-attribute instance-attribute

Whether this method creates weights on meta device for online quantization. When True, weights are created on meta device and quantized layer-wise in process_weights_after_loading, reducing peak memory during loading.

apply(layer, *args, **kwargs) abstractmethod

Apply the weights in layer to the input tensor.

Expects create_weights to have been called before on the layer.

create_weights(layer, *weight_args, **extra_weight_attrs) abstractmethod

Create weights for a layer.

The weights will be set as attributes of the layer.

dequantize_weight(layer)

Materialize a serialized quantized weight for requantization.

Parameters:

  • layer

    (Module) –

    Layer holding the serialized weights.

Returns:

embedding(layer, *args, **kwargs)

Gather embeddings in the layer based on indices in the input tensor.

Expects create_weights to have been called before on the layer.

process_weights_after_loading(layer)

Process the weight after loading.

This can be used for example, to transpose weights for computation.

tie_weights(layer, embed_tokens)

Tie layer's weight to embed_tokens' weight.

The default shares the weight tensor, which is the standard behavior for tied word embeddings and matches what ParallelLMHead.tie_weights did directly before quantization methods became responsible for it. Quantization methods that need special weight handling (e.g. repacked weights) override this.

Expects create_weights to have been called before on the layer.

method_has_implemented_embedding(method_class)

Not all quant methods have embedding implemented, so we need to check that it exists for our given method. We check this by making sure the function has been changed from the base implementation.

resolve_quant_method(quant_config, layer, prefix)

Return the checkpoint method with configured online quantization.