Skip to content

Commit

Permalink
[PTQ] Update get_conv_weights_layout method (openvinotoolkit#2442)
Browse files Browse the repository at this point in the history
### Changes

- Updated `get_conv_weights_layout` to prevent linked list
incrementation;

### Reason for changes

- Failed tests;

### Related tickets

- 131207

### Tests

- Should be tested with the newest `pytest` version;

---------

Co-authored-by: dlyakhov <daniil.lyakhov@intel.com>
  • Loading branch information
KodiaqQ and daniil-lyakhov authored Feb 1, 2024
1 parent bdeef8d commit bea1bfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions nncf/openvino/graph/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class OVLayoutElem(Enum):


_CONV_BASE_CONST_LAYOUT = {
OVConvolutionMetatype: [OVLayoutElem.C_OUT, OVLayoutElem.C_IN],
OVConvolutionBackpropDataMetatype: [OVLayoutElem.C_IN, OVLayoutElem.C_OUT],
OVDepthwiseConvolutionMetatype: [OVLayoutElem.GROUPS, OVLayoutElem.C_OUT, OVLayoutElem.C_IN],
OVGroupConvolutionMetatype: [OVLayoutElem.GROUPS, OVLayoutElem.C_OUT, OVLayoutElem.C_IN],
OVGroupConvolutionBackpropDataMetatype: [OVLayoutElem.GROUPS, OVLayoutElem.C_IN, OVLayoutElem.C_OUT],
OVConvolutionMetatype: (OVLayoutElem.C_OUT, OVLayoutElem.C_IN),
OVConvolutionBackpropDataMetatype: (OVLayoutElem.C_IN, OVLayoutElem.C_OUT),
OVDepthwiseConvolutionMetatype: (OVLayoutElem.GROUPS, OVLayoutElem.C_OUT, OVLayoutElem.C_IN),
OVGroupConvolutionMetatype: (OVLayoutElem.GROUPS, OVLayoutElem.C_OUT, OVLayoutElem.C_IN),
OVGroupConvolutionBackpropDataMetatype: (OVLayoutElem.GROUPS, OVLayoutElem.C_IN, OVLayoutElem.C_OUT),
}


Expand Down Expand Up @@ -85,9 +85,9 @@ def get_conv_weights_layout(ov_metatype: OVOpMetatype, weights_shape: Tuple[int,
:param weights_shape: Shape of the target convolution node weight.
:return: Target convolution node weights layout.
"""
weights_layout = _CONV_BASE_CONST_LAYOUT[ov_metatype]
kernel_size = weights_shape[len(weights_layout) :]
weights_layout += [OVLayoutElem.SPATIAL] * len(kernel_size)
base_layout = _CONV_BASE_CONST_LAYOUT[ov_metatype]
kernel_size = weights_shape[len(base_layout) :]
weights_layout = list(base_layout) + [OVLayoutElem.SPATIAL] * len(kernel_size)
return tuple(weights_layout)


Expand Down
10 changes: 6 additions & 4 deletions tests/openvino/native/test_layer_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,14 @@ def test_layer_attributes(test_descriptor: LayerAttributesTestCase):
@pytest.mark.parametrize("test_descriptor", TEST_CASES_CONV)
def test_get_conv_weights_layout_from_node(test_descriptor: LayerAttributesTestCase):
node = _get_node_to_test(test_descriptor)
weights_layout = get_conv_weights_layout_from_node(node)
assert weights_layout == test_descriptor.ref_weights_layout
for _ in range(2): # To test get_conv_weights_layout_from_node is a clean function
weights_layout = get_conv_weights_layout_from_node(node)
assert weights_layout == test_descriptor.ref_weights_layout


@pytest.mark.parametrize("test_descriptor", TEST_CASES_LINEAR)
def test_get_linear_weights_layout_from_node(test_descriptor: LayerAttributesTestCase):
node = _get_node_to_test(test_descriptor)
weights_layout = get_linear_weights_layout_from_node(node)
assert weights_layout == test_descriptor.ref_weights_layout
for _ in range(2): # To test get_linear_weights_layout_from_node is a clean function
weights_layout = get_linear_weights_layout_from_node(node)
assert weights_layout == test_descriptor.ref_weights_layout

0 comments on commit bea1bfc

Please sign in to comment.