2020import re
2121import sys
2222import time
23+ from datetime import datetime
2324
2425from defs .trt_test_alternative import print_info
2526
@@ -198,7 +199,7 @@ def get_job_info():
198199 }
199200
200201
201- def query_history_data ():
202+ def query_history_data (gpu_type ):
202203 """
203204 Query post-merge data with specific gpu type and model name
204205 """
@@ -218,6 +219,16 @@ def query_history_data():
218219 "b_is_post_merge" : True
219220 }
220221 },
222+ {
223+ "term" : {
224+ "b_is_regression" : False
225+ }
226+ },
227+ {
228+ "term" : {
229+ "s_gpu_type" : gpu_type
230+ }
231+ },
221232 {
222233 "range" : {
223234 "ts_created" : {
@@ -348,27 +359,42 @@ def calculate_best_perf_result(history_data_list, new_data):
348359 return best_metrics
349360
350361
351- def get_history_data (new_data_dict ):
362+ def get_history_data (new_data_dict , gpu_type ):
352363 """
353364 Query history post-merge data for each cmd_idx
354365 """
366+
367+ def get_latest_data (data_list ):
368+ if not data_list :
369+ return None
370+ time_format = "%b %d, %Y @ %H:%M:%S.%f"
371+ # Find the item with the maximum ts_created value
372+ latest_data = max (
373+ data_list ,
374+ key = lambda x : datetime .strptime (x ["ts_created" ], time_format ))
375+ return latest_data
376+
355377 history_baseline_dict = {}
356378 history_data_dict = {}
357379 cmd_idxs = new_data_dict .keys ()
358380 for cmd_idx in cmd_idxs :
359381 history_data_dict [cmd_idx ] = []
360- history_baseline_dict [cmd_idx ] = None
361- history_data_list = query_history_data ()
382+ history_baseline_dict [cmd_idx ] = []
383+ history_data_list = query_history_data (gpu_type )
362384 if history_data_list :
363385 for history_data in history_data_list :
364386 for cmd_idx in cmd_idxs :
365387 if match (history_data , new_data_dict [cmd_idx ]):
366388 if history_data .get ("b_is_baseline" ) and history_data .get (
367389 "b_is_baseline" ) == True :
368- history_baseline_dict [cmd_idx ] = history_data
390+ history_baseline_dict [cmd_idx ]. append ( history_data )
369391 else :
370392 history_data_dict [cmd_idx ].append (history_data )
371393 break
394+ # Sometime database has several baselines and we only use the latest baseline one
395+ for cmd_idx , baseline_list in history_baseline_dict :
396+ latest_baseline = get_latest_data (baseline_list )
397+ history_baseline_dict [cmd_idx ] = latest_baseline
372398 return history_baseline_dict , history_data_dict
373399
374400
0 commit comments