Dynamic Linear Quantization Function(PPQ 动态量化函数). When calling this method, we firstly solve a scale & offset setting by min-max observer. Then we applys ordinary Linear Quantization Function with solved setting. If there is a pre-defined scale & offset within given c
(tensor: torch.Tensor, config: TensorQuantizationConfig)
| 173 | return dy, None |
| 174 | |
| 175 | def PPQDyamicLinearQuantFunction(tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor: |
| 176 | """ |
| 177 | Dynamic Linear Quantization Function(PPQ 动态量化函数). |
| 178 | |
| 179 | When calling this method, we firstly solve a scale & offset setting by min-max observer. |
| 180 | |
| 181 | Then we applys ordinary Linear Quantization Function with solved setting. |
| 182 | |
| 183 | If there is a pre-defined scale & offset within given config, they will be dropped without warning. |
| 184 | |
| 185 | 动态量化函数将在执行量化之前统计出 tensor 的 min - max, 而后计算出 scale & offset 并完成量化 |
| 186 | |
| 187 | 此时 TQC 中的 scale 与 offset 将被忽略 |
| 188 | """ |
| 189 | if not QuantizationStates.is_activated(config.state): return tensor |
| 190 | if not config.policy.has_property(QuantizationProperty.LINEAR): |
| 191 | raise ValueError('Critical Quantization Error! Non-linear config detected.') |
| 192 | if not config.policy.has_property(QuantizationProperty.DYNAMIC): |
| 193 | raise ValueError('Quantization Policy Do Not Have Dynamic Flag!') |
| 194 | |
| 195 | if config.policy.has_property(QuantizationProperty.PER_CHANNEL): |
| 196 | return ChannelwiseDynamicLinearQuantImpl.apply(tensor, config) |
| 197 | elif config.policy.has_property(QuantizationProperty.PER_TENSOR): |
| 198 | return TensorwiseDynamicLinearQuantImpl.apply(tensor, config) |
| 199 | |
| 200 | def PPQLinearQuantFunction( |
| 201 | tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor: |
no test coverage detected