5
5
# This source code is licensed under the BSD-style license found in the
6
6
# LICENSE file in the root directory of this source tree.
7
7
8
+ import itertools
8
9
import json
9
10
import os
10
11
from typing import Any
@@ -47,6 +48,15 @@ def parse_args() -> Any:
47
48
default = "linux" ,
48
49
help = "the target OS" ,
49
50
)
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
+
50
60
return parser .parse_args ()
51
61
52
62
@@ -63,49 +73,64 @@ def set_output(name: str, val: Any) -> None:
63
73
print (f"::set-output name={ name } ::{ val } " )
64
74
65
75
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 ]:
67
87
"""
68
88
This gathers all the example models that we want to test on GitHub OSS CI
69
89
"""
70
90
args = parse_args ()
71
91
target_os = args .target_os
92
+ event = args .event
72
93
73
94
# This is the JSON syntax for configuration matrix used by GitHub
74
95
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
75
96
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" ,
84
126
}
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 )
109
134
110
135
set_output ("models" , json .dumps (models ))
111
136
0 commit comments