r""" Exclude speific operators from quantizer annotation. Skipped operators will defaultly stay in CPU, set 'fallback_to_cpu' to False for trying to delegate them with FP16 precision. e.g.: consider following graph: bias_1 weight_1 input_1 bias_2 weight_2 input_2 | (plac
(
nn_module: torch.nn.Module,
quantizer,
compiler_specs,
sample_input: Tuple[torch.Tensor, ...],
calibration_cb: Callable[[torch.fx.GraphModule], None],
fp_node_id_set: set = None,
fp_node_op_set: set = None,
fallback_to_cpu: bool = True,
)
| 602 | |
| 603 | |
| 604 | def skip_annotation( |
| 605 | nn_module: torch.nn.Module, |
| 606 | quantizer, |
| 607 | compiler_specs, |
| 608 | sample_input: Tuple[torch.Tensor, ...], |
| 609 | calibration_cb: Callable[[torch.fx.GraphModule], None], |
| 610 | fp_node_id_set: set = None, |
| 611 | fp_node_op_set: set = None, |
| 612 | fallback_to_cpu: bool = True, |
| 613 | ): |
| 614 | r""" |
| 615 | Exclude speific operators from quantizer annotation. |
| 616 | Skipped operators will defaultly stay in CPU, set 'fallback_to_cpu' |
| 617 | to False for trying to delegate them with FP16 precision. |
| 618 | |
| 619 | e.g.: consider following graph: |
| 620 | bias_1 weight_1 input_1 bias_2 weight_2 input_2 |
| 621 | | (placeholder) | | (placeholder) | |
| 622 | \ | / \ | / |
| 623 | \ | / \ | / |
| 624 | \ | / \ | / |
| 625 | conv2d_1 conv2d_2 |
| 626 | (torch.ops.aten.conv2d.default) |
| 627 | \ / |
| 628 | \ / |
| 629 | \_______ _______/ |
| 630 | add_1 |
| 631 | (torch.ops.aten.add.default) |
| 632 | | |
| 633 | output |
| 634 | |
| 635 | If user wants to skip convolution op by names with |
| 636 | 'skip_node_id_set' = {"conv2d_1"} |
| 637 | "bias_1 / weight_1 / input_1 / input_2 / conv2d_1" |
| 638 | will be partitioned out and not annotated / lowered with QNN. |
| 639 | |
| 640 | [Generated graph] |
| 641 | bias_1 weight_1 input_1 input_2 |
| 642 | | (placeholder) | | |
| 643 | \ | / | |
| 644 | \ | / | |
| 645 | \ | / | |
| 646 | conv2d_1 | |
| 647 | \ / |
| 648 | \ / |
| 649 | \ / |
| 650 | lowered_module_1 |
| 651 | (QNN fixed precision) |
| 652 | | |
| 653 | output |
| 654 | |
| 655 | If user wants to skip convolution op by target with |
| 656 | 'skip_node_op_set' = {torch.ops.aten.conv2d.default} |
| 657 | "bias_1 / weight_1 / input_1 / conv2d_1, |
| 658 | bias_2 / weight_2 / input_2 / conv2d_2" |
| 659 | will be partitioned out and not annotated / lowered with QNN. |
| 660 | |
| 661 | [Generated graph] |