@@ -89,6 +89,14 @@ def parse_args() -> argparse.Namespace:
8989 default = DEFAULT_TIMEOUT_S ,
9090 help = "Per-run subprocess timeout in seconds (includes setup and teardown)." ,
9191 )
92+ parser .add_argument (
93+ "--verbose" ,
94+ action = "store_true" ,
95+ help = (
96+ "Stream benchmark output to the terminal in real time in addition "
97+ "to saving it to the per-run log file. Useful for debugging failures."
98+ ),
99+ )
92100 return parser .parse_args ()
93101
94102
@@ -117,33 +125,56 @@ def render_config(
117125
118126
119127def run_single_benchmark (
120- config : dict , timeout_seconds : int , log_path : Path
128+ config : dict , timeout_seconds : int , log_path : Path , verbose : bool = False
121129) -> tuple [str , str ]:
122130 with tempfile .NamedTemporaryFile (
123131 mode = "w" , suffix = ".yaml" , delete = False , dir = "."
124132 ) as tmp :
125133 yaml .safe_dump (config , tmp , sort_keys = False )
126134 temp_config_path = Path (tmp .name )
127135
136+ cmd = [
137+ "inference-endpoint" ,
138+ "benchmark" ,
139+ "from-config" ,
140+ "-c" ,
141+ str (temp_config_path ),
142+ ]
143+
128144 try :
129- with log_path .open ("w" ) as log_file :
130- result = subprocess .run (
131- [
132- "inference-endpoint" ,
133- "benchmark" ,
134- "from-config" ,
135- "-c" ,
136- str (temp_config_path ),
137- ],
138- stdout = log_file ,
139- stderr = subprocess .STDOUT ,
140- text = True ,
141- timeout = timeout_seconds ,
142- check = False ,
143- )
144- if result .returncode == 0 :
145+ if verbose :
146+ with log_path .open ("w" ) as log_file :
147+ proc = subprocess .Popen (
148+ cmd ,
149+ stdout = subprocess .PIPE ,
150+ stderr = subprocess .STDOUT ,
151+ text = True ,
152+ )
153+ assert proc .stdout is not None
154+ for line in proc .stdout :
155+ print (line , end = "" , flush = True )
156+ log_file .write (line )
157+ try :
158+ proc .wait (timeout = timeout_seconds )
159+ except subprocess .TimeoutExpired :
160+ proc .kill ()
161+ raise
162+ returncode = proc .returncode
163+ else :
164+ with log_path .open ("w" ) as log_file :
165+ result = subprocess .run (
166+ cmd ,
167+ stdout = log_file ,
168+ stderr = subprocess .STDOUT ,
169+ text = True ,
170+ timeout = timeout_seconds ,
171+ check = False ,
172+ )
173+ returncode = result .returncode
174+
175+ if returncode == 0 :
145176 return "success" , ""
146- return "failed" , f"exit code { result . returncode } "
177+ return "failed" , f"exit code { returncode } , see { log_path } "
147178 except subprocess .TimeoutExpired :
148179 return "timeout" , f"exceeded { timeout_seconds } seconds"
149180 finally :
@@ -209,8 +240,11 @@ def main() -> int:
209240 config = config ,
210241 timeout_seconds = args .timeout_seconds ,
211242 log_path = log_path ,
243+ verbose = args .verbose ,
212244 )
213245 print (f" status: { status } " + (f" ({ detail } )" if detail else "" ))
246+ if status != "success" and not args .verbose :
247+ print (f" Re-run with --verbose to stream output, or inspect: { log_path } " )
214248
215249 summary_rows .append (
216250 {
0 commit comments