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

Tensor for PTQ #2058

Merged
merged 50 commits into from
Oct 9, 2023
Merged

Conversation

AlexanderDokuchaev
Copy link
Collaborator

@AlexanderDokuchaev AlexanderDokuchaev commented Aug 18, 2023

Changes

  • Update MinMax and FastBiasCorrection to use common Tensor.
  • Remove converting torch -> numpy -> torch of data.
  • FakeQuantizeParameters collect data wrapped by tensor.
  • Add support cuda for torch backend.
  • Add new functions for Tensor:
    • stack
    • unstack
    • moveaxis
    • mean
    • round
  • Removed __all__ from function.py, it's works like default behavior.
  • Add statistical_functions.py for high level functions that used only function from functions.py and have no backend specific implementations:
    • mean_per_channel
  • Disable warnings for divide operators of numpy

Related tickets

113315

Tests

@AlexanderDokuchaev AlexanderDokuchaev requested a review from a team as a code owner August 18, 2023 00:45
@github-actions github-actions bot added NNCF PT Pull requests that updates NNCF PyTorch experimental NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF ONNX Pull requests that updates NNCF ONNX NNCF PTQ Pull requests that updates NNCF PTQ labels Aug 18, 2023
@vshampor vshampor added the API Public API-impacting changes label Aug 18, 2023
@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Merging #2058 (d5de2a4) into develop (eaddf18) will increase coverage by 0.19%.
Report is 9 commits behind head on develop.
The diff coverage is 83.43%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2058      +/-   ##
===========================================
+ Coverage    36.13%   36.33%   +0.19%     
===========================================
  Files          480      480              
  Lines        42998    43223     +225     
===========================================
+ Hits         15539    15703     +164     
- Misses       27459    27520      +61     
Files Coverage Δ
.../common/tensor_statistics/statistical_functions.py 100.00% <100.00%> (ø)
nncf/experimental/tensor/numpy_functions.py 100.00% <100.00%> (ø)
nncf/experimental/tensor/tensor.py 98.03% <100.00%> (+0.10%) ⬆️
nncf/onnx/quantization/quantizer_parameters.py 88.88% <100.00%> (ø)
...ation/algorithms/fast_bias_correction/algorithm.py 91.54% <100.00%> (+0.70%) ⬆️
...ization/algorithms/fast_bias_correction/backend.py 100.00% <100.00%> (ø)
...on/algorithms/fast_bias_correction/onnx_backend.py 97.05% <100.00%> (-0.59%) ⬇️
...cf/quantization/algorithms/min_max/onnx_backend.py 99.23% <100.00%> (ø)
...uantization/algorithms/min_max/openvino_backend.py 0.00% <ø> (ø)
nncf/experimental/tensor/functions.py 99.24% <98.24%> (-0.76%) ⬇️
... and 6 more

... and 15 files with indirect coverage changes

def squeeze(a: TTensor, axis: Optional[Union[int, Tuple[int]]] = None) -> TTensor:
def squeeze(a: TTensor, axis: Optional[Union[int, Tuple[int]]] = None) -> Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please explain why do you change this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Functions in this file always return Tensor or list of Tensor

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is not entirely correct. I mean these functions return a Tensor object only if there is no registered version for the type of the passed argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update all return type to Tensor to correctly works "pop-up suggestions" (or how it names when editor suggest functions by first symbols?).
So set Tensor type to first argument. But not sure about second, added like Union[torch.Tensor, float], because it can be used like torch.tensor(1) + 1 or fns.min(torch.tensor(1), 0). May be do you have anny suugestion about it?

@@ -223,7 +245,7 @@ def input_filter_func(point):
node_name, input_filter_func, self._algorithm_key
):
statistics = tensor_collector.get_statistics()
input_fp.extend(statistics.mean_values)
input_fp.extend(Tensor(statistics.mean_values))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the tensor_collector should return already wrapped tensor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but i dont want to refactor all in one PR. In this PR fixed ptq for cuda and shows how to use Tensor on real code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO, we should provide the changes in case of UX improvements or developing/code support improvements.
Providing changes only for demonstration is not good.
So, this is why I still can't understand why should we add a new wrapper for all tensors in this PR.

@AlexanderDokuchaev
Copy link
Collaborator Author

post_training_quantization/141/

@AlexanderDokuchaev
Copy link
Collaborator Author

post_training_quantization/159

Copy link
Collaborator

@KodiaqQ KodiaqQ left a comment

Choose a reason for hiding this comment

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

One of the major changes that are not clear:

  • Why shouldn't we place all tensor-related entities in the one namespace (Tensor, functions);
  • Why the one algorithm updated with the Tensor and the others are not;
  • Why the developers should use multiple imports to start working with the Tensor instead of import numpy as np.

Comment on lines 30 to 32
from nncf.experimental.common.tensor_statistics import statistical_functions as s_fns
from nncf.experimental.tensor import Tensor
from nncf.experimental.tensor import functions as fns
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still don't get when the fns and s_fns would be merged.

nncf/experimental/tensor/__init__.py Outdated Show resolved Hide resolved
Comment on lines 30 to 32
from nncf.experimental.common.tensor_statistics import statistical_functions as s_fns
from nncf.experimental.tensor import Tensor
from nncf.experimental.tensor import functions as fns
Copy link
Contributor

Choose a reason for hiding this comment

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

What is reason to merge them?

@vshampor vshampor self-requested a review October 4, 2023 14:21
Copy link
Contributor

@vshampor vshampor left a comment

Choose a reason for hiding this comment

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

I'd like to see the _dispatch_list improved as directed - after that I don't see major blockers for merging this PR (other than the already visible deficiencies of this approach code-wise as compared to the proper OOP approach)

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.

Please, address my minor comment

@alexsu52 alexsu52 merged commit bbb7e56 into openvinotoolkit:develop Oct 9, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Public API-impacting changes documentation Improvements or additions to documentation experimental NNCF ONNX Pull requests that updates NNCF ONNX NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch NNCF PTQ Pull requests that updates NNCF PTQ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants