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

Method register_quantize_delegate

ppq/executor/torch.py:296–323  ·  view source on GitHub ↗

Since PPQ 0.6.2, Interface TorchQuantizeDelegate is introduced to customize quantization logic: To be specific, you are suppose to inherit this class, and define your own computation logic within function __call__. Pass your Delegate to TorchExecutor by TorchExec

(
        self, config: TensorQuantizationConfig,
        delegator: TorchQuantizeDelegator)

Source from the content-addressed store, hash-verified

294 self.deploy()
295
296 def register_quantize_delegate(
297 self, config: TensorQuantizationConfig,
298 delegator: TorchQuantizeDelegator):
299 """Since PPQ 0.6.2, Interface TorchQuantizeDelegate is introduced to
300 customize quantization logic: To be specific, you are suppose to
301 inherit this class, and define your own computation logic within
302 function __call__.
303
304 Pass your Delegate to TorchExecutor by TorchExecutor.register_quantize_delegate(c, d)
305 Where c is the target quantization config, d is your delegator class.
306 Once you invoke this function, PPQ execution system will hand the quantization
307 computation of config c over to your delegate. PPQ execution system will no
308 longer quantize variable related with config c anymore.
309
310 Notice that a delegate replaces quantization computation only, it still under the control of PPQ quantization
311 System, so to say if your config has an invalid state like DEQUANTIZED, PPQ execution system will never been
312 required to quantize related tensor and so your delegate class will take no effects on config c.
313
314 Remove delegate function by TorchExecutor.remove_quantize_delegate(c)
315 """
316 if not isinstance(delegator, TorchQuantizeDelegator):
317 raise TypeError(
318 f'You can only register a TorchQuantizeDelegate as quantization delegator function,'
319 f' however a/an {type(delegator)} was given')
320 if not isinstance(config, TensorQuantizationConfig):
321 raise TypeError(
322 f'Except a TensorQuantizationConfig instance, however {type(config)} was passed.')
323 self._delegates[config] = delegator
324
325 def remove_quantize_delegate(
326 self, config: TensorQuantizationConfig):

Callers 4

calib_blockMethod · 0.80
finetuneMethod · 0.80
finetuneMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected