Skip to content

Commit 156c7f0

Browse files
kirklandsignfacebook-github-bot
authored andcommitted
Improve gather_test_models (#1038)
Summary: * In export_models_for_ci(), use itertools.product to simplify the code * Add a helper model_should_run_on_event() to check whether we are doing pull.yml (pull_request) or trunk.yml (push). Only run high priority models for pull_request. To test, the envvar set by the script should be same, except for the models filtered by model_should_run_on_event() when event is pull_request Pull Request resolved: #1038 Reviewed By: huydhn Differential Revision: D50485044 Pulled By: kirklandsign fbshipit-source-id: 366cc51dfc9b2aef734e1b8acbef0fe56c9d6644
1 parent 17f6252 commit 156c7f0

File tree

3 files changed

+60
-35
lines changed

3 files changed

+60
-35
lines changed

.ci/scripts/gather_test_models.py

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8+
import itertools
89
import json
910
import os
1011
from typing import Any
@@ -47,6 +48,15 @@ def parse_args() -> Any:
4748
default="linux",
4849
help="the target OS",
4950
)
51+
parser.add_argument(
52+
"-e",
53+
"--event",
54+
type=str,
55+
choices=["pull_request", "push"],
56+
required=True,
57+
help="GitHub CI Event. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on",
58+
)
59+
5060
return parser.parse_args()
5161

5262

@@ -63,49 +73,64 @@ def set_output(name: str, val: Any) -> None:
6373
print(f"::set-output name={name}::{val}")
6474

6575

66-
def export_models_for_ci() -> None:
76+
def model_should_run_on_event(model: str, event: str) -> bool:
77+
"""
78+
A helper function to decide whether a model should be tested on an event (pull_request/push)
79+
We put higher priority and fast models to pull request and rest to push.
80+
"""
81+
if event == "pull_request":
82+
return model in ["add", "ic3", "mv2", "mv3", "resnet18", "vit"]
83+
return True
84+
85+
86+
def export_models_for_ci() -> dict[str, dict]:
6787
"""
6888
This gathers all the example models that we want to test on GitHub OSS CI
6989
"""
7090
args = parse_args()
7191
target_os = args.target_os
92+
event = args.event
7293

7394
# This is the JSON syntax for configuration matrix used by GitHub
7495
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
7596
models = {"include": []}
76-
for name in MODEL_NAME_TO_MODEL.keys():
77-
quantization_configs = {
78-
False,
79-
name in MODEL_NAME_TO_OPTIONS and MODEL_NAME_TO_OPTIONS[name].quantization,
80-
}
81-
delegation_configs = {
82-
False,
83-
name in MODEL_NAME_TO_OPTIONS and MODEL_NAME_TO_OPTIONS[name].delegation,
97+
for (name, build_tool, q_config, d_config) in itertools.product(
98+
MODEL_NAME_TO_MODEL.keys(), BUILD_TOOLS.keys(), [False, True], [False, True]
99+
):
100+
if not model_should_run_on_event(name, event):
101+
continue
102+
103+
if q_config and (
104+
(name not in MODEL_NAME_TO_OPTIONS)
105+
or (not MODEL_NAME_TO_OPTIONS[name].quantization)
106+
):
107+
continue
108+
109+
if d_config and (
110+
(name not in MODEL_NAME_TO_OPTIONS)
111+
or (not MODEL_NAME_TO_OPTIONS[name].delegation)
112+
):
113+
continue
114+
115+
if target_os not in BUILD_TOOLS[build_tool]:
116+
continue
117+
118+
record = {
119+
"build-tool": build_tool,
120+
"model": name,
121+
"xnnpack_quantization": q_config,
122+
"xnnpack_delegation": d_config,
123+
"runner": DEFAULT_RUNNERS.get(target_os, "linux.2xlarge"),
124+
# demo_backend_delegation test only supports add_mul model
125+
"demo_backend_delegation": name == "add_mul",
84126
}
85-
for build_tool in BUILD_TOOLS.keys():
86-
if target_os not in BUILD_TOOLS[build_tool]:
87-
continue
88-
89-
for q_config in quantization_configs:
90-
for d_config in delegation_configs:
91-
record = {
92-
"build-tool": build_tool,
93-
"model": name,
94-
"xnnpack_quantization": q_config,
95-
"xnnpack_delegation": d_config,
96-
"runner": DEFAULT_RUNNERS.get(target_os, "linux.2xlarge"),
97-
# demo_backend_delegation test only supports add_mul model
98-
"demo_backend_delegation": name == "add_mul",
99-
}
100-
101-
# NB: Some model requires much bigger Linux runner to avoid
102-
# running OOM. The team is investigating the root cause
103-
if target_os in CUSTOM_RUNNERS and name in CUSTOM_RUNNERS.get(
104-
target_os, {}
105-
):
106-
record["runner"] = CUSTOM_RUNNERS[target_os][name]
107-
108-
models["include"].append(record)
127+
128+
# NB: Some model requires much bigger Linux runner to avoid
129+
# running OOM. The team is investigating the root cause
130+
if target_os in CUSTOM_RUNNERS and name in CUSTOM_RUNNERS.get(target_os, {}):
131+
record["runner"] = CUSTOM_RUNNERS[target_os][name]
132+
133+
models["include"].append(record)
109134

110135
set_output("models", json.dumps(models))
111136

.github/workflows/pull.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
install_pip_dependencies
3737
install_executorch
3838
39-
PYTHONPATH="${PWD}" python .ci/scripts/gather_test_models.py
39+
PYTHONPATH="${PWD}" python .ci/scripts/gather_test_models.py --event "${GITHUB_EVENT_NAME}"
4040
4141
test-models-linux:
4242
name: test-models-linux

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
install_pip_dependencies
3636
install_executorch
3737
38-
PYTHONPATH="${PWD}" python .ci/scripts/gather_test_models.py --target-os macos
38+
PYTHONPATH="${PWD}" python .ci/scripts/gather_test_models.py --target-os macos --event "${GITHUB_EVENT_NAME}"
3939
4040
test-models-macos:
4141
name: test-models-macos

0 commit comments

Comments
 (0)