From 2d5a02b375f8544adbb58db3f9f66d26b48bc8b0 Mon Sep 17 00:00:00 2001 From: dlyakhov Date: Thu, 27 Jun 2024 13:56:18 +0200 Subject: [PATCH] Comments --- .github/workflows/precommit.yml | 44 ------------------- Makefile | 1 + nncf/common/factory.py | 8 ++-- .../{torch_fx => torch/fx}/__init__.py | 0 .../{torch_fx => torch/fx}/engine.py | 0 .../fx}/model_transformer.py | 0 .../fx}/nncf_graph_builder.py | 6 +-- .../fx}/quantization/__init__.py | 0 .../fx}/quantization/quantize_model.py | 8 +++- .../fx}/statistics/__init__.py | 0 .../fx}/statistics/aggregator.py | 2 +- .../{torch_fx => torch/fx}/transformations.py | 2 +- .../fast_bias_correction/torch_fx_backend.py | 6 +-- .../algorithms/min_max/torch_fx_backend.py | 4 +- nncf/quantization/quantize_model.py | 2 +- 15 files changed, 23 insertions(+), 60 deletions(-) rename nncf/experimental/{torch_fx => torch/fx}/__init__.py (100%) rename nncf/experimental/{torch_fx => torch/fx}/engine.py (100%) rename nncf/experimental/{torch_fx => torch/fx}/model_transformer.py (100%) rename nncf/experimental/{torch_fx => torch/fx}/nncf_graph_builder.py (97%) rename nncf/experimental/{torch_fx => torch/fx}/quantization/__init__.py (100%) rename nncf/experimental/{torch_fx => torch/fx}/quantization/quantize_model.py (91%) rename nncf/experimental/{torch_fx => torch/fx}/statistics/__init__.py (100%) rename nncf/experimental/{torch_fx => torch/fx}/statistics/aggregator.py (98%) rename nncf/experimental/{torch_fx => torch/fx}/transformations.py (99%) diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml index b18ea60137a..6f7ec2906d6 100644 --- a/.github/workflows/precommit.yml +++ b/.github/workflows/precommit.yml @@ -95,50 +95,6 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} name: coverage_openvino flags: OPENVINO - torchFX: - timeout-minutes: 40 - defaults: - run: - shell: bash - runs-on: ubuntu-20.04-8-cores - env: - DEBIAN_FRONTEND: noninteractive - steps: - - name: Install dependencies - run : | - sudo apt-get update - sudo apt-get --assume-yes install gcc g++ build-essential ninja-build libgl1-mesa-dev libglib2.0-0 - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - with: - lfs: true - - uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 - with: - python-version: 3.8.18 - cache: pip - - name: Runner info - continue-on-error: true - run: | - cat /etc/*release - cat /proc/cpuinfo - - name: Install NNCF and test requirements - run: make install-torch-fx-test - - name: Run TorchFX precommit test scope - run: | - make test-torch-fx - env: - NNCF_COVERAGE: 1 - NUM_WORKERS: 4 - - name: Upload coverage report as artifact - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3 - with: - name: coverage_fx_cpu - path: ./coverage.xml - - name: Upload coverage report to codecov - uses: codecov/codecov-action@125fc84a9a348dbcf27191600683ec096ec9021c # v4.4.1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - name: coverage_fx_cpu - flags: TORCH pytorch-cpu: timeout-minutes: 40 defaults: diff --git a/Makefile b/Makefile index 7842dd68ffd..3086eea0b92 100644 --- a/Makefile +++ b/Makefile @@ -153,6 +153,7 @@ test-torch-cuda: test-torch-nightly: pytest ${COVERAGE_ARGS} tests/torch -m nightly --junitxml ${JUNITXML_PATH} $(DATA_ARG) + test-torch-fx test-torch-weekly: pytest ${COVERAGE_ARGS} tests/torch -m weekly \ diff --git a/nncf/common/factory.py b/nncf/common/factory.py index d5d13605a07..8cc7dd018e5 100644 --- a/nncf/common/factory.py +++ b/nncf/common/factory.py @@ -43,7 +43,7 @@ def create(model: TModel) -> NNCFGraph: return GraphConverter.create_nncf_graph(model) if model_backend == BackendType.TORCH_FX: - from nncf.experimental.torch_fx.nncf_graph_builder import GraphConverter + from nncf.experimental.torch.fx.nncf_graph_builder import GraphConverter return GraphConverter.create_nncf_graph(model) if model_backend == BackendType.TORCH: @@ -77,7 +77,7 @@ def create(model: TModel, inplace: bool = False) -> ModelTransformer: return PTModelTransformer(model) if model_backend == BackendType.TORCH_FX: - from nncf.experimental.torch_fx.model_transformer import FXModelTransformer + from nncf.experimental.torch.fx.model_transformer import FXModelTransformer return FXModelTransformer(model) raise nncf.UnsupportedBackendError( @@ -108,7 +108,7 @@ def create(model: TModel) -> Engine: return PTEngine(model) if model_backend == BackendType.TORCH_FX: - from nncf.experimental.torch_fx.engine import FXEngine + from nncf.experimental.torch.fx.engine import FXEngine return FXEngine(model) raise nncf.UnsupportedBackendError( @@ -164,7 +164,7 @@ def create(model: TModel, dataset: Dataset) -> aggregator.StatisticsAggregator: return PTStatisticsAggregator(dataset) if model_backend == BackendType.TORCH_FX: - from nncf.experimental.torch_fx.statistics.aggregator import FXStatisticsAggregator + from nncf.experimental.torch.fx.statistics.aggregator import FXStatisticsAggregator return FXStatisticsAggregator(dataset) raise nncf.UnsupportedBackendError( diff --git a/nncf/experimental/torch_fx/__init__.py b/nncf/experimental/torch/fx/__init__.py similarity index 100% rename from nncf/experimental/torch_fx/__init__.py rename to nncf/experimental/torch/fx/__init__.py diff --git a/nncf/experimental/torch_fx/engine.py b/nncf/experimental/torch/fx/engine.py similarity index 100% rename from nncf/experimental/torch_fx/engine.py rename to nncf/experimental/torch/fx/engine.py diff --git a/nncf/experimental/torch_fx/model_transformer.py b/nncf/experimental/torch/fx/model_transformer.py similarity index 100% rename from nncf/experimental/torch_fx/model_transformer.py rename to nncf/experimental/torch/fx/model_transformer.py diff --git a/nncf/experimental/torch_fx/nncf_graph_builder.py b/nncf/experimental/torch/fx/nncf_graph_builder.py similarity index 97% rename from nncf/experimental/torch_fx/nncf_graph_builder.py rename to nncf/experimental/torch/fx/nncf_graph_builder.py index 9990ee3bf2f..febab2af969 100644 --- a/nncf/experimental/torch_fx/nncf_graph_builder.py +++ b/nncf/experimental/torch/fx/nncf_graph_builder.py @@ -21,9 +21,9 @@ from nncf.common.graph.layer_attributes import Dtype from nncf.common.graph.operator_metatypes import UnknownMetatype from nncf.common.logging import nncf_logger -from nncf.experimental.torch_fx.transformations import separate_conv_and_bias -from nncf.experimental.torch_fx.transformations import separate_linear_and_bias -from nncf.experimental.torch_fx.transformations import view_to_reshape +from nncf.experimental.torch.fx.transformations import separate_conv_and_bias +from nncf.experimental.torch.fx.transformations import separate_linear_and_bias +from nncf.experimental.torch.fx.transformations import view_to_reshape from nncf.torch.graph.graph import PTNNCFGraph from nncf.torch.graph.operator_metatypes import PT_OPERATOR_METATYPES diff --git a/nncf/experimental/torch_fx/quantization/__init__.py b/nncf/experimental/torch/fx/quantization/__init__.py similarity index 100% rename from nncf/experimental/torch_fx/quantization/__init__.py rename to nncf/experimental/torch/fx/quantization/__init__.py diff --git a/nncf/experimental/torch_fx/quantization/quantize_model.py b/nncf/experimental/torch/fx/quantization/quantize_model.py similarity index 91% rename from nncf/experimental/torch_fx/quantization/quantize_model.py rename to nncf/experimental/torch/fx/quantization/quantize_model.py index 0f40800fb49..4ea8c263cb7 100644 --- a/nncf/experimental/torch_fx/quantization/quantize_model.py +++ b/nncf/experimental/torch/fx/quantization/quantize_model.py @@ -23,10 +23,11 @@ import nncf from nncf.common.factory import NNCFGraphFactory +from nncf.common.logging import nncf_logger from nncf.common.quantization.structs import QuantizationPreset from nncf.common.quantization.structs import QuantizationScheme from nncf.data import Dataset -from nncf.experimental.torch_fx.transformations import merge_conv_and_bias +from nncf.experimental.torch.fx.transformations import merge_conv_and_bias from nncf.parameters import ModelType from nncf.parameters import QuantizationMode from nncf.parameters import TargetDevice @@ -53,6 +54,11 @@ def quantize_impl( """ Implementation of the `quantize()` method for the Torch FX backend. """ + 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." + ) if fast_bias_correction is False: raise ValueError(f"fast_bias_correction={fast_bias_correction} is not supported") if target_device == TargetDevice.CPU_SPR: diff --git a/nncf/experimental/torch_fx/statistics/__init__.py b/nncf/experimental/torch/fx/statistics/__init__.py similarity index 100% rename from nncf/experimental/torch_fx/statistics/__init__.py rename to nncf/experimental/torch/fx/statistics/__init__.py diff --git a/nncf/experimental/torch_fx/statistics/aggregator.py b/nncf/experimental/torch/fx/statistics/aggregator.py similarity index 98% rename from nncf/experimental/torch_fx/statistics/aggregator.py rename to nncf/experimental/torch/fx/statistics/aggregator.py index f1ce6ff05ec..774430b1834 100644 --- a/nncf/experimental/torch_fx/statistics/aggregator.py +++ b/nncf/experimental/torch/fx/statistics/aggregator.py @@ -21,7 +21,7 @@ from nncf.common.tensor_statistics.aggregator import StatisticPointsContainer from nncf.common.tensor_statistics.aggregator import StatisticsAggregator from nncf.experimental.common.tensor_statistics.collectors import TensorCollector -from nncf.experimental.torch_fx.model_transformer import FXModuleInsertionCommand +from nncf.experimental.torch.fx.model_transformer import FXModuleInsertionCommand from nncf.tensor import Tensor from nncf.torch.nncf_network import NNCFNetwork from nncf.torch.return_types import maybe_get_values_from_torch_return_type diff --git a/nncf/experimental/torch_fx/transformations.py b/nncf/experimental/torch/fx/transformations.py similarity index 99% rename from nncf/experimental/torch_fx/transformations.py rename to nncf/experimental/torch/fx/transformations.py index d572c06b120..9c608c90290 100644 --- a/nncf/experimental/torch_fx/transformations.py +++ b/nncf/experimental/torch/fx/transformations.py @@ -21,7 +21,7 @@ from nncf.common.graph.graph import NNCFNode from nncf.common.graph.transformations.commands import TargetType -from nncf.experimental.torch_fx.model_transformer import FXModelTransformer +from nncf.experimental.torch.fx.model_transformer import FXModelTransformer from nncf.torch.graph.transformations.commands import PTTargetPoint diff --git a/nncf/quantization/algorithms/fast_bias_correction/torch_fx_backend.py b/nncf/quantization/algorithms/fast_bias_correction/torch_fx_backend.py index 089afd4ab11..850df6f7d7b 100644 --- a/nncf/quantization/algorithms/fast_bias_correction/torch_fx_backend.py +++ b/nncf/quantization/algorithms/fast_bias_correction/torch_fx_backend.py @@ -22,8 +22,8 @@ from nncf.common.graph.definitions import NNCFGraphNodeType from nncf.common.graph.transformations.commands import TargetType from nncf.experimental.common.tensor_statistics.collectors import TensorCollector -from nncf.experimental.torch_fx.model_transformer import FXApplyTransformationCommand -from nncf.experimental.torch_fx.transformations import bias_update_transformation_builder +from nncf.experimental.torch.fx.model_transformer import FXApplyTransformationCommand +from nncf.experimental.torch.fx.transformations import bias_update_transformation_builder from nncf.quantization.algorithms.fast_bias_correction.backend import FastBiasCorrectionAlgoBackend from nncf.tensor import Tensor from nncf.torch.graph.transformations.commands import PTModelExtractionCommand @@ -83,7 +83,7 @@ def create_input_data(shape: Tuple[int], data: List[Tensor], input_name: str, ch @staticmethod def get_bias_value(node: NNCFNode, nncf_graph: NNCFGraph, model: torch.fx.GraphModule) -> Tensor: # TODO: make a node_name_vs_node map to speed up the process - from nncf.experimental.torch_fx.model_transformer import FXModelTransformer + from nncf.experimental.torch.fx.model_transformer import FXModelTransformer bias_node = nncf_graph.get_next_nodes(node)[0] graph_bias_node = FXModelTransformer.get_graph_node_by_name(model.graph, bias_node.node_name) diff --git a/nncf/quantization/algorithms/min_max/torch_fx_backend.py b/nncf/quantization/algorithms/min_max/torch_fx_backend.py index bdeed5343c8..a21fcc883ab 100644 --- a/nncf/quantization/algorithms/min_max/torch_fx_backend.py +++ b/nncf/quantization/algorithms/min_max/torch_fx_backend.py @@ -27,8 +27,8 @@ from nncf.experimental.common.tensor_statistics.collectors import AGGREGATORS_MAP from nncf.experimental.common.tensor_statistics.collectors import TensorCollector from nncf.experimental.common.tensor_statistics.statistics import MinMaxTensorStatistic -from nncf.experimental.torch_fx.model_transformer import FXApplyTransformationCommand -from nncf.experimental.torch_fx.transformations import qdq_insertion_tranformation_builder +from nncf.experimental.torch.fx.model_transformer import FXApplyTransformationCommand +from nncf.experimental.torch.fx.transformations import qdq_insertion_tranformation_builder from nncf.parameters import ModelType from nncf.parameters import TargetDevice from nncf.quantization.advanced_parameters import StatisticsType diff --git a/nncf/quantization/quantize_model.py b/nncf/quantization/quantize_model.py index bdc096a4982..1e717588bc4 100644 --- a/nncf/quantization/quantize_model.py +++ b/nncf/quantization/quantize_model.py @@ -229,7 +229,7 @@ def quantize( advanced_parameters=advanced_parameters, ) if backend == BackendType.TORCH_FX: - from nncf.experimental.torch_fx.quantization.quantize_model import quantize_impl + from nncf.experimental.torch.fx.quantization.quantize_model import quantize_impl return quantize_impl( model=model,