This repository includes a AWS Cloud Development Kit template for quickly building the pipeline
This solution introduces an automated solution for monitoring and evaluating the performance of time-series models, and creating new model using Amazon SageMaker Autopilot, specifically tailored for applications like day-ahead power forecasting for solar panels. Given the critical reliance on accurate forecasts in such applications, maintaining model performance is important.Currently, there are significant challenges as the existing Amazon SageMaker Model Monitor do not support time-series data monitoring. This solution intends to address this gap by automating the continuous evaluation of model outputs against daily ground truth data, identifying performance degradation swiftly.
When a model's performance drops below predefined thresholds, this pipeline automatically initiates Autopilot training processes to ensure predictions remain reliable and robust with new model. This not only enhances the trust in model outputs but also significantly reduces the manual effort required from data scientists and business owners. Following retraining, the system sends notifications to data scientists, allowing them to review and decide whether to deploy the updated model or continue with the existing one.
- Include inference job in the pipeline
- Support more objective metrics
New version will be released in July, click here fore more information
- Simplified the new model evaluation by directly using the object metric value from Autopilot job
- Only use RMSE as example metric for evaluation and training. If you want to use other metric, replace this code block in evaluation function
- Generate synthetic dataset in jupyter notebook and upload data to S3 bucket
- S3
object create
event triggers Lambda function - The Lambda function processes the event and start state machine
- Download ground truth from
s3://<your-bucket>/data/hist
and predicted result froms3://<your-bucket>/data/pred
, calculate the RMSE of a certain day's prediction, and share the result - If perform well comparing with threshold, keep the current model and end the workflow, otherwise start to train new model
- Start new Autopilot job vis calling
create_auto_ml_job_v2
- Share the Autopilot job result and current model performance to data scientist for further investigation
This is a list of the majority of the AWS services used in this project:
AWS Services | Usage | Comment |
---|---|---|
Amazon S3 | Store all data and models | |
AWS Step Function | Orchestrate the steps from performance evaluation to send notification to data scientist for model review | You could achieve the same function using Amazon SageMaker Pipeline |
Amazon SageMaker Autopilot | AutoML to generate new time-series model | |
AWS Lambda | Calculate the metrics and execute steps in workflow | |
AWS System Manager Parameter Store | Store model performance threshold | You could use Amazon DynamoDB to log all historical evaluation result |
Replace [email protected]
with your email address to receive the notifcation of model performance
$ cdk deploy -c [email protected]
Once the deployment of SNS completed, you should receive a email notification. Please click Confirm subscription for further notification.
Execute the solar-power-synthetic-data-generation notebook
You can find a running state machine in AWS Step Function Console once all cells ran:
Another email will be sent to your email address once the state machine completed. You can decide wheather to promote the new model or keep the current one after reviwing.
First, empty the S3 bucket.
To dispose of the stack afterwards, run the command:
$ cdk destroy
- Generate synthetic dataset in jupyter notebook and upload data to S3 bucket. On Upload a wrokflow is triggered to generate parameters for evaluation, pulling these from Parameter Store.
- Using a SageMaker Batch Transform Job, Predictions are generated for evaluation from the ground truth dataset. A Time Series evaluation lambda calculates the RMSE for our Model.
- If our Model metric meets our business metric threshold, we update our registered model's metric metadata in the SageMaker Model Registry 4.If not, we generate a Model using the SageMaker AutoML V2 API. We then evaluate this model using a Batch Transform Job.
- If the new model, performs better than the current model, a Model Package is registered for review in the Model Registry
- Once our, evaluation is complete, we notify the relevant stakeholder to review the changes in model performance for potential approval.
cdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation
Enjoy!
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.