(self, config: Dict, pre_quant_layer: nn.Linear)
| 47 | class QuantizedLinear(nn.Linear): |
| 48 | |
| 49 | def __init__(self, config: Dict, pre_quant_layer: nn.Linear) -> None: |
| 50 | super(QuantizedLinear, self).__init__(in_features=pre_quant_layer.in_features, |
| 51 | out_features=pre_quant_layer.out_features, |
| 52 | bias=pre_quant_layer.bias is not None, |
| 53 | device=pre_quant_layer.weight.device, |
| 54 | dtype=pre_quant_layer.weight.dtype) |
| 55 | self.config = config |
| 56 | |
| 57 | self.quantizer = Quantizer(config=config) |
| 58 | self.bias = pre_quant_layer.bias |
| 59 | self.weight = get_quantized_weight_wrapper(self, pre_quant_layer.weight, |
| 60 | get_quantize_weight_fn(self.quantizer, pre_quant_layer.weight)) |
| 61 | |
| 62 | self.weight.dequantizer = DeQuantizer(config, pre_quant_layer.weight.dtype) |
| 63 | |
| 64 | def forward(self, input: Tensor) -> Tensor: |
| 65 | quantized_weight, quant_scale, quant_min = self.weight.deconcat(self.weight) |
no test coverage detected