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

[PTQ][OV] Fix inplace statistic reducers names and hashes #1796

Conversation

daniil-lyakhov
Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov commented May 10, 2023

Changes

  • Names of reducers is used instead of types of reducers to name statistic subnet operations
  • Reducer names now differs one from another if they have different attributes and aren't merged
  • Hash of reducer now take into account reduction_shape

Reason for changes

To fix problem when two different statistics that are instances of one class and share target point have equal name

Related tickets

109989

Tests

TODO:

  • Add test on reducers merging
  • Add test with a model that have target point with two different reducers that are instances of one class

@github-actions github-actions bot added experimental NNCF OpenVINO Pull requests that updates NNCF OpenVINO labels May 10, 2023
@daniil-lyakhov daniil-lyakhov force-pushed the dl/ov/fix_names_in_inplace_stats branch from e1b3883 to 52f5100 Compare May 11, 2023 07:42
@github-actions github-actions bot added NNCF Common Pull request that updates NNCF Common NNCF ONNX Pull requests that updates NNCF ONNX NNCF PT Pull requests that updates NNCF PyTorch labels May 11, 2023
@daniil-lyakhov daniil-lyakhov marked this pull request as ready for review May 11, 2023 09:01
@daniil-lyakhov daniil-lyakhov force-pushed the dl/ov/fix_names_in_inplace_stats branch 3 times, most recently from 7981448 to 15c38fa Compare May 11, 2023 09:06
@daniil-lyakhov
Copy link
Collaborator Author

Conformance tests showed no regressions

@@ -39,6 +39,7 @@ def __init__(self, reduction_shape: Optional[ReductionShape] = None, inplace: bo

"""
self._reduction_shape = reduction_shape
self._init_reduction_shape = reduction_shape
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the difference between self._reduction_shape and self._init_reduction_shape? They have the same value, as I can see.

Copy link
Collaborator Author

@daniil-lyakhov daniil-lyakhov May 15, 2023

Choose a reason for hiding this comment

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

The problem is that reduction_shape is needed to calculate reducer hash value to distinguish two different reducer with equal class. In case reduction shape is None at the beginning, it's calculated on first iteration

if self._reduction_shape is None:
self._reduction_shape = tuple(range(len(x[0].shape)))
so, reducer hash during registration and reducer hash after first iteration are different, so maps inside TensorCollector will be invalid after the first iteration. This _init_reduction_shape doesn't change during reducer life so it's safe for hash calculation

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like if reduction_shape is None than the reducer should reduce by all dimensions. I suggest to implement this logic in each reducer not in the base class. You can implement the method to create reduction shape by tensor and use it in any inhered class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, please check

@daniil-lyakhov daniil-lyakhov force-pushed the dl/ov/fix_names_in_inplace_stats branch from 16d18e8 to e9f9c8d Compare May 15, 2023 13:45
@@ -39,6 +39,7 @@ def __init__(self, reduction_shape: Optional[ReductionShape] = None, inplace: bo

"""
self._reduction_shape = reduction_shape
self._init_reduction_shape = reduction_shape
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like if reduction_shape is None than the reducer should reduce by all dimensions. I suggest to implement this logic in each reducer not in the base class. You can implement the method to create reduction shape by tensor and use it in any inhered class.

nncf/openvino/statistics/collectors.py Show resolved Hide resolved
@daniil-lyakhov
Copy link
Collaborator Author

Full check showed on regression on this PR, it safe to merge it to develop and release

Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

LGTM

@alexsu52 alexsu52 merged commit b07b652 into openvinotoolkit:develop May 17, 2023
KodiaqQ pushed a commit that referenced this pull request May 19, 2023
…1827)

Copy of #1796 

### Changes
Names of reducers is used instead of types of reducers to name statistic
subnet operations
Reducer names now differs one from another if they have different
attributes and aren't merged
Hash of reducer now take into account reduction_shape

### Reason for changes
To fix problem when two different statistics that are instances of one
class and share target point have equal name

### Related tickets
109989

### Tests

Test on reducers merging
Test with a model that have target point with two different reducers
that are instances of one class

---------

Co-authored-by: Nikita Savelyev <nikita.savelyev@intel.com>
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 ONNX Pull requests that updates NNCF ONNX NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants