(
self,
operation_name: str,
target_platform: TargetPlatform,
quantization_config: OperationQuantizationConfig
)
| 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, |
no test coverage detected