## PPQ Quant Alignment Pass(通用量化对齐过程) When deploy on real hardware and inference framework, we will find that there are various restrictions or rules that we have to follow. * AVERAGE_POOL_2D: Input and outputs must all have same scale/zero_point * CONCATENATION:
| 290 | |
| 291 | |
| 292 | class QuantAlignmentPass(QuantizationOptimizationPass): |
| 293 | """ |
| 294 | ## PPQ Quant Alignment Pass(通用量化对齐过程) |
| 295 | |
| 296 | When deploy on real hardware and inference framework, |
| 297 | we will find that there are various restrictions or rules that we have to follow. |
| 298 | |
| 299 | * AVERAGE_POOL_2D: Input and outputs must all have same scale/zero_point |
| 300 | |
| 301 | * CONCATENATION: Input and outputs must all have same scale/zero_point |
| 302 | |
| 303 | * SLICE: Input and outputs must all have same scale/zero_point |
| 304 | |
| 305 | More detailed restrictions please refer to: https://www.tensorflow.org/lite/performance/quantization_spec |
| 306 | |
| 307 | Those restrictions, can be concluded as some quantization should share |
| 308 | the same quantization parameter with others. PPQ Quant Alignment Pass is designed |
| 309 | for dealing with problems like this. |
| 310 | |
| 311 | PPQ uses Tensor Quantization Config (A data structure defined in ppq.core) to control the |
| 312 | quantization logic, so to say if we want to align quantization parameters, we align |
| 313 | their TQC in fact. |
| 314 | |
| 315 | The way to align TQC is simple, code like: |
| 316 | tqc1.set_master(master=tqc2) |
| 317 | Will make tqc1 and tqc2 share the same quantization parameters as tqc1 has, and change the |
| 318 | state of tqc2 to be QuantizationState.PASSIVE |
| 319 | |
| 320 | If we access the scale of tqc2, PPQ will return its master TQC's scale instead, so does offset. |
| 321 | |
| 322 | That is tqc1 and tqc2 are bonuded with statement "tqc1.set_master(master=tqc2)". |
| 323 | |
| 324 | ### Parameters: |
| 325 | |
| 326 | * elementwise_alignment(Set[str]): |
| 327 | |
| 328 | Alignment method for elementwise ops. |
| 329 | |
| 330 | PPQ Supports 4 alignment methods: |
| 331 | namely 'Align to Input', 'Align to Large', 'Align to Output', 'None'. |
| 332 | |
| 333 | All elementwise ops are listed in ppq.core.common.py |
| 334 | |
| 335 | * concat_alignment(Set[str]) |
| 336 | |
| 337 | Alignment method for concat-like ops. |
| 338 | |
| 339 | PPQ Supports 4 alignment methods: |
| 340 | namely 'Align to Input', 'Align to Large', 'Align to Output', 'None'. |
| 341 | |
| 342 | All concat-like ops are listed in ppq.core.common.py |
| 343 | |
| 344 | * averagepool_alignment(Set[str]) |
| 345 | |
| 346 | Alignment method for pooling-like ops. |
| 347 | |
| 348 | PPQ Supports 4 alignment methods: |
| 349 | namely 'Align to Input', 'Align to Large', 'Align to Output', 'None'. |
no outgoing calls
no test coverage detected