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

Conversation

shumaari
Copy link
Contributor

@shumaari shumaari commented Feb 17, 2025

Changes

  1. Moved and renamed backend-specific class methods from common layer
    attributes in nncf/common/graph/layer_attributes.py to self-contained
    functions in nncf/common/graph/utils.py
  • layer_attributes.get_bias_shape ->
    get_bias_shape_legacy(layer_attributes: WeightedLayerAttributes)
  • layer_attributes.get_num_filters ->
    get_num_filters_legacy(layer_attributes: WeightedLayerAttributes)
  • layer_attributes.get_target_dim_for_compression ->
    get_target_dim_for_compression_legacy(layer_attributes: WeightedLayerAttributes)
  • layer_attributes.get_weight_shape ->
    get_weight_shape_legacy(layer_attributes: WeightedLayerAttributes)
  1. Calls to above class methods were replaced with calls to their
    corresponding legacy functions in the following locations
  • /nncf/experimental/common/ folder
    • pruning/nodes_grouping.py
  • /nncf/experimental/tensorflow/ folder
    • quantization/algorithm.py
  • /nncf/experimental/torch/ folder
    • nas/bootstrapNAS/elasticity/elastic_width.py
    • sparsity/movement/layers.py
    • sparsity/movement/structured_mask_handler.py
  • /nncf/torch/ folder
    • quantization/algo.py
    • quantization/init_range.py
    • sparsity/const/algo.py
    • sparsity/magnitude/algo.py
    • sparsity/rb/algo.py

Reason for changes

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 (resolves #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_weight_shape ->
get_weight_shape_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
…olkit#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
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_bias_shape ->
get_bias_shape_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
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:

(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
Changes:

Call to following class method in
nncf/common/graph/layer_attributes.py was replaced with call to its
corresponding self-contained legacy function in
nncf/common/graph/utils.py:
- layer_attributes.get_weight_shape ->
get_weight_shape_legacy(layer_attributes: WeightedLayerAttributes)

Location in /nncf/experimental/tensorflow/quantization/ folder
  - algorithm.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
Changes:

Call to following class method in
nncf/common/graph/layer_attributes.py was replaced with call to its
corresponding self-contained legacy function in
nncf/common/graph/utils.py:
- layer_attributes.get_target_dim_for_compression ->
get_target_dim_for_compression_legacy(
    layer_attributes: WeightedLayerAttributes)

Locations in /nncf/experimental/common/pruning/
  - nodes_grouping.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
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
@github-actions github-actions bot added NNCF PT Pull requests that updates NNCF PyTorch NNCF Common Pull request that updates NNCF Common experimental labels Feb 17, 2025
Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shumaari, thank you for the contribution! Please remove the redundant get_weights_shape, get_target_dim_for_compression and get_bias_shape methods from the Layer attributes

Changes:

Removed backend-specific class methods from common layer attributes in
nncf/common/graph/layer_attributes.py
- get_weight_shape
- get_target_dim_for_compression
- get_bias_shape

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
@shumaari
Copy link
Contributor Author

@daniil-lyakhov done!

@shumaari shumaari marked this pull request as ready for review February 17, 2025 17:23
@shumaari shumaari requested a review from a team as a code owner February 17, 2025 17:23
Changes:

1. Added missing import statements in nncf/common/graph/utils.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
@shumaari
Copy link
Contributor Author

shumaari commented Feb 18, 2025

@daniil-lyakhov I have added the missing import statements which might fix the error in linter and pytest. Could you please rerun the checks? thank you!

@shumaari shumaari marked this pull request as draft February 18, 2025 06:33
@daniil-lyakhov
Copy link
Collaborator

daniil-lyakhov commented Feb 18, 2025

Removed abstract class methods from common layer attributes in
nncf/common/graph/layer_attributes.py
- get_weight_shape
- get_target_dim_for_compression

Reason for changes:

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
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_num_filters ->
get_num_filters_legacy(layer_attributes: WeightedLayerAttributes)

Reason for changes:

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
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_num_filters ->
get_num_filters_legacy(layer_attributes: WeightedLayerAttributes)

Locations in
/nncf/experimental/torch/nas/bootstrapNAS/elasticity/ folder
  - elastic_width.py

Reason for changes:

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
Removed backend-specific class method from common layer attributes in
nncf/common/graph/layer_attributes.py
- get_num_filters

Reason for changes:

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
Refactoring and formatting changes

Reason for changes:

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
Refactoring and formatting changes

Reason for changes:

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
Refactoring and formatting changes

Reason for changes:

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
Copy link
Contributor Author

@daniil-lyakhov I have made some changes, could you please check again?

Thank you so much for the hand-holding! :)

@shumaari
Copy link
Contributor Author

shumaari commented Feb 21, 2025

@daniil-lyakhov could you please clarify which option is correct:

  1. Removing back-end specific methods means that layer_attributes file should not contain any class methods (as it is after my commits), which implies wherever these methods are being called (directly or indirectly) need to be replaced by legacy calls.

  2. Some class methods have been incorrectly removed and need to be restored.

Thank you

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/ folder
  - quantization/algo.py
  - sparsity/const/algo.py
  - sparsity/magnitude/algo.py
  - sparsity/rb/algo.py

Reason for changes:

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
Copy link
Contributor Author

@daniil-lyakhov I have made some changes, could you please check once more? Thank you!

@shumaari
Copy link
Contributor Author

@daniil-lyakhov Thanks for the feedback, changes are done.

Is there anything else required before merging?

@shumaari shumaari marked this pull request as ready for review February 24, 2025 14:45
Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shumaari, thank you for your updates! Please address my last minor comments and convert PR to a non draft one. I'll start review process with the NNCF team

@daniil-lyakhov daniil-lyakhov self-requested a review February 24, 2025 15:34
@shumaari
Copy link
Contributor Author

@daniil-lyakhov Thank you for all your help!

I would like to work on another issue, please let me know which one. 👍

@daniil-lyakhov
Copy link
Collaborator

@ljaljushkin, @AlexanderDokuchaev, please share your opinion on this PR

Copy link
Contributor

@ljaljushkin ljaljushkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AlexanderDokuchaev AlexanderDokuchaev merged commit 7996e73 into openvinotoolkit:develop Feb 25, 2025
17 checks passed
shumaari added a commit to shumaari/nncf that referenced this pull request Mar 8, 2025
…mmon layer attributes (openvinotoolkit#3287)

### Changes

1. Moved and renamed backend-specific class methods from common layer
attributes in nncf/common/graph/layer_attributes.py to self-contained 
functions in nncf/common/graph/utils.py
- layer_attributes.get_bias_shape -> 
get_bias_shape_legacy(layer_attributes: WeightedLayerAttributes)
- layer_attributes.get_num_filters ->
get_num_filters_legacy(layer_attributes: WeightedLayerAttributes)
- layer_attributes.get_target_dim_for_compression -> 
get_target_dim_for_compression_legacy(layer_attributes:
WeightedLayerAttributes)
- layer_attributes.get_weight_shape -> 
get_weight_shape_legacy(layer_attributes: WeightedLayerAttributes)


2. Calls to above class methods were replaced with calls to their
corresponding legacy functions in the following locations
- /nncf/experimental/common/ folder
  - pruning/nodes_grouping.py
- /nncf/experimental/tensorflow/ folder
  - quantization/algorithm.py
- /nncf/experimental/torch/ folder
  - nas/bootstrapNAS/elasticity/elastic_width.py
  - sparsity/movement/layers.py
  - sparsity/movement/structured_mask_handler.py
- /nncf/torch/ folder
  - quantization/algo.py
  - quantization/init_range.py
  - sparsity/const/algo.py
  - sparsity/magnitude/algo.py
  - sparsity/rb/algo.py


### Reason for changes

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 (resolves openvinotoolkit#3249)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental NNCF Common Pull request that updates NNCF Common NNCF PT Pull requests that updates NNCF PyTorch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Good First Issue][NNCF]: Remove backend-specific methods from the common layer attributes
4 participants