When using Databricks Unity Catalog for managing multiple models and their versions, there is no built-in automatic mechanism that dynamically selects the "latest" version of a model when running a project.
To automatically choose the latest version of multiple models when working with Unity Catalog, Databricks recommends using aliases, such as the "Champion" alias, which can reference a specific model version. Once an alias is set, inference workloads can use it to dynamically point to the latest model version without manually specifying the version number each time. Hereโs an example:
-
Set an Alias for a Model Version: python
from mlflow import MlflowClient
client = MlflowClient()
# Set alias for a model version
client.set_registered_model_alias(name="prod.ml_team.iris_model", alias="Champion", version=2)
This reassigns the alias "Champion" to the specified model version.
-
Load a Model Version Using Alias: python
import mlflow.pyfunc
model_uri = "models:/prod.ml_team.iris_model@Champion"
model = mlflow.pyfunc.load_model(model_uri)
predictions = model.predict(test_data)
As long as the alias "Champion" is updated whenever a new model version is promoted, workloads referencing the alias will automatically use the latest version.
The use of model aliases eliminates the need to reference specific version numbers explicitly, streamlining workflows and ensuring that inference processes always utilize the desired version automatically. Note, however, that Unity Catalog's usage of aliases supports up to 10 aliases per registered model.
If you prefer not to use aliases, you can manually track versions through more specific mechanisms, such as filtering model versions via the search_model_versions
API, which allows finding model versions based on metadata like tags or attributes such as "latest_approved".
Hope this helps, Lou.