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

Function FloatingQuantizationConfig

ppq/lib/quant.py:137–164  ·  view source on GitHub ↗

Create a Floating Quantization Config. 创建浮点量化配置信息。

(
    symmetrical: bool = True,
    power_of_2: bool = True,
    channel_axis: int = None,
    quant_min: float = -448.0,
    quant_max: float = 448.0,
    exponent: int = 4,
    mantissa: int = 3,
    calibration: str = 'constant',
    rounding: RoundingPolicy = RoundingPolicy.ROUND_HALF_EVEN)

Source from the content-addressed store, hash-verified

135
136
137def FloatingQuantizationConfig(
138 symmetrical: bool = True,
139 power_of_2: bool = True,
140 channel_axis: int = None,
141 quant_min: float = -448.0,
142 quant_max: float = 448.0,
143 exponent: int = 4,
144 mantissa: int = 3,
145 calibration: str = 'constant',
146 rounding: RoundingPolicy = RoundingPolicy.ROUND_HALF_EVEN) -> TensorQuantizationConfig:
147 """
148 Create a Floating Quantization Config.
149
150 创建浮点量化配置信息。
151 """
152
153 sym = QuantizationProperty.SYMMETRICAL if symmetrical else QuantizationProperty.ASYMMETRICAL
154 pw2 = QuantizationProperty.POWER_OF_2 if power_of_2 else 0
155 chn = QuantizationProperty.PER_TENSOR if channel_axis is None else QuantizationProperty.PER_CHANNEL
156
157 return TensorQuantizationConfig(
158 policy = QuantizationPolicy(sym + pw2 + chn + QuantizationProperty.FLOATING),
159 rounding = rounding,
160 num_of_bits = exponent + mantissa + 1,
161 exponent_bits = exponent,
162 quant_min = quant_min,
163 quant_max = quant_max,
164 observer_algorithm = calibration)
165
166
167def Dispatcher(graph: BaseGraph, method: str='conservative') -> GraphDispatcher:

Callers

nothing calls this directly

Calls 2

QuantizationPolicyClass · 0.90

Tested by

no test coverage detected