mlflow / mlflow

Open source platform for the machine learning lifecycle
https://mlflow.org
Apache License 2.0
18.23k stars 4.13k forks source link

[BUG] R Unsupported scheme: 'azureml' #6692

Open lizelive opened 1 year ago

lizelive commented 1 year ago

Willingness to contribute

Yes. I would be willing to contribute a fix for this bug with guidance from the MLflow community.

MLflow version

1.28.0

System information

R.Version()

packageVersion("mlflow")

$platform 'x86_64-pc-linux-gnu' $arch 'x86_64' $os 'linux-gnu' $system 'x86_64, linux-gnu' $status '' $major '4' $minor '2.1' $year '2022' $month '06' $day '23' $svn rev '82513' $language 'R' $version.string 'R version 4.2.1 (2022-06-23)' $nickname 'Funny-Looking Kid'

[1] ‘1.28.0’

Describe the problem

MLflow R

Error in new_mlflow_client.default(tracking_uri): Unsupported scheme: 'azureml'

Tracking information

mlflow_get_tracking_uri()

'azureml://westus2.api.azureml.ms/mlflow/v1.0/subscriptions/033186f6-96b0-429c-98a6-98ad3dc9ab4c/resourceGroups/mats/providers/Microsoft.MachineLearningServices/workspaces/mats'

Code to reproduce issue

install.packages("mlflow")
install.packages("carrier")
install.packages("dotenv")

mlflow::install_mlflow()

library(mlflow)
library(glmnet)
library(carrier)

# Read the wine-quality csv file
data <- read.csv("mlflow-example/wine-quality.csv")

# Split the data into training and test sets. (0.75, 0.25) split.
sampled <- sample(1:nrow(data), 0.75 * nrow(data))
train <- data[sampled, ]
test <- data[-sampled, ]

# The predicted column is "quality" which is a scalar from [3, 9]
train_x <- as.matrix(train[, !(names(train) == "quality")])
test_x <- as.matrix(test[, !(names(train) == "quality")])
train_y <- train[, "quality"]
test_y <- test[, "quality"]

alpha <- mlflow_param("alpha", 0.5, "numeric")
lambda <- mlflow_param("lambda", 0.5, "numeric")

with(mlflow_start_run(), {
  model <- glmnet(train_x, train_y, alpha = alpha, lambda = lambda, family = "gaussian")
  predictor <- crate(~ glmnet::predict.glmnet(model, as.matrix(.x)), model = model)
  predicted <- predictor(test_x)

  rmse <- sqrt(mean((predicted - test_y) ^ 2))
  mae <- mean(abs(predicted - test_y))
  r2 <- as.numeric(cor(predicted, test_y) ^ 2)

  message("Elasticnet model (alpha=", alpha, ", lambda=", lambda, "):")
  message("  RMSE: ", rmse)
  message("  MAE: ", mae)
  message("  R2: ", r2)

  mlflow_log_param("alpha", alpha)
  mlflow_log_param("lambda", lambda)
  mlflow_log_metric("rmse", rmse)
  mlflow_log_metric("r2", r2)
  mlflow_log_metric("mae", mae)

  mlflow_log_model(predictor, "model")
})

Stack trace

Error in new_mlflow_client.default(tracking_uri): Unsupported scheme: 'azureml'
Traceback:

1. with(mlflow_start_run(), {
 .     model <- glmnet(train_x, train_y, alpha = alpha, lambda = lambda, 
 .         family = "gaussian")
 .     predictor <- crate(~glmnet::predict.glmnet(model, as.matrix(.x)), 
 .         model = model)
 .     predicted <- predictor(test_x)
 .     rmse <- sqrt(mean((predicted - test_y)^2))
 .     mae <- mean(abs(predicted - test_y))
 .     r2 <- as.numeric(cor(predicted, test_y)^2)
 .     message("Elasticnet model (alpha=", alpha, ", lambda=", lambda, 
 .         "):")
 .     message("  RMSE: ", rmse)
 .     message("  MAE: ", mae)
 .     message("  R2: ", r2)
 .     mlflow_log_param("alpha", alpha)
 .     mlflow_log_param("lambda", lambda)
 .     mlflow_log_metric("rmse", rmse)
 .     mlflow_log_metric("r2", r2)
 .     mlflow_log_metric("mae", mae)
 .     mlflow_log_model(predictor, "model")
 . })
2. mlflow_start_run()
3. mlflow_client()
4. new_mlflow_client(tracking_uri)
5. new_mlflow_client.default(tracking_uri)
6. stop(paste("Unsupported scheme: '", tracking_uri$scheme, "'", 
 .     sep = ""))

Other info / logs

No response

What component(s) does this bug affect?

What interface(s) does this bug affect?

What language(s) does this bug affect?

What integration(s) does this bug affect?

dbczumar commented 1 year ago

@akshaya-a @trangevi @wamartin-aml Can you provide guidance here for usage of MLflow + R on AzureML?

santiagxf commented 1 year ago

Hi @lizelive. This error is likely produced because the plugin azureml-mlflow is not installed. Even when using R, this package is used under the hood to understand the azureml:/ protocol. Do you have the package in your default Python installation? How are you running/submitting the experiment?

mlflow-automation commented 1 year ago

@BenWilson2 @dbczumar @harupy @WeichenXu123 Please assign a maintainer and start triaging this issue.

dbczumar commented 1 year ago

@lizelive I'm going to go ahead and close this out, since @santiagxf has provided the solution. Feel free to reopen this issue if it's still occurring.

marQca commented 1 year ago

The solution provided does not correct this error. Even with azureml-mlflow installed, the R function new_mlflow_client() will return an error as there are no method for the mlflow_azureml class. The default method is used (see new_mlflow_client.default()) and simply returns the unsupported scheme error.

Could the issue be reopen so that a solution to this problem could be found?

BenWilson2 commented 1 year ago

@marQca What is your environment setup? Version of MLflow that you're trying to use?

pmags commented 9 months ago

Same here, mlflow 2.8.1

BenWilson2 commented 9 months ago

@pmags would you be open to updating the R function new_mlflow_client() to check for an Azure URI and utilize the correct loader in a PR?

pmags commented 9 months ago

@BenWilson2 sure let me look into it.

BenWilson2 commented 9 months ago

@pmags awesome! Tag me on the PR for review and if you have any questions at all.