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

Method align_to_input

ppq/quantization/optim/refine.py:415–427  ·  view source on GitHub ↗

Align quant scale and offset to input config. All output configs would share a same scale and offset with output config. (as a slave to input config) Any change to slave config will be rejected since then.

(self, op: QuantableOperation)

Source from the content-addressed store, hash-verified

413 super().__init__(name='PPQ Quantization Alignment Pass')
414
415 def align_to_input(self, op: QuantableOperation) -> TensorQuantizationConfig:
416 """Align quant scale and offset to input config. All output configs
417 would share a same scale and offset with output config. (as a slave to
418 input config)
419
420 Any change to slave config will be rejected since then.
421 """
422 master_config = op.config.input_quantization_config[0]
423 for slave_config in op.config.output_quantization_config:
424 if slave_config.policy.has_property(QuantizationProperty.FLOATING): continue
425 if slave_config.state not in {QuantizationStates.FP32, QuantizationStates.SOI}:
426 slave_config.master_by = master_config
427 return master_config
428
429 def align_to_large(self, op: QuantableOperation) -> TensorQuantizationConfig:
430 """Align quant scale and offset to larger input config. The first input

Callers 1

optimizeMethod · 0.95

Calls 1

has_propertyMethod · 0.80

Tested by

no test coverage detected