-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Torch FX] Post Quantize Weights Compression (#2984)
### Changes Transformation for removing fake quantize nodes and saving all weights to disk in int8 format after quantization. It works as follows: 1. Reshape the scale if qdq operation is per-channel. 2. Pattern match the quantize-dequantize nodes. 3. Filter the matches to only include quantize-dequantize ops with constant input. 4. Replace with the multiplication of the scale and input. ### Reason for changes To compress the model after quantization ### Tests Add `test_post_quantization_compression()` in `tests/torch/fx/test_model_transformer.py` which checks the data type of all weights in the model after applying quantization and also checks the value after the decompression step (element-wise multiplication operation). ### Tickets #2766 --------- Co-authored-by: Daniil Lyakhov <[email protected]>
- Loading branch information
1 parent
7385c41
commit 7c94b23
Showing
19 changed files
with
15,068 additions
and
3,490 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
nncf/experimental/torch/fx/quantization/backend_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) 2024 Intel Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Optional | ||
|
||
from nncf.quantization.advanced_parameters import AdvancedQuantizationParameters | ||
|
||
|
||
class FXBackendParameters: | ||
COMPRESS_WEIGHTS = "compress_weights" | ||
|
||
|
||
def is_weight_compression_needed(advanced_parameters: Optional[AdvancedQuantizationParameters]) -> bool: | ||
""" | ||
Determines whether weight compression is needed based on the provided | ||
advanced quantization parameters. | ||
:param advanced_parameters: Advanced quantization parameters. | ||
:return: True if weight compression is needed, False otherwise. | ||
""" | ||
if advanced_parameters is not None and advanced_parameters.backend_params is not None: | ||
return advanced_parameters.backend_params.get(FXBackendParameters.COMPRESS_WEIGHTS, True) | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.