1
1
"""
2
2
Tritonbench nightly run, dashboard: https://hud.pytorch.org/tritonbench/commit_view
3
+ Run all operators in nightly/autogen.yaml.
3
4
Requires the operator to support the speedup metric.
4
5
"""
5
6
@@ -37,57 +38,6 @@ def setup_tritonbench_cwd():
37
38
return original_dir
38
39
39
40
40
- def reduce (run_timestamp , output_dir , output_files , args ):
41
- """aggregate all op benchmark csvs into json file"""
42
- from tritonbench .utils .gpu_utils import get_nvidia_gpu_states , has_nvidia_smi
43
- from tritonbench .utils .path_utils import REPO_PATH
44
- from tritonbench .utils .run_utils import get_github_env , get_run_env
45
-
46
- repo_locs = {
47
- "tritonbench" : REPO_PATH ,
48
- }
49
- if args .ci and "TRITONBENCH_TRITON_REPO_PATH" in os .environ :
50
- repo_locs ["triton" ] = os .environ .get ("TRITONBENCH_TRITON_REPO_PATH" , None )
51
- repo_locs ["pytorch" ] = os .environ .get ("TRITONBENCH_PYTORCH_REPO_PATH" , None )
52
- aggregated_obj = {
53
- "name" : "nightly" ,
54
- "env" : get_run_env (run_timestamp , repo_locs ),
55
- "metrics" : {},
56
- }
57
- if has_nvidia_smi ():
58
- aggregated_obj .update (
59
- {
60
- "nvidia_gpu_states" : get_nvidia_gpu_states (),
61
- }
62
- )
63
-
64
- # Collecting GitHub environment variables when running in CI environment
65
- if args .ci :
66
- aggregated_obj ["github" ] = get_github_env ()
67
-
68
- for result_json_file in output_files :
69
- logger .info (f"Loading output file: { result_json_file } ." )
70
- result_json_filename = Path (result_json_file ).stem
71
- if (
72
- not os .path .exists (result_json_file )
73
- or os .path .getsize (result_json_file ) == 0
74
- ):
75
- aggregated_obj ["metrics" ][f"tritonbench_{ result_json_filename } -pass" ] = 0
76
- continue
77
- # TODO: check if all inputs pass
78
- aggregated_obj ["metrics" ][f"tritonbench_{ result_json_filename } -pass" ] = 1
79
- with open (
80
- result_json_file ,
81
- "r" ,
82
- ) as fp :
83
- result_obj = json .load (fp )
84
- aggregated_obj ["metrics" ].update (result_obj )
85
- result_json_path = os .path .join (output_dir , "result.json" )
86
- with open (result_json_path , "w" ) as fp :
87
- json .dump (aggregated_obj , fp , indent = 4 )
88
- return result_json_path
89
-
90
-
91
41
def get_operator_benchmarks () -> Dict [str , Any ]:
92
42
def _load_benchmarks (config_path : str ) -> Dict [str , Any ]:
93
43
out = {}
@@ -111,12 +61,17 @@ def _load_benchmarks(config_path: str) -> Dict[str, Any]:
111
61
112
62
def run ():
113
63
parser = argparse .ArgumentParser ()
64
+ parser .add_argument ("--name" , default = "nightly" , help = "Benchmark name." )
114
65
parser .add_argument (
115
66
"--ci" , action = "store_true" , help = "Running in GitHub Actions CI mode."
116
67
)
68
+ parser .add_argument (
69
+ "--log-scuba" , action = "store_true" , help = "Upload results to Scuba."
70
+ )
117
71
args = parser .parse_args ()
118
72
setup_tritonbench_cwd ()
119
73
from tritonbench .utils .run_utils import run_in_task , setup_output_dir
74
+ from tritonbench .utils .scuba_utils import decorate_benchmark_data , log_benchmark
120
75
121
76
run_timestamp , output_dir = setup_output_dir ("nightly" )
122
77
# Run each operator
@@ -127,10 +82,32 @@ def run():
127
82
output_file = output_dir .joinpath (f"{ op_bench } .json" )
128
83
op_args .extend (["--output-json" , str (output_file .absolute ())])
129
84
run_in_task (op = op_name , op_args = op_args , benchmark_name = op_bench )
85
+ # write pass or fail to result json
86
+ # todo: check every input shape has passed
87
+ output_file_name = Path (output_file ).stem
88
+ if not os .path .exists (output_file ) or os .path .getsize (output_file ) == 0 :
89
+ logger .warning (f"[nightly] Failed to run { output_file_name } ." )
90
+ with open (output_file , "w" ) as f :
91
+ json .dump ({f"tritonbench_{ output_file_name } -pass" : 0 }, f )
92
+ else :
93
+ with open (output_file , "r" ) as f :
94
+ obj = json .load (f )
95
+ obj [f"tritonbench_{ output_file_name } -pass" ] = 1
96
+ with open (output_file , "w" ) as f :
97
+ json .dump (obj , f , indent = 4 )
130
98
output_files .append (output_file )
131
99
# Reduce all operator CSV outputs to a single output json
132
- result_json_file = reduce (run_timestamp , output_dir , output_files , args )
100
+ benchmark_data = [json .load (open (f , "r" )) for f in output_files ]
101
+ aggregated_obj = decorate_benchmark_data (
102
+ args .name , run_timestamp , args .ci , benchmark_data
103
+ )
104
+ result_json_file = os .path .join (output_dir , "result.json" )
105
+ with open (result_json_file , "w" ) as fp :
106
+ json .dump (aggregated_obj , fp , indent = 4 )
133
107
logger .info (f"[nightly] logging result json file to { result_json_file } ." )
108
+ if args .log_scuba :
109
+ log_benchmark (aggregated_obj )
110
+ logger .info (f"[nightly] logging results to scuba." )
134
111
135
112
136
113
if __name__ == "__main__" :
0 commit comments