Skip to content

Commit 950600a

Browse files
committed
[NNCF] Add get_target_dim_for_compression_legacy function (openvinotoolkit#3249)
Changes: Moved and renamed backend-specific class method from common layer attributes in nncf/common/graph/layer_attributes.py to self-contained function in nncf/common/graph/utils.py - layer_attributes.get_target_dim_for_compression -> get_target_dim_for_compression_legacy(layer_attributes: WeightedLayerAttributes) Reason for changes: (openvinotoolkit#3249) Torch and Tensorflow backend-specific methods need to be removed from common layer attributes and all related calls need to be replaced by their corresponding legacy function calls
1 parent 516e6c5 commit 950600a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

nncf/common/graph/utils.py

+19
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,22 @@ def get_weight_shape_legacy(
159159

160160
if isinstance(layer_attributes, GroupNormLayerAttributes):
161161
return [layer_attributes.num_channels]
162+
163+
164+
def get_target_dim_for_compression_legacy(
165+
layer_attributes: WeightedLayerAttributes) -> int:
166+
"""
167+
Returns hard-coded target dim for compression only for Torch and Tensorflow models.
168+
169+
:param layer_attributes: layer attributes of NNCFNode.
170+
:return: target dim for compression.
171+
"""
172+
if isinstance(layer_attributes, (GenericWeightedLayerAttributes,
173+
LinearLayerAttributes, GroupNormLayerAttributes)):
174+
return 0
175+
176+
if isinstance(layer_attributes, ConvolutionLayerAttributes):
177+
# Always quantize per each "out" channel
178+
if layer_attributes.transpose:
179+
return 1
180+
return 0

0 commit comments

Comments
 (0)