Skip to content

Commit 1683a6a

Browse files
Move the FC_BN_HSWISH_ACTIVATION pattern from fused to ignored (#1919)
Changes: Move the `FC_BN_HSWISH_ACTIVATION` pattern from fused patterns to ignored patterns. Reason for changes: This is an incorrect fused pattern because we cannot fuse batch normalization in `Unsqueeze` operation. The correct fused pattern is Convolution + Bias + Activation + Unsqueeze + BatchNormalization + Squeeze Related tickets: Ref: 112991 Tests: N/A
1 parent 9f7f5a2 commit 1683a6a

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

nncf/common/graph/patterns/patterns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ class HWFusedPatternNames(Enum):
292292
ADD_SCALE_SHIFT_OUTPUT = PatternDesc("add_scale_shift_output")
293293
BATCH_INDEX = PatternDesc("batch_index")
294294
EQUAL_LOGICALNOT = PatternDesc("equal_logicalnot")
295-
FC_BN_HSWISH_ACTIVATION = PatternDesc("fc_bn_hswish_activation")
296295
LINEAR_WITH_BIAS = PatternDesc("linear_with_bias")
297296
MVN_SCALE_SHIFT = PatternDesc("mvn_scale_shift")
298297
NORMALIZE_L2_MULTIPLY = PatternDesc("normalize_l2_multiply")
@@ -387,3 +386,4 @@ class IgnoredPatternNames(Enum):
387386
"""
388387

389388
MULTIHEAD_ATTENTION_OUTPUT = PatternDesc("multihead_attention_output", model_types=[ModelType.TRANSFORMER])
389+
FC_BN_HSWISH_ACTIVATION = PatternDesc("fc_bn_hswish_activation")

nncf/openvino/hardware/fused_patterns.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,6 @@ def create_equal_logicalnot() -> GraphPattern:
193193
return pattern
194194

195195

196-
@OPENVINO_HW_FUSED_PATTERNS.register(HWFusedPatternNames.FC_BN_HSWISH_ACTIVATION)
197-
def create_fc_bn_hswish() -> GraphPattern:
198-
pattern = GraphPattern()
199-
unsqueeze_node = pattern.add_node(
200-
**{GraphPattern.LABEL_ATTR: "UNSQUEEZE", GraphPattern.METATYPE_ATTR: om.OVUnsqueezeMetatype}
201-
)
202-
multiply_node = pattern.add_node(
203-
**{GraphPattern.LABEL_ATTR: "MULTIPLY", GraphPattern.METATYPE_ATTR: om.OVMultiplyMetatype}
204-
)
205-
add_node = pattern.add_node(**{GraphPattern.LABEL_ATTR: "ADD", GraphPattern.METATYPE_ATTR: om.OVAddMetatype})
206-
squeeze_node = pattern.add_node(
207-
**{GraphPattern.LABEL_ATTR: "SQUEEZE", GraphPattern.METATYPE_ATTR: om.OVSqueezeMetatype}
208-
)
209-
210-
pattern.add_edge(unsqueeze_node, multiply_node)
211-
pattern.add_edge(multiply_node, add_node)
212-
pattern.add_edge(add_node, squeeze_node)
213-
return pattern
214-
215-
216196
# ACTIVATIONS
217197

218198

nncf/openvino/quantization/ignored_patterns.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,23 @@ def create_multihead_attention_output() -> GraphPattern:
7676
_add_softmax_matmul(pattern)
7777
_add_softmax_reshape_matmul(pattern)
7878
return pattern
79+
80+
81+
@OPENVINO_IGNORED_PATTERNS.register(IgnoredPatternNames.FC_BN_HSWISH_ACTIVATION)
82+
def create_fc_bn_hswish() -> GraphPattern:
83+
pattern = GraphPattern()
84+
unsqueeze_node = pattern.add_node(
85+
**{GraphPattern.LABEL_ATTR: "UNSQUEEZE", GraphPattern.METATYPE_ATTR: om.OVUnsqueezeMetatype}
86+
)
87+
multiply_node = pattern.add_node(
88+
**{GraphPattern.LABEL_ATTR: "MULTIPLY", GraphPattern.METATYPE_ATTR: om.OVMultiplyMetatype}
89+
)
90+
add_node = pattern.add_node(**{GraphPattern.LABEL_ATTR: "ADD", GraphPattern.METATYPE_ATTR: om.OVAddMetatype})
91+
squeeze_node = pattern.add_node(
92+
**{GraphPattern.LABEL_ATTR: "SQUEEZE", GraphPattern.METATYPE_ATTR: om.OVSqueezeMetatype}
93+
)
94+
95+
pattern.add_edge(unsqueeze_node, multiply_node)
96+
pattern.add_edge(multiply_node, add_node)
97+
pattern.add_edge(add_node, squeeze_node)
98+
return pattern

tests/onnx/test_pattern_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
11+
1112
from nncf.common.graph.patterns import HWFusedPatternNames
13+
from nncf.common.graph.patterns import IgnoredPatternNames
1214
from nncf.common.utils.backend import BackendType
1315
from tests.shared.patterns import check_hw_patterns
1416
from tests.shared.patterns import check_ignored_patterns
@@ -25,7 +27,6 @@
2527
HWFusedPatternNames.SE_BLOCK: "Not relevant for ONNX.",
2628
HWFusedPatternNames.SOFTMAX_DIV: "Not relevant for ONNX.",
2729
HWFusedPatternNames.EQUAL_LOGICALNOT: "Not relevant for ONNX.",
28-
HWFusedPatternNames.FC_BN_HSWISH_ACTIVATION: "Not relevant for ONNX.",
2930
HWFusedPatternNames.HSWISH_ACTIVATION: "Not relevant for ONNX.",
3031
HWFusedPatternNames.HSWISH_ACTIVATION_V2: "Not relevant for ONNX.",
3132
HWFusedPatternNames.HSWISH_ACTIVATION_WITHOUT_DENOMINATOR: "Not relevant for ONNX.",
@@ -52,7 +53,9 @@
5253
HWFusedPatternNames.LINEAR_ACTIVATIONS_UNSQUEEZE_BN_SQUEEZE: "Not relevant for ONNX.",
5354
}
5455

55-
IGNORING_IGNORED_PATTERN_REASONS = {}
56+
IGNORING_IGNORED_PATTERN_REASONS = {
57+
IgnoredPatternNames.FC_BN_HSWISH_ACTIVATION: "Not relevant for ONNX.",
58+
}
5659

5760

5861
def test_pattern_manager():

tests/torch/test_pattern_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
11+
1112
from nncf.common.graph.patterns import HWFusedPatternNames
13+
from nncf.common.graph.patterns import IgnoredPatternNames
1214
from nncf.common.utils.backend import BackendType
1315
from tests.shared.patterns import check_hw_patterns
1416
from tests.shared.patterns import check_ignored_patterns
@@ -17,7 +19,6 @@
1719
HWFusedPatternNames.ADD_SCALE_SHIFT_OUTPUT: "Not relevant for Torch.",
1820
HWFusedPatternNames.BATCH_INDEX: "Not relevant for Torch.",
1921
HWFusedPatternNames.EQUAL_LOGICALNOT: "Not relevant for Torch.",
20-
HWFusedPatternNames.FC_BN_HSWISH_ACTIVATION: "Not relevant for Torch.",
2122
HWFusedPatternNames.LINEAR_WITH_BIAS: "Not relevant for Torch.",
2223
HWFusedPatternNames.MVN_SCALE_SHIFT: "Not relevant for Torch.",
2324
HWFusedPatternNames.NORMALIZE_L2_MULTIPLY: "Not relevant for Torch.",
@@ -66,7 +67,9 @@
6667
HWFusedPatternNames.LINEAR_ACTIVATIONS_UNSQUEEZE_BN_SQUEEZE: "Not relevant for Torch.",
6768
}
6869

69-
IGNORING_IGNORED_PATTERN_REASONS = {}
70+
IGNORING_IGNORED_PATTERN_REASONS = {
71+
IgnoredPatternNames.FC_BN_HSWISH_ACTIVATION: "Not relevant for Torch.",
72+
}
7073

7174

7275
def test_pattern_manager():

0 commit comments

Comments
 (0)