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 onnxrt RTN WOQ to 3.x API #1544

Merged
merged 25 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
653ce7d
migrate onnx woq to 3.x API
yuwenzho Jan 16, 2024
cff0a04
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 16, 2024
cebecfa
Merge branch 'master' into yuwenzho/onnx_woq_3x
yuwenzho Jan 16, 2024
65b6f6e
Merge branch 'master' into yuwenzho/onnx_woq_3x
yuwenzho Jan 17, 2024
207a393
update onnxrt RTN 3.x API
yuwenzho Jan 17, 2024
c01efee
Merge branch 'master' into yuwenzho/onnx_woq_3x
yuwenzho Jan 17, 2024
40f910a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 17, 2024
f1b1d13
update ort 3.x code install
chensuyue Jan 18, 2024
dc1c3c3
support ort 3.x CI test
chensuyue Jan 18, 2024
ec33940
remove 3.x API in 2.x binary
chensuyue Jan 18, 2024
82dde53
update onnxrt 3.x RTN
yuwenzho Jan 18, 2024
f1552a3
Merge branch 'master' into yuwenzho/onnx_woq_3x
yuwenzho Jan 18, 2024
d4bffd1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 18, 2024
fda323c
add requirments
chensuyue Jan 19, 2024
2fa01d3
Merge branch 'yuwenzho/onnx_woq_3x' of https://github.com/intel/neura…
chensuyue Jan 19, 2024
d4d3dd0
add separate requirements file for fw api ut test
chensuyue Jan 19, 2024
47ea383
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 19, 2024
090a29e
fix typo
chensuyue Jan 19, 2024
5891a59
Merge branch 'yuwenzho/onnx_woq_3x' of https://github.com/intel/neura…
chensuyue Jan 19, 2024
3b1759a
add the missing init file
chensuyue Jan 19, 2024
eab4777
fix 3.x coverage counting issue
chensuyue Jan 19, 2024
5957b8e
Rename RTNWeightOnlyConfig to RTNConfig (#1551)
xin3he Jan 19, 2024
4d124d0
update ort RTN 3.xAPI
yuwenzho Jan 19, 2024
d4b0a0b
Merge branch 'master' into yuwenzho/onnx_woq_3x
yuwenzho Jan 19, 2024
c4c9ee7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 19, 2024
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
4 changes: 4 additions & 0 deletions .azure-pipelines/scripts/install_nc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ 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
elif [[ $1 = *"3x_ort" ]]; then
python -m pip install --no-cache-dir -r requirements_ort.txt
python setup.py ort 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
Expand Down
15 changes: 15 additions & 0 deletions .azure-pipelines/scripts/ut/3x/coverage.3x_ort
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:
34 changes: 34 additions & 0 deletions .azure-pipelines/scripts/ut/3x/run_3x_ort.sh
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! "
3 changes: 1 addition & 2 deletions .azure-pipelines/scripts/ut/3x/run_3x_pt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ echo "${test_case}"

# install requirements
echo "set up UT env..."
pip install transformers
pip install -r /neural-compressor/test/3x/torch/requirements.txt
pip install coverage
pip install pytest
pip list

export COVERAGE_RCFILE=/neural-compressor/.azure-pipelines/scripts/ut/3x/coverage.3x_pt
Expand Down
2 changes: 1 addition & 1 deletion .azure-pipelines/scripts/ut/3x/run_3x_tf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ echo "${test_case}"

# install requirements
echo "set up UT env..."
pip install -r /neural-compressor/test/3x/tensorflow/requirements.txt
pip install coverage
pip install pytest
pip list

export COVERAGE_RCFILE=/neural-compressor/.azure-pipelines/scripts/ut/3x/coverage.3x_tf
Expand Down
106 changes: 106 additions & 0 deletions .azure-pipelines/ut-3x-ort.yml
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 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"
1 change: 1 addition & 0 deletions .azure-pipelines/ut-basic-no-cover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pr:
- neural_compressor/common
- neural_compressor/torch
- neural_compressor/tensorflow
- neural_compressor/onnxrt

pool: ICX-16C

Expand Down
1 change: 1 addition & 0 deletions .azure-pipelines/ut-basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pr:
- neural_compressor/common
- neural_compressor/torch
- neural_compressor/tensorflow
- neural_compressor/onnxrt

pool: ICX-16C

Expand Down
22 changes: 22 additions & 0 deletions neural_compressor/onnxrt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.utils.utility import register_algo
from neural_compressor.onnxrt.algorithms import rtn_quantize_entry

from neural_compressor.onnxrt.quantization import (
_quantize,
yuwenzho marked this conversation as resolved.
Show resolved Hide resolved
RTNWeightQuantConfig,
get_default_rtn_config,
)
16 changes: 16 additions & 0 deletions neural_compressor/onnxrt/algorithms/__init__.py
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 neural_compressor/onnxrt/algorithms/weight_only/__init__.py
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.
39 changes: 39 additions & 0 deletions neural_compressor/onnxrt/algorithms/weight_only/algo_entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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 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_WEIGHT_ONLY_QUANT
from neural_compressor.onnxrt.quantization.config import RTNWeightQuantConfig
from neural_compressor.onnxrt.utils.utility import register_algo

logger = Logger().get_logger()


###################### RTN Algo Entry ##################################
@register_algo(name=RTN_WEIGHT_ONLY_QUANT)
def rtn_quantize_entry(
model: Union[Path, str],
configs_mapping: Dict[Tuple[str, callable], RTNWeightQuantConfig],
yuwenzho marked this conversation as resolved.
Show resolved Hide resolved
) -> onnx.ModelProto:
"""The main entry to apply rtn quantization."""
from neural_compressor.onnxrt.algorithms.weight_only.rtn import apply_rtn_on_model

model = apply_rtn_on_model(model, configs_mapping)
return model
Loading
Loading