Skip to content

Commit c524960

Browse files
authored
Support '-' in script input arguments, --mlc_output for printing scri… (#199)
1 parent de3ca65 commit c524960

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

.github/workflows/mlperf-inference-resnet50.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- name: Test MLPerf inference ResNet50 on Windows (prebuilt loadgen)
4545
if: runner.os == 'Windows'
4646
run: |
47+
git config --system core.longpaths true
4748
mlc run script --tags=run-mlperf,inference,_submission,_short --submitter="MLCommons" --hw_name=gh_action --model=resnet50 --implementation=${{ matrix.implementation }} --backend=${{ matrix.backend }} --device=cpu --scenario=Offline --test_query_count=100 --target_qps=1 -v --quiet --adr.loadgen.tags=_from-pip --pip_loadgen=yes
4849
4950
- name: Test MLPerf inference ResNet50 on Unix systems

mlc/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ def process_console_output(res, target, action, run_args):
125125
log_flag_aliases = {'-v': '--verbose', '-s': '--silent'}
126126
log_levels = {'--verbose': logging.DEBUG, '--silent': logging.WARNING}
127127

128+
def convert_hyphen_to_underscore_in_args():
129+
for i, arg in enumerate(sys.argv):
130+
if arg.startswith("--") and "=" not in arg:
131+
prefix = "--"
132+
rest = arg[2:].replace("-", "_")
133+
a = prefix + rest
134+
sys.argv[i] = a
135+
128136

129137
def build_pre_parser():
130138
pre_parser = argparse.ArgumentParser(add_help=False)
@@ -265,6 +273,7 @@ def main():
265273
"""
266274

267275
check_raw_arguments_for_non_ascii()
276+
convert_hyphen_to_underscore_in_args()
268277

269278
pre_parser = build_pre_parser()
270279
pre_args, remaining_args = pre_parser.parse_known_args()

mlc/repo_action.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ def register_repo(self, repo_path, repo_meta):
143143
with open(repos_file_path, 'w') as f:
144144
json.dump(repos_list, f, indent=2)
145145
logger.info(f"Updated repos.json at {repos_file_path}")
146+
147+
146148
return {'return': 0}
147149

148150
def unregister_repo(self, repo_path):
149151
repos_file_path = os.path.join(self.repos_path, 'repos.json')
152+
150153
return unregister_repo(repo_path, repos_file_path)
151154

152155

@@ -366,6 +369,7 @@ def pull_repo(self, repo_url, branch=None, checkout = None, tag = None, pat = No
366369
r = self.register_repo(repo_path, meta_data)
367370
if r['return'] > 0:
368371
return r
372+
369373
return {"return": 0}
370374

371375
except subprocess.CalledProcessError as e:
@@ -441,6 +445,7 @@ def pull(self, run_args):
441445
if res['return'] > 0:
442446
return res
443447

448+
444449
return {'return': 0}
445450

446451

@@ -546,6 +551,8 @@ def rm_repo(repo_path, repos_file_path, force_remove):
546551
unregister_repo(repo_path, repos_file_path)
547552
else:
548553
logger.info("rm repo ooperation cancelled by user!")
554+
555+
549556
else:
550557
logger.warning(f"Repo {repo_name} was not found in the repo folder. repos.json will be checked for any corrupted entry. If any, that will be removed.")
551558
unregister_repo(repo_path, repos_file_path)
@@ -565,5 +572,6 @@ def unregister_repo(repo_path, repos_file_path):
565572
logger.info(f"Path: {repo_path} has been removed.")
566573
else:
567574
logger.info(f"Path: {repo_path} not found in {repos_file_path}. Nothing to be unregistered!")
575+
568576
return {'return': 0}
569577

mlc/script_action.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
import sys
44
import importlib
5+
import json
6+
from .index import Index
57
from . import utils
68
from .logger import logger
79

@@ -228,8 +230,11 @@ def call_script_module_function(self, function_name, run_args):
228230
"repo": "mlcommons@mlperf-automations",
229231
"branch": "dev"
230232
})
231-
233+
232234
if result['return'] == 0:
235+
self.repos = self.load_repos_and_meta()
236+
self.index = Index(self.repos_path, self.repos)
237+
233238
# Try to find the script path again after pulling
234239
script_path = self.find_target_folder("script")
235240
if not script_path:
@@ -267,6 +272,15 @@ def call_script_module_function(self, function_name, run_args):
267272
if result['return'] > 0:
268273
error = result.get('error', "")
269274
raise ScriptExecutionError(f"Script {function_name} execution failed. Error : {error}")
275+
276+
if str(run_args.get("mlc_output")).lower() in ["on", "true", "yes", "1"]:
277+
with open("tmp-state.json", "w") as f:
278+
json.dump(result['new_state'], f, indent=2)
279+
280+
with open("tmp-run-env.out", "w") as f:
281+
for key,val in result['new_env'].items():
282+
f.write(f"""{key}="{val}"\n""")
283+
270284
return result
271285
else:
272286
logger.info("ScriptAutomation class not found in the script.")

0 commit comments

Comments
 (0)