Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NNCF] (#3249) Remove backend-specific methods from common layer attributes #3287

Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
868335b
[NNCF] Add get_weight_shape_legacy function (#3249)
shumaari Feb 16, 2025
f04a525
[NNCF] Add get_target_dim_for_compression_legacy function (#3249)
shumaari Feb 17, 2025
a94e2a1
[NNCF] Add get_bias_shape_legacy function (#3249)
shumaari Feb 17, 2025
e0db330
[NNCF] Experimental torch backend: Replace (#3249)
shumaari Feb 16, 2025
433ff6b
[NNCF] Experimental tensorflow backend: Replace (#3249)
shumaari Feb 16, 2025
e437274
[NNCF] Experimental common backend: Replace (#3249)
shumaari Feb 16, 2025
39efbbd
[NNCF] Torch backend: Replace (#3249)
shumaari Feb 17, 2025
eb7905f
[NNCF] Remove backend-specific methods from common layer attributes
shumaari Feb 17, 2025
58d5112
[NNCF] Missing import statements in utils.py
shumaari Feb 18, 2025
bdd8b61
[NNCF] Remove abstract methods from common layer attributes
shumaari Feb 21, 2025
6c3e101
[NNCF] Add get_num_filters_legacy function
shumaari Feb 21, 2025
53f1ede
[NNCF] Replace get_num_filters: experimental torch backend
shumaari Feb 21, 2025
948ae9f
[NNCF] Remove get_num_filters from common layer attributes
shumaari Feb 21, 2025
0425fbb
[NNCF] Update get_weight_shape_legacy function
shumaari Feb 21, 2025
b6f3a39
[NNCF] Update get_target_dim_for_compression_legacy function
shumaari Feb 21, 2025
02ecd45
[NNCF] Update get_bias_shape_legacy function
shumaari Feb 21, 2025
907f35f
Formatting changes due black and isort
shumaari Feb 21, 2025
b70c03a
Merge branch 'openvinotoolkit:develop' into 3249__remove_backend_spec…
shumaari Feb 22, 2025
d4493d5
[NNCF] Replace calls: Torch backend
shumaari Feb 23, 2025
c24ac61
Implement suggested changes in doc strings
shumaari Feb 24, 2025
7de7e8b
Implement suggested refactoring of code
shumaari Feb 24, 2025
0377d87
Implement suggested changes
shumaari Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[NNCF] Experimental torch backend: Replace (#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_bias_shape ->
get_bias_shape_legacy(layer_attributes: WeightedLayerAttributes)

Locations in /nncf/experimental/torch/sparsity/movement/ folder
  - layers.py
  - structured_mask_handler.py

Reason for changes:

(#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
shumaari committed Feb 17, 2025
commit e0db33022cb7b12553061312503af4b37388b31a
6 changes: 4 additions & 2 deletions nncf/experimental/torch/sparsity/movement/layers.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@

import nncf
from nncf.common.graph import NNCFNode
from nncf.common.graph.utils import get_weight_shape_legacy
from nncf.common.graph.utils import get_bias_shape_legacy
from nncf.experimental.torch.sparsity.movement.functions import binary_mask_by_threshold
from nncf.torch.layer_utils import COMPRESSION_MODULES
from nncf.torch.layer_utils import CompressionParameter
@@ -167,7 +169,7 @@ def __init__(
self._importance_threshold = -math.inf
self._importance_regularization_factor = 0.0

weight_shape: List[int] = target_module_node.layer_attributes.get_weight_shape()
weight_shape: List[int] = get_weight_shape_legacy(target_module_node.layer_attributes)
assert len(weight_shape) == 2, "Unsupported module with weight shape not in 2D."
self.weight_ctx = BinaryMask(weight_shape)
self.sparse_factors = self._get_sparse_factors(weight_shape, sparse_cfg)
@@ -185,7 +187,7 @@ def __init__(
self.weight_ctx.binary_mask = self._calc_training_binary_mask()

if self.prune_bias:
bias_shape = target_module_node.layer_attributes.get_bias_shape()
bias_shape = get_bias_shape_legacy(target_module_node.layer_attributes)
self.bias_ctx = BinaryMask(bias_shape)
bias_importance_shape = weight_importance_shape[0]
self.bias_importance = CompressionParameter(
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@

from nncf.common.graph.graph import NNCFNodeName
from nncf.common.graph.layer_attributes import LinearLayerAttributes
from nncf.common.graph.utils import get_weight_shape_legacy
from nncf.common.graph.utils import get_bias_shape_legacy
from nncf.common.logging import nncf_logger
from nncf.experimental.common.pruning.nodes_grouping import get_pruning_groups
from nncf.experimental.common.pruning.nodes_grouping import select_largest_groups
@@ -209,9 +211,9 @@ def gather_statistics_from_operand(self) -> StructuredMaskContextStatistics:
"""
node = self.sparsifier_operand.target_module_node
assert isinstance(node.layer_attributes, tuple(EXPECTED_NODE_LAYER_ATTRS))
weight_shape: Tuple[int, int] = tuple(node.layer_attributes.get_weight_shape())
weight_shape: Tuple[int, int] = tuple(get_weight_shape_legacy(node.layer_attributes))
bias_shape: Tuple[int] = (
(node.layer_attributes.get_bias_shape(),) if self.sparsifier_operand.prune_bias else (0,)
(get_bias_shape_legacy(node.layer_attributes),) if self.sparsifier_operand.prune_bias else (0,)
)

pruned_weight_shape = list(weight_shape)