PPQ 核心量化函数,没啥好说的了吧,这个玩意既做 quant 也做 dequant
(
tensor: torch.Tensor, config: TensorQuantizationConfig)
| 198 | return TensorwiseDynamicLinearQuantImpl.apply(tensor, config) |
| 199 | |
| 200 | def PPQLinearQuantFunction( |
| 201 | tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor: |
| 202 | """PPQ 核心量化函数,没啥好说的了吧,这个玩意既做 quant 也做 dequant""" |
| 203 | if not QuantizationStates.is_activated(config.state): return tensor |
| 204 | if not config.policy.has_property(QuantizationProperty.LINEAR): |
| 205 | raise ValueError('Critical Quantization Error! Non-linear config detected.') |
| 206 | if config.policy.has_property(QuantizationProperty.DYNAMIC): |
| 207 | raise ValueError('Unexpected Dynamic Flag in Quantization Policy. Use PPQDyamicQuantFunction Instead.') |
| 208 | |
| 209 | if config.policy.has_property(QuantizationProperty.PER_CHANNEL): |
| 210 | return ChannelwiseLinearQuantImpl.apply( |
| 211 | tensor, config.scale, config.offset, config.channel_axis, |
| 212 | config.quant_min, config.quant_max, config.rounding) |
| 213 | elif config.policy.has_property(QuantizationProperty.PER_TENSOR): |
| 214 | return TensorwiseLinearQuantImpl.apply( |
| 215 | tensor, config.scale, config.offset, |
| 216 | config.quant_min, config.quant_max, config.rounding) |
| 217 | |
| 218 | def PPQLinearQuant_toInt(tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor: |
| 219 | """PPQ 核心量化函数,没啥好说的了吧,这个玩意只做 quant 不做 dequant""" |
no test coverage detected