vllm.model_executor.layers.quantization.torchao
TorchAOConfig
¶
Bases: QuantizationConfig
Config class for torchao.
Source code in vllm/model_executor/layers/quantization/torchao.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
__init__
¶
TorchAO quantization relies on tensor subclasses. In order,¶
to enable proper caching this needs standalone compile¶
if is_torch_equal_or_newer("2.8.0.dev"): os.environ["VLLM_TEST_STANDALONE_COMPILE"] = "1" logger.info( "Using TorchAO: Setting VLLM_TEST_STANDALONE_COMPILE=1")
TODO: remove after the torch dependency is updated to 2.8¶
if is_torch_equal_or_newer( "2.7.0") and not is_torch_equal_or_newer("2.8.0.dev"): os.environ["VLLM_DISABLE_COMPILE_CACHE"] = "1" logger.info("Using TorchAO: Setting VLLM_DISABLE_COMPILE_CACHE=1")
Source code in vllm/model_executor/layers/quantization/torchao.py
from_config
classmethod
¶
from_config(config: dict[str, Any]) -> TorchAOConfig
Create the quant config from an hf model config
Source code in vllm/model_executor/layers/quantization/torchao.py
get_config_filenames
staticmethod
¶
get_name
¶
get_name() -> QuantizationMethods
get_quant_method
¶
get_quant_method(
layer: Module, prefix: str
) -> Optional[QuantizeMethodBase]
Source code in vllm/model_executor/layers/quantization/torchao.py
get_scaled_act_names
¶
TorchAOLinearMethod
¶
Bases: LinearMethodBase
Linear method for torchao.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
torchao_config
|
The torchao quantization config, a string |
required |
Source code in vllm/model_executor/layers/quantization/torchao.py
__init__
¶
__init__(quant_config: TorchAOConfig)
apply
¶
create_weights
¶
create_weights(
layer: Module,
input_size_per_partition: int,
output_partition_sizes: list[int],
input_size: int,
output_size: int,
params_dtype: dtype,
**extra_weight_attrs,
)
Source code in vllm/model_executor/layers/quantization/torchao.py
should_skip
¶
Robust skipping logic: should_skip("model.model.layers.1.q_proj", ["model.model.layers.1.q_proj"]) # True should_skip("model.model.layers.10.o_proj", ["o_proj"]) -> True should_skip("visual.model.layers.1.q_proj", ["visual"]) -> True should_skip("model.model.layers.1.q_proj", ["layers.1"]) -> True should_skip("model.model.layers.11.q_proj", ["layers.1"]) -> False
Source code in vllm/model_executor/layers/quantization/torchao.py
torchao_quantize_param_data
¶
Quantize a Tensor with torchao quantization specified by torchao_config
Parameters:
Name | Type | Description | Default |
---|---|---|---|
`param`
|
weight parameter of the linear module |
required | |
`torchao_config`
|
type of quantization and their arguments we want to use to quantize the Tensor |
required |