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

Method quantize_operation

ppq/IR/quantize.py:271–302  ·  view source on GitHub ↗
(
        self,
        operation_name: str,
        target_platform: TargetPlatform,
        quantization_config: OperationQuantizationConfig
    )

Source from the content-addressed store, hash-verified

269 ]
270
271 def quantize_operation(
272 self,
273 operation_name: str,
274 target_platform: TargetPlatform,
275 quantization_config: OperationQuantizationConfig
276 ) -> QuantableOperation:
277 if operation_name not in self.graph.operations:
278 raise KeyError(f'Operation {operation_name} is not in your graph, Please check your input.')
279
280 operation = self._graph.operations[operation_name]
281 quantized_operation = QuantableOperation(
282 convert_from=operation,
283 quantize_config=quantization_config,
284 platform=target_platform,
285 )
286
287 # calling other chain responder to replace operation with quantized one.
288 if self._next_command_processor is None:
289 raise RuntimeError(
290 'To replace a operation, your processor chain must have a GraphReplacer Processor.')
291 self._next_command_processor(ReplaceOperationCommand(operation_name, quantized_operation))
292
293 # replace all related variable with quantable one.
294 for var in quantized_operation.inputs + quantized_operation.outputs:
295 if isinstance(var, QuantableVariable): continue
296 self._next_command_processor(
297 ReplaceVariableCommand(
298 var_name=var.name,
299 replace_to=QuantableVariable(convert_from=var)
300 )
301 )
302 quantized_operation.store_parameter_value()
303
304 def dequantize_operation(
305 self,

Callers 15

processMethod · 0.95
yolo6_sample.pyFile · 0.45
fp8_sample.pyFile · 0.45
bert_sample.pyFile · 0.45
fp8_sample.pyFile · 0.45
QuantZoo_Yolo.pyFile · 0.45
QuantZoo_OCR.pyFile · 0.45
myquantizer.pyFile · 0.45

Calls 5

store_parameter_valueMethod · 0.95
QuantableOperationClass · 0.85
QuantableVariableClass · 0.85

Tested by

no test coverage detected