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

Migrate TF Smooth Quant to 3.x API #1594

Merged
merged 20 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .azure-pipelines/scripts/codeScan/pylint/pylint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ apt-get install -y --no-install-recommends --fix-missing \
build-essential

pip install -r /neural-compressor/requirements.txt
pip install -r /neural-compressor/requirements_tf.txt
pip install cmake

pip install torch==1.12.0 \
Expand Down
8 changes: 8 additions & 0 deletions .azure-pipelines/scripts/ut/3x/run_3x_tf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inc_path=$(python -c 'import neural_compressor; print(neural_compressor.__path__
cd /neural-compressor/test || exit 1
find ./3x/tensorflow/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'> run.sh
find ./3x/common/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'>> run.sh
sed -i '/tensorflow\/keras\//d' run.sh

find ./3x/tensorflow/keras/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'> run_keras.sh

LOG_DIR=/neural-compressor/log_dir
mkdir -p ${LOG_DIR}
Expand All @@ -22,8 +25,13 @@ ut_log_name=${LOG_DIR}/ut_3x_tf.log
echo "cat run.sh..."
sort run.sh -o run.sh
cat run.sh | tee ${ut_log_name}
echo "cat run_keras.sh..."
sort run_keras.sh -o run_keras.sh
cat run_keras.sh | tee ${ut_log_name}
echo "------UT start-------"
bash -x run.sh 2>&1 | tee -a ${ut_log_name}
pip install intel-extension-for-tensorflow[cpu]
bash -x run_keras.sh 2>&1 | tee -a ${ut_log_name}
cp .coverage ${LOG_DIR}/.coverage

echo "------UT end -------"
Expand Down
11 changes: 8 additions & 3 deletions neural_compressor/tensorflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from neural_compressor.tensorflow.utils import register_algo
from neural_compressor.tensorflow.algorithms import static_quantize_entry
from neural_compressor.tensorflow.quantization import quantize_model, StaticQuantConfig, get_default_static_quant_config
from neural_compressor.tensorflow.utils import register_algo, Model
from neural_compressor.tensorflow.quantization import (
quantize_model,
StaticQuantConfig,
SmoothQuantConfig,
get_default_sq_config,
get_default_static_quant_config,
)
3 changes: 2 additions & 1 deletion neural_compressor/tensorflow/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.


from neural_compressor.tensorflow.algorithms.static_quantize import static_quantize_entry
from neural_compressor.tensorflow.algorithms.smoother import SmoothQuant
from neural_compressor.tensorflow.algorithms.static_quant import KerasAdaptor
26 changes: 26 additions & 0 deletions neural_compressor/tensorflow/algorithms/smoother/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# 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 neural_compressor.tensorflow.algorithms.smoother.core import SmoothQuant
from neural_compressor.tensorflow.algorithms.smoother.scaler import (
SmoothQuantScaler,
SmoothQuantScalerLLM,
)
from neural_compressor.tensorflow.algorithms.smoother.calibration import (
SmoothQuantCalibration,
SmoothQuantCalibrationLLM,
)
Loading
Loading