Skip to content

Commit

Permalink
[PTQ] Added hswish metatype and LINEAR_ARITHMETIC_ACTIVATIONS_ARITHME…
Browse files Browse the repository at this point in the history
…TIC pattern (#1990)

### Changes

Added hswish metatype and LINEAR_ARITHMETIC_ACTIVATIONS_ARITHMETIC
pattern

### Reason for changes

Support for OpenVINO HSwish operation.

### Related tickets

#1936

### Tests

N/A
  • Loading branch information
alexsu52 authored Jul 24, 2023
1 parent d6e7dcc commit b3f240d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nncf/common/graph/patterns/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions nncf/onnx/hardware/fused_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 6 additions & 0 deletions nncf/openvino/graph/metatypes/openvino_metatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions nncf/openvino/hardware/fused_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions nncf/openvino/hardware/pattern_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
ov_metatypes.OVSigmoidMetatype,
ov_metatypes.OVHardSigmoidMetatype,
ov_metatypes.OVSwishMetatype,
ov_metatypes.OVHSwishMetatype,
],
GraphPattern.LABEL_ATTR: "ATOMIC_ACTIVATIONS",
}
Expand Down
1 change: 1 addition & 0 deletions tests/torch/test_pattern_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit b3f240d

Please sign in to comment.