-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate onnxrt RTN WOQ to 3.x API (#1544)
Signed-off-by: yuwenzho <yuwen.zhou@intel.com> Signed-off-by: chensuyue <suyue.chen@intel.com> Signed-off-by: xin3he <xin3.he@intel.com>
- Loading branch information
Showing
30 changed files
with
2,775 additions
and
10 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
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,15 @@ | ||
[run] | ||
branch = True | ||
|
||
[report] | ||
include = | ||
*/neural_compressor/common/* | ||
*/neural_compressor/onnxrt/* | ||
exclude_lines = | ||
pragma: no cover | ||
raise NotImplementedError | ||
raise TypeError | ||
if self.device == "gpu": | ||
if device == "gpu": | ||
except ImportError: | ||
except Exception as e: |
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 ONNXRT" | ||
echo "${test_case}" | ||
|
||
# install requirements | ||
echo "set up UT env..." | ||
pip install -r /neural-compressor/test/3x/onnxrt/requirements.txt | ||
pip install coverage | ||
pip list | ||
|
||
export COVERAGE_RCFILE=/neural-compressor/.azure-pipelines/scripts/ut/3x/coverage.3x_ort | ||
inc_path=$(python -c 'import neural_compressor; print(neural_compressor.__path__[0])') | ||
cd /neural-compressor/test || exit 1 | ||
find ./3x/onnxrt/* -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_ort.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
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/onnxrt | ||
- test/3x/onnxrt | ||
- setup.py | ||
- requirements_ort.txt | ||
|
||
pool: ICX-16C | ||
|
||
variables: | ||
IMAGE_NAME: "neural-compressor" | ||
IMAGE_TAG: "py310" | ||
UPLOAD_PATH: $(Build.SourcesDirectory)/log_dir | ||
DOWNLOAD_PATH: $(Build.SourcesDirectory)/log_dir | ||
ARTIFACT_NAME: "UT_coverage_report_3x_ort" | ||
REPO: $(Build.Repository.Uri) | ||
|
||
stages: | ||
- stage: ONNXRT | ||
displayName: Unit Test 3x ONNXRT | ||
dependsOn: [] | ||
jobs: | ||
- job: | ||
displayName: Unit Test 3x ONNXRT | ||
steps: | ||
- template: template/ut-template.yml | ||
parameters: | ||
dockerConfigName: "commonDockerConfig" | ||
utScriptFileName: "3x/run_3x_ort" | ||
uploadPath: $(UPLOAD_PATH) | ||
utArtifact: "ut_coverage_3x" | ||
|
||
|
||
- stage: ONNXRT_baseline | ||
displayName: Unit Test 3x ONNXRT baseline | ||
dependsOn: [] | ||
jobs: | ||
- job: | ||
displayName: Unit Test 3x ONNXRT baseline | ||
steps: | ||
- template: template/ut-template.yml | ||
parameters: | ||
dockerConfigName: "gitCloneDockerConfig" | ||
utScriptFileName: "3x/run_3x_ort" | ||
uploadPath: $(UPLOAD_PATH) | ||
utArtifact: "ut_coverage_3x_baseline" | ||
repo: $(REPO) | ||
|
||
- stage: Coverage | ||
displayName: "Coverage Combine" | ||
pool: | ||
vmImage: "ubuntu-latest" | ||
dependsOn: [ONNXRT, ONNXRT_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_ort \ | ||
&& bash ut/3x/collect_log_3x.sh 3x_ort" | ||
displayName: "Collect UT Coverage" | ||
- 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
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,21 @@ | ||
# 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.onnxrt.utils.utility import register_algo | ||
from neural_compressor.onnxrt.algorithms import rtn_quantize_entry | ||
|
||
from neural_compressor.onnxrt.quantization import ( | ||
RTNConfig, | ||
get_default_rtn_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) 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.onnxrt.algorithms.weight_only.algo_entry import rtn_quantize_entry |
13 changes: 13 additions & 0 deletions
13
neural_compressor/onnxrt/algorithms/weight_only/__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,13 @@ | ||
# 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. |
40 changes: 40 additions & 0 deletions
40
neural_compressor/onnxrt/algorithms/weight_only/algo_entry.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,40 @@ | ||
# 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 pathlib import Path | ||
from typing import Dict, Tuple, Union | ||
|
||
import onnx | ||
|
||
from neural_compressor.common.logger import Logger | ||
from neural_compressor.common.utility import RTN | ||
from neural_compressor.onnxrt.quantization.config import RTNConfig | ||
from neural_compressor.onnxrt.utils.utility import register_algo | ||
|
||
logger = Logger().get_logger() | ||
|
||
|
||
###################### RTN Algo Entry ################################## | ||
@register_algo(name=RTN) | ||
def rtn_quantize_entry(model: Union[Path, str], quant_config: RTNConfig, *args, **kwargs) -> onnx.ModelProto: | ||
"""The main entry to apply rtn quantization.""" | ||
from neural_compressor.onnxrt.algorithms.weight_only.rtn import apply_rtn_on_model | ||
|
||
# map config to each op | ||
model_info = quant_config.get_model_info(model=model) | ||
configs_mapping = quant_config.to_config_mapping(model_info=model_info) | ||
logger.debug(configs_mapping) | ||
model = apply_rtn_on_model(model, configs_mapping) | ||
return model |
Oops, something went wrong.