Search code examples
rmlflowmlops

How to organize registerd models in R with mlflow?


Questions

  • How should I deal with this situation, should I just use stages until the R package gets updated? What would be the most sensible approach here? Using tags and accepting the problem that tags are not unique?
  • Does anyone know if the alias related methods will be introduced into the R package anytime soon?

Solution

  • I found a somewhat okeyish workaround: I just use the mlflow rest api (https://mlflow.org/docs/latest/rest-api.html#set-registered-model-alias) from R to set the alias...

    mlflowSetRegisteredModelAlias <- function(mlflowUri, modelName, alias, version) {
      # Define api request payload
      payload <- list(name = modelName,
                      alias = alias,
                      version = as.character(version))
      
      # Make the POST request
      mlflowApiEndpoint <- paste0(mlflowUri, "api/2.0/mlflow/registered-models/alias")
      response <- mlflowApiEndpoint %>%
        httr2::request() %>%
        httr2::req_body_json(payload) %>%
        httr2::req_perform()
    }
    

    For deleting an alias it would be with ad DELETE method:

     payload <- list(name = modelName, alias = alias)
      
      # Make the DELETE request
      response <-  mlflowApiEndpoint %>%
        httr2::request() %>%
        httr2::req_method("DELETE") %>%
        httr2::req_body_json(payload) %>%
        httr2::req_perform()