A machine learning engineer is using MLflow to track experiments and has logged a model with a signature. They now want to register this model in the MLflow Model Registry and promote it to Production. Which MLflow API call should they use to add the model to the registry?
Trap 1: mlflow.log_model(model, artifact_path, registered_model_name=name)
While mlflow.log_model with registered_model_name can register a model during logging, the scenario states the model is already logged. Using this call would log a new model, which is not desired. The engineer needs to register the existing model, so register_model is the appropriate API.
Trap 2: mlflow.pyfunc.save_model(path, loader_module, data_path,…
This saves a pyfunc model to a local path and optionally registers it, but it is used for creating a new model, not for registering an existing run's artifact. It requires specifying a loader module and data path, which is not applicable here. The correct approach is to register the already logged model.
Trap 3: mlflow.create_registered_model(name)
mlflow.create_registered_model only creates the registered model entity (a container) without a version. It does not link a specific run's model artifact. To add a version, you need to call register_model. This option is a step that might precede registration, but it does not register the model itself.
- A
mlflow.log_model(model, artifact_path, registered_model_name=name)
Why it fails: While mlflow.log_model with registered_model_name can register a model during logging, the scenario states the model is already logged. Using this call would log a new model, which is not desired. The engineer needs to register the existing model, so register_model is the appropriate API.
- B
mlflow.pyfunc.save_model(path, loader_module, data_path, registered_model_name=name)
Why it fails: This saves a pyfunc model to a local path and optionally registers it, but it is used for creating a new model, not for registering an existing run's artifact. It requires specifying a loader module and data path, which is not applicable here. The correct approach is to register the already logged model.
- C
mlflow.register_model(model_uri, name)
mlflow.register_model is the correct API to register an existing model artifact from a run into the Model Registry. It takes the model URI (e.g., runs:/<run_id>/model) and the desired model name. This call creates a new model version in the registry, which can then be transitioned to Production.
- D
mlflow.create_registered_model(name)
Why it fails: mlflow.create_registered_model only creates the registered model entity (a container) without a version. It does not link a specific run's model artifact. To add a version, you need to call register_model. This option is a step that might precede registration, but it does not register the model itself.