Skip to content

Commit 3882e9c

Browse files
authored
Migrate TF Smooth Quant to 3.x API (#1594)
Signed-off-by: zehao-intel <[email protected]> Signed-off-by: chensuyue <[email protected]>
1 parent 1d49048 commit 3882e9c

File tree

74 files changed

+10996
-268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+10996
-268
lines changed

.azure-pipelines/scripts/codeScan/pylint/pylint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ pip install torch==1.12.0 \
3535
accelerate \
3636
flask==2.1.3 \
3737
xgboost \
38-
datasets
38+
datasets \
39+
prettytable \
40+
psutil \
41+
py-cpuinfo \
42+
pyyaml
3943

4044
if [ "${scan_module}" = "neural_solution" ]; then
4145
cd /neural-compressor

.azure-pipelines/scripts/ut/3x/run_3x_tf.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ inc_path=$(python -c 'import neural_compressor; print(neural_compressor.__path__
1414
cd /neural-compressor/test || exit 1
1515
find ./3x/tensorflow/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'> run.sh
1616
find ./3x/common/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'>> run.sh
17+
sed -i '/tensorflow\/keras\//d' run.sh
18+
19+
find ./3x/tensorflow/keras/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'> run_keras.sh
1720

1821
LOG_DIR=/neural-compressor/log_dir
1922
mkdir -p ${LOG_DIR}
@@ -22,8 +25,13 @@ ut_log_name=${LOG_DIR}/ut_3x_tf.log
2225
echo "cat run.sh..."
2326
sort run.sh -o run.sh
2427
cat run.sh | tee ${ut_log_name}
28+
echo "cat run_keras.sh..."
29+
sort run_keras.sh -o run_keras.sh
30+
cat run_keras.sh | tee ${ut_log_name}
2531
echo "------UT start-------"
2632
bash -x run.sh 2>&1 | tee -a ${ut_log_name}
33+
pip install intel-extension-for-tensorflow[cpu]
34+
bash -x run_keras.sh 2>&1 | tee -a ${ut_log_name}
2735
cp .coverage ${LOG_DIR}/.coverage
2836

2937
echo "------UT end -------"

neural_compressor/tensorflow/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from neural_compressor.tensorflow.utils import register_algo
16-
from neural_compressor.tensorflow.algorithms import static_quantize_entry
17-
from neural_compressor.tensorflow.quantization import quantize_model, StaticQuantConfig, get_default_static_quant_config
15+
from neural_compressor.tensorflow.utils import register_algo, Model
16+
from neural_compressor.tensorflow.quantization import (
17+
quantize_model,
18+
StaticQuantConfig,
19+
SmoothQuantConfig,
20+
get_default_sq_config,
21+
get_default_static_quant_config,
22+
)

neural_compressor/tensorflow/algorithms/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
# limitations under the License.
1414

1515

16-
from neural_compressor.tensorflow.algorithms.static_quantize import static_quantize_entry
16+
from neural_compressor.tensorflow.algorithms.smoother import SmoothQuant
17+
from neural_compressor.tensorflow.algorithms.static_quant import KerasAdaptor
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2024 Intel Corporation
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
from neural_compressor.tensorflow.algorithms.smoother.core import SmoothQuant
19+
from neural_compressor.tensorflow.algorithms.smoother.scaler import (
20+
SmoothQuantScaler,
21+
SmoothQuantScalerLLM,
22+
)
23+
from neural_compressor.tensorflow.algorithms.smoother.calibration import (
24+
SmoothQuantCalibration,
25+
SmoothQuantCalibrationLLM,
26+
)

0 commit comments

Comments
 (0)