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

Method quantize_operation

ppq/quantization/quantizer/base.py:80–104  ·  view source on GitHub ↗
(self, op_name: str, platform: TargetPlatform=None)

Source from the content-addressed store, hash-verified

78 print('Network Quantization Finished.')
79
80 def quantize_operation(self, op_name: str, platform: TargetPlatform=None) -> QuantableOperation:
81 if op_name not in self._graph.operations:
82 raise KeyError(f'Can not find op {op_name} in your graph, chech operation name again.')
83 converting_operation = self._graph.operations[op_name]
84 if isinstance(converting_operation, QuantableOperation):
85 ppq_warning(f'Operation {op_name} has been quantized, can not to quantize it twice.')
86 return converting_operation
87
88 # override platform with calling parameter.
89 if platform is not None: converting_operation.platform = platform
90 else: platform = converting_operation.platform
91
92 if platform in {TargetPlatform.FP32, TargetPlatform.SOI}:
93 return self._graph.operations[op_name]
94
95 # if platform == TargetPlatform.UNSPECIFIED we can skip its quantization when type is not supported.
96 if platform == TargetPlatform.UNSPECIFIED and converting_operation.type not in self.quant_operation_types:
97 return self._graph.operations[op_name]
98
99 # create quantize config and convert operation.
100 self._processor(QuantizeOperationCommand(
101 op_name=op_name, target_platform=platform,
102 config=self.init_quantize_config(operation=converting_operation)
103 ))
104 return self._graph.operations[op_name]
105
106 @ staticmethod
107 def create_default_quant_config(

Callers 1

quantizeMethod · 0.95

Calls 3

init_quantize_configMethod · 0.95
ppq_warningFunction · 0.85

Tested by

no test coverage detected