(
self,
graph: BaseGraph,
**kwargs
)
| 630 | |
| 631 | @ empty_ppq_cache |
| 632 | def optimize( |
| 633 | self, |
| 634 | graph: BaseGraph, |
| 635 | **kwargs |
| 636 | ) -> None: |
| 637 | processor = SearchableGraph(graph) |
| 638 | |
| 639 | relu_fusion_matching = processor.activation_matching( |
| 640 | start_op_types=['Conv', 'Add'], end_types=['Relu']) |
| 641 | for conv_name, activation_names in relu_fusion_matching.items(): |
| 642 | conv = graph.operations[conv_name] |
| 643 | if not isinstance(conv, QuantableOperation): continue |
| 644 | if len(activation_names) == 1: |
| 645 | activation = graph.operations[activation_names[0]] |
| 646 | if not isinstance(activation, QuantableOperation): continue |
| 647 | activation_cfg = activation.config.output_quantization_config[0] |
| 648 | conv_cfg = conv.config.output_quantization_config[0] |
| 649 | conv_cfg.dominated_by = activation_cfg |
| 650 | conv_cfg.state = QuantizationStates.OVERLAPPED |
| 651 | |
| 652 | concat_fusion_matching = processor.concat_matching( |
| 653 | relay_pattern=lambda x, y: False, end_pattern=lambda _: True) |
| 654 | for concat_name, upstream_layer_collection in concat_fusion_matching.items(): |
| 655 | concat = graph.operations[concat_name] |
| 656 | if not isinstance(concat, QuantableOperation): continue |
| 657 | for upstream_layer_name in upstream_layer_collection: |
| 658 | upstream_layer = graph.operations[upstream_layer_name] |
| 659 | if not isinstance(upstream_layer, QuantableOperation): continue |
| 660 | upstream_cfg = upstream_layer.config.output_quantization_config[0] |
| 661 | concat_cfg = concat.config.output_quantization_config[0] |
| 662 | upstream_cfg.dominated_by = concat_cfg |
| 663 | upstream_cfg.state = QuantizationStates.OVERLAPPED |
nothing calls this directly
no test coverage detected