vllm.model_executor.layers.quantization.rtn
NUM_BITS
module-attribute
¶
NUM_BITS = getenv('RTN_NUM_BITS', '8')
By default, use group size of 128 parameters, but it can be overridden by setting the RTN_GROUP_SIZE envvar
logger
module-attribute
¶
logger = init_logger(__name__)
By default, use 8 bit as target precision, but it can be overridden by setting the RTN_NUM_BITS envvar
RTNConfig
¶
Bases: QuantizationConfig
Config class for RTN.
Source code in vllm/model_executor/layers/quantization/rtn.py
__init__
¶
Source code in vllm/model_executor/layers/quantization/rtn.py
from_config
classmethod
¶
get_config_filenames
classmethod
¶
get_name
classmethod
¶
get_name() -> QuantizationMethods
get_quant_method
¶
get_quant_method(
layer: Module, prefix: str
) -> Optional[RTNLinearMethod]
RTNLinearMethod
¶
Bases: LinearMethodBase
Linear method for RTN.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quant_config
|
RTNConfig
|
The RTN quantization config. |
required |
Source code in vllm/model_executor/layers/quantization/rtn.py
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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
apply
¶
Source code in vllm/model_executor/layers/quantization/rtn.py
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/rtn.py
process_weights_after_loading
¶
process_weights_after_loading(layer: Module) -> None
torch.compile does not know how to deal with a Parameter subclass (aka RTNParameter). As we don't really need RTNParameters for the forward pass, we replace them with equivalent instances of Parameters.
Source code in vllm/model_executor/layers/quantization/rtn.py
RTNParameter
¶
Bases: Parameter
A wrapper over Parameter that returns RTNTensor (a wrapper over Tensor) when its data is accessed. We need this wrapper for the data loading phase only, so we can intercept a weight copying function (torch.Tensor.copy_) and apply quantization on-the-fly.
Source code in vllm/model_executor/layers/quantization/rtn.py
__init__
¶
RTNTensor
¶
A wrapper over Tensor that enables quantization on-the-fly by overloading the copy_ method.
Source code in vllm/model_executor/layers/quantization/rtn.py
rtn_dequantize
¶
Dequantize a tensor using per-group static scaling factors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor
|
Tensor
|
The input tensor. |
required |
scale
|
Tensor
|
The tensor with per-group scale factors. |
required |
Source code in vllm/model_executor/layers/quantization/rtn.py
rtn_quantize
¶
Quantize a tensor using per-group static scaling factor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor
|
Tensor
|
The input tensor. |
required |
num_bits
|
int
|
Target precision for the result (supported values are 8 or 4). |
required |
group_size
|
int
|
Quantization granularity. If equal to -1, each row in the input tensor is treated as one group. |
required |