vllm.model_executor.layers.quantization.base_config
¶
Classes:
-
QuantizationConfig–Base class for quantization configs.
-
QuantizeMethodBase–Base class for different quantized methods.
Functions:
-
method_has_implemented_embedding–Not all quant methods have embedding implemented, so we need to check that
-
resolve_quant_method–Return the checkpoint method with configured online quantization.
QuantizationConfig
¶
Bases: ABC
Base class for quantization configs.
Methods:
-
apply_vllm_mapper–Interface for models to update module names referenced in
-
from_config–Create a config class from the model's quantization config.
-
get_cache_scale_mapper–Mapping from checkpoint KV-cache scale names to vLLM scale names.
-
get_checkpoint_weight_mapper–Discard activation-order metadata unused by supported kernels.
-
get_config_filenames–List of filenames to search for in the model directory.
-
get_from_keys–Get a value from the model's quantization config.
-
get_from_keys_or–Get an optional value from the model's quantization config.
-
get_kv_cache_dtype–Return a checkpoint-selected KV-cache dtype for one layer.
-
get_min_capability–Minimum GPU capability to support the quantization method.
-
get_name–Name of the quantization method.
-
get_quant_method–Get the quantize method to use for the quantized layer, from the
-
get_supported_act_dtypes–List of supported activation dtypes.
-
maybe_update_config–Interface to update values after config initialization.
-
override_quantization_method–Detects if this quantization method can support a given checkpoint
_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)
¶
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:
QuantizeMethodBase
¶
Bases: ABC
Base class for different quantized methods.
Methods:
-
apply–Apply the weights in layer to the input tensor.
-
create_weights–Create weights for a layer.
-
dequantize_weight–Materialize a serialized quantized weight for requantization.
-
embedding–Gather embeddings in the layer based on indices in the input tensor.
-
process_weights_after_loading–Process the weight after loading.
-
tie_weights–Tie
layer's weight toembed_tokens' weight.
Attributes:
-
requires_device_loading(bool) –Whether post-load processing requires parameters on the target device.
-
supports_pre_processed_weights(bool) –Whether
process_weights_after_loadingsupports running under -
uses_meta_device(bool) –Whether this method creates weights on meta device for online quantization.
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:
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.