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] Serialize and load NNCF transformations #2531

Merged
merged 6 commits into from
May 6, 2024

Conversation

daniil-lyakhov
Copy link
Collaborator

@daniil-lyakhov daniil-lyakhov commented Feb 28, 2024

On top of #2584 #2595

Changes

  • serialize_transformations and load_transformations functions are introduced: serialize_transformations could serialize PTTransformationLayout to a dict which could be serialized by json; serialized transformation could be recovered by the load_transformations function.
  • StatefullTorchModuleInterface is introduced to make it possible to serialize all compression modules for quantization, sparisification, weights compression and pruning algorithms
  • Quantizers are created with scale shape specified in the quantization spec

Reason for changes

  • To make it possible to serialize/deserialize PT nncf transformations
  • To make it possible to serialize/deserialize compression modules which are the part of each transformation
  • To align scales shapes after nncf.quantize and quantizes initialization

Related tickets

129586

Tests

  • tests/torch/test_serialization.py
  • tests/torch/test_serialization.py
  • tests/torch/test_serialization.py

@github-actions github-actions bot added documentation Improvements or additions to documentation NNCF PT Pull requests that updates NNCF PyTorch NNCF PTQ Pull requests that updates NNCF PTQ labels Feb 28, 2024
@openvino-nncf-ci openvino-nncf-ci added the API Public API-impacting changes label Feb 28, 2024
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 145 lines in your changes are missing coverage. Please review.

Project coverage is 29.88%. Comparing base (a95e9af) to head (c2242b1).
Report is 15 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           develop    #2531       +/-   ##
============================================
- Coverage    91.20%   29.88%   -61.32%     
============================================
  Files          493      495        +2     
  Lines        45519    45961      +442     
============================================
- Hits         41514    13734    -27780     
- Misses        4005    32227    +28222     
Files Coverage Δ
...f/quantization/algorithms/min_max/torch_backend.py 0.00% <0.00%> (-97.52%) ⬇️
nncf/torch/quantization/layers.py 0.00% <0.00%> (-95.86%) ⬇️
nncf/torch/sparsity/layers.py 0.00% <0.00%> (-100.00%) ⬇️
nncf/torch/layer_utils.py 0.00% <0.00%> (-96.93%) ⬇️
nncf/torch/pruning/filter_pruning/layers.py 0.00% <0.00%> (-100.00%) ⬇️
nncf/torch/sparsity/rb/layers.py 0.00% <0.00%> (-97.44%) ⬇️
...ntization/algorithms/smooth_quant/torch_backend.py 0.00% <0.00%> (-95.00%) ⬇️
nncf/torch/graph/transformations/serialization.py 0.00% <0.00%> (ø)

... and 323 files with indirect coverage changes

Flag Coverage Δ
COMMON ?
ONNX ?
OPENVINO ?
TENSORFLOW 29.88% <0.00%> (-0.16%) ⬇️
TORCH ?

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

Components Coverage Δ
common 76.35% <ø> (-17.41%) ⬇️
torch 0.01% <0.00%> (-93.61%) ⬇️
tensorflow 93.74% <ø> (ø)
onnx 0.00% <ø> (-93.07%) ⬇️
openvino 0.00% <ø> (-94.19%) ⬇️
ptq 15.20% <0.00%> (-74.87%) ⬇️

@daniil-lyakhov daniil-lyakhov force-pushed the dl/ptq/load_state branch 2 times, most recently from 86d1356 to e8f7f15 Compare March 15, 2024 13:31
@daniil-lyakhov daniil-lyakhov force-pushed the dl/ptq/load_state branch 6 times, most recently from d616ca0 to ec9e451 Compare March 26, 2024 18:35
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Mar 26, 2024
@daniil-lyakhov daniil-lyakhov force-pushed the dl/ptq/load_state branch 4 times, most recently from 42d0b67 to c95fcf6 Compare March 28, 2024 16:40
@daniil-lyakhov daniil-lyakhov changed the title [WIP][PTQ][Torch] Save and load quantization transformation [Torch] Save and load quantization transformations Mar 28, 2024
@openvino-nncf-ci openvino-nncf-ci removed the API Public API-impacting changes label Mar 28, 2024
@daniil-lyakhov daniil-lyakhov marked this pull request as ready for review March 28, 2024 17:20
@daniil-lyakhov daniil-lyakhov requested a review from a team as a code owner March 28, 2024 17:20
@daniil-lyakhov daniil-lyakhov changed the title [Torch] Save and load quantization transformations [Torch] Serialize and load NNCF transformations Mar 28, 2024
AlexanderDokuchaev pushed a commit that referenced this pull request Apr 2, 2024
Preparation for #2531

### Changes

1) `PTQuantizerInsertionCommand` is removed and replaced with
create_quantizer_insertion_command function
2) `SharedFNInsertionCommand` updates with one new attribute:
compression_module_type
3) `ExtraOpCallHook` doesn't require context in constructor anymore
4) Multidevice support is moved from
`apply_quantizers_insertion_commands_transformation` to
`apply_insertion_transformation`

### Reason for changes

1) To make it easier to store and restore commands: less commands - less
amount of adapters are needed
2) To make it possible to express `PTQuantizerInsertionCommand` by
`SharedFNInsertionCommand`
3) To make it possible to create `ExtraOpCallHook` outside of the
`PTModelTransformer`
4) To unify multidevice support for all insertion operations

### Related tickets
2531

### Tests

1)`test_quantizer_insertion_transformation` is updated
2) -
3) `test_shared_fn_insertion_point` is updated
4) `test_pt_insertion_command` is introduced
@daniil-lyakhov daniil-lyakhov force-pushed the dl/ptq/load_state branch 2 times, most recently from 808d068 to f14aa92 Compare April 25, 2024 11:21
@daniil-lyakhov daniil-lyakhov force-pushed the dl/ptq/load_state branch 4 times, most recently from 846fe06 to fa077fa Compare April 25, 2024 12:55
@daniil-lyakhov daniil-lyakhov requested a review from alexsu52 April 25, 2024 14:04
"""

@abstractmethod
def get_state(self) -> Dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about get_config, from_config to align with high-level API?

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

nncf/torch/graph/transformations/serialization.py Outdated Show resolved Hide resolved
nncf/torch/graph/transformations/serialization.py Outdated Show resolved Hide resolved
@daniil-lyakhov daniil-lyakhov requested a review from alexsu52 May 3, 2024 08:20
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

nncf/torch/layer_utils.py Outdated Show resolved Hide resolved
@daniil-lyakhov daniil-lyakhov requested a review from alexsu52 May 6, 2024 09:07
@alexsu52 alexsu52 merged commit d507585 into openvinotoolkit:develop May 6, 2024
12 checks passed
alexsu52 pushed a commit that referenced this pull request May 8, 2024
### Changes

`_compression_lr_multiplier` attribute introduced in #2531 is removed
from the `CompressionParameter`

### Reason for changes

`_compression_lr_multiplier` makes the `CompressionParameter` a stateful
parameter which for some reason does not work properly in
distributed/dataparallel mode


### Tests

torch_nightly/213/ - finished successfully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants