(
cls,
data: Optional[torch.Tensor] = None,
requires_grad: bool = False, # quantized weights must be frozen
quantization_config: QuantizationConfig = None,
quantizer: Quantizer = None,
)
| 35 | """ |
| 36 | |
| 37 | def __new__( |
| 38 | cls, |
| 39 | data: Optional[torch.Tensor] = None, |
| 40 | requires_grad: bool = False, # quantized weights must be frozen |
| 41 | quantization_config: QuantizationConfig = None, |
| 42 | quantizer: Quantizer = None, |
| 43 | ): |
| 44 | if requires_grad: |
| 45 | raise ValueError("requires_grad=True is not supported with QuantizedParameter") |
| 46 | if data is None: |
| 47 | data = torch.empty(0) |
| 48 | self = torch.Tensor._make_subclass(cls, data, requires_grad) |
| 49 | self.quantization_config = QuantizationConfig() if quantization_config is None else quantization_config |
| 50 | if quantizer is not None: |
| 51 | self.quantizer = quantizer |
| 52 | else: |
| 53 | # if FPQuantizerBuilder is not compatible in this env this init will fail |
| 54 | self.quantizer = FP_Quantize(quantization_config=self.quantization_config) |
| 55 | self._ensure_quantized(self) |
| 56 | return self |
| 57 | |
| 58 | def _ensure_quantized(self, tensor: torch.Tensor): |
| 59 | # If the tensor is on the accelerator and is not quantized, then quantize it in-place. |
no test coverage detected