-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update INC 3.0 New API for Keras Static Quant (#1400)
Signed-off-by: zehao-intel <zehao.huang@intel.com> Signed-off-by: chensuyue <suyue.chen@intel.com>
- Loading branch information
1 parent
8160c71
commit 2627d33
Showing
31 changed files
with
2,518 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
#!/bin/bash | ||
|
||
echo -e "\n Install Neural Compressor ... " | ||
cd /neural-compressor | ||
python -m pip install --no-cache-dir -r requirements.txt | ||
python setup.py bdist_wheel | ||
pip install dist/neural_compressor*.whl | ||
if [[ $1 = *"3x_pt" ]]; then | ||
python -m pip install --no-cache-dir -r requirements_pt.txt | ||
python setup.py pt bdist_wheel | ||
pip install dist/neural_compressor*.whl | ||
elif [[ $1 = *"3x_tf" ]]; then | ||
python -m pip install --no-cache-dir -r requirements_tf.txt | ||
python setup.py tf bdist_wheel | ||
pip install dist/neural_compressor*.whl | ||
else | ||
python -m pip install --no-cache-dir -r requirements.txt | ||
python setup.py 2x bdist_wheel | ||
pip install dist/neural_compressor*.whl | ||
fi | ||
|
||
echo -e "\n pip list after install Neural Compressor ... " | ||
pip list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[run] | ||
branch = True | ||
|
||
[report] | ||
include = | ||
*/neural_compressor/common/* | ||
*/neural_compressor/tensorflow/* | ||
exclude_lines = | ||
pragma: no cover | ||
raise NotImplementedError | ||
raise TypeError | ||
if self.device == "gpu": | ||
if device == "gpu": | ||
except ImportError: | ||
except Exception as e: |
9 changes: 4 additions & 5 deletions
9
.azure-pipelines/scripts/ut/run_3x_pt.sh → .azure-pipelines/scripts/ut/3x/run_3x_pt.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
python -c "import neural_compressor as nc" | ||
test_case="run 3x TensorFlow" | ||
echo "${test_case}" | ||
|
||
# install requirements | ||
echo "set up UT env..." | ||
pip install coverage | ||
pip install pytest | ||
pip list | ||
|
||
export COVERAGE_RCFILE=/neural-compressor/.azure-pipelines/scripts/ut/3x/coverage.3x_tf | ||
inc_path=$(python -c 'import neural_compressor; print(neural_compressor.__path__[0])') | ||
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 | ||
|
||
LOG_DIR=/neural-compressor/log_dir | ||
mkdir -p ${LOG_DIR} | ||
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 "------UT start-------" | ||
bash -x run.sh 2>&1 | tee -a ${ut_log_name} | ||
cp .coverage ${LOG_DIR}/.coverage | ||
|
||
echo "------UT end -------" | ||
|
||
if [ $(grep -c "FAILED" ${ut_log_name}) != 0 ] || [ $(grep -c "core dumped" ${ut_log_name}) != 0 ] || [ $(grep -c "ModuleNotFoundError:" ${ut_log_name}) != 0 ] || [ $(grep -c "OK" ${ut_log_name}) == 0 ];then | ||
echo "Find errors in UT test, please check the output..." | ||
exit 1 | ||
fi | ||
echo "UT finished successfully! " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
trigger: none | ||
|
||
pr: | ||
autoCancel: true | ||
drafts: false | ||
branches: | ||
include: | ||
- master | ||
paths: | ||
include: | ||
- neural_compressor/common | ||
- neural_compressor/tensorflow | ||
- test/3x/tensorflow | ||
- setup.py | ||
- requirements_tf.txt | ||
|
||
pool: ICX-16C | ||
|
||
variables: | ||
IMAGE_NAME: "neural-compressor" | ||
IMAGE_TAG: "py38" | ||
UPLOAD_PATH: $(Build.SourcesDirectory)/log_dir | ||
DOWNLOAD_PATH: $(Build.SourcesDirectory)/log_dir | ||
ARTIFACT_NAME: "UT_coverage_report_3x_tf" | ||
REPO: $(Build.Repository.Uri) | ||
|
||
stages: | ||
- stage: TensorFlow | ||
displayName: Unit Test 3x TensorFlow | ||
dependsOn: [] | ||
jobs: | ||
- job: | ||
displayName: Unit Test 3x TensorFlow | ||
steps: | ||
- template: template/ut-template.yml | ||
parameters: | ||
dockerConfigName: "commonDockerConfig" | ||
utScriptFileName: "3x/run_3x_tf" | ||
uploadPath: $(UPLOAD_PATH) | ||
utArtifact: "ut_coverage_3x" | ||
|
||
|
||
- stage: TensorFlow_baseline | ||
displayName: Unit Test 3x TensorFlow baseline | ||
dependsOn: [] | ||
jobs: | ||
- job: | ||
displayName: Unit Test 3x TensorFlow baseline | ||
steps: | ||
- template: template/ut-template.yml | ||
parameters: | ||
dockerConfigName: "gitCloneDockerConfig" | ||
utScriptFileName: "3x/run_3x_tf" | ||
uploadPath: $(UPLOAD_PATH) | ||
utArtifact: "ut_coverage_3x_baseline" | ||
repo: $(REPO) | ||
|
||
- stage: Coverage | ||
displayName: "Coverage Combine" | ||
pool: | ||
vmImage: "ubuntu-latest" | ||
dependsOn: [TensorFlow, TensorFlow_baseline] | ||
jobs: | ||
- job: CollectDatafiles | ||
steps: | ||
- script: | | ||
if [[ ! $(docker images | grep -i ${IMAGE_NAME}:${IMAGE_TAG}) ]]; then | ||
docker build -f ${BUILD_SOURCESDIRECTORY}/.azure-pipelines/docker/Dockerfile.devel -t ${IMAGE_NAME}:${IMAGE_TAG} . | ||
fi | ||
docker images | grep -i ${IMAGE_NAME} | ||
if [[ $? -ne 0 ]]; then | ||
echo "NO Such Repo" | ||
exit 1 | ||
fi | ||
displayName: "Build develop docker image" | ||
- task: DownloadPipelineArtifact@2 | ||
inputs: | ||
artifact: | ||
path: $(DOWNLOAD_PATH) | ||
|
||
- script: | | ||
echo "--- create container ---" | ||
docker run -d -it --name="collectLogs" -v ${BUILD_SOURCESDIRECTORY}:/neural-compressor ${IMAGE_NAME}:${IMAGE_TAG} /bin/bash | ||
echo "--- docker ps ---" | ||
docker ps | ||
echo "--- collect logs ---" | ||
docker exec collectLogs /bin/bash +x -c "cd /neural-compressor/.azure-pipelines/scripts \ | ||
&& bash install_nc.sh 3x_tf \ | ||
&& bash ut/3x/collect_log_3x.sh 3x_tf" | ||
displayName: "collect logs" | ||
- task: PublishPipelineArtifact@1 | ||
condition: succeededOrFailed() | ||
inputs: | ||
targetPath: $(UPLOAD_PATH) | ||
artifact: $(ARTIFACT_NAME) | ||
publishLocation: "pipeline" | ||
|
||
- task: Bash@3 | ||
condition: always() | ||
inputs: | ||
targetType: "inline" | ||
script: | | ||
docker exec collectLogs bash -c "rm -fr /neural-compressor/* && rm -fr /neural-compressor/.* || true" | ||
displayName: "Docker clean up" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2023 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.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) 2023 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.static_quantize import static_quantize_entry |
15 changes: 15 additions & 0 deletions
15
neural_compressor/tensorflow/algorithms/static_quantize/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) 2023 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.static_quantize.quantize_entry import static_quantize_entry |
Oops, something went wrong.