log model with tags #6040
-
Hi there, I want to add a tag when logging my model using the Python API. How can I achieve this? I know there should be a way, because I can add tags to a model in the UI. I would really appreciate your help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The There are a few ways to do this... import mlflow
with mlflow.start_run(run_name="My super cool model",
tags={
"iteration_name": "test_gbt_sklearn",
"feature_set_version": "trial_26b"
},
description="Trial of adding weather data and removing geolocation data"):
mlflow.sklearn.log_model(sk_model=gbt_model, artifact_path="gbt", registered_model_name="CIDpipeline")
mlflow.log_param("max_depth": 12) Setting the tags using the fluent API one by one: import mlflow
with mlflow.start_run(run_name="Another test", description="hope this one works" ):
mlflow.sklearn.log_model(sk_model=rf_model, artifact_path="gbt", registered_model_name="CIDpipeline")
mlflow.log_param("max_depth": 12)
mlflow.set_tag("iteration_name": "test_rf_sklearn")
mlflow.set_tag("feature_set_version": "trial_27bslash6") Or doing a bulk set with the fluent API: import mlflow
with mlflow.start_run(run_name="Yet another test", description="this HAS to work" ):
mlflow.sklearn.log_model(sk_model=xgboost_model, artifact_path="xgboost", registered_model_name="CIDpipeline")
mlflow.set_tags({"iteration_name": "xgboost_trial", "feature_set_version": "fire_everything"}) Hope that helps! (and let me know if that's not helpful) |
Beta Was this translation helpful? Give feedback.
-
After my experiments, the method @BenWilson2 used are assigning tags to certain model versions. Giving tags to the model itself instead of model version should use "set_registered_model_tag". I went though mlflow doc and only found this only one.
|
Beta Was this translation helpful? Give feedback.
The
log_model()
function in all flavors is a single-purpose function serving solely to do what it is intended to do: log the model as an artifact to a location defined by your artifact_uri and the path you specify, as well as applying a metadata entry to the tracking server about where to fetch it when used through other APIs.That being said, the tags that you see in the UI aren't linked to the model artifact; rather, then are associated to the run.
In order to populate these tags programmatically you'll want to refer to the active run and apply your tags within the run context by using the fluent API.
There are a few ways to do this...
An example of using the active run context at insan…