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

[Torch][PTQ] Examples are updated for the new PTQ TORCH backend #2246

Conversation

daniil-lyakhov
Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov commented Nov 3, 2023

Changes

  • Do not filter constant nodes for torch backend in the inference graph
  • Fix version in requarements.txt for examples of post_training_quantization
    • for ssd300_vgg16 is not available to use torch 2.1.0 (failed on export to onnx Unsupported: ONNX export of operator get_pool_ceil_padding, tracing is not supporting too)
    • Update metrics
  • Add to PTEngine convert inputs to model's device to sync behavior with create_compress_model
  • Mobilenet_v2 example converting PyTorch model to IR by tracing (without onnx).
  • nncf.quantize for PyTorch works with copy of the target model

Reason for changes

To make PTQ work properly with disconnected graphs (like in example)

Related tickets

124417

Tests

test_examples build 128

@daniil-lyakhov daniil-lyakhov requested a review from a team as a code owner November 3, 2023 15:57
@github-actions github-actions bot added the NNCF PTQ Pull requests that updates NNCF PTQ label Nov 3, 2023
@daniil-lyakhov daniil-lyakhov force-pushed the dl/torch/fix_splitted_inference_graph branch from 7ffdcf7 to f921950 Compare November 3, 2023 16:01
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Merging #2246 (abe39aa) into develop (074e749) will decrease coverage by 4.80%.
Report is 4 commits behind head on develop.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2246      +/-   ##
===========================================
- Coverage    90.71%   85.92%   -4.80%     
===========================================
  Files          485      485              
  Lines        43632    43679      +47     
===========================================
- Hits         39582    37531    -2051     
- Misses        4050     6148    +2098     
Flag Coverage Δ
COMMON 15.75% <0.00%> (-0.02%) ⬇️
ONNX ?
OPENVINO 38.58% <16.66%> (+0.03%) ⬆️
TENSORFLOW 30.03% <0.00%> (-0.03%) ⬇️
TORCH 62.72% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
nncf/quantization/algorithms/min_max/algorithm.py 98.12% <ø> (-0.81%) ⬇️
nncf/quantization/passes.py 98.70% <100.00%> (+0.01%) ⬆️
nncf/torch/engine.py 100.00% <100.00%> (ø)
nncf/torch/quantization/quantize_model.py 92.85% <100.00%> (-2.86%) ⬇️

... and 47 files with indirect coverage changes

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.

What is the reason for the disconnectedness of the graph?

@github-actions github-actions bot added the NNCF PT Pull requests that updates NNCF PyTorch label Nov 6, 2023
@daniil-lyakhov daniil-lyakhov changed the title [Torch][InferenceGraph] Do not filter constant nodes for torch backend [Torch][PTQ] Examples are updated for the new PTQ TORCH backend Nov 6, 2023
@daniil-lyakhov
Copy link
Collaborator Author

What is the reason for the disconnectedness of the graph?

Ticket 124397

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

Copy link
Collaborator

@nikita-savelyevv nikita-savelyevv left a comment

Choose a reason for hiding this comment

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

Good job improving nncf examples 👍 Minor comments from my side

@daniil-lyakhov daniil-lyakhov force-pushed the dl/torch/fix_splitted_inference_graph branch from a6bf44f to 5c0ab0b Compare November 7, 2023 14:12
@@ -540,6 +540,7 @@ def _get_quantization_target_points(
self._backend_entity.shapeof_metatypes,
self._backend_entity.dropout_metatypes,
self._backend_entity.read_variable_metatypes,
nncf_graph_contains_constants=backend != BackendType.TORCH,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to note that we introduce backend-specific logic into a common part of the PTQ, which does not fit with our approach. Do you agree with that @alexsu52, @AlexanderDokuchaev, @nikita-savelyevv?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree. @daniil-lyakhov Could you update filter_constant_nodes pass for discontinuous graphs?

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

Copy link
Collaborator Author

@daniil-lyakhov daniil-lyakhov Nov 8, 2023

Choose a reason for hiding this comment

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

I tried implementation we discussed db0ad8d, but found a corner case that is breaking the pass:
Graph
Before pass:
image
Expected after pass:
image
Actual after pass:
image
That's because convolution node should be an input node to survive filtering, but we have no prior information yet that can help us to mark this convolution as an input node

@github-actions github-actions bot added NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF ONNX Pull requests that updates NNCF ONNX labels Nov 8, 2023
@daniil-lyakhov daniil-lyakhov force-pushed the dl/torch/fix_splitted_inference_graph branch from 87c8d95 to db0ad8d Compare November 8, 2023 13:10
@github-actions github-actions bot added NNCF Common Pull request that updates NNCF Common and removed NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF ONNX Pull requests that updates NNCF ONNX labels Nov 8, 2023
@daniil-lyakhov
Copy link
Collaborator Author

daniil-lyakhov commented Nov 8, 2023

Torch precommit is failing due to problems in e00f6b7, ticket 124679

@alexsu52 alexsu52 merged commit 1493149 into openvinotoolkit:develop Nov 10, 2023
daniil-lyakhov added a commit to daniil-lyakhov/nncf that referenced this pull request Nov 10, 2023
…vinotoolkit#2246)

- Do not filter constant nodes for torch backend in the inference graph
- Fix version in requarements.txt for examples of
post_training_quantization
- for ssd300_vgg16 is not available to use torch 2.1.0 (failed on export
to onnx Unsupported: ONNX export of operator get_pool_ceil_padding,
tracing is not supporting too)
    - Update metrics
- Add to PTEngine convert inputs to model's device to sync behavior with
`create_compress_model`
- Mobilenet_v2 example converting PyTorch model to IR by tracing
(without onnx).
- nncf.quantize for PyTorch works with copy of the target model

To make PTQ work properly with disconnected graphs (like in
[example](https://github.com/openvinotoolkit/nncf/blob/develop/examples/post_training_quantization/torch/ssd300_vgg16/main.py))

124417

test_examples build 128

---------

Co-authored-by: Alexander Dokuchaev <alexander.dokuchaev@intel.com>
alexsu52 pushed a commit that referenced this pull request Mar 21, 2024
### Changes

Update accuracy drop reference value. 

### Reason for changes

In #2246 reference accuracy values for original and quantized models
were updated, but the corresponding accuracy drop reference value was
not updated.

### Related tickets

136123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NNCF Common Pull request that updates NNCF Common 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