0
0
MLOpsdevops~10 mins

MLflow Model Registry in MLOps - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - MLflow Model Registry
Register Model
Create Model Version
Transition Stage
Staging
Archive Old Versions
End
This flow shows how a model is registered, versioned, moved through stages like staging and production, and old versions archived.
Execution Sample
MLOps
import mlflow

# Register model
model_uri = "runs:/12345/model"
model_details = mlflow.register_model(model_uri, "MyModel")

# Transition model stage
client = mlflow.MlflowClient()
client.transition_model_version_stage("MyModel", model_details.version, "Staging")
This code registers a model from a run and moves it to the Staging stage in the MLflow Model Registry.
Process Table
StepActionInputOutput/Result
1Register modelmodel_uri = runs:/12345/modelModel 'MyModel' version 1 created
2Create MLflow clientNoneClient object ready
3Transition model stageModel 'MyModel' version 1 to 'Staging'Model version 1 stage updated to 'Staging'
4Check model stageQuery model version 1Stage = 'Staging'
5Archive old versionsNoneNo old versions to archive
6EndNoneProcess complete
💡 All steps completed successfully; model is now in Staging stage.
Status Tracker
VariableStartAfter Step 1After Step 3Final
model_uriNoneruns:/12345/modelruns:/12345/modelruns:/12345/model
model_details.versionNone111
model_stageNoneNoneStagingStaging
Key Moments - 2 Insights
Why do we need to create a client object before transitioning the model stage?
The client object (mlflow.MlflowClient) is required to interact with the Model Registry API, as shown in step 2 and used in step 3 to change the model stage.
What happens if we try to transition a model version that does not exist?
An error will occur because the model version must exist before changing its stage. Step 1 ensures the version is created before step 3 transitions it.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the model stage after step 3?
AStaging
BProduction
CArchived
DNone
💡 Hint
Check the 'Output/Result' column in step 3 and step 4 for the model stage.
At which step is the model version created?
AStep 3
BStep 2
CStep 1
DStep 5
💡 Hint
Look at the 'Action' and 'Output/Result' columns to find when the model version is created.
If we skip creating the client object, what will happen at step 3?
AModel stage will transition successfully
BAn error will occur because client is undefined
CModel version will be deleted
DNothing will happen
💡 Hint
Step 3 uses the client object to transition the model stage; without it, the code cannot run.
Concept Snapshot
MLflow Model Registry manages model versions and stages.
Use mlflow.register_model() to register a model.
Use MlflowClient.transition_model_version_stage() to move stages.
Stages include None, Staging, Production, Archived.
Keep track of versions to deploy or archive models safely.
Full Transcript
This visual execution shows how to register a model in MLflow Model Registry, create a version, and transition it to the Staging stage. First, the model URI from a run is registered, creating version 1. Then, a client object is created to interact with the registry API. Using this client, the model version's stage is changed to Staging. The execution table tracks each step's input and output, confirming the model stage update. Variables like model_uri, model_details.version, and model_stage are tracked through the process. Key moments clarify why the client is needed and what happens if the version does not exist. The quiz tests understanding of model stages, version creation, and client usage. The snapshot summarizes the main commands and concepts for quick reference.