Skip to content

Commit 207ded9

Browse files
committed
[NNCF] Torch backend: Replace (openvinotoolkit#3249)
Changes: Calls to following class methods in nncf/common/graph/layer_attributes.py were replaced with calls to their corresponding self-contained legacy functions in nncf/common/graph/utils.py: - layer_attributes.get_weight_shape -> get_weight_shape_legacy(layer_attributes: WeightedLayerAttributes) - layer_attributes.get_target_dim_for_compression -> get_target_dim_for_compression_legacy( layer_attributes: WeightedLayerAttributes) Locations in /nncf/torch/quantization folder - algo.py - init_range.py 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 b37408f commit 207ded9

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

nncf/torch/quantization/algo.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
from nncf.common.graph.patterns.manager import TargetDevice
3636
from nncf.common.graph.transformations.commands import TargetType
3737
from nncf.common.graph.utils import get_first_nodes_of_type
38+
from nncf.common.graph.utils import get_weight_shape_legacy
39+
from nncf.common.graph.utils import get_target_dim_for_compression_legacy
3840
from nncf.common.hardware.config import HWConfig
3941
from nncf.common.hardware.config import HWConfigType
4042
from nncf.common.hardware.config import get_hw_config_type
@@ -773,10 +775,10 @@ def _get_quantizer_setup(self, target_model: NNCFNetwork) -> PTQuantizerSetup:
773775
layer_attributes = target_node.layer_attributes
774776
assert isinstance(layer_attributes, WeightedLayerAttributes)
775777
scale_shape = get_scale_shape(
776-
layer_attributes.get_weight_shape(),
778+
get_weight_shape_legacy(layer_attributes),
777779
is_weights=True,
778780
per_channel=qconfig.per_channel,
779-
channel_idx=layer_attributes.get_target_dim_for_compression(),
781+
channel_idx=get_target_dim_for_compression_legacy(layer_attributes),
780782
)
781783
else:
782784
input_shape = target_model_graph.get_input_shape_for_insertion_point(insertion_point)
@@ -1182,7 +1184,7 @@ def is_weights(ip: PTTargetPoint) -> bool:
11821184
)
11831185
module_node = target_model_graph.get_node_by_name(primary_ip.target_node_name)
11841186
layer_attributes = module_node.layer_attributes
1185-
input_shape = layer_attributes.get_weight_shape()
1187+
input_shape = get_weight_shape_legacy(layer_attributes)
11861188
self._quantizers_input_shapes[primary_qid] = tuple(input_shape)
11871189
else:
11881190
primary_qid = NonWeightQuantizerId(primary_ip.target_node_name, primary_ip.input_port_id)

nncf/torch/quantization/init_range.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import nncf
2020
from nncf.common.graph.layer_attributes import WeightedLayerAttributes
21+
from nncf.common.graph.utils import get_weight_shape_legacy
22+
from nncf.common.graph.utils import get_target_dim_for_compression_legacy
2123
from nncf.common.quantization.initialization.range import RangeInitCollectorParams
2224
from nncf.common.quantization.initialization.range import RangeInitConfig
2325
from nncf.common.quantization.initialization.range import RangeInitParams
@@ -226,8 +228,8 @@ def get_all_scale_shapes_with_params(
226228
module_node = target_nncf_graph.get_node_by_name(qp.insertion_point.target_node_name)
227229
layer_attributes = module_node.layer_attributes
228230
assert isinstance(layer_attributes, WeightedLayerAttributes)
229-
input_shape = layer_attributes.get_weight_shape()
230-
channel_idx = layer_attributes.get_target_dim_for_compression()
231+
input_shape = get_weight_shape_legacy(layer_attributes)
232+
channel_idx = get_target_dim_for_compression_legacy(layer_attributes)
231233
else:
232234
input_shape = target_nncf_graph.get_input_shape_for_insertion_point(qp.insertion_point)
233235
channel_idx = 1 # channel dim for activations

0 commit comments

Comments
 (0)