Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-lyakhov committed Dec 23, 2024
1 parent e285dc6 commit 2221e04
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from nncf.common.graph.graph import NNCFGraph
from nncf.common.tensor_statistics.statistic_point import StatisticPointsContainer
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.quantization.algorithms.post_training.pipeline import experimental_create_ptq_pipeline
from nncf.experimental.common.quantization.algorithms.quantizer.base_quantizer import NNCFQuantizer
from nncf.experimental.quantization.algorithms.post_training.pipeline import experimental_create_ptq_pipeline
from nncf.experimental.quantization.algorithms.quantizer.base_quantizer import Quantizer as NNCFQuantizer
from nncf.quantization.advanced_parameters import AdvancedBiasCorrectionParameters
from nncf.quantization.advanced_parameters import AdvancedSmoothQuantParameters
from nncf.quantization.advanced_parameters import RangeEstimatorParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from typing import Optional, TypeVar

from nncf.experimental.common.quantization.algorithms.quantizer.base_quantizer import NNCFQuantizer
from nncf.experimental.common.quantization.algorithms.range_estimator.range_estimator import MinMaxRangeEstimator
from nncf.experimental.quantization.algorithms.quantizer.base_quantizer import Quantizer as NNCFQuantizer
from nncf.experimental.quantization.algorithms.range_estimator.algorithm import MinMaxRangeEstimator
from nncf.quantization.advanced_parameters import AdvancedBiasCorrectionParameters
from nncf.quantization.advanced_parameters import AdvancedSmoothQuantParameters
from nncf.quantization.advanced_parameters import RangeEstimatorParameters
Expand Down
10 changes: 10 additions & 0 deletions nncf/experimental/quantization/algorithms/quantizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
TModel = TypeVar("TModel")


class NNCFQuantizer:
class Quantizer:
@abstractmethod
def get_quantization_setup(self, model: TModel, nncf_graph: NNCFGraph) -> SingleConfigQuantizerSetup:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from nncf.common.quantization.quantizer_setup import WeightQuantizationInsertionPoint
from nncf.common.quantization.structs import QuantizationScheme as QuantizationMode
from nncf.common.quantization.structs import QuantizerConfig
from nncf.experimental.common.quantization.algorithms.quantizer.base_quantizer import NNCFQuantizer
from nncf.experimental.quantization.algorithms.quantizer.base_quantizer import Quantizer as NNCFQuantizer

EdgeOrNode = Union[Tuple[torch.fx.Node, torch.fx.Node]]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from nncf.common.graph.graph import NNCFGraph
from nncf.common.tensor_statistics.statistic_point import StatisticPointsContainer
from nncf.common.utils.backend import BackendType
from nncf.experimental.common.quantization.algorithms.quantizer.base_quantizer import NNCFQuantizer
from nncf.experimental.quantization.algorithms.quantizer.base_quantizer import Quantizer
from nncf.quantization.algorithms.algorithm import Algorithm
from nncf.quantization.algorithms.min_max.algorithm import MinMaxQuantization
from nncf.quantization.range_estimator import RangeEstimatorParameters
Expand All @@ -26,7 +26,7 @@
class MinMaxRangeEstimator(Algorithm):
def __init__(
self,
quantizer: NNCFQuantizer,
quantizer: Quantizer,
subset_size: int = 300,
inplace_statistics: bool = True,
batchwise_statistics: bool = False,
Expand Down
18 changes: 5 additions & 13 deletions nncf/experimental/torch/fx/quantization/quantize_pt2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import torch.fx
from torch.ao.quantization.pt2e.duplicate_dq_pass import DuplicateDQPass
from torch.ao.quantization.pt2e.port_metadata_pass import PortNodeMetaForQDQ
from torch.ao.quantization.pt2e.qat_utils import _fold_conv_bn_qat
from torch.ao.quantization.pt2e.utils import _disallow_eval_train
from torch.ao.quantization.quantizer import Quantizer
from torch.fx import GraphModule
Expand All @@ -26,11 +25,9 @@
from nncf.common.factory import NNCFGraphFactory
from nncf.common.logging import nncf_logger
from nncf.data import Dataset
from nncf.experimental.common.quantization.algorithms.post_training.algorithm import (
ExperimentalPostTrainingQuantization,
)
from nncf.experimental.common.quantization.algorithms.quantizer.base_quantizer import NNCFQuantizer
from nncf.experimental.common.quantization.algorithms.quantizer.fx_quantizer import NNCFFXQuantizer
from nncf.experimental.quantization.algorithms.post_training.algorithm import ExperimentalPostTrainingQuantization
from nncf.experimental.quantization.algorithms.quantizer.base_quantizer import Quantizer as NNCFQuantizer
from nncf.experimental.quantization.algorithms.quantizer.fx_quantizer import NNCFFXQuantizer
from nncf.experimental.torch.fx.constant_folding import constant_fold
from nncf.experimental.torch.fx.transformations import QUANTIZE_NODE_TARGETS
from nncf.experimental.torch.fx.transformations import fuse_conv_bn
Expand All @@ -50,7 +47,7 @@ def quantize_pt2e(
smooth_quant_params: Optional[AdvancedSmoothQuantParameters] = None,
activations_range_estimator_params: Optional[RangeEstimatorParameters] = None,
weights_range_estimator_params: Optional[RangeEstimatorParameters] = None,
batchwise_statistics: bool = False,
batchwise_statistics: Optional[bool] = None,
fold_quantize: bool = False,
) -> torch.fx.GraphModule:
"""
Expand All @@ -75,11 +72,7 @@ def quantize_pt2e(
for each item of the batch or for the entire batch, default is False.
:param fold_quantize: Boolean flag for whether fold the quantize op or not.
"""
nncf_logger.warning(
"Experimental Torch FX quantization backend is being used for the given torch.fx.GraphModule model."
" Torch FX PTQ is an experimental feature, consider using Torch or OpenVino PTQ backends"
" in case of errors or a poor model performance."
)
nncf_logger.warning("This is an experimental feature and may change in the future without notice.")

if subset_size < 1:
raise nncf.ValidationError("Subset size must be positive.")
Expand Down Expand Up @@ -121,7 +114,6 @@ def quantize_pt2e(
# is not preformant
quantized_model = GraphModule(quantized_model, quantized_model.graph)

quantized_model = _fold_conv_bn_qat(quantized_model)
if fold_quantize:
constant_fold(quantized_model, _quant_node_constraint)

Expand Down
2 changes: 1 addition & 1 deletion nncf/quantization/algorithms/min_max/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def fill_quantization_target_points(
"""
Initializes a cache, finds quantization target points and them puts in the cache.
:param model: Backend-specific model, for which Quantization Target Points are being seek.
:param quantizer_setup: Quantization Target Points in format of SingleConfigQuantizerSetup.
:param nncf_graph: NNCFGraph instance.
:return: Mapping of quantization target points with associated quantization configuration,
along with target points for scale unification.
Expand Down

0 comments on commit 2221e04

Please sign in to comment.