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

Add model test CI #18

Merged
merged 61 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0fa6ea8
Add model test CI
XuehaoSun May 31, 2024
64375ae
Update branch name in model-test.yml
XuehaoSun May 31, 2024
66cf8e8
Update ONNXRT framework version to 1.17.1
XuehaoSun May 31, 2024
228f92f
test models
XuehaoSun Jun 4, 2024
4183947
fix name
XuehaoSun Jun 4, 2024
c8c4710
fix
XuehaoSun Jun 4, 2024
6ef7a78
test
XuehaoSun Jun 4, 2024
2375774
test
XuehaoSun Jun 4, 2024
79a6773
test
XuehaoSun Jun 4, 2024
a6f82bc
test
XuehaoSun Jun 4, 2024
353c105
add model test
XuehaoSun Jun 24, 2024
de0b11d
add path
XuehaoSun Jun 24, 2024
30cd0ca
fix params name
XuehaoSun Jun 24, 2024
f44f811
fix docker
XuehaoSun Jun 24, 2024
e3dfcef
fix jq cmd
XuehaoSun Jun 24, 2024
d09ef2e
fix typo
XuehaoSun Jun 24, 2024
1b5549f
fix spellcheck
XuehaoSun Jun 24, 2024
25e7408
fix spellcheck
XuehaoSun Jun 24, 2024
06e4b59
fix spellcheck
XuehaoSun Jun 24, 2024
fd91977
Merge branch 'main' into xuehao/model_test
XuehaoSun Jun 28, 2024
65cee90
fix
XuehaoSun Jun 28, 2024
0d7e50d
fix
XuehaoSun Jun 28, 2024
4d8974e
fix
XuehaoSun Jun 28, 2024
b417c94
fix
XuehaoSun Jun 28, 2024
a49d612
fix batch size
XuehaoSun Jul 1, 2024
1b47a5e
test
XuehaoSun Jul 1, 2024
145472a
fix env setup
XuehaoSun Jul 1, 2024
c05d2c6
Update dependencies for image_recognition and nlp models
XuehaoSun Jul 1, 2024
7934b93
fix
XuehaoSun Jul 1, 2024
4418482
fix: Update dataset location for resnet models
XuehaoSun Jul 1, 2024
7a5e0ee
fix: Update dataset location for resnet models
XuehaoSun Jul 1, 2024
234369e
fix
XuehaoSun Jul 1, 2024
30ebe8c
chore: Add script to collect performance and accuracy results
XuehaoSun Jul 1, 2024
b4738a5
fix log collect
XuehaoSun Jul 1, 2024
076f08d
fix name
XuehaoSun Jul 1, 2024
c1cdb26
fix
XuehaoSun Jul 1, 2024
84d2e0c
fix
XuehaoSun Jul 1, 2024
dd8cef8
fix
XuehaoSun Jul 2, 2024
df16325
fix
XuehaoSun Jul 2, 2024
1849f4a
fix
XuehaoSun Jul 2, 2024
f4c499e
test
XuehaoSun Jul 2, 2024
cacefb0
fix
XuehaoSun Jul 2, 2024
d58042e
fix
XuehaoSun Jul 2, 2024
454bea2
fix
XuehaoSun Jul 2, 2024
a0231b6
fix
XuehaoSun Jul 2, 2024
d2f1ebe
fix
XuehaoSun Jul 2, 2024
12abd31
fix
XuehaoSun Jul 2, 2024
fed0114
fix
XuehaoSun Jul 2, 2024
1c63a98
fix
XuehaoSun Jul 2, 2024
fd60cfb
for test
XuehaoSun Jul 2, 2024
55ed6db
update ratio
XuehaoSun Jul 2, 2024
7a4e580
add status check
XuehaoSun Jul 3, 2024
37f8944
fix
XuehaoSun Jul 3, 2024
e7b9ff0
fix
XuehaoSun Jul 3, 2024
55df1b2
fix typo
XuehaoSun Jul 3, 2024
3c7ccbe
fix report
XuehaoSun Jul 4, 2024
d708cdb
fix lint
XuehaoSun Jul 5, 2024
bbd9f37
fix path
XuehaoSun Jul 5, 2024
aa35000
update agent pool
XuehaoSun Jul 5, 2024
6ca582b
fix
XuehaoSun Jul 16, 2024
012f372
add name
XuehaoSun Jul 16, 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
1 change: 1 addition & 0 deletions .azure-pipelines/docker/Dockerfile.devel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
time \
wget \
bc \
jq \
vim

RUN ln -sf $(which python3) /usr/bin/python
Expand Down
121 changes: 121 additions & 0 deletions .azure-pipelines/model-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
trigger: none

pr:
autoCancel: true
drafts: false
branches:
include:
- main
paths:
include:
- onnx_neural_compressor
- setup.py
- requirements.txt
- .azure-pipelines/scripts/models
- .azure-pipelines/model-test.yml
- .azure-pipelines/template/model-template.yml
exclude:
- test

variables:
OUT_SCRIPT_PATH: $(Build.SourcesDirectory)/.azure-pipelines/scripts/models
SCRIPT_PATH: /neural_compressor/.azure-pipelines/scripts

parameters:
- name: algorithms
type: object
default:
- SQ
- WOQ
- name: models
type: object
default:
- bert_base_MRPC
- bert_base_MRPC_dynamic
- resnet50-v1-12_qdq
- resnet50-v1-12

stages:
# - stage: ONNX_LLM_Models
chensuyue marked this conversation as resolved.
Show resolved Hide resolved
# displayName: Run ONNX LLM Model
# pool: ICX-16C
# dependsOn: []
# jobs:
# - ${{ each algorithm in parameters.algorithms }}:
# - job:
# steps:
# - template: template/model-template.yml
# parameters:
# modelName: "facebook/opt-125m"
# algorithm: "${{ algorithm }}"
# script_path: "run_onnxrt_llm_models_trigger.sh"

- stage: ONNX_Models
displayName: Run ONNX Model
pool: MODEL_PERF_TEST
dependsOn: []
jobs:
- ${{ each model in parameters.models }}:
- job:
chensuyue marked this conversation as resolved.
Show resolved Hide resolved
displayName: ${{ model }}
steps:
- template: template/model-template.yml
parameters:
modelName: "${{ model }}"
algorithm: "Quantize"
script_path: "run_onnxrt_models_trigger.sh"

- stage: GenerateLogs
displayName: Generate Report
pool:
vmImage: "ubuntu-latest"
dependsOn: [ONNX_Models]
jobs:
- job: GenerateReport
steps:
- script: |
echo ${BUILD_SOURCESDIRECTORY}
rm -fr ${BUILD_SOURCESDIRECTORY} || sudo rm -fr ${BUILD_SOURCESDIRECTORY} || true
echo y | docker system prune
displayName: "Clean workspace"
- checkout: self
clean: true
displayName: "Checkout out Repo"
- task: DownloadPipelineArtifact@2
inputs:
artifact:
patterns: "**/result.json"
path: $(OUT_SCRIPT_PATH)
- task: UsePythonVersion@0
displayName: "Use Python 3.10"
inputs:
versionSpec: "3.10"
- script: |
cd ${OUT_SCRIPT_PATH}
mkdir generated last_generated
python -u summarize_results.py --logs_dir $(OUT_SCRIPT_PATH) --output_dir generated
displayName: "Summarize all results"
- task: DownloadPipelineArtifact@2
continueOnError: true
inputs:
source: "specific"
artifact: "FinalReport"
patterns: "**.json"
path: $(OUT_SCRIPT_PATH)/last_generated
project: $(System.TeamProject)
pipeline: "onc model test"
runVersion: "specific"
runId: $(refer_buildId)
displayName: "Download last logs"
- script: |
echo "------ Generating final report.html ------"
cd ${OUT_SCRIPT_PATH}
pip install jinja2
python generate_report.py --json_path generated/summary.json --last_json_path last_generated/summary.json
displayName: "Generate report"
- task: PublishPipelineArtifact@1
inputs:
targetPath: $(OUT_SCRIPT_PATH)/generated
artifact: FinalReport
publishLocation: "pipeline"
displayName: "Publish report"
84 changes: 84 additions & 0 deletions .azure-pipelines/scripts/models/collect_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import argparse
import json
import os
import re

parser = argparse.ArgumentParser()
parser.add_argument("--model", required=True, type=str)
parser.add_argument("--build_id", required=True, type=str)
args = parser.parse_args()

URL = (
"https://dev.azure.com/lpot-inc/onnx-neural-compressor/_build/results?buildId="
+ args.build_id
+ "&view=artifacts&pathAsName=false&type=publishedArtifacts"
)
REFER_SUMMARY_PATH = "/neural-compressor/.azure-pipelines/scripts/models/summary.json"


def str_to_float(value):
try:
return round(float(value), 4)
except ValueError:
return value


def get_refer_data():
if not os.path.exists(REFER_SUMMARY_PATH):
print(f"The file '{REFER_SUMMARY_PATH}' does not exist.")
return {}

with open(REFER_SUMMARY_PATH, "r") as file:
refer = json.load(file)
return refer


def check_status(performance, accuracy):
refer = get_refer_data()

refer_accuracy = refer.get(args.model, {}).get("accuracy", {}).get("value", "N/A")
refer_performance = refer.get(args.model, {}).get("performance", {}).get("value", "N/A")
print(f"{accuracy=}\n{refer_accuracy=}\n{performance=}\n{refer_performance=}")

assert accuracy != "N/A" and performance != "N/A"
if refer_accuracy != "N/A":
assert abs(accuracy - refer_accuracy) <= 0.001
if refer_performance != "N/A":
assert (refer_performance - performance) / refer_performance <= 0.08


def main():
result_dict = {
args.model: {
"performance": {"value": "N/A", "log_path": URL},
"accuracy": {"value": "N/A", "log_path": URL},
}
}

pattern = {
"performance": r"Throughput: ([\d.]+)",
"accuracy": r"Accuracy: ([\d.]+)",
}

for mode, _ in result_dict[args.model].items():
log_file = f"/neural-compressor/.azure-pipelines/scripts/models/{args.model}/{mode}.log"
if not os.path.exists(log_file):
print(f"The file '{log_file}' does not exist.")
continue

with open(log_file, "r") as file:
log_content = file.read()

match = re.search(pattern[mode], log_content)

if match:
result_dict[args.model][mode]["value"] = str_to_float(match.group(1))

with open(f"/neural-compressor/.azure-pipelines/scripts/models/{args.model}/result.json", "w") as json_file:
json.dump(result_dict, json_file, indent=4)

check_status(result_dict[args.model]["performance"]["value"], result_dict[args.model]["accuracy"]["value"])


if __name__ == "__main__":
main()
39 changes: 39 additions & 0 deletions .azure-pipelines/scripts/models/env_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -eo pipefail
PATTERN='[-a-zA-Z0-9_]*='

for i in "$@"; do
case $i in
--model=*)
model=${i//${PATTERN}/}
;;
*)
echo "Parameter $i not recognized."
exit 1
;;
esac
done

CONFIG_PATH="/neural-compressor/examples/.config/model_params_onnxrt.json"
model_src_dir=$(jq -r ".\"onnxrt\".\"$model\".\"model_src_dir\"" "$CONFIG_PATH")

log_dir="/neural-compressor/.azure-pipelines/scripts/models"

$BOLD_YELLOW && echo "======= creat log_dir =========" && $RESET
if [ -d "${log_dir}/${model}" ]; then
$BOLD_GREEN && echo "${log_dir}/${model} already exists, don't need to mkdir." && $RESET
else
$BOLD_GREEN && echo "no log dir ${log_dir}/${model}, create." && $RESET
cd "${log_dir}"
mkdir "${model}"
fi

$BOLD_YELLOW && echo "====== install ONC ======" && $RESET
cd /neural-compressor
source .azure-pipelines/scripts/change_color.sh
/bin/bash .azure-pipelines/scripts/install_nc.sh

$BOLD_YELLOW && echo "====== install requirements ======" && $RESET
cd "/neural-compressor/examples/$model_src_dir"
pip install -r requirements.txt
pip list
103 changes: 103 additions & 0 deletions .azure-pipelines/scripts/models/generate_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import argparse
import json
import os

from jinja2 import Environment, FileSystemLoader

parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument("--json_path", type=str, required=True)
parser.add_argument("--last_json_path", type=str, required=True)
args = parser.parse_args()


def get_data(json_path):
"""
{
model: {
"performance": {"value": "N/A"|number, "log_path": string},
"accuracy": {"value": "N/A"|number, "log_path": string},
}
}
"""
if os.path.exists(json_path):
with open(json_path, "r") as f:
return json.load(f)
else:
return {}


def get_ratio(cur, last):
if cur == "N/A" or last == "N/A":
ratio = "N/A"
else:
ratio = (float(cur) - float(last)) / float(last) * 100
ratio = round(float(ratio), 2)
return ratio


def get_accuracy_ratio(current_json, last_accuracy_dict):
compare_result_dict = []
for model, item in current_json.items():
current_accuracy = item.get("accuracy", {}).get("value", "N/A")
last_accuracy = last_accuracy_dict.get(model, {}).get("accuracy", {}).get("value", "N/A")
accuracy_ratio = get_ratio(current_accuracy, last_accuracy)

current_performance = item.get("performance", {}).get("value", "N/A")
last_performance = last_accuracy_dict.get(model, {}).get("performance", {}).get("value", "N/A")
performance_ratio = get_ratio(current_performance, last_performance)

if accuracy_ratio == "N/A" or performance_ratio == "N/A":
status = "FAILURE"
elif accuracy_ratio != 0:
status = "FAILURE"
elif performance_ratio > 8 or performance_ratio < -8:
status = "FAILURE"
else:
status = "SUCCESS"

format_ratio = lambda x: f"{x}%" if x != "N/A" else x

compare_result_dict.append(
{
"model": model,
"current_accuracy": current_accuracy,
"last_accuracy": last_accuracy,
"accuracy_ratio": format_ratio(accuracy_ratio),
"current_performance": current_performance,
"last_performance": last_performance,
"performance_ratio": format_ratio(performance_ratio),
"status": status,
}
)
return compare_result_dict


def generate(rendered_template):
with open("generated/report.html", "w") as html_file:
html_file.write(rendered_template)


def main():
path = "{}/templates/".format(os.path.dirname(__file__))
BUILD_BUILDID = os.getenv("BUILD_BUILDID")

loader = FileSystemLoader(path)
env = Environment(loader=loader)
template = env.get_template("model.jinja2")

data = get_data(args.json_path)
last_data = get_data(args.last_json_path)
data = get_accuracy_ratio(data, last_data)
info = {
"url": f"https://dev.azure.com/lpot-inc/onnx-neural-compressor/_build/results?buildId={BUILD_BUILDID}",
"branch": os.getenv("SYSTEM_PULLREQUEST_SOURCEBRANCH"),
"commit": os.getenv("BUILD_SOURCEVERSION"),
"build_number": BUILD_BUILDID,
}

rendered_template = template.render(data=data, info=info)
generate(rendered_template)


if __name__ == "__main__":
main()
Loading
Loading