mirror of
https://github.com/Hestia-Homes/ML.git
synced 2026-06-30 13:10:43 +00:00
trigger only one model to warm up, speed up dataframe generation
This commit is contained in:
parent
3b9699038a
commit
175bf87a95
1 changed files with 15 additions and 8 deletions
|
|
@ -47,21 +47,28 @@ def upload_dataframe_to_s3(df, bucket, s3_file_name):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def warming_up_invocation(model_filepath: str):
|
def warming_up_invocation(
|
||||||
|
model,
|
||||||
|
model_filepath: str,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Function to handle warm up invocations
|
Function to handle warm up invocations
|
||||||
"""
|
"""
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
model = model_factory(settings.build_model["model_type"])
|
|
||||||
model_filepath = settings.build_model["model_save_filepath"]
|
|
||||||
model.load_model(model_filepath)
|
model.load_model(model_filepath)
|
||||||
|
|
||||||
warmup_df = pd.DataFrame(columns=model.model.original_features)
|
warmup_df = pd.DataFrame(
|
||||||
warmup_df = pd.concat([warmup_df.T, pd.DataFrame([0] * len(warmup_df.T))], axis=1).T
|
np.zeros((1, len(model.model.original_features))),
|
||||||
warmup_df.fillna(0, inplace=True)
|
columns=model.model.original_features,
|
||||||
|
)
|
||||||
|
|
||||||
model.predict(data=warmup_df)
|
model_names = model.model.model_names()
|
||||||
|
if "NeuralNetFastAI" in model_names:
|
||||||
|
model.model.predict(warmup_df, model="NeuralNetFastAI")
|
||||||
|
else:
|
||||||
|
model.predict(data=warmup_df)
|
||||||
|
|
||||||
|
|
||||||
def handler(event, context):
|
def handler(event, context):
|
||||||
|
|
@ -97,7 +104,7 @@ def handler(event, context):
|
||||||
if "warm" in body:
|
if "warm" in body:
|
||||||
logger.info("Warm up invocation - synthetic prediction")
|
logger.info("Warm up invocation - synthetic prediction")
|
||||||
|
|
||||||
warming_up_invocation(model_filepath=model_filepath)
|
warming_up_invocation(model=model, model_filepath=model_filepath)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"statusCode": 200,
|
"statusCode": 200,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue