aws-samples / sagemaker-custom-project-templates

MIT No Attribution
210 stars 150 forks source link

Unapproved models do trigger the deployment pipeline - `mlops-template-gitlab` #15

Open zoltan-fedor opened 2 years ago

zoltan-fedor commented 2 years ago

Hi, Thank you for the great patterns, especially the mlops-template-gitlab one.

I believe I have found an issue with the mlops-template-gitlab pattern though.

Based on the design the deployment pipeline is only supposed to be triggered when the model is approved in the SageMaker Model Registry - but that doesn't seem to be the case. The deployment pipeline is triggered every time there is a new model in the registry, whether or not it has been approved.

Every time a new model makes it into the Model Registry it will trigger the EventBridge event (and so the deployment GitLab pipeline) as that is triggered by "SageMaker Model Package State Change" (which includes adding a new model) and NOT only by new approval of a model - see https://github.com/aws-samples/sagemaker-custom-project-templates/blob/main/mlops-template-gitlab/project.yml#L142

This means once the build pipeline completes and a model makes it into the Model Registry, that will trigger the build pipeline even if the new model is not (yet) approved, so staging deployment WILL BE performed. But it is true, that it is the latest "approved" model that will get deployed (or rather re-deployed) in staging, due to https://github.com/aws-samples/sagemaker-custom-project-templates/blob/main/mlops-template-gitlab/seedcode/mlops-gitlab-project-seedcode-model-deploy/build.py#L, so not necessarily the one that triggered the deployment pipeline (as that still might be unapproved).

Would it be possible to update the EventBridge rule (https://github.com/aws-samples/sagemaker-custom-project-templates/blob/main/mlops-template-gitlab/project.yml#L152) to only trigger on model approval?

Thanks

zoltan-fedor commented 2 years ago

I have provided a fix for this in PR: https://github.com/aws-samples/sagemaker-custom-project-templates/pull/16