(self, parameter_only: bool = False, expire_device: str = 'cpu')
| 122 | return self |
| 123 | |
| 124 | def dequantize(self, parameter_only: bool = False, expire_device: str = 'cpu'): |
| 125 | if self._dequantized: return self |
| 126 | for var, quant_config in zip(self.inputs + self.outputs, |
| 127 | self.config.input_quantization_config + self.config.output_quantization_config): |
| 128 | if parameter_only and not var.is_parameter: continue |
| 129 | quant_config.detail['Stored State'] = quant_config.state |
| 130 | assert isinstance(var, QuantableVariable), f'Unexpected error with variable {var.name}.' |
| 131 | if var.is_parameter: |
| 132 | # convert var.value to torch.Tensor |
| 133 | # notice here we set device = None, this conversion will not change var.value.device anyway. |
| 134 | # so that we can use var.value.device as a deploy device for stored_value |
| 135 | stored_value = convert_any_to_torch_tensor(var.value, device=expire_device) |
| 136 | var.value = convert_any_to_torch_tensor(var.value, device=None) |
| 137 | var.value = convert_any_to_torch_tensor(var.stored_value, device=var.value.device if var.value is not None else None) |
| 138 | var.stored_value = stored_value |
| 139 | quant_config.state = QuantizationStates.FP32 |
| 140 | self._dequantized = True |
| 141 | return self |
| 142 | |
| 143 | def restore_quantize_state(self, expire_device: str = 'cpu'): |
| 144 | if not self._dequantized: return self |
no test coverage detected