Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 4, 2024
1 parent d4f1181 commit 3b6ab7a
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 31 deletions.
13 changes: 3 additions & 10 deletions neural_compressor/tensorflow/algorithms/smoother/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
SmoothQuantCalibration,
SmoothQuantCalibrationLLM,
)
from neural_compressor.tensorflow.algorithms.smoother.scaler import (
SmoothQuantScaler,
SmoothQuantScalerLLM,
)
from neural_compressor.tensorflow.algorithms.smoother.scaler import SmoothQuantScaler, SmoothQuantScalerLLM
from neural_compressor.tensorflow.quantization.config import SmoothQuantConfig
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer
from neural_compressor.tensorflow.utils import SPR_BASE_VERSIONS, BaseModel, TensorflowLLMModel, framework_specific_info
Expand Down Expand Up @@ -122,9 +119,7 @@ def apply_smooth_quant(self, model: BaseModel):
logger.info("Start Smoothing process for Smooth Quantization.")

# Do a pre-optimization before smooth quant
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.generic.pre_optimize import (
PreOptimization,
)
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.generic.pre_optimize import PreOptimization

pre_optimizer_handle = PreOptimization(model, self.new_api, self.device)
pre_optimized_model = pre_optimizer_handle.get_optimized_model(self.itex_mode)
Expand All @@ -151,9 +146,7 @@ def apply_smooth_quant(self, model: BaseModel):
def apply_smooth_quant_LLM(self, model: BaseModel):
"""Apply smooth quant to the LLM model."""
# Do a pre-optimization before smooth quant
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.generic.pre_optimize import (
PreOptimization,
)
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.generic.pre_optimize import PreOptimization

pre_optimizer_handle = PreOptimization(model, self.new_api, self.device)
pre_optimized_model = pre_optimizer_handle.get_optimized_model(self.itex_mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import numpy as np
from tensorflow.python.framework import dtypes, tensor_util

from neural_compressor.tensorflow.utils import SPR_BASE_VERSIONS, dump_elapsed_time
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import SPR_BASE_VERSIONS, dump_elapsed_time


class ConvertAddToBiasAddOptimizer(GraphRewriterBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from tensorflow.python.grappler import tf_optimizer
from tensorflow.python.training import saver as saver_lib

from neural_compressor.tensorflow.utils import dump_elapsed_time, version1_gt_version2
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import dump_elapsed_time, version1_gt_version2


class ConvertLayoutOptimizer(GraphRewriterBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import tensorflow as tf
from tensorflow.python.framework import dtypes

from neural_compressor.tensorflow.utils import dump_elapsed_time
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import dump_elapsed_time


class InjectDummyBiasAddOptimizer(GraphRewriterBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import tensorflow as tf
from tensorflow.python.framework import dtypes

from neural_compressor.tensorflow.utils import SPR_BASE_VERSIONS
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import SPR_BASE_VERSIONS


class FuseGeluOptimizer(GraphRewriterBase): # pragma: no cover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import tensorflow as tf
from tensorflow.python.framework import tensor_util

from neural_compressor.tensorflow.utils import version1_gt_version2
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import version1_gt_version2


class FusePadWithConv2DOptimizer(GraphRewriterBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import tensorflow as tf
from tensorflow.python.framework import tensor_util

from neural_compressor.tensorflow.utils import version1_gt_version2
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import version1_gt_version2


class FusePadWithFP32Conv2DOptimizer(GraphRewriterBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from tensorflow.python.grappler import tf_optimizer
from tensorflow.python.training import saver

from neural_compressor.tensorflow.utils import dump_elapsed_time, version1_gt_version2
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import dump_elapsed_time, version1_gt_version2


class GrapplerOptimizer(GraphRewriterBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import tensor_util as tu

from neural_compressor.tensorflow.utils import version1_gt_version2
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphRewriterHelper as Helper
from neural_compressor.tensorflow.quantization.utils.graph_rewriter.graph_base import GraphRewriterBase
from neural_compressor.tensorflow.utils import version1_gt_version2


class InsertPrintMinMaxNode(GraphRewriterBase):
Expand Down
2 changes: 1 addition & 1 deletion neural_compressor/tensorflow/quantization/utils/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import numpy as np
import tensorflow as tf
from google.protobuf import text_format

from tensorflow.core.framework import attr_value_pb2, graph_pb2, node_def_pb2, variable_pb2
from tensorflow.core.protobuf import config_pb2, meta_graph_pb2
from tensorflow.python.eager import context, wrap_function
Expand All @@ -37,6 +36,7 @@
from neural_compressor.common import logger
from neural_compressor.tensorflow.quantization.utils.graph_util import GraphAnalyzer, GraphRewriterHelper


def disable_random(seed=1):
"""A Decorator to disable tf random seed."""

Expand Down
7 changes: 1 addition & 6 deletions neural_compressor/tensorflow/utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
# limitations under the License.

from neural_compressor.common.utils import DEFAULT_WORKSPACE
from neural_compressor.tensorflow.utils.model_wrappers import (
BaseModel,
KerasModel,
TensorflowModel,
get_tf_model_type,
)
from neural_compressor.tensorflow.utils.model_wrappers import BaseModel, KerasModel, TensorflowModel, get_tf_model_type

framework_specific_info = {
"device": "cpu",
Expand Down

0 comments on commit 3b6ab7a

Please sign in to comment.