@@ -18,17 +18,19 @@ def __init__(self, config):
1818 and "performance" in self .config .experiment .auto_tuner
1919 ):
2020 self .metric = self .config .experiment .auto_tuner .performance .get (
21- "name" , "elapsed time per iteration \(ms\):"
21+ "name" , r "elapsed time per iteration \(ms\):"
2222 )
2323 else :
24- self .metric = "elapsed time per iteration \(ms\):"
24+ self .metric = r "elapsed time per iteration \(ms\):"
2525
2626 # Sort order of performance, order just in [ascend, and descend], default ascend
2727 if (
2828 "auto_tuner" in self .config .experiment
2929 and "performance" in self .config .experiment .auto_tuner
3030 ):
31- self .sorted_order = self .config .experiment .auto_tuner .performance .get ("order" , "ascend" )
31+ self .sorted_order = self .config .experiment .auto_tuner .performance .get (
32+ "order" , "ascend"
33+ )
3234 else :
3335 self .sorted_order = "ascend"
3436
@@ -83,7 +85,10 @@ def pass_back_to_platform(self, strategy):
8385 seq_len = int (self .config .train .model .seq_length )
8486 throughput = gbs * seq_len / (strategy ["performance" ] / 1000 )
8587 day = round (
86- self .config .train .model .train_samples * seq_len / (throughput * 60 * 60 * 24 ), 2
88+ self .config .train .model .train_samples
89+ * seq_len
90+ / (throughput * 60 * 60 * 24 ),
91+ 2 ,
8792 )
8893 command = [
8994 "airsctl job performance" ,
@@ -110,9 +115,17 @@ def pass_back_to_platform(self, strategy):
110115 else "None"
111116 ),
112117 "-R" ,
113- (f"{ strategy ['recompute_method' ]} " if strategy ["recompute_granularity" ] else "None" ),
118+ (
119+ f"{ strategy ['recompute_method' ]} "
120+ if strategy ["recompute_granularity" ]
121+ else "None"
122+ ),
114123 "-N" ,
115- (f"{ strategy ['recompute_num_layers' ]} " if strategy ["recompute_num_layers" ] else "0" ),
124+ (
125+ f"{ strategy ['recompute_num_layers' ]} "
126+ if strategy ["recompute_num_layers" ]
127+ else "0"
128+ ),
116129 "-S" ,
117130 (
118131 f"{ strategy ['sequence_parallel' ]} "
@@ -211,7 +224,7 @@ def get_all_performance_and_host_paths(self, task):
211224 all_log_paths .append (log_path )
212225 return all_log_paths , logs
213226
214- def grep_performance (self , paths , pattern = "elapsed time per iteration \(ms\):" ):
227+ def grep_performance (self , paths , pattern = r "elapsed time per iteration \(ms\):" ):
215228 """Read the log file and return the performance."""
216229 metric_pattern = pattern + r":* *(\d+(\.\d*)?)|(\d+(\.\d*)?) *" + pattern
217230 if not paths :
@@ -242,11 +255,15 @@ def grep_performance(self, paths, pattern="elapsed time per iteration \(ms\):"):
242255 self .logger .info (f"task_{ self .cur_strategy ['idx' ]} performance: { None } " )
243256 return None
244257 if len (performance ) == 1 :
245- self .logger .info (f"task_{ self .cur_strategy ['idx' ]} performance: { performance [0 ]} ms" )
258+ self .logger .info (
259+ f"task_{ self .cur_strategy ['idx' ]} performance: { performance [0 ]} ms"
260+ )
246261 return round (performance [0 ], 3 )
247262 else :
248263 average = sum (performance [1 :]) / (len (performance ) - 1 )
249- self .logger .info (f"task_{ self .cur_strategy ['idx' ]} performance: { average } ms" )
264+ self .logger .info (
265+ f"task_{ self .cur_strategy ['idx' ]} performance: { average } ms"
266+ )
250267 return round (average , 3 )
251268
252269 def grep_error (self , path , pattern = "Error:" ):
@@ -287,12 +304,16 @@ def sort(self, history):
287304 if self .sorted_order == "ascend" :
288305 sorted_history = sorted (
289306 no_pruned_history ,
290- key = lambda x : (x ["performance" ] if x ["performance" ] is not None else float ("inf" )),
307+ key = lambda x : (
308+ x ["performance" ] if x ["performance" ] is not None else float ("inf" )
309+ ),
291310 )
292311 elif self .sorted_order == "descend" :
293312 sorted_history = sorted (
294313 no_pruned_history ,
295- key = lambda x : (x ["performance" ] if x ["performance" ] is not None else float ("-inf" )),
314+ key = lambda x : (
315+ x ["performance" ] if x ["performance" ] is not None else float ("-inf" )
316+ ),
296317 reverse = True ,
297318 )
298319 else :
@@ -315,6 +336,7 @@ def save(self, history):
315336 cols .insert (0 , cols .pop (cols .index ("idx" )))
316337 if "stopped_by_tuner" in cols :
317338 df = df .drop (columns = ["stopped_by_tuner" ])
339+ cols .remove ("stopped_by_tuner" )
318340 df = df .reindex (columns = cols )
319341 for c in df .columns :
320342 df [c ] = df [c ].map (self .to_str )
@@ -338,7 +360,9 @@ def parse_value(self, s):
338360 pass
339361 try :
340362 # Check for JSON string start/end characters as a heuristic
341- if (s .startswith ("[" ) and s .endswith ("]" )) or (s .startswith ("{" ) and s .endswith ("}" )):
363+ if (s .startswith ("[" ) and s .endswith ("]" )) or (
364+ s .startswith ("{" ) and s .endswith ("}" )
365+ ):
342366 return json .loads (s )
343367 except (json .JSONDecodeError , TypeError ):
344368 pass
@@ -348,7 +372,11 @@ def read(self):
348372 if not os .path .exists (self .path ):
349373 return []
350374 df = pd .read_csv (
351- self .path , dtype = str , keep_default_na = False , na_filter = False , escapechar = "\\ "
375+ self .path ,
376+ dtype = str ,
377+ keep_default_na = False ,
378+ na_filter = False ,
379+ escapechar = "\\ " ,
352380 )
353381 for c in df .columns :
354382 df [c ] = df [c ].map (self .parse_value )
@@ -362,7 +390,9 @@ def __init__(self, config):
362390 "auto_tuner" in self .config .experiment
363391 and "performance" in self .config .experiment .auto_tuner
364392 ):
365- self .metric = self .config .experiment .auto_tuner .performance .get ("metric" , "itl" )
393+ self .metric = self .config .experiment .auto_tuner .performance .get (
394+ "metric" , "itl"
395+ )
366396 else :
367397 self .metric = "itl"
368398
@@ -371,7 +401,9 @@ def __init__(self, config):
371401 "auto_tuner" in self .config .experiment
372402 and "performance" in self .config .experiment .auto_tuner
373403 ):
374- self .sorted_order = self .config .experiment .auto_tuner .performance .get ("order" , "ascend" )
404+ self .sorted_order = self .config .experiment .auto_tuner .performance .get (
405+ "order" , "ascend"
406+ )
375407 else :
376408 self .sorted_order = "ascend"
377409 self .logger = logging .getLogger ("FlagScale-AutoTuner" )
@@ -392,12 +424,16 @@ def sort(self, history):
392424 if self .sorted_order == "ascend" :
393425 sorted_history = sorted (
394426 history ,
395- key = lambda x : (x [self .metric ] if x [self .metric ] is not None else float ("inf" )),
427+ key = lambda x : (
428+ x [self .metric ] if x [self .metric ] is not None else float ("inf" )
429+ ),
396430 )
397431 elif self .sorted_order == "descend" :
398432 sorted_history = sorted (
399433 history ,
400- key = lambda x : (x [self .metric ] if x [self .metric ] is not None else float ("-inf" )),
434+ key = lambda x : (
435+ x [self .metric ] if x [self .metric ] is not None else float ("-inf" )
436+ ),
401437 reverse = True ,
402438 )
403439 else :
0 commit comments