diff --git a/nncf/common/graph/patterns/patterns.py b/nncf/common/graph/patterns/patterns.py index c6ab0e32e8f..32c3d02ac53 100644 --- a/nncf/common/graph/patterns/patterns.py +++ b/nncf/common/graph/patterns/patterns.py @@ -339,6 +339,8 @@ class HWFusedPatternNames(Enum): LINEAR_ACTIVATIONS_SCALE_SHIFT = PatternDesc("linear_activations_scale_shift") LINEAR_ARITHMETIC = PatternDesc("linear_arithmetic") LINEAR_ARITHMETIC_ACTIVATIONS = PatternDesc("linear_arithmetic_activations") + # Found in PicoDet models + LINEAR_ARITHMETIC_ACTIVATIONS_ARITHMETIC = PatternDesc("linear_arithmetic_activations_arithmetic") LINEAR_BATCH_NORM = PatternDesc("linear_batch_norm") LINEAR_BATCH_NORM_ACTIVATIONS = PatternDesc("linear_batch_norm_activations") LINEAR_BATCH_NORM_SCALE_SHIFT_ACTIVATIONS = PatternDesc("linear_batch_norm_scale_shift_activations") diff --git a/nncf/onnx/hardware/fused_patterns.py b/nncf/onnx/hardware/fused_patterns.py index 025e103b6a3..2b5c3580a89 100644 --- a/nncf/onnx/hardware/fused_patterns.py +++ b/nncf/onnx/hardware/fused_patterns.py @@ -352,6 +352,15 @@ def create_linear_arithmetic_activations() -> GraphPattern: return linear +@ONNX_HW_FUSED_PATTERNS.register(HWFusedPatternNames.LINEAR_ARITHMETIC_ACTIVATIONS_ARITHMETIC) +def create_linear_arithmetic_activations_arithmetic() -> GraphPattern: + linear_arithmetic_activations = create_linear_arithmetic_activations() + arithmetic = arithmetic_operations() + + linear_arithmetic_activations.join_patterns(arithmetic) + return linear_arithmetic_activations + + # DEVICE PATTERNS diff --git a/nncf/openvino/graph/metatypes/openvino_metatypes.py b/nncf/openvino/graph/metatypes/openvino_metatypes.py index 4a86d2c9815..748d436bd15 100644 --- a/nncf/openvino/graph/metatypes/openvino_metatypes.py +++ b/nncf/openvino/graph/metatypes/openvino_metatypes.py @@ -629,6 +629,12 @@ class OVSwishMetatype(OVOpMetatype): op_names = ["Swish"] +@OV_OPERATOR_METATYPES.register() +class OVHSwishMetatype(OVOpMetatype): + name = "HSwishhOp" + op_names = ["HSwish"] + + @OV_OPERATOR_METATYPES.register() class OVClampMetatype(OVOpMetatype): name = "ClampOp" diff --git a/nncf/openvino/hardware/fused_patterns.py b/nncf/openvino/hardware/fused_patterns.py index cd3677fafb7..b89e548fade 100644 --- a/nncf/openvino/hardware/fused_patterns.py +++ b/nncf/openvino/hardware/fused_patterns.py @@ -575,6 +575,15 @@ def create_linear_arithmetic_activations() -> GraphPattern: return linear +@OPENVINO_HW_FUSED_PATTERNS.register(HWFusedPatternNames.LINEAR_ARITHMETIC_ACTIVATIONS_ARITHMETIC) +def create_linear_arithmetic_activations_arithmetic() -> GraphPattern: + linear_arithmetic_activations = create_linear_arithmetic_activations() + arithmetic = arithmetic_operations() + + linear_arithmetic_activations.join_patterns(arithmetic) + return linear_arithmetic_activations + + @OPENVINO_HW_FUSED_PATTERNS.register(HWFusedPatternNames.LINEAR_SQUEEZE_ACTIVATIONS) def create_linear_squeeze_activation() -> GraphPattern: linear = linear_operations() diff --git a/nncf/openvino/hardware/pattern_operations.py b/nncf/openvino/hardware/pattern_operations.py index 66ac6dea0cc..1e05f577f92 100644 --- a/nncf/openvino/hardware/pattern_operations.py +++ b/nncf/openvino/hardware/pattern_operations.py @@ -39,6 +39,7 @@ ov_metatypes.OVSigmoidMetatype, ov_metatypes.OVHardSigmoidMetatype, ov_metatypes.OVSwishMetatype, + ov_metatypes.OVHSwishMetatype, ], GraphPattern.LABEL_ATTR: "ATOMIC_ACTIVATIONS", } diff --git a/tests/torch/test_pattern_manager.py b/tests/torch/test_pattern_manager.py index cc037ca505f..3a0b6e8309f 100644 --- a/tests/torch/test_pattern_manager.py +++ b/tests/torch/test_pattern_manager.py @@ -50,6 +50,7 @@ HWFusedPatternNames.BATCH_NORM_SCALE_SHIFT_ACTIVATIONS: "Not relevant for Torch.", HWFusedPatternNames.LINEAR_ACTIVATIONS_SCALE_SHIFT: "Not relevant for Torch.", HWFusedPatternNames.LINEAR_ARITHMETIC_ACTIVATIONS: "Not relevant for Torch.", + HWFusedPatternNames.LINEAR_ARITHMETIC_ACTIVATIONS_ARITHMETIC: "Not relevant for Torch.", HWFusedPatternNames.LINEAR_BATCH_NORM_SCALE_SHIFT_ACTIVATIONS: "Not relevant for Torch.", HWFusedPatternNames.LINEAR_SCALE_SHIFT_ACTIVATIONS: "Not relevant for Torch.", HWFusedPatternNames.SCALE_SHIFT_ACTIVATIONS: "Not relevant for Torch.",