(self, graph: BaseGraph, **kwargs)
| 479 | return master_config |
| 480 | |
| 481 | def optimize(self, graph: BaseGraph, **kwargs) -> None: |
| 482 | |
| 483 | for operation in graph.operations.values(): |
| 484 | if not isinstance(operation, QuantableOperation): continue |
| 485 | |
| 486 | master_config = None |
| 487 | if operation.type in TYPES_FOR_ALIGNMENT['Elementwise']: |
| 488 | if self.elementwise_alignment == 'None': continue |
| 489 | if self.elementwise_alignment == 'Align to Large': |
| 490 | master_config = self.align_to_large(operation) |
| 491 | else: master_config = self.align_to_output(operation) |
| 492 | |
| 493 | elif operation.type in TYPES_FOR_ALIGNMENT['Concat']: |
| 494 | if self.concat_alignment == 'None': continue |
| 495 | if self.concat_alignment == 'Align to Large': |
| 496 | master_config = self.align_to_large(operation) |
| 497 | else: master_config = self.align_to_output(operation) |
| 498 | |
| 499 | elif operation.type in TYPES_FOR_ALIGNMENT['Pooling']: |
| 500 | if self.pooling_alignment == 'None': continue |
| 501 | if self.pooling_alignment == 'Align to Input': |
| 502 | self.align_to_input(operation) # do not set master_config |
| 503 | if self.pooling_alignment == 'Align to Output': |
| 504 | master_config = self.align_to_output(operation) |
| 505 | if self.pooling_alignment == 'Align to Large': |
| 506 | raise ValueError('Alignment Method Error, Pooling Op can not align to lager input.') |
| 507 | |
| 508 | elif operation.type == 'Resize': |
| 509 | if self.resize_alignment == 'None': continue |
| 510 | if self.resize_alignment == 'Align to Output': |
| 511 | master_config = self.align_to_output(operation) |
| 512 | if self.resize_alignment == 'Align to Input': |
| 513 | self.align_to_input(operation) # do not set master_config |
| 514 | if self.resize_alignment == 'Align to Large': |
| 515 | raise ValueError('Alignment Method Error, Resize Op can not align to lager.') |
| 516 | |
| 517 | elif ALIGNMENT_MANUL_OVERRIDE in operation.extension_attrib: |
| 518 | method = operation.extension_attrib[ALIGNMENT_MANUL_OVERRIDE] |
| 519 | if self.concat_alignment == 'Align to Large': |
| 520 | master_config = self.align_to_large(operation) |
| 521 | elif self.concat_alignment == 'Align to Large': |
| 522 | master_config = self.align_to_output(operation) |
| 523 | else: |
| 524 | ppq_warning(f'Unrecognized Alignment Method {method} for operation {operation.name}') |
| 525 | |
| 526 | if master_config is not None: |
| 527 | # override up stream layer's config if possible |
| 528 | for up_op in graph.get_upstream_operations(operation): |
| 529 | if not isinstance(up_op, QuantableOperation): continue |
| 530 | |
| 531 | if len(graph.get_downstream_operations(up_op)) != 1 and not self.force_overlap: continue |
| 532 | for cfg, var in up_op.config_with_variable: |
| 533 | if operation in var.dest_ops: |
| 534 | cfg.dominated_by = master_config |
| 535 | |
| 536 | |
| 537 | class SwishFusionPass(QuantizationOptimizationPass): |
nothing calls this directly
no test coverage detected