2323
2424BENCHMARK_RESULTS_FILENAME = "benchmark_results.json"
2525ARTIFACTS_FILENAME_REGEX = re .compile (r"(android|ios)-artifacts-(?P<job_id>\d+).json" )
26+ BENCHMARK_CONFIG_REGEX = re .compile (
27+ r"# The benchmark config is (?P<benchmark_config>.+)"
28+ )
2629
2730# iOS-related regexes and variables
2831IOS_TEST_SPEC_REGEX = re .compile (
@@ -308,7 +311,7 @@ def extract_job_id(artifacts_filename: str) -> int:
308311 return int (m .group ("job_id" ))
309312
310313
311- def read_benchmark_configs ( benchmark_configs : str ) -> Dict [str , Dict [str , str ]]:
314+ def read_all_benchmark_configs ( ) -> Dict [str , Dict [str , str ]]:
312315 """
313316 Read all the benchmark configs that we can find
314317 """
@@ -325,16 +328,44 @@ def read_benchmark_configs(benchmark_configs: str) -> Dict[str, Dict[str, str]]:
325328 return benchmark_configs
326329
327330
328- def get_benchmark_configs (benchmark_configs : Dict [str , Dict [str , str ]]) -> str :
331+ def read_benchmark_config (
332+ artifact_s3_url : str , benchmark_configs_dir : str
333+ ) -> Dict [str , str ]:
329334 """
330335 Get the correct benchmark config for this benchmark run
331336 """
337+ try :
338+ with request .urlopen (artifact_s3_url ) as data :
339+ for line in data .read ().decode ("utf8" ).splitlines ():
340+ m = IOS_TEST_SPEC_REGEX .match (line )
341+ if not m :
342+ continue
343+
344+ benchmark_config = m .group ("benchmark_config" )
345+ filename = os .path .join (
346+ benchmark_configs_dir , f"{ benchmark_config } .json"
347+ )
348+
349+ if not os .path .exists (filename ):
350+ warning (f"There is no benchmark config { filename } " )
351+ continue
352+
353+ with open (filename ) as f :
354+ try :
355+ return json .load (f )
356+ except json .JSONDecodeError as e :
357+ warning (f"Fail to load benchmark config { filename } : { e } " )
358+
359+ except error .HTTPError :
360+ warning (f"Fail to read the test spec output at { artifact_s3_url } " )
361+
362+ return {}
332363
333364
334365def transform (
335366 app_type : str ,
336367 benchmark_results : List ,
337- benchmark_configs : Dict [str , Dict [ str , str ] ],
368+ benchmark_config : Dict [str , str ],
338369 repo : str ,
339370 head_branch : str ,
340371 workflow_name : str ,
@@ -384,25 +415,25 @@ def transform(
384415 for r in benchmark_results
385416 ]
386417 elif schema_version == "v3" :
418+ v3_benchmark_results = []
387419 # From https://github.com/pytorch/pytorch/wiki/How-to-integrate-with-PyTorch-OSS-benchmark-database
388420 return [
389421 {
390422 "benchmark" : {
391423 "name" : "ExecuTorch" ,
392424 "mode" : "inference" ,
393- "dtype" : quantization ,
394425 "extra_info" : {
395426 "app_type" : app_type ,
396- "benchmark_configs" :
427+ # Just keep a copy of the benchmark config here
428+ "benchmark_config" : json .dumps (benchmark_config ),
397429 },
398430 },
399431 "model" : {
400- "name" : r ["benchmarkModel" ]["name" ],
432+ "name" : benchmark_config . get ( "model" , r ["benchmarkModel" ]["name" ]) ,
401433 "type" : "OSS model" ,
402- "backend" : r ["benchmarkModel" ].get ("backend" , "" ),
403- "extra_info" : {
404- "quantization" : quantization ,
405- },
434+ "backend" : benchmark_config .get (
435+ "config" , r ["benchmarkModel" ].get ("backend" , "" )
436+ ),
406437 },
407438 "metric" : {
408439 "name" : r ["metric" ],
@@ -433,7 +464,7 @@ def main() -> None:
433464 "v2" : [],
434465 "v3" : [],
435466 }
436- benchmark_configs = read_benchmark_configs ( args . benchmark_configs )
467+ benchmark_config = {}
437468
438469 with open (args .artifacts ) as f :
439470 for artifact in json .load (f ):
@@ -449,6 +480,11 @@ def main() -> None:
449480 artifact_type = artifact ["type" ]
450481 artifact_s3_url = artifact ["s3_url" ]
451482
483+ if artifact_type == "TESTSPEC_OUTPUT" :
484+ benchmark_config = read_benchmark_config (
485+ artifact_s3_url , args .benchmark_configs
486+ )
487+
452488 if app_type == "ANDROID_APP" :
453489 benchmark_results = extract_android_benchmark_results (
454490 job_name , artifact_type , artifact_s3_url
@@ -464,7 +500,7 @@ def main() -> None:
464500 results = transform (
465501 app_type ,
466502 benchmark_results ,
467- benchmark_configs ,
503+ benchmark_config ,
468504 args .repo ,
469505 args .head_branch ,
470506 args .workflow_name ,
0 commit comments