vllm.model_executor.layers.quantization.torchao ¶
TorchAOConfig ¶
Bases: QuantizationConfig
Config class for torchao.
Source code in vllm/model_executor/layers/quantization/torchao.py
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
is_checkpoint_torchao_serialized instance-attribute
¶
__init__ ¶
__init__(
torchao_config,
skip_modules: Optional[list[str]] = None,
is_checkpoint_torchao_serialized: bool = False,
) -> None
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
from_config_dict_json classmethod
¶
from_config_dict_json(
config_dict_json: str,
) -> TorchAOConfig
Iniitalize class from a config_dict json string, got from torchao_config_object = some AOBaseConfig object json.dumps(config_to_dict(torchao_config_object))
Source code in vllm/model_executor/layers/quantization/torchao.py
from_config_file classmethod
¶
from_config_file(config_file: str) -> TorchAOConfig
Initialize class from a config file. Example:
config = Float8DynamicActivationFloat8WeightConfig(granularity=PerRow())
fn = "torchao_config.json"
with open(fn, "w") as f:
f.write(json.dumps(config_to_dict(config)))
Source code in vllm/model_executor/layers/quantization/torchao.py
get_config_filenames staticmethod
¶
torchao doesn't require additional config files, we use config.json
from huggingface: model_config.hf_config
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 |
---|---|---|---|
quant_config | TorchAOConfig | The torchao quantization config, a string that encodes the type of quantization and all relevant arguments. | 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
process_weights_after_loading ¶
process_weights_after_loading(layer: Module) -> None
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 | Tensor | weight parameter of the linear module | required |
torchao_config | Any | type of quantization and their arguments we want to use to quantize the Tensor | required |