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][Torch][KQV self attention] Align FQ placement between OV and Torch backend #2166

Merged

Conversation

daniil-lyakhov
Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov commented Sep 29, 2023

Changes

  • "unbing" and "matmul" ops are added to torch patterns
  • Dropout removing pass is added to function transform_to_inference_graph
  • LayerNorm and GroupNorm metatypes are added to ignored metatypes in MinMax algorithm

Reason for changes

To align quantization placement between OV and Torch backends for the following models:

  • timm/crossvit_9_240
  • timm/deit3_small_patch16_224
  • timm/swin_base_patch4_window7_224

Related tickets

121647

Tests

  • test_metatypes_to_ignore for quantization propagation solver

@github-actions github-actions bot added the NNCF PT Pull requests that updates NNCF PyTorch label Sep 29, 2023
@codecov
Copy link

codecov bot commented Sep 29, 2023

Codecov Report

Merging #2166 (ce14175) into develop (5150867) will increase coverage by 0.05%.
Report is 2 commits behind head on develop.
The diff coverage is 73.43%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2166      +/-   ##
===========================================
+ Coverage    36.62%   36.67%   +0.05%     
===========================================
  Files          486      486              
  Lines        43373    43417      +44     
===========================================
+ Hits         15885    15923      +38     
- Misses       27488    27494       +6     
Files Coverage Δ
nncf/common/graph/graph.py 74.92% <100.00%> (+0.81%) ⬆️
nncf/quantization/algorithms/min_max/algorithm.py 95.30% <ø> (ø)
nncf/quantization/algorithms/min_max/backend.py 100.00% <100.00%> (ø)
...cf/quantization/algorithms/min_max/onnx_backend.py 99.25% <100.00%> (+0.01%) ⬆️
nncf/quantization/passes.py 92.85% <100.00%> (+2.38%) ⬆️
nncf/torch/quantization/ignored_patterns.py 0.00% <0.00%> (ø)
...f/quantization/algorithms/min_max/torch_backend.py 0.00% <0.00%> (ø)
...uantization/algorithms/min_max/openvino_backend.py 0.00% <0.00%> (ø)

@github-actions github-actions bot added the NNCF PTQ Pull requests that updates NNCF PTQ label Oct 4, 2023
@daniil-lyakhov daniil-lyakhov force-pushed the dl/torch/patterns_alignment branch from 7abfdaf to 9698e6c Compare October 4, 2023 11:52
@daniil-lyakhov daniil-lyakhov marked this pull request as ready for review October 5, 2023 09:19
@daniil-lyakhov daniil-lyakhov requested a review from a team as a code owner October 5, 2023 09:19
@daniil-lyakhov daniil-lyakhov changed the title [PTQ][Torch] Align FQ placement between OV and Torch backend [PTQ][Torch][CrossVIT model] Align FQ placement between OV and Torch backend Oct 5, 2023
@AlexanderDokuchaev
Copy link
Collaborator

Please run post_training build and update metrics if needed.

@github-actions github-actions bot added NNCF Common Pull request that updates NNCF Common NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF ONNX Pull requests that updates NNCF ONNX labels Oct 6, 2023
@daniil-lyakhov daniil-lyakhov force-pushed the dl/torch/patterns_alignment branch 2 times, most recently from b7816df to c6dcc08 Compare October 6, 2023 16:26
@daniil-lyakhov
Copy link
Collaborator Author

PTQ conformance test finished successfully (build 175), metrics are updated accordingly

@daniil-lyakhov daniil-lyakhov changed the title [PTQ][Torch][CrossVIT model] Align FQ placement between OV and Torch backend [PTQ][Torch] Align FQ placement between OV and Torch backend Oct 11, 2023
@daniil-lyakhov daniil-lyakhov changed the title [PTQ][Torch] Align FQ placement between OV and Torch backend [PTQ][Torch][KQV self attention] Align FQ placement between OV and Torch backend Oct 11, 2023
@daniil-lyakhov daniil-lyakhov force-pushed the dl/torch/patterns_alignment branch from 9f6ebe0 to 9837d2b Compare October 12, 2023 07:04
nncf/common/graph/graph.py Show resolved Hide resolved
nncf/quantization/algorithms/accuracy_control/ranker.py Outdated Show resolved Hide resolved
nncf/quantization/algorithms/accuracy_control/ranker.py Outdated Show resolved Hide resolved
nncf/quantization/passes.py Outdated Show resolved Hide resolved
nncf/quantization/passes.py Outdated Show resolved Hide resolved
nncf/quantization/passes.py Outdated Show resolved Hide resolved
tests/common/quantization/test_passes.py Outdated Show resolved Hide resolved
tests/post_training/test_templates/test_ptq_params.py Outdated Show resolved Hide resolved
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, please consider avoiding valuable useless refactoring in PR.

@daniil-lyakhov daniil-lyakhov force-pushed the dl/torch/patterns_alignment branch 2 times, most recently from 6db6937 to ce14175 Compare October 19, 2023 15:59
@alexsu52 alexsu52 merged commit d879361 into openvinotoolkit:develop Oct 24, 2023
6 checks passed
ksilligan added a commit to ksilligan/nncf that referenced this pull request Nov 6, 2023
* Bump `numpy` version upper bound (openvinotoolkit#2202)

### Changes

Bump `numpy` version.

### Reason for changes

Current version causes issues in OpenVINO CI: https://github.com/intel-innersource/frameworks.ai.openvino.ci.product-configs/pull/2803

### Related tickets

122802

* Add links to OneFormer and InstructPix2Pix notebooks (openvinotoolkit#2201)

### Changes

Added links to `OneFormer` and `InstructPix2Pix` OpenVINO notebooks

* Added documentation for NF4 mode (openvinotoolkit#2194)

Co-authored-by: Alexander Kozlov <[email protected]>

* [Torch] SE block HW fusing pattern is presented (openvinotoolkit#2177)

### Changes

* SE block ignored pattern is presented for Torch backend

![image](https://github.com/openvinotoolkit/nncf/assets/74656388/2bbf0d3c-ac9d-4db0-9c28-ff6b1bf299af)
* SE block ignored pattern for OV backend is adjusted
* NON_PATTERN_NODE_WITH_TYPE is introduced in the graph matcher


### Reason for changes

To align FQ layout between TORCH and OV backend for efficientnet_b0
model
To fix FQ placement for SE block:
Before: 

![image](https://github.com/openvinotoolkit/nncf/assets/74656388/7e8b27a3-fafc-41f9-ace2-1945bce32b65)
After:

![image](https://github.com/openvinotoolkit/nncf/assets/74656388/e4479c90-bd4f-47fb-b2c2-acd76a685030)


### Related tickets

121647

### Tests
* test_non_pattern_node_with_type for the graph matcher

Post training quantization manual build 180

| Model | Backend | Metric name | Metric value | Metric diff | Num FQ |
RAM MiB | Quant. time | Total time | Status |

|-------|----------------------|-------------|--------------|-------------|---------|---------|-------------|------------|---------|
| 1 | timm/efficientnet_b0 | OV | Acc@1 | 0.7688 | -0.0042 | 92 | 1033 |
0:00:25 | 1:03:58 | |
| 2 | timm/efficientnet_b0 | TORCH | Acc@1 | 0.7680 | -0.0049 | 92 | 892
| 0:00:48 | 1:04:27 |


* pattern manager tests

* [PTQ][Torch][KQV self attention] Align FQ placement between OV and Torch backend (openvinotoolkit#2166)

### Changes

* "unbing" and "__matmul__" ops are added to torch patterns
* Dropout removing pass is added to function
`transform_to_inference_graph`
* LayerNorm and GroupNorm metatypes are added to ignored metatypes in
MinMax algorithm

### Reason for changes

To align quantization placement between OV and Torch backends for the
following models:
* timm/crossvit_9_240
* timm/deit3_small_patch16_224
* timm/swin_base_patch4_window7_224


### Related tickets

121647

### Tests
*  test_metatypes_to_ignore for quantization propagation solver

* Added ov_version parameter to the env tests (openvinotoolkit#2209)

### Changes

- Added `ov_version` variable for the pytest in `test_examples`;
- Added `ov_version` variable for the pytest in the `test_install_*`;

### Reason for changes

- More flexible tests

### Related tickets

- 122860

### Tests

- Updated

* Do not test common code in backend-specific test targets (openvinotoolkit#2212)

### Changes
As stated in the title

### Reason for changes
Common code has an own target now which is run using GH actions, no reason to run these tests additionally in the backend-specific targets.

### Related tickets
TBA

### Tests
Existing precommit scope

* Enable SmoothQuant only for OV backend (openvinotoolkit#2208)

### Changes

Run the SmoothQuant and ChannelAlignment algorithms only for the
OpenVINO backend.

### Reason for changes

Only the OpenVINO backend supports SmoothQuant and ChannelAlignment
algorithms.

### Related tickets
N/A

### Tests
N/A

* [OV] Add caching of OMZ models (openvinotoolkit#2214)

### Changes

Added cache_dir for OMZ models

### Reason for changes

* Сhanges made according to the requirements of the validation team

### Related tickets

<!--- Post the numerical ID of the ticket, if available -->

### Tests

<!--- How was the correctness of changes tested and whether new tests
were added -->

* QuantizationPreset.MIXED for ModelType.TRANSFORMER by default (openvinotoolkit#2216)

### Changes

Made the QuantizationPreset.MIXED preset for ModelType.TRANSFORMER by
default.

### Reason for changes

Quantization of transformer-based models with QuantizationPreset.MIXED
preset shows the best accuracy w/o performance degradation.

### Related tickets

ref: 123235

### Tests
test_create_nncf_config
test_quantization_preset

* Updated reference for 2023.2.0-12979-04c766e9f17 (openvinotoolkit#2219)

- [ ] pass nncf + openvino-nightly tests - build#7

### Changes

<!--- What was changed (briefly), how to reproduce (if applicable), what
the reviewers should focus on -->

### Reason for changes

<!--- Why should the change be applied -->

### Related tickets

<!--- Post the numerical ID of the ticket, if available -->

### Tests

<!--- How was the correctness of changes tested and whether new tests
were added -->

* Using ov.save_model(...) in PTQ examples (openvinotoolkit#2156)

### Changes

Using ov.save_model(...) in PTQ examples

### Reason for changes

ov.save_model(...) is introduced in OpenVINO==2023.1.0

### Related tickets

N/A

### Tests

examples

* [PTQ] Remove insert_null_biases pass (openvinotoolkit#2217)

### Changes

- Removed `insert_bull_biases` method

### Reason for changes

- Inserting is not necessary since correcting the null biases is limited
by magnitude.
- Inserting of the new increases binary file size.

### Related tickets

- 120843

* Fix index out of range (openvinotoolkit#2224)

### Changes

Fix index out of range

### Reason for changes

File "nncf/nncf/quantization/algorithms/pipeline.py", line 119, in
run_step
current_model = pipeline_step[-1].apply(current_model, current_graph,
step_statistics)
IndexError: list index out of range

### Related tickets

N/A

### Tests

N/A

* Added `keepdims` argument for min,max functions (openvinotoolkit#2225)

### Changes

as stated in the title

### Reason for changes

Follow-up from comment
openvinotoolkit#2218 (comment)

### Related tickets

n/a

### Tests

test_fn_max
test_fn_min
test_max
test_min

* [PTQ] Avg pool is added as ignored metatype for TRANSFORMER model_type (openvinotoolkit#2228)

### Changes

[PTQ] Avg pool is added as ignored metatype for TRANSFORMER model_type
in TORCH/OV/ONNX backends

### Reason for changes

* To align PTQ backends as for example TORCH avg_pool is mapping to
reduce_mean in OV, for timm/visformer_small in particular

### Related tickets

110985
119910

### Tests

* Remove pylint (openvinotoolkit#2205)

### Changes
Pylint was removed from the make targets and from code. Added `.pylintrc` to `.gitignore` so that developers could have their own `.pylintrc` if they still want to use pylint in informational capacity locally.

### Reason for changes
Following through with the decision to use ruff as the main linter. Most of the pylint rules not covered by ruff will be covered by mypy in the future.

### Related tickets
N/A

### Tests
Existing test scope

* Use torch 2.1 and remove torch 1.13 (openvinotoolkit#2211)

### Changes
As stated in the title

### Reason for changes
Keeping up with the latest torch version

### Related tickets
N/A

### Tests
Existing torch test scope

* [Graph visualization] Reserved dot symbols are replaced for each graph visualization (openvinotoolkit#2231)

### Changes

Visualization of debug graph is fixed by replacing : to ^

### Reason for changes

To fix graph visualization for OV backend

### Related tickets


### Tests

* [ONNX][OV] Update SE block pattern (openvinotoolkit#2229)

### Changes

Add SE block ignored pattern for ONNX;

![image](https://github.com/openvinotoolkit/nncf/assets/32935044/edd1d9ad-3eb5-4f73-bc94-021c465b345a)

Add hsigmoid to OV SE block pattern

OV new quantization scheme for mobilentv3

![image](https://github.com/openvinotoolkit/nncf/assets/32935044/d089fda8-54c9-400f-9720-4957d2f077d5)
ONNX efficientnet-b0:

![image](https://github.com/openvinotoolkit/nncf/assets/32935044/c673cf55-03bb-49b0-971a-00c0e8e39420)
ONNX mobilentv3:

![image](https://github.com/openvinotoolkit/nncf/assets/32935044/e0dec26e-8607-4a2c-b889-7e250decb253)


### Reason for changes

Improve accuracy metrics for modes with SE block

### Related tickets

123692
123691

### Tests

Models from conformance test are tested manually

* Fix github actions codecov uploader for ONNX

* Fix github actions codecov uploader for ONNX and COMMON

* Update upload_coverage_for_develop.yml

---------

Co-authored-by: Przemyslaw Wysocki <[email protected]>
Co-authored-by: Liubov Talamanova <[email protected]>
Co-authored-by: Lyalyushkin Nikolay <[email protected]>
Co-authored-by: Alexander Kozlov <[email protected]>
Co-authored-by: Daniil Lyakhov <[email protected]>
Co-authored-by: Nikita Malinin <[email protected]>
Co-authored-by: Vasily Shamporov <[email protected]>
Co-authored-by: Andrey Churkin <[email protected]>
Co-authored-by: Alexander Suslov <[email protected]>
Co-authored-by: Aleksei Kashapov <[email protected]>
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 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.

4 participants