MCPcopy
hub / github.com/OpenPPL/ppq / dequantize

Method dequantize

ppq/IR/quantize.py:124–141  ·  view source on GitHub ↗
(self, parameter_only: bool = False, expire_device: str = 'cpu')

Source from the content-addressed store, hash-verified

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

Callers 12

dequantize.pyFile · 0.80
optimizeMethod · 0.80
dequantize_pairMethod · 0.80
dequantize_blockMethod · 0.80
layerwise_error_analyseFunction · 0.80
graphwise_error_analyseFunction · 0.80
statistical_analyseFunction · 0.80
dequantize_operationMethod · 0.80
dequantize_graphMethod · 0.80
__enter__Method · 0.80
test_block.pyFile · 0.80

Calls 1

Tested by

no test coverage detected