-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Apply mlagility to create ONNX model in CI #605
Changes from all commits
a5a82ef
9db5fb2
65c5d7e
d913609
ccbaf72
b24081d
acf2326
2731ca4
398b63d
f6c54a1
0c06ef3
ac5f5ec
05c495d
1a583ec
1f1db90
500b542
ab889ae
0380b2f
6ff1014
db69afb
a0f0339
dd41d77
2795d20
37cf55e
cea6c52
19f6bc3
934765a
a6f9618
fa5d290
00e4e01
5edb28f
388806f
943fc34
d789edd
3b34a19
ff87370
28c7da1
d755004
9eff439
e0f0ff0
358887a
bec94e5
2e99292
9a1c97a
6192ee7
53b3c98
0158b32
6196319
2f6d3ee
cfeacf1
38d44af
d7d3d27
7af0369
355c6c3
4dae47a
0e1a570
0ef4ef4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Validate created ONNX model from mlagility | ||
|
||
on: | ||
push: | ||
branches: [ main, new-models] | ||
pull_request: | ||
branches: [ main, new-models] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.8'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
name: Checkout repo | ||
- uses: conda-incubator/setup-miniconda@v2 | ||
with: | ||
miniconda-version: "latest" | ||
activate-environment: mla | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies and mlagility | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install onnx onnxruntime requests py-cpuinfo | ||
# Print CPU info for debugging ONNX Runtime inference difference | ||
python -m cpuinfo | ||
git clone https://github.com/groq/mlagility.git | ||
cd mlagility | ||
pip install -r models/requirements.txt | ||
pip install -e . | ||
|
||
- name: Validate created ONNX model from mlagility | ||
run: | | ||
pip install -r models/mlagility/requirements.txt | ||
python workflow_scripts/run_mlagility.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
torch==2.0.0 | ||
torchvision==0.15.1 | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These requirements are also covered by mlagility. Do we need a separate requirements file here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, mlagility is still using torch<=1.14.0 according to https://github.com/groq/mlagility/blob/main/models/requirements.txt. ONNX needs PyTorch 2.0 here to convert opset_version 18. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MLAgility includes a setup.py that installs the base dependencies and a requirements.txt that installs additional packages for the mlagility/models. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
models_info = [ | ||
# (script_path, model_name, model_zoo_directory) | ||
("torch_hub/alexnet.py", "alexnet_torch_hub_7df2a577", "alexnet"), | ||
("torch_hub/resnet50.py", "resnet50_torch_hub_31acb52e", "resnet50"), | ||
("torchvision/fasterrcnn_resnet50_fpn_v2.py", "fasterrcnn_resnet50_fpn_v2_torchvision_ec445cac", "fasterrcnn_resnet50_fpn_v2"), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import config | ||
import os.path as osp | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
|
||
ZOO_OPSET_VERSION = "18" | ||
base_name = f"-op{ZOO_OPSET_VERSION}-base.onnx" | ||
cwd_path = Path.cwd() | ||
mlagility_root = "mlagility/models" | ||
mlagility_models_dir = "models/mlagility" | ||
cache_converted_dir = ".cache" | ||
|
||
errors = 0 | ||
|
||
for script_path, model_name, model_zoo_dir in config.models_info: | ||
try: | ||
print(f"----------------Checking {model_zoo_dir}----------------") | ||
final_model_path = osp.join(mlagility_models_dir, model_zoo_dir, f"{model_zoo_dir}-{ZOO_OPSET_VERSION}.onnx") | ||
subprocess.run(["benchit", osp.join(mlagility_root, script_path), "--cache-dir", cache_converted_dir, | ||
"--onnx-opset", ZOO_OPSET_VERSION, "--export-only"], | ||
cwd=cwd_path, stdout=sys.stdout, | ||
stderr=sys.stderr) | ||
shutil.copy(osp.join(cache_converted_dir, model_name, "onnx", model_name + base_name), final_model_path) | ||
subprocess.run(["git", "diff", "--exit-code", "--", final_model_path], | ||
cwd=cwd_path, stdout=sys.stdout, | ||
stderr=sys.stderr) | ||
print(f"Successfully checked {model_zoo_dir}.") | ||
except Exception as e: | ||
errors += 1 | ||
print(f"Failed to check {model_zoo_dir} because of {e}.") | ||
|
||
if errors > 0: | ||
print(f"All {len(config.models_info)} model(s) have been checked, but {errors} model(s) failed.") | ||
|
||
sys.exit(1) | ||
else: | ||
print(f"All {len(config.models_info)} model(s) have been checked.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 36 installs both onnx and onnxruntime. Do we need a separate pip install here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you are talking about this requirements: https://github.com/groq/mlagility/blob/main/models/requirements.txt, but actually onnx and onnxruntime are not there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installation of MLAgility here installs onnx and onnxruntime