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

first onnx neural compressor commit #3

Merged
merged 18 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .azure-pipelines/docker/Dockerfile.devel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For CI, I would prefer github actions when possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can have a migrate plan. May I know the reason to choose GHA instead of Azure pipeline?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - ONNX has moved to use github actions because they are easier to manage (doesn't need to belong to an ado organization which would require additional permissions) and they run faster. So that's two wins. I use chatgpt to translate the yaml files and it was pretty straightforward: onnx/onnx#6075

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw there are several comments on CI tools, those are good suggestions. In our plan, this PR intends to land a MVP scope code migration to community first and enhance the CI/CD continuously during maintenance. I suggest to get this PR merged first and address these items progressively. does it make sense? @freddychiu @justinchuby

Copy link
Contributor

@thuang6 thuang6 May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Copyright (c) 2022 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.
ARG UBUNTU_VER=22.04
FROM ubuntu:${UBUNTU_VER} as devel

# See http://bugs.python.org/issue19846
ENV LANG C.UTF-8

RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
python3 \
python3-pip \
python3-dev \
python3-distutils \
autoconf \
build-essential \
git \
libgl1-mesa-glx \
libglib2.0-0 \
numactl \
time \
wget \
bc \
vim

RUN ln -sf $(which python3) /usr/bin/python

RUN python -m pip --no-cache-dir install --upgrade pip
RUN python -m pip install --no-cache-dir setuptools

RUN pip list

WORKDIR /

81 changes: 81 additions & 0 deletions .azure-pipelines/scripts/change_color.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# -------------- general approach start----------------

# 1. import this file:
# source path/change_color.sh
# 2. use COLOR/BG:
# $VARIABLE_NAME && out_put_content && $RESET
# 3. COLOR + BG:
# $COLOR/BG_VARIABLE_NAME && $BG/COLOR_VARIABLE_NAME && out_put_content && $RESET
# 4. custom
# abbreviation(change number)
# txt number range (30, 37)
# bg number range (40, 47)
# special effects number range (1, 7)
# echo -en \\E[number1 + ; + number2 + ; + number3 + m"
# e.g - BG_GRAY+LIGHT_RED = "echo -en \\E[47;31m"

# -------------- general approach end----------------==


# general setting
# ------------- light_color start----------------
# black
LIGHT_BLACK="echo -en \\E[30m"
# red
LIGHT_RED="echo -en \\E[31m"
# green
LIGHT_GREEN="echo -en \\E[32m"
# yellow
LIGHT_YELLOW="echo -en \\E[33m"
# blue
LIGHT_BLUE="echo -en \\E[34m"
# purple
LIGHT_PURPLE="echo -en \\E[35m"
# cyan
LIGHT_CYAN="echo -en \\E[36m"
# gray
LIGHT_GRAY="echo -en \\E[37m"
# ------------- light_color end----------------

# ------------- bold_color start----------------
# black
BOLD_BLACK="echo -en \\E[1;30m"
# red
BOLD_RED="echo -en \\E[1;31m"
# green
BOLD_GREEN="echo -en \\E[1;32m"
# yellow
BOLD_YELLOW="echo -en \\E[1;33m"
# blue
BOLD_BLUE="echo -en \\E[1;34m"
# purple
BOLD_PURPLE="echo -en \\E[1;35m"
# cyan
BOLD_CYAN="echo -en \\E[1;36m"
# gray
BOLD_GRAY="echo -en \\E[1;37m"
# ------------- bold_color end----------------

# ------------- background_color start----------------
# black
BG_BLACK="echo -en \\E[40m"
# red
BG_RED="echo -en \\E[41m"
# green
BG_GREEN="echo -en \\E[42m"
# yellow
BG_YELLOW="echo -en \\E[43m"
# blue
BG_BLUE="echo -en \\E[44m"
# purple
BG_PURPLE="echo -en \\E[45m"
# cyan
BG_CYAN="echo -en \\E[46m"
# gray
BG_GRAY="echo -en \\E[47m"
# ------------- background_color end----------------

# close
RESET="echo -en \\E[0m"
14 changes: 14 additions & 0 deletions .azure-pipelines/scripts/codeScan/codespell/inc_dict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
activ
ans
datas
ende
lates
masia
mutli
nd
ot
rouge
te
tne
ue
womens
11 changes: 11 additions & 0 deletions .azure-pipelines/scripts/install_nc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/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 --force-reinstall

echo -e "\n pip list after install Neural Compressor ... "
pip list
133 changes: 133 additions & 0 deletions .azure-pipelines/scripts/ut/collect_log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
source /neural-compressor/.azure-pipelines/scripts/change_color.sh

set -e
pip install coverage
export COVERAGE_RCFILE=/neural-compressor/.azure-pipelines/scripts/ut/coverage.ort
coverage_log="/neural-compressor/log_dir/coverage_log"
coverage_log_base="/neural-compressor/log_dir/coverage_log_base"
coverage_compare="/neural-compressor/log_dir/coverage_compare.html"
cd /neural-compressor/log_dir

$BOLD_YELLOW && echo "collect coverage for PR branch" && $RESET
cp ut_coverage/.coverage /neural-compressor/
mkdir -p coverage_PR
cd /neural-compressor
coverage report -m --rcfile=${COVERAGE_RCFILE} | tee ${coverage_log}
coverage html -d log_dir/coverage_PR/htmlcov --rcfile=${COVERAGE_RCFILE}
coverage xml -o log_dir/coverage_PR/coverage.xml --rcfile=${COVERAGE_RCFILE}
ls -l log_dir/coverage_PR/htmlcov


$BOLD_YELLOW && echo "collect coverage for baseline" && $RESET
cd /neural-compressor
cp -r /neural-compressor/.azure-pipelines .azure-pipelines-pr
git config --global --add safe.directory /neural-compressor
git fetch
git checkout ONC
rm -rf build dist *egg-info
echo y | pip uninstall neural_compressor_ort
cd /neural-compressor/.azure-pipelines-pr/scripts && bash install_nc.sh

coverage erase
cd /neural-compressor/log_dir
mkdir -p coverage_base
rm -rf /neural-compressor/.coverage || true
cp ut_baseline_coverage/.coverage /neural-compressor

cd /neural-compressor
coverage report -m --rcfile=${COVERAGE_RCFILE} | tee ${coverage_log_base}
coverage html -d log_dir/coverage_base/htmlcov --rcfile=${COVERAGE_RCFILE}
coverage xml -o log_dir/coverage_base/coverage.xml --rcfile=${COVERAGE_RCFILE}
ls -l log_dir/coverage_base/htmlcov

get_coverage_data() {
# Input argument
local coverage_xml="$1"

# Get coverage data
local coverage_data=$(python3 -c "import xml.etree.ElementTree as ET; root = ET.parse('$coverage_xml').getroot(); print(ET.tostring(root).decode())")
if [[ -z "$coverage_data" ]]; then
echo "Failed to get coverage data from $coverage_xml."
exit 1
fi

# Get lines coverage
local lines_covered=$(echo "$coverage_data" | grep -o 'lines-covered="[0-9]*"' | cut -d '"' -f 2)
local lines_valid=$(echo "$coverage_data" | grep -o 'lines-valid="[0-9]*"' | cut -d '"' -f 2)
if [ $lines_valid == 0 ]; then
local lines_coverage=0
else
local lines_coverage=$(awk "BEGIN {printf \"%.3f\", 100 * $lines_covered / $lines_valid}")
fi

# Get branches coverage
local branches_covered=$(echo "$coverage_data" | grep -o 'branches-covered="[0-9]*"' | cut -d '"' -f 2)
local branches_valid=$(echo "$coverage_data" | grep -o 'branches-valid="[0-9]*"' | cut -d '"' -f 2)
if [ $branches_valid == 0 ]; then
local branches_coverage=0
else
local branches_coverage=$(awk "BEGIN {printf \"%.3f\", 100 * $branches_covered/$branches_valid}")
fi

# Return values
echo "$lines_covered $lines_valid $lines_coverage $branches_covered $branches_valid $branches_coverage"
}

$BOLD_YELLOW && echo "compare coverage" && $RESET

coverage_PR_xml="log_dir/coverage_PR/coverage.xml"
coverage_PR_data=$(get_coverage_data $coverage_PR_xml)
read lines_PR_covered lines_PR_valid coverage_PR_lines_rate branches_PR_covered branches_PR_valid coverage_PR_branches_rate <<<"$coverage_PR_data"

coverage_base_xml="log_dir/coverage_base/coverage.xml"
coverage_base_data=$(get_coverage_data $coverage_base_xml)
read lines_base_covered lines_base_valid coverage_base_lines_rate branches_base_covered branches_base_valid coverage_base_branches_rate <<<"$coverage_base_data"

$BOLD_BLUE && echo "PR lines coverage: $lines_PR_covered/$lines_PR_valid ($coverage_PR_lines_rate%)" && $RESET
$BOLD_BLUE && echo "PR branches coverage: $branches_PR_covered/$branches_PR_valid ($coverage_PR_branches_rate%)" && $RESET
$BOLD_BLUE && echo "BASE lines coverage: $lines_base_covered/$lines_base_valid ($coverage_base_lines_rate%)" && $RESET
$BOLD_BLUE && echo "BASE branches coverage: $branches_base_covered/$branches_base_valid ($coverage_base_branches_rate%)" && $RESET

$BOLD_YELLOW && echo "clear upload path" && $RESET
rm -fr log_dir/coverage_PR/.coverage*
rm -fr log_dir/coverage_base/.coverage*
rm -fr log_dir/ut-coverage-*

# Declare an array to hold failed items
declare -a fail_items=()

if (( $(bc -l <<< "${coverage_PR_lines_rate}+0.05 < ${coverage_base_lines_rate}") )); then
fail_items+=("lines")
fi
if (( $(bc -l <<< "${coverage_PR_branches_rate}+0.05 < ${coverage_base_branches_rate}") )); then
fail_items+=("branches")
fi

if [[ ${#fail_items[@]} -ne 0 ]]; then
fail_items_str=$(
IFS=', '
echo "${fail_items[*]}"
)
for item in "${fail_items[@]}"; do
case "$item" in
lines)
decrease=$(echo $(printf "%.3f" $(echo "$coverage_PR_lines_rate - $coverage_base_lines_rate" | bc -l)))
;;
branches)
decrease=$(echo $(printf "%.3f" $(echo "$coverage_PR_branches_rate - $coverage_base_branches_rate" | bc -l)))
;;
*)
echo "Unknown item: $item"
continue
;;
esac
$BOLD_RED && echo "Unit Test failed with ${item} coverage decrease ${decrease}%" && $RESET
done
$BOLD_RED && echo "compare coverage to give detail info" && $RESET
bash /neural-compressor/.azure-pipelines-pr/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "FAILED" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
exit 1
else
$BOLD_GREEN && echo "Unit Test success with coverage lines: ${coverage_PR_lines_rate}%, branches: ${coverage_PR_branches_rate}%" && $RESET
$BOLD_GREEN && echo "compare coverage to give detail info" && $RESET
bash /neural-compressor/.azure-pipelines-pr/scripts/ut/compare_coverage.sh ${coverage_compare} ${coverage_log} ${coverage_log_base} "SUCCESS" ${coverage_PR_lines_rate} ${coverage_base_lines_rate} ${coverage_PR_branches_rate} ${coverage_base_branches_rate}
fi