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