(param: nn.Parameter, quant_config: Dict)
| 221 | |
| 222 | |
| 223 | def _quantize_param(param: nn.Parameter, quant_config: Dict): |
| 224 | assert not hasattr(param, 'weight_quantized'), 'Parameter has already been quantized.' |
| 225 | quantizer = Quantizer(quant_config) |
| 226 | dequantizer = DeQuantizer(quant_config, param.dtype) |
| 227 | |
| 228 | quantized_weight, quant_scale, quant_min = quantizer.quantize(param.data) |
| 229 | |
| 230 | quantized_weight = quantized_weight.view(param.dtype) |
| 231 | quant_scale = quant_scale.view(param.dtype) |
| 232 | quant_min = quant_min.view(param.dtype) |
| 233 | |
| 234 | quantized_compat_tensor = concat_to_compat_param(quantized_weight, quant_scale, quant_min) |
| 235 | param.data = quantized_compat_tensor |
| 236 | param.deconcat = quantized_compat_tensor.deconcat |
| 237 | |
| 238 | param.quantizer = quantizer |
| 239 | param.dequantizer = dequantizer |
| 240 | setattr(param, 'weight_quantized', True) |
| 241 | |
| 242 | |
| 243 | def wrap_quantized_functional(f): |
no test coverage detected