0
0
MLOpsdevops~5 mins

Model approval workflows in MLOps - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you train machine learning models, you want to make sure only good models get used in real projects. Model approval workflows help you check and approve models before they go live. This keeps your system safe and reliable.
When you want to review a new model's performance before using it in production.
When multiple team members need to approve a model before deployment.
When you want to keep track of which models were approved and when.
When you want to automate the approval process to avoid manual errors.
When you want to reject models that do not meet quality standards.
Commands
This command registers a trained model from a specific run into the model registry with the name 'my_model'. It prepares the model for approval and deployment.
Terminal
mlflow models register -m runs:/1234567890abcdef/model -n my_model
Expected OutputExpected
Successfully registered model 'my_model' with version 1
-m - Specifies the model path from the run to register
-n - Names the registered model
This command moves the registered model version 1 to the 'Staging' stage, indicating it is ready for testing and review before approval.
Terminal
mlflow models transition --model-name my_model --version 1 --stage Staging
Expected OutputExpected
Model 'my_model' version 1 transitioned to stage 'Staging'
--model-name - Specifies the model to transition
--version - Specifies the model version to transition
--stage - Specifies the target stage for the model
After review and approval, this command moves the model to the 'Production' stage, meaning it is approved and ready for real use.
Terminal
mlflow models transition --model-name my_model --version 1 --stage Production
Expected OutputExpected
Model 'my_model' version 1 transitioned to stage 'Production'
--model-name - Specifies the model to transition
--version - Specifies the model version to transition
--stage - Moves the model to the approved production stage
This command lists all versions of the model 'my_model' along with their current stages, so you can see which models are approved or still in review.
Terminal
mlflow models list-versions --model-name my_model
Expected OutputExpected
Version 1: Production Version 2: None Version 3: Staging
--model-name - Specifies the model to list versions for
Key Concept

If you remember nothing else from this pattern, remember: model approval workflows let you control which models are safe and ready to use by moving them through stages like Staging and Production.

Code Example
MLOps
import mlflow

# Register a model from a run
model_uri = "runs:/1234567890abcdef/model"
model_name = "my_model"

result = mlflow.register_model(model_uri, model_name)
print(f"Registered model version: {result.version}")

# Transition model to Staging
client = mlflow.MlflowClient()
client.transition_model_version_stage(
    name=model_name,
    version=result.version,
    stage="Staging"
)
print(f"Model version {result.version} moved to Staging")

# After approval, transition to Production
client.transition_model_version_stage(
    name=model_name,
    version=result.version,
    stage="Production"
)
print(f"Model version {result.version} moved to Production")
OutputSuccess
Common Mistakes
Skipping the staging step and moving models directly to production.
This can cause untested or low-quality models to be used in real applications, risking errors.
Always move models to 'Staging' first for testing and review before approving them to 'Production'.
Not specifying the correct model version when transitioning stages.
You might accidentally approve or reject the wrong model version.
Always check and specify the exact model version number when running transition commands.
Not listing model versions to verify their stages before deployment.
You may deploy an unapproved model or miss the latest approved version.
Use the list-versions command to confirm model stages before deployment.
Summary
Register your trained model to the model registry to track it.
Move the model to 'Staging' for testing and review before approval.
After approval, transition the model to 'Production' to mark it as ready for use.
Use commands to list model versions and their stages to keep track of approvals.