def grid_search_controller(config_path): # start = time.time() # Dynamic importing config file from config_path config = load(config_path) # Dynamic loading lambda name LAMBDA_NAME = getattr(config.Cross_Validation, "LAMBDA_NAME") # Clean the log of specified lambda function clean_logs('/aws/lambda/' + LAMBDA_NAME) # Dynamic load parameters PARAMETERS = [] CV_SETTINGS = [] for key in dir(config.Hyperparameter): if key.isupper(): PARAMETERS.append(key) for key in dir(config.Cross_Validation): if key.isupper(): CV_SETTINGS.append(key) # Tune forecast horizon of the chosen model payload_list = create_event(config, PARAMETERS, CV_SETTINGS) min_metric = float('inf') chosen_model_event = None metrics = [] # from src.lambda_func.prophet.prophet import grid_search_worker # for payload in payload_list: # map_item = grid_search_worker(payload) # metrics.append(map_item['average_metric']) # if map_item['average_metric'] < min_metric: # print ("======Update chosen model event==========") # chosen_model_event = map_item['event'] # min_metric = map_item['average_metric'] # print ("=======Metric=======") # print (min_metric) # print ("======Event=======") # print (chosen_model_event) # print ("======Metrics=======") # print (metrics) # print ("====Execution time====") # print (time.time() - start) start = time.time() print ("=====Time Stamp======") print (start) job = group(invoke_lambda.s( function_name = LAMBDA_NAME, sync = True, payload = payload ) for payload in payload_list) print("===Async Tasks start===") result = job.apply_async() result.save() from celery.result import GroupResult saved_result = GroupResult.restore(result.id) while not saved_result.ready(): time.sleep(0.1) model_list = saved_result.get(timeout=None) print("===Async Tasks end===") print (time.time() - start) for item in model_list: payload = item['Payload'] if payload['average_metric'] < min_metric: chosen_model_event = payload['event'] min_metric = payload['average_metric'] from src.celery_lambda import measurement measurement.parse_log("/aws/lambda/prophet_worker") # Non-zero forecast period makes lambda upload graphs to s3 chosen_model_event['forecast'] = getattr(config.Cross_Validation, "FORECAST") # Invoke Lambda with forecast response = invoke_lambda(function_name = LAMBDA_NAME, sync=True, payload=chosen_model_event) print ("=======The Execution Time===========") print (time.time() - start) print (response)
def grid_search_controller(config_path): # start = time.time() # Dynamic importing config file from config_path config = load(config_path) # Dynamic loading lambda name LAMBDA_NAME = getattr(config.Hyperparameter, "LAMBDA_NAME") # Clean the log of specified lambda function clean_logs('/aws/lambda/' + LAMBDA_NAME) # Dynamic load parameters DATASETS = [] TARGETS = getattr(config.Hyperparameter, 'TARGETS') for key in getattr(config.Hyperparameter, 'DATASETS'): DATASETS.append(key) # Tune forecast horizon of the chosen model payload_list = create_event(config, DATASETS, TARGETS) min_metric = float('inf') chosen_model_event = None metrics = [] # from src.lambda_func.multi_regression.multi_regression import lambda_handler # for payload in payload_list: # print ("======Payload========") # print (payload) # map_item = lambda_handler(payload) # metrics.append(map_item['metric']) # if map_item['metric'] < min_metric: # print ("======Update chosen model event==========") # chosen_model_event = map_item['event'] # min_metric = map_item['metric'] # print ("======Metric=======") # print (min_metric) # print ("======Event=======") # print (chosen_model_event) # print ("======Metrics========") # print (metrics) # print ("====Execution time====") # print (time.time() - start) start = time.time() print ("=====Time Stamp======") print (start) job = group(invoke_lambda.s( function_name = LAMBDA_NAME, sync = True, payload = payload ) for payload in payload_list) print("===Async Tasks start===") result = job.apply_async() result.save() from celery.result import GroupResult saved_result = GroupResult.restore(result.id) while not saved_result.ready(): time.sleep(0.1) model_list = saved_result.get(timeout=None) print("===Async Tasks end===") print (time.time() - start) for item in model_list: payload = item['Payload'] if payload['metric'] < min_metric: chosen_model_event = payload['event'] min_metric = payload['metric'] print (chosen_model_event) from src.celery_lambda import measurement measurement.parse_log("/aws/lambda/multi_regression_worker")
def grid_search_controller(config_path): # start = time.time() # Dynamic importing config file from config_path config = load(config_path) # Dynamic loading lambda name LAMBDA_NAME = getattr(config.Config, "LAMBDA_NAME") # Clean the log of specified lambda function # clean_logs('/aws/lambda/' + LAMBDA_NAME) # Dynamic load parameters PARAMETERS = [] CONFIG = [] for key in dir(config.Hyperparameter): if key.isupper(): PARAMETERS.append(key) for key in dir(config.Config): if key.isupper(): CONFIG.append(key) # Tune forecast horizon of the chosen model payload_list = create_event(config, PARAMETERS, CONFIG) max_metric = float('-inf') chosen_model_event = None metrics = [] # from src.lambda_func.svc.svc import lambda_handler # for payload in payload_list: # map_item = lambda_handler(payload) # # Metric is Accuracy Score => Large than # metrics.append(map_item['metric']) # if map_item['metric'] > max_metric: # print ("======Update chosen model event==========") # chosen_model_event = map_item['event'] # max_metric = map_item['metric'] # print ("====Max Accuracy Score=====") # print (max_metric) # print ("====Event============") # print (chosen_model_event) # print ("====Metrics List=====") # print (metrics) # print ("====Execution time=====") # print (time.time() - start) start = time.time() print("=====Time Stamp======") print(start) job = group( invoke_lambda.s(function_name=LAMBDA_NAME, sync=True, payload=payload) for payload in payload_list) print("===Async Tasks start===") result = job.apply_async() result.save() from celery.result import GroupResult saved_result = GroupResult.restore(result.id) while not saved_result.ready(): time.sleep(0.1) model_list = saved_result.get(timeout=None) print("===Async Tasks end===") print(time.time() - start) for item in model_list: payload = item['Payload'] # Metric is Accuracy Score => Large than if payload['metric'] > max_metric: chosen_model_event = payload['event'] max_metric = payload['metric'] print(max_metric) print(chosen_model_event) from src.celery_lambda import measurement measurement.parse_log("/aws/lambda/svc_worker")